2.0.2 • Published 2 years ago
@plugola/query-params v2.0.2
@plugola/query-params
Parses search query parameters
Examples
Strings
parseQueryParams('?foo=bar&mung=face')
// { foo: 'bar', mung: 'face' }
Booleans
parseQueryParams('foo&!bar')
// { foo: true, bar: false }
Arrays
parseQueryParams('foo[]=foo,bar')
// { foo: ['foo', 'bar'] }
Flags
parseQueryParams('foo{x}=mung,!face')
/* {
foo: { mung: true, false: false }
} */
JSON
parseQueryParams('foo{}={"bar": [1, 2]}')
/* {
foo: {
bar: [1, 2]
}
} */
Using all the options
parseQueryParams('ignore[]=foo,bar&ac.foo=bar', {
into: { version: 1 },
filter: (key) => key.startsWith('ac.'),
amendKey: (key) => key.substr(3),
})
// { foo: 'bar', version: 1 }