npm install @ferrow/query-string-liteParse/stringify URL query strings: nested bracket notation, arrays, type coercion, prototype-pollution guard.
import { parse, stringify } from "query-string-lite";
// Parse nested bracket notation
parse("user[name]=John&user[age]=30");
// { user: { name: "John", age: "30" } }
// Parse arrays
parse("tags[]=a&tags[]=b&tags[]=c");
// { tags: ["a", "b", "c"] }
// Type coercion
parse("count=42&active=true", { coerce: true });
// { count: 42, active: true }
// Stringify back
stringify({ user: { name: "John" }, tags: ["a", "b"] });
// "user[name]=John&tags[]=a&tags[]=b"Parse query string to object.
Options:
arrayFormat?: "bracket" | "repeat"— Array notation style (default: "bracket" = a[]=1&a[]=2; "repeat" = a=1&a=2)sort?: boolean— Sort keys (default: false)coerce?: boolean— Convert "true"→true, "42"→42, etc. (default: false)
Features:
- Nested bracket notation:
a[b][c]=1→{a: {b: {c: "1"}}} - Prototype-pollution protection:
__proto__/constructor/prototypekeys are ignored - URL decoding
Stringify object to query string.
Options:
arrayFormat?: "bracket" | "repeat"— Array format (default: "bracket")sort?: boolean— Sort keys (default: false)
- No support for very deeply nested structures (naive recursive implementation)
- Date objects are converted via toString()
- Functions/symbols are ignored
Part of the ferrow-toolkit collection · Sponsored by Ferrow