@feugene/mu
Version:
Helpful TS utilities without dependencies
28 lines • 1.4 kB
TypeScript
type FromQueryStringOptions = {
decodeName: boolean;
};
/**
* Converts a query string back into an object.
*
* Implementation notes (v5):
* - Uses native `URLSearchParams` for decoding; input may start with leading `?`.
* - When `recursive=false` (default), repeated keys become arrays, otherwise the Rails-style
* bracket syntax is parsed to objects/arrays (e.g., `a[b]=1&a[c]=2`, `arr[0]=x`).
* - Security: forbidden keys (`"__proto__"`, `"prototype"`, `"constructor"`) are ignored at all nesting levels
* to prevent prototype pollution.
*
* @example
* fromQueryString("foo=1&bar=2"); // returns {foo: '1', bar: '2'}
* fromQueryString("foo=&bar=2"); // returns {foo: '', bar: '2'}
* fromQueryString("some%20price=%24300"); // returns {'some price': '$300'}
* fromQueryString("colors=red&colors=green&colors=blue"); // returns {colors: ['red', 'green', 'blue']}
*
*
* @param queryString The query string to decode.
* @param recursive True to interpret bracket syntax and build nested structures.
* @param options Options bag: `{ decodeName: boolean }` (names are already decoded by URLSearchParams).
* @returns A plain object constructed from the query string.
*/
export default function fromQueryString(queryString: string, recursive?: boolean, options?: FromQueryStringOptions): Record<string, any>;
export {};
//# sourceMappingURL=fromQueryString.d.ts.map