-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: reduce dependency on $URL for less encode/decoding
BREAKING CHANGE: api updates and params renamed to query
- Loading branch information
Showing
11 changed files
with
276 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './utils' | ||
export * from './parse' | ||
export * from './ufo' | ||
export * from './encoding' | ||
export * from './parse' | ||
export * from './query' | ||
export * from './url' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { decode, encodeQueryKey, encodeQueryValue } from './encoding' | ||
|
||
export type QueryValue = string | string[] | undefined | ||
export type QueryObject = Record<string, QueryValue> | ||
|
||
export function parseQuery (paramsStr: string = ''): QueryObject { | ||
const obj: QueryObject = {} | ||
if (paramsStr[0] === '?') { | ||
paramsStr = paramsStr.substr(1) | ||
} | ||
for (const param of paramsStr.split('&')) { | ||
const s = param.split('=') | ||
if (!s[0]) { continue } | ||
const key = decode(s[0]) | ||
const value = decode(s[1]) | ||
if (obj[key]) { | ||
if (Array.isArray(obj[key])) { | ||
(obj[key] as string[]).push(value) | ||
} else { | ||
obj[key] = [obj[key] as string, value] | ||
} | ||
} else { | ||
obj[key] = value | ||
} | ||
} | ||
return obj | ||
} | ||
|
||
export function encodeQueryItem (key: string, val: QueryValue): string { | ||
if (!val) { | ||
return encodeQueryKey(key) | ||
} | ||
|
||
if (Array.isArray(val)) { | ||
return val.map(_val => `${encodeQueryKey(key)}=${encodeQueryValue(_val)}`).join('&') | ||
} | ||
|
||
return `${encodeQueryKey(key)}=${encodeQueryValue(val)}` | ||
} | ||
|
||
export function stringifyQuery (query: QueryObject) { | ||
return Object.keys(query).map(k => encodeQueryItem(k, query[k])).join('&') | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.