@kaelyx/ts-kit / object / fromQueryString
Function: fromQueryString()
fromQueryString(
input):FromQueryStringResult
Defined in: object/from-query-string/from-query-string.ts:29
fromQueryString, converts a query string to a flat object with URLSearchParams.
A key that occurs once gives a string. A key that occurs two or more times gives an array of strings, in order. Values are not converted, so "page=2" gives { page: '2' }. Keys are not split, so "a.b=1" gives { 'a.b': '1' }.
Keys such as __proto__ become normal own properties. They do not change the prototype of the result.
Parameters
input
string
The query string to parse. A leading ? is removed. An empty string returns {}.
Returns
A plain object with one property for each key.
Example
fromQueryString('q=red+shoes&page=2') // { q: 'red shoes', page: '2' }
fromQueryString('?tags=new&tags=sale') // { tags: ['new', 'sale'] }
fromQueryString('a=') // { a: '' }
fromQueryString('name=Ada%20Lovelace') // { name: 'Ada Lovelace' }
fromQueryString('a.b=1') // { 'a.b': '1' }
fromQueryString('') // {}Types
FromQueryStringResult type
FromQueryStringResult =
Record<string,string|string[]>
Defined in: object/from-query-string/from-query-string.types.ts:10
The result of fromQueryString. A key that occurs once gives a string. A key that occurs two or more times gives an array of strings.