/**
* @module
* URL utility.
*/
export type Pattern = readonly [string, string,type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
RegExp | true] | '*' interface RegExp
export const splitPath = const splitPath: (path: string) => string[]
(path: string): string[] => { (parameter) path: string
const paths =const paths: string[]
path(parameter) path: string
.split('/') (method) String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)
Split a string into substrings using the specified separator and return them as an array.
@param separator — A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
@param limit — A value used to limit the number of elements returned in the array.
if (paths[0] === '') { const paths: string[]
pathsconst paths: string[]
.shift() (method) Array<string>.shift(): string | undefined
Removes the first element from an array and returns it.
If the array is empty, undefined is returned and the array is not modified.
}
return paths const paths: string[]
}
export const splitRoutingPath = const splitRoutingPath: (routePath: string) => string[]
(routePath: string): string[] => { (parameter) routePath: string
const { groups,const groups: [string, string][]
path } =const path: string
extractGroupsFromPathconst extractGroupsFromPath: (path: string) => {
groups: [string, string][];
path: string;
}
(routePath) (parameter) routePath: string
const paths =const paths: string[]
splitPathconst splitPath: (path: string) => string[]
(path) const path: string
return replaceGroupMarksconst replaceGroupMarks: (paths: string[], groups: [string, string][]) => string[]
(paths,const paths: string[]
groups) const groups: [string, string][]
}
const extractGroupsFromPath = const extractGroupsFromPath: (path: string) => {
groups: [string, string][];
path: string;
}
(path: string): {(parameter) path: string
groups: [string, string][];(property) groups: [string, string][]
path: string } => { (property) path: string
const groups: [string, string][] = [] const groups: [string, string][]
path =(parameter) path: string
path(parameter) path: string
.replace(/\{[^}]+\}/g, (method) String.replace(searchValue: {
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
}, replacer: (substring: string, ...args: any[]) => string): string (+3 overloads)
Replaces text in a string, using an object that supports replacement within a string.
@param searchValue — A object can search for and replace matches within a string.
@param replacer — A function that returns the replacement text.
(match,(parameter) match: string
index) => { (parameter) index: any
const mark = `@$const mark: string
{index}` (parameter) index: any
groupsconst groups: [string, string][]
.push((method) Array<[string, string]>.push(...items: [string, string][]): number
Appends new elements to the end of an array, and returns the new length of the array.
@param items — New elements to add to the array.
[mark,const mark: string
match]) (parameter) match: string
return mark const mark: string
})
return { groups,(property) groups: [string, string][]
path } (property) path: string
}
const replaceGroupMarks = const replaceGroupMarks: (paths: string[], groups: [string, string][]) => string[]
(paths: string[],(parameter) paths: string[]
groups: [string, string][]): string[] => { (parameter) groups: [string, string][]
for (let i =let i: number
groups(parameter) groups: [string, string][]
.length - 1;(property) Array<[string, string]>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
i >= 0;let i: number
i--) { let i: number
const [mark] =const mark: string
groups(parameter) groups: [string, string][]
[i] let i: number
for (let j =let j: number
paths(parameter) paths: string[]
.length - 1;(property) Array<string>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
j >= 0;let j: number
j--) { let j: number
if (paths(parameter) paths: string[]
[j]let j: number
.includes(method) String.includes(searchString: string, position?: number): boolean
Returns true if searchString appears as a substring of the result of converting this
object to a String, at one or more positions that are
greater than or equal to position; otherwise, returns false.
@param searchString — search string
@param position — If position is undefined, 0 is assumed, so as to search all of the String.
(mark)) { const mark: string
paths(parameter) paths: string[]
[j] =let j: number
paths(parameter) paths: string[]
[j]let j: number
.replace(method) String.replace(searchValue: string | RegExp, replaceValue: string): string (+3 overloads)
Replaces text in a string, using a regular expression or search string.
@param searchValue — A string or regular expression to search for.
@param replaceValue — A string containing the text to replace. When the searchValue is a RegExp, all matches are replaced if the g flag is set (or only those matches at the beginning, if the y flag is also present). Otherwise, only the first match of searchValue is replaced.
(mark,const mark: string
groups(parameter) groups: [string, string][]
[i][1]) let i: number
break
}
}
}
return paths (parameter) paths: string[]
}
const patternCache: { const patternCache: {
[key: string]: Pattern;
}
[key: string]:(parameter) key: string
Pattern } = {} type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
export const getPattern = const getPattern: (label: string) => Pattern | null
(label: string):(parameter) label: string
Pattern | null => { type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
// * => wildcard
// :id{[0-9]+} => ([0-9]+)
// :id => (.+)
//const name = ''
if (label === '*') { (parameter) label: string
return '*'
}
const match =const match: RegExpMatchArray | null
label(parameter) label: string
.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/) (method) String.match(matcher: {
[Symbol.match](string: string): RegExpMatchArray | null;
}): RegExpMatchArray | null (+1 overload)
Matches a string or an object that supports being matched against, and returns an array
containing the results of that search, or null if no matches are found.
@param matcher — An object that supports being matched against.
if (match) { const match: RegExpMatchArray | null
if (!patternCacheconst patternCache: {
[key: string]: Pattern;
}
[label]) { (parameter) label: string
if (match[2]) { const match: RegExpMatchArray
patternCacheconst patternCache: {
[key: string]: Pattern;
}
[label] = (parameter) label: string
[label,(parameter) label: string
match[1], newconst match: RegExpMatchArray
RegExp('^' +var RegExp: RegExpConstructor
new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
match[2] + '$')] const match: RegExpMatchArray
} else {
patternCacheconst patternCache: {
[key: string]: Pattern;
}
[label] = (parameter) label: string
[label,(parameter) label: string
match[1], true] const match: RegExpMatchArray
}
}
return patternCacheconst patternCache: {
[key: string]: Pattern;
}
[label] (parameter) label: string
}
return null
}
/**
* Try to apply decodeURI() to given string.
* If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
* @param str The string to decode.
* @returns The decoded string that sometimes contains undecodable percent encoding.
* @example
* tryDecodeURI('Hello%20World') // 'Hello World'
* tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
*/
const tryDecodeURI = const tryDecodeURI: (str: string) => string
Try to apply decodeURI() to given string.
If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
@param str — The string to decode.
@returns — The decoded string that sometimes contains undecodable percent encoding.
@example
tryDecodeURI('Hello%20World') // 'Hello World'
tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
(str: string): string => { (parameter) str: string
The string to decode.
@param str — The string to decode.
try {
return decodeURIfunction decodeURI(encodedURI: string): string
Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
@param encodedURI — A value representing an encoded URI.
(str) (parameter) str: string
The string to decode.
@param str — The string to decode.
} catch {
return str(parameter) str: string
The string to decode.
@param str — The string to decode.
.replace(/(?:%[0-9A-Fa-f]{2})+/g, (method) String.replace(searchValue: {
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
}, replacer: (substring: string, ...args: any[]) => string): string (+3 overloads)
Replaces text in a string, using an object that supports replacement within a string.
@param searchValue — A object can search for and replace matches within a string.
@param replacer — A function that returns the replacement text.
(match) => { (parameter) match: string
try {
return decodeURIfunction decodeURI(encodedURI: string): string
Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
@param encodedURI — A value representing an encoded URI.
(match) (parameter) match: string
} catch {
return match (parameter) match: string
}
})
}
}
export const getPath = const getPath: (request: Request) => string
(request:(parameter) request: Request
Request): string => { interface Request
This Fetch API interface represents a resource request.
const url =const url: string
request(parameter) request: Request
.url (property) Request.url: string
Returns the URL of request as a string.
const start =const start: number
urlconst url: string
.indexOf('/', 8) (method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
let i =let i: number
start const start: number
for (; i <let i: number
urlconst url: string
.length;(property) String.length: number
Returns the length of a String object.
i++) { let i: number
const charCode =const charCode: number
urlconst url: string
.charCodeAt(method) String.charCodeAt(index: number): number
Returns the Unicode value of the character at the specified location.
@param index — The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
(i) let i: number
if (charCode === 37) { const charCode: number
// '%'
// If the path contains percent encoding, use `indexOf()` to find '?' and return the result immediately.
// Although this is a performance disadvantage, it is acceptable since we prefer cases that do not include percent encoding.
const queryIndex =const queryIndex: number
urlconst url: string
.indexOf('?',(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
i) let i: number
const path =const path: string
urlconst url: string
.slice(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
(start,const start: number
queryIndex === -1 ? undefined :const queryIndex: number
queryIndex) const queryIndex: number
return tryDecodeURIconst tryDecodeURI: (str: string) => string
Try to apply decodeURI() to given string.
If it fails, skip invalid percent encoding or invalid UTF-8 sequences, and apply decodeURI() to the rest as much as possible.
@param str — The string to decode.
@returns — The decoded string that sometimes contains undecodable percent encoding.
@example
tryDecodeURI('Hello%20World') // 'Hello World'
tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
(pathconst path: string
.includes('%25') ?(method) String.includes(searchString: string, position?: number): boolean
Returns true if searchString appears as a substring of the result of converting this
object to a String, at one or more positions that are
greater than or equal to position; otherwise, returns false.
@param searchString — search string
@param position — If position is undefined, 0 is assumed, so as to search all of the String.
pathconst path: string
.replace(/%25/g, '%2525') :(method) String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and replaceValue to the [Symbol.replace] method on searchValue. This method is expected to implement its own replacement algorithm.
@param searchValue — An object that supports searching for and replacing matches within a string.
@param replaceValue — The replacement text.
path) const path: string
} else if (charCode === 63) { const charCode: number
// '?'
break
}
}
return urlconst url: string
.slice(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
(start,const start: number
i) let i: number
}
export const getQueryStrings = const getQueryStrings: (url: string) => string
(url: string): string => { (parameter) url: string
const queryIndex =const queryIndex: number
url(parameter) url: string
.indexOf('?', 8) (method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
return queryIndex === -1 ? '' : '?' +const queryIndex: number
url(parameter) url: string
.slice(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
(queryIndex + 1) const queryIndex: number
}
export const getPathNoStrict = const getPathNoStrict: (request: Request) => string
(request:(parameter) request: Request
Request): string => { interface Request
This Fetch API interface represents a resource request.
const result =const result: string
getPathconst getPath: (request: Request) => string
(request) (parameter) request: Request
// if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same
return resultconst result: string
.length > 1 &&(property) String.length: number
Returns the length of a String object.
resultconst result: string
[resultconst result: string
.length - 1] === '/' ?(property) String.length: number
Returns the length of a String object.
resultconst result: string
.slice(0, -1) :(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
result const result: string
}
export const mergePath = (..const mergePath: (...paths: string[]) => string
.paths: string[]): string => { (parameter) paths: string[]
let p: string = '' let p: string
let endsWithSlash = false let endsWithSlash: boolean
for (let path oflet path: string
paths) { (parameter) paths: string[]
/* ['/hey/','/say'] => ['/hey', '/say'] */
if (plet p: string
[plet p: string
.length - 1] === '/') { (property) String.length: number
Returns the length of a String object.
p =let p: string
plet p: string
.slice(0, -1) (method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
endsWithSlash = true let endsWithSlash: boolean
}
/* ['/hey','say'] => ['/hey', '/say'] */
if (path[0] !== '/') { let path: string
path = `/$let path: string
{path}` let path: string
}
/* ['/hey/', '/'] => `/hey/` */
if (path === '/' &&let path: string
endsWithSlash) { let endsWithSlash: boolean
p = `$let p: string
{p}/` let p: string
} else if (path !== '/') { let path: string
p = `$let p: string
{p}$let p: string
{path}` let path: string
}
/* ['/', '/'] => `/` */
if (path === '/' &&let path: string
p === '') { let p: string
p = '/' let p: string
}
}
return p let p: string
}
export const checkOptionalParameter = const checkOptionalParameter: (path: string) => string[] | null
(path: string): string[] | null => { (parameter) path: string
/*
If path is `/api/animals/:type?` it will return:
[`/api/animals`, `/api/animals/:type`]
in other cases it will return null
*/
if (!path(parameter) path: string
.match(/\:.+\?$/)) { (method) String.match(matcher: {
[Symbol.match](string: string): RegExpMatchArray | null;
}): RegExpMatchArray | null (+1 overload)
Matches a string or an object that supports being matched against, and returns an array
containing the results of that search, or null if no matches are found.
@param matcher — An object that supports being matched against.
return null
}
const segments =const segments: string[]
path(parameter) path: string
.split('/') (method) String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)
Split a string into substrings using the specified separator and return them as an array.
@param separator — A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
@param limit — A value used to limit the number of elements returned in the array.
const results: string[] = [] const results: string[]
let basePath = '' let basePath: string
segmentsconst segments: string[]
.forEach((method) Array<string>.forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.
@param callbackfn — A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
@param thisArg — An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
(segment) => { (parameter) segment: string
if (segment !== '' && !/\:/(parameter) segment: string
.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(segment)) { (parameter) segment: string
basePath += '/' +let basePath: string
segment (parameter) segment: string
} else if (/\:/.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(segment)) { (parameter) segment: string
if (/\?/.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(segment)) { (parameter) segment: string
if (resultsconst results: string[]
.length === 0 &&(property) Array<string>.length: number
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
basePath === '') { let basePath: string
resultsconst results: string[]
.push('/') (method) Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
@param items — New elements to add to the array.
} else {
resultsconst results: string[]
.push(method) Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
@param items — New elements to add to the array.
(basePath) let basePath: string
}
const optionalSegment =const optionalSegment: string
segment(parameter) segment: string
.replace('?', '') (method) String.replace(searchValue: string | RegExp, replaceValue: string): string (+3 overloads)
Replaces text in a string, using a regular expression or search string.
@param searchValue — A string or regular expression to search for.
@param replaceValue — A string containing the text to replace. When the searchValue is a RegExp, all matches are replaced if the g flag is set (or only those matches at the beginning, if the y flag is also present). Otherwise, only the first match of searchValue is replaced.
basePath += '/' +let basePath: string
optionalSegment const optionalSegment: string
resultsconst results: string[]
.push(method) Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
@param items — New elements to add to the array.
(basePath) let basePath: string
} else {
basePath += '/' +let basePath: string
segment (parameter) segment: string
}
}
})
return resultsconst results: string[]
.filter((method) Array<string>.filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.
@param predicate — A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
@param thisArg — An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
(v,(parameter) v: string
i,(parameter) i: number
a) =>(parameter) a: string[]
a(parameter) a: string[]
.indexOf(method) Array<string>.indexOf(searchElement: string, fromIndex?: number): number
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
@param searchElement — The value to locate in the array.
@param fromIndex — The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
(v) ===(parameter) v: string
i) (parameter) i: number
}
// Optimized
const _decodeURI = const _decodeURI: (value: string) => string
(value: string) => { (parameter) value: string
if (!/[%+]/.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(value)) { (parameter) value: string
return value (parameter) value: string
}
if (value(parameter) value: string
.indexOf('+') !== -1) { (method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
value =(parameter) value: string
value(parameter) value: string
.replace(/\+/g, ' ') (method) String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and replaceValue to the [Symbol.replace] method on searchValue. This method is expected to implement its own replacement algorithm.
@param searchValue — An object that supports searching for and replacing matches within a string.
@param replaceValue — The replacement text.
}
return /%/.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(value) ?(parameter) value: string
decodeURIComponent_const decodeURIComponent_: (encodedURIComponent: string) => string
Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
@param encodedURIComponent — A value representing an encoded URI component.
(value) :(parameter) value: string
value (parameter) value: string
}
const _getQueryParam = ( const _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
url: string, (parameter) url: string
key?: string, (parameter) key: string | undefined
multiple?: boolean (parameter) multiple: boolean | undefined
): string | undefined | Record | string[] |type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record => { type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
let encoded let encoded: any
if (!multiple &&(parameter) multiple: boolean | undefined
key && !/[%+]/(parameter) key: string | undefined
.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(key)) { (parameter) key: string
// optimized for unencoded key
let keyIndex =let keyIndex: number
url(parameter) url: string
.indexOf(`?$(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
{key}`, 8) (parameter) key: string
if (keyIndex === -1) { let keyIndex: number
keyIndex =let keyIndex: number
url(parameter) url: string
.indexOf(`&$(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
{key}`, 8) (parameter) key: string
}
while (keyIndex !== -1) { let keyIndex: number
const trailingKeyCode =const trailingKeyCode: number
url(parameter) url: string
.charCodeAt(method) String.charCodeAt(index: number): number
Returns the Unicode value of the character at the specified location.
@param index — The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
(keyIndex +let keyIndex: number
key(parameter) key: string
.length + 1) (property) String.length: number
Returns the length of a String object.
if (trailingKeyCode === 61) { const trailingKeyCode: number
const valueIndex =const valueIndex: number
keyIndex +let keyIndex: number
key(parameter) key: string
.length + 2 (property) String.length: number
Returns the length of a String object.
const endIndex =const endIndex: number
url(parameter) url: string
.indexOf('&',(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
valueIndex) const valueIndex: number
return _decodeURIconst _decodeURI: (value: string) => string
(url(parameter) url: string
.slice(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
(valueIndex,const valueIndex: number
endIndex === -1 ? undefined :const endIndex: number
endIndex)) const endIndex: number
} else if (trailingKeyCode == 38 ||const trailingKeyCode: number
isNaNfunction isNaN(number: number): boolean
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).
@param number — A numeric value.
(trailingKeyCode)) { const trailingKeyCode: number
return ''
}
keyIndex =let keyIndex: number
url(parameter) url: string
.indexOf(`&$(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
{key}`,(parameter) key: string
keyIndex + 1) let keyIndex: number
}
encoded = /[%+]/let encoded: any
.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(url) (parameter) url: string
if (!encoded) { let encoded: boolean
return undefined
}
// fallback to default routine
}
const results:const results: Record<string, string> | Record<string, string[]>
Record |type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
Record = {} type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
encoded ??= /[%+]/let encoded: any
.test(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.
@param string — String on which to perform the search.
(url) (parameter) url: string
let keyIndex =let keyIndex: number
url(parameter) url: string
.indexOf('?', 8) (method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
while (keyIndex !== -1) { let keyIndex: number
const nextKeyIndex =const nextKeyIndex: number
url(parameter) url: string
.indexOf('&',(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
keyIndex + 1) let keyIndex: number
let valueIndex =let valueIndex: number
url(parameter) url: string
.indexOf('=',(method) String.indexOf(searchString: string, position?: number): number
Returns the position of the first occurrence of a substring.
@param searchString — The substring to search for in the string
@param position — The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.
keyIndex) let keyIndex: number
if (valueIndex >let valueIndex: number
nextKeyIndex &&const nextKeyIndex: number
nextKeyIndex !== -1) { const nextKeyIndex: number
valueIndex = -1 let valueIndex: number
}
let name =let name: string
url(parameter) url: string
.slice( (method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
keyIndex + 1, let keyIndex: number
valueIndex === -1 ? let valueIndex: number
(nextKeyIndex === -1 ? undefined :const nextKeyIndex: number
nextKeyIndex) :const nextKeyIndex: number
valueIndex let valueIndex: number
)
if (encoded) { let encoded: boolean
name =let name: string
_decodeURIconst _decodeURI: (value: string) => string
(name) let name: string
}
keyIndex =let keyIndex: number
nextKeyIndex const nextKeyIndex: number
if (name === '') { let name: string
continue
}
let value let value: any
if (valueIndex === -1) { let valueIndex: number
value = '' let value: any
} else {
value =let value: any
url(parameter) url: string
.slice(method) String.slice(start?: number, end?: number): string
Returns a section of a string.
@param start — The index to the beginning of the specified portion of stringObj.
@param end
The index to the end of the specified portion of stringObj. The substring includes the characters up to, but not including, the character indicated by end.
If this value is not specified, the substring continues to the end of stringObj.
(valueIndex + 1,let valueIndex: number
nextKeyIndex === -1 ? undefined :const nextKeyIndex: number
nextKeyIndex) const nextKeyIndex: number
if (encoded) { let encoded: boolean
value =let value: any
_decodeURIconst _decodeURI: (value: string) => string
(value) let value: string
}
}
if (multiple) { (parameter) multiple: boolean | undefined
if (!(resultsconst results: Record<string, string> | Record<string, string[]>
[name] &&let name: string
Arrayvar Array: ArrayConstructor
.isArray(method) ArrayConstructor.isArray(arg: any): arg is any[]
(resultsconst results: Record<string, string> | Record<string, string[]>
[name]))) { let name: string
resultsconst results: Record<string, string> | Record<string, string[]>
[name] = [] let name: string
}
;(resultsconst results: Record<string, string> | Record<string, string[]>
[name] as string[])let name: string
.push(method) Array<string>.push(...items: string[]): number
Appends new elements to the end of an array, and returns the new length of the array.
@param items — New elements to add to the array.
(value) let value: string
} else {
resultsconst results: Record<string, string> | Record<string, string[]>
[name] ??=let name: string
value let value: string
}
}
return key ?(parameter) key: string | undefined
resultsconst results: Record<string, string> | Record<string, string[]>
[key] :(parameter) key: string
results const results: Record<string, string> | Record<string, string[]>
}
export const getQueryParam: ( const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>
url: string, (parameter) url: string
key?: string (parameter) key: string | undefined
) => string | undefined | Record =type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
_getQueryParam as ( const _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
url: string, (parameter) url: string
key?: string (parameter) key: string | undefined
) => string | undefined | Record type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
export const getQueryParams = ( const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>
url: string, (parameter) url: string
key?: string (parameter) key: string | undefined
): string[] | undefined | Record => { type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
return _getQueryParamconst _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
(url,(parameter) url: string
key, true) as string[] | undefined |(parameter) key: string | undefined
Record type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T
}
// `decodeURIComponent` is a long name.
// By making it a function, we can use it commonly when minified, reducing the amount of code.
export const decodeURIComponent_ =const decodeURIComponent_: (encodedURIComponent: string) => string
decodeURIComponent function decodeURIComponent(encodedURIComponent: string): string
Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
@param encodedURIComponent — A value representing an encoded URI component.