/** * @module * URL utility. */ export type Pattern = readonly [string, string,
type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
RegExp | true] | '*'export const splitPath =
interface RegExp
(path: string): string[] => {
const splitPath: (path: string) => string[]
const paths =
(parameter) path: string
path
const paths: string[]
.split('/')
(parameter) path: string
(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
if (paths[0] === '') {limit
— A value used to limit the number of elements returned in the array.paths
const paths: string[]
.shift()
const paths: string[]
} return paths
(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.} export const splitRoutingPath =
const paths: string[]
(routePath: string): string[] => {
const splitRoutingPath: (routePath: string) => string[]
const { groups,
(parameter) routePath: string
path } =
const groups: [string, string][]
extractGroupsFromPath
const path: string
(routePath)
const extractGroupsFromPath: (path: string) => { groups: [string, string][]; path: string; }
const paths =
(parameter) routePath: string
splitPath
const paths: string[]
(path)
const splitPath: (path: string) => string[]
return replaceGroupMarks
const path: string
(paths,
const replaceGroupMarks: (paths: string[], groups: [string, string][]) => string[]
groups)
const paths: string[]
} const extractGroupsFromPath =
const groups: [string, string][]
(path: string): {
const extractGroupsFromPath: (path: string) => { groups: [string, string][]; path: string; }
groups: [string, string][];
(parameter) path: string
path: string } => {
(property) groups: [string, string][]
const groups: [string, string][] = []
(property) path: string
path =
const groups: [string, string][]
path
(parameter) path: string
.replace(/\{[^}]+\}/g,
(parameter) path: string
(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
(match,replacer
— A function that returns the replacement text.index) => {
(parameter) match: string
const mark = `@$
(parameter) index: any
{index}`
const mark: string
groups
(parameter) index: any
.push(
const groups: [string, string][]
(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
[mark,items
— New elements to add to the array.match])
const mark: string
return mark
(parameter) match: string
}) return { groups,
const mark: string
path }
(property) groups: [string, string][]
} const replaceGroupMarks =
(property) path: string
(paths: string[],
const replaceGroupMarks: (paths: string[], groups: [string, string][]) => string[]
groups: [string, string][]): string[] => {
(parameter) paths: string[]
for (let i =
(parameter) groups: [string, string][]
groups
let i: number
.length - 1;
(parameter) groups: [string, string][]
i >= 0;
(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--) {
let i: number
const [mark] =
let i: number
groups
const mark: string
[i]
(parameter) groups: [string, string][]
for (let j =
let i: number
paths
let j: number
.length - 1;
(parameter) paths: string[]
j >= 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.j--) {
let j: number
if (paths
let j: number
[j]
(parameter) paths: string[]
.includes
let j: number
(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
(mark)) {position
— If position is undefined, 0 is assumed, so as to search all of the String.paths
const mark: string
[j] =
(parameter) paths: string[]
paths
let j: number
[j]
(parameter) paths: string[]
.replace
let j: number
(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
(mark,replaceValue
— A string containing the text to replace. When thesearchValue
is aRegExp
, all matches are replaced if theg
flag is set (or only those matches at the beginning, if they
flag is also present). Otherwise, only the first match ofsearchValue
is replaced.groups
const mark: string
[i][1])
(parameter) groups: [string, string][]
break } } } return paths
let i: number
} const patternCache: {
(parameter) paths: string[]
[key: string]:
const patternCache: { [key: string]: Pattern; }
Pattern } = {}
(parameter) key: string
type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
export const getPattern =(label: string):
const getPattern: (label: string) => Pattern | null
Pattern | null => {
(parameter) label: string
type Pattern = readonly [string, string, true | RegExp] | "*"
@module — URL utility.
// * => wildcard // :id{[0-9]+} => ([0-9]+) // :id => (.+) //const name = '' if (label === '*') {return '*' } const match =
(parameter) label: string
label
const match: RegExpMatchArray | null
.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/)
(parameter) label: string
(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
if (match) {matcher
— An object that supports being matched against.if (!patternCache
const match: RegExpMatchArray | null
[label]) {
const patternCache: { [key: string]: Pattern; }
if (match[2]) {
(parameter) label: string
patternCache
const match: RegExpMatchArray
[label] =
const patternCache: { [key: string]: Pattern; }
[label,
(parameter) label: string
match[1], new
(parameter) label: string
RegExp('^' +
const match: RegExpMatchArray
match[2] + '$')]
var RegExp: RegExpConstructor new (pattern: RegExp | string, flags?: string) => RegExp (+2 overloads)
} else { patternCache
const match: RegExpMatchArray
[label] =
const patternCache: { [key: string]: Pattern; }
[label,
(parameter) label: string
match[1], true]
(parameter) label: string
} } return patternCache
const match: RegExpMatchArray
[label]
const patternCache: { [key: string]: Pattern; }
} 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 =
(parameter) label: string
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
(str: string): string => {
tryDecodeURI('Hello%20World') // 'Hello World' tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
(parameter) str: string
The string to decode.@param
try { return decodeURIstr
— The string to decode.
function decodeURI(encodedURI: string): string
Gets the unencoded version of an encoded Uniform Resource Identifier (URI).@param
(str)encodedURI
— A value representing an encoded URI.
(parameter) str: string
The string to decode.@param
} catch { return strstr
— The string to decode.
(parameter) str: string
The string to decode.@param
.replace(/(?:%[0-9A-Fa-f]{2})+/g,str
— The string to decode.
(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
(match) => {replacer
— A function that returns the replacement text.try { return decodeURI
(parameter) match: string
function decodeURI(encodedURI: string): string
Gets the unencoded version of an encoded Uniform Resource Identifier (URI).@param
(match)encodedURI
— A value representing an encoded URI.} catch { return match
(parameter) match: string
} }) } } export const getPath =
(parameter) match: string
(request:
const getPath: (request: Request) => string
Request): string => {
(parameter) request: Request
const url =
interface Request
This Fetch API interface represents a resource request.request
const url: string
.url
(parameter) request: Request
const start =
(property) Request.url: string
Returns the URL of request as a string.url
const start: number
.indexOf('/', 8)
const url: string
(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
let i =position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.start
let i: number
for (; i <
const start: number
url
let i: number
.length;
const url: string
i++) {
(property) String.length: number
Returns the length of a String object.const charCode =
let i: number
url
const charCode: number
.charCodeAt
const url: string
(method) String.charCodeAt(index: number): number
Returns the Unicode value of the character at the specified location.@param
(i)index
— The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.if (charCode === 37) {
let i: 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 charCode: number
url
const queryIndex: number
.indexOf('?',
const url: string
(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
i)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.const path =
let i: number
url
const path: string
.slice
const url: string
(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
(start,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 ? undefined :
const start: number
queryIndex)
const queryIndex: number
return tryDecodeURI
const queryIndex: number
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
(path
tryDecodeURI('Hello%20World') // 'Hello World' tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
.includes('%25') ?
const path: string
(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
pathposition
— If position is undefined, 0 is assumed, so as to search all of the String..replace(/%25/g, '%2525') :
const path: string
(method) String.replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string (+3 overloads)
Passes a string andreplaceValue
to the[Symbol.replace]
method onsearchValue
. 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
path)replaceValue
— The replacement text.} else if (charCode === 63) {
const path: string
// '?' break } } return url
const charCode: number
.slice
const url: string
(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
(start,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.i)
const start: number
} export const getQueryStrings =
let i: number
(url: string): string => {
const getQueryStrings: (url: string) => string
const queryIndex =
(parameter) url: string
url
const queryIndex: number
.indexOf('?', 8)
(parameter) url: string
(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
return queryIndex === -1 ? '' : '?' +position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.url
const queryIndex: number
.slice
(parameter) url: string
(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
(queryIndex + 1)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.} export const getPathNoStrict =
const queryIndex: number
(request:
const getPathNoStrict: (request: Request) => string
Request): string => {
(parameter) request: Request
const result =
interface Request
This Fetch API interface represents a resource request.getPath
const result: string
(request)
const getPath: (request: Request) => string
// if strict routing is false => `/hello/hey/` and `/hello/hey` are treated the same return result
(parameter) request: Request
.length > 1 &&
const result: string
result
(property) String.length: number
Returns the length of a String object.[result
const result: string
.length - 1] === '/' ?
const result: string
result
(property) String.length: number
Returns the length of a String object..slice(0, -1) :
const result: string
(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
resultend
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.} export const mergePath = (..
const result: string
.paths: string[]): string => {
const mergePath: (...paths: string[]) => string
let p: string = ''
(parameter) paths: string[]
let endsWithSlash = false
let p: string
for (let path of
let endsWithSlash: boolean
paths) {
let path: string
/* ['/hey/','/say'] => ['/hey', '/say'] */ if (p
(parameter) paths: string[]
[p
let p: string
.length - 1] === '/') {
let p: string
p =
(property) String.length: number
Returns the length of a String object.p
let p: string
.slice(0, -1)
let p: string
(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
endsWithSlash = trueend
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.} /* ['/hey','say'] => ['/hey', '/say'] */ if (path[0] !== '/') {
let endsWithSlash: boolean
path = `/$
let path: string
{path}`
let path: string
} /* ['/hey/', '/'] => `/hey/` */ if (path === '/' &&
let path: string
endsWithSlash) {
let path: string
p = `$
let endsWithSlash: boolean
{p}/`
let p: string
} else if (path !== '/') {
let p: string
p = `$
let path: string
{p}$
let p: string
{path}`
let p: string
} /* ['/', '/'] => `/` */ if (path === '/' &&
let path: string
p === '') {
let path: string
p = '/'
let p: string
} } return p
let p: string
} export const checkOptionalParameter =
let p: string
(path: string): string[] | null => {
const checkOptionalParameter: (path: string) => string[] | null
/* 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(/\:.+\?$/)) {
(parameter) path: string
(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
return null } const segments =matcher
— An object that supports being matched against.path
const segments: string[]
.split('/')
(parameter) path: string
(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
const results: string[] = []limit
— A value used to limit the number of elements returned in the array.let basePath = ''
const results: string[]
segments
let basePath: string
.forEach(
const segments: string[]
(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
(segment) => {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.if (segment !== '' && !/\:/
(parameter) segment: string
.test
(parameter) segment: string
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(segment)) {string
— String on which to perform the search.basePath += '/' +
(parameter) segment: string
segment
let basePath: string
} else if (/\:/.test
(parameter) segment: string
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(segment)) {string
— String on which to perform the search.if (/\?/.test
(parameter) segment: string
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(segment)) {string
— String on which to perform the search.if (results
(parameter) segment: string
.length === 0 &&
const results: string[]
basePath === '') {
(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.results
let basePath: string
.push('/')
const results: string[]
(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
} else { resultsitems
— New elements to add to the array..push
const results: string[]
(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
(basePath)items
— New elements to add to the array.} const optionalSegment =
let basePath: string
segment
const optionalSegment: string
.replace('?', '')
(parameter) segment: string
(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
basePath += '/' +replaceValue
— A string containing the text to replace. When thesearchValue
is aRegExp
, all matches are replaced if theg
flag is set (or only those matches at the beginning, if they
flag is also present). Otherwise, only the first match ofsearchValue
is replaced.optionalSegment
let basePath: string
results
const optionalSegment: string
.push
const results: string[]
(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
(basePath)items
— New elements to add to the array.} else { basePath += '/' +
let basePath: string
segment
let basePath: string
} } }) return results
(parameter) segment: string
.filter(
const results: string[]
(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
(v,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.i,
(parameter) v: string
a) =>
(parameter) i: number
a
(parameter) a: string[]
.indexOf
(parameter) a: string[]
(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
(v) ===fromIndex
— The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.i)
(parameter) v: string
} // Optimized const _decodeURI =
(parameter) i: number
(value: string) => {
const _decodeURI: (value: string) => string
if (!/[%+]/.test
(parameter) value: string
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(value)) {string
— String on which to perform the search.return value
(parameter) value: string
} if (value
(parameter) value: string
.indexOf('+') !== -1) {
(parameter) value: string
(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
value =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
.replace(/\+/g, ' ')
(parameter) value: string
(method) String.replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string (+3 overloads)
Passes a string andreplaceValue
to the[Symbol.replace]
method onsearchValue
. 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
} return /%/.testreplaceValue
— The replacement text.
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(value) ?string
— String on which to perform the search.decodeURIComponent_
(parameter) value: string
const decodeURIComponent_: (encodedURIComponent: string) => string
Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).@param
(value) :encodedURIComponent
— A value representing an encoded URI component.value
(parameter) value: string
} const _getQueryParam = (
(parameter) value: string
url: string,
const _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
key?: string,
(parameter) url: string
multiple?: boolean
(parameter) key: string | undefined
): string | undefined | Record
(parameter) multiple: boolean | undefined
| 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=> { let encoded
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type Tif (!multiple &&
let encoded: any
key && !/[%+]/
(parameter) multiple: boolean | undefined
.test
(parameter) key: string | undefined
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(key)) {string
— String on which to perform the search.// optimized for unencoded key let keyIndex =
(parameter) key: string
url
let keyIndex: number
.indexOf(`?$
(parameter) url: string
(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
{key}`, 8)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.if (keyIndex === -1) {
(parameter) key: string
keyIndex =
let keyIndex: number
url
let keyIndex: number
.indexOf(`&$
(parameter) url: string
(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
{key}`, 8)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.} while (keyIndex !== -1) {
(parameter) key: string
const trailingKeyCode =
let keyIndex: number
url
const trailingKeyCode: number
.charCodeAt
(parameter) url: string
(method) String.charCodeAt(index: number): number
Returns the Unicode value of the character at the specified location.@param
(keyIndex +index
— The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.key
let keyIndex: number
.length + 1)
(parameter) key: string
if (trailingKeyCode === 61) {
(property) String.length: number
Returns the length of a String object.const valueIndex =
const trailingKeyCode: number
keyIndex +
const valueIndex: number
key
let keyIndex: number
.length + 2
(parameter) key: string
const endIndex =
(property) String.length: number
Returns the length of a String object.url
const endIndex: number
.indexOf('&',
(parameter) url: string
(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
valueIndex)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.return _decodeURI
const valueIndex: number
(url
const _decodeURI: (value: string) => string
.slice
(parameter) url: string
(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
(valueIndex,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.endIndex === -1 ? undefined :
const valueIndex: number
endIndex))
const endIndex: number
} else if (trailingKeyCode == 38 ||
const endIndex: number
isNaN
const trailingKeyCode: number
function isNaN(number: number): boolean
Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number).@param
(trailingKeyCode)) {number
— A numeric value.return '' } keyIndex =
const trailingKeyCode: number
url
let keyIndex: number
.indexOf(`&$
(parameter) url: string
(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
{key}`,position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.keyIndex + 1)
(parameter) key: string
} encoded = /[%+]/
let keyIndex: number
.test
let encoded: any
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(url)string
— String on which to perform the search.if (!encoded) {
(parameter) url: string
return undefined } // fallback to default routine } const results:
let encoded: boolean
Record
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= {} encoded ??= /[%+]/
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T.test
let encoded: any
(method) RegExp.test(string: string): boolean
Returns a Boolean value that indicates whether or not a pattern exists in a searched string.@param
(url)string
— String on which to perform the search.let keyIndex =
(parameter) url: string
url
let keyIndex: number
.indexOf('?', 8)
(parameter) url: string
(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
while (keyIndex !== -1) {position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.const nextKeyIndex =
let keyIndex: number
url
const nextKeyIndex: number
.indexOf('&',
(parameter) url: string
(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
keyIndex + 1)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.let valueIndex =
let keyIndex: number
url
let valueIndex: number
.indexOf('=',
(parameter) url: string
(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
keyIndex)position
— The index at which to begin searching the String object. If omitted, search starts at the beginning of the string.if (valueIndex >
let keyIndex: number
nextKeyIndex &&
let valueIndex: number
nextKeyIndex !== -1) {
const nextKeyIndex: number
valueIndex = -1
const nextKeyIndex: number
} let name =
let valueIndex: number
url
let name: string
.slice(
(parameter) url: string
(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
keyIndex + 1,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 keyIndex: number
(nextKeyIndex === -1 ? undefined :
let valueIndex: number
nextKeyIndex) :
const nextKeyIndex: number
valueIndex
const nextKeyIndex: number
) if (encoded) {
let valueIndex: number
name =
let encoded: boolean
_decodeURI
let name: string
(name)
const _decodeURI: (value: string) => string
} keyIndex =
let name: string
nextKeyIndex
let keyIndex: number
if (name === '') {
const nextKeyIndex: number
continue } let value
let name: string
if (valueIndex === -1) {
let value: any
value = ''
let valueIndex: number
} else { value =
let value: any
url
let value: any
.slice
(parameter) url: string
(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
(valueIndex + 1,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.nextKeyIndex === -1 ? undefined :
let valueIndex: number
nextKeyIndex)
const nextKeyIndex: number
if (encoded) {
const nextKeyIndex: number
value =
let encoded: boolean
_decodeURI
let value: any
(value)
const _decodeURI: (value: string) => string
} } if (multiple) {
let value: string
if (!(results
(parameter) multiple: boolean | undefined
[name] &&
const results: Record<string, string> | Record<string, string[]>
Array
let name: string
.isArray
var Array: ArrayConstructor
(results
(method) ArrayConstructor.isArray(arg: any): arg is any[]
[name]))) {
const results: Record<string, string> | Record<string, string[]>
results
let name: string
[name] = []
const results: Record<string, string> | Record<string, string[]>
} ;(results
let name: string
[name] as string[])
const results: Record<string, string> | Record<string, string[]>
.push
let name: string
(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
(value)items
— New elements to add to the array.} else { results
let value: string
[name] ??=
const results: Record<string, string> | Record<string, string[]>
value
let name: string
} } return key ?
let value: string
results
(parameter) key: string | undefined
[key] :
const results: Record<string, string> | Record<string, string[]>
results
(parameter) key: string
} export const getQueryParam: (
const results: Record<string, string> | Record<string, string[]>
url: string,
const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>
key?: string
(parameter) url: string
) => string | undefined | Record
(parameter) key: string | undefined
= _getQueryParam as (
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type Turl: string,
const _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
key?: string
(parameter) url: string
) => string | undefined | Record
(parameter) key: string | undefined
export const getQueryParams = (
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type Turl: string,
const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>
key?: string
(parameter) url: string
): string[] | undefined | Record
(parameter) key: string | undefined
=> { return _getQueryParam
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type T(url,
const _getQueryParam: (url: string, key?: string, multiple?: boolean) => string | undefined | Record<string, string> | string[] | Record<string, string[]>
key, true) as string[] | undefined |
(parameter) url: string
Record
(parameter) key: string | undefined
} // `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_ =
type Record<K extends keyof any, T> = { [P in K]: T; }
Construct a type with a set of properties K of type TdecodeURIComponent
const decodeURIComponent_: (encodedURIComponent: string) => string
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.