Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

query-string-lite

npm install @ferrow/query-string-lite

CI

Parse/stringify URL query strings: nested bracket notation, arrays, type coercion, prototype-pollution guard.

Quick Start

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"

API

parse(qs: string, opts?: ParseOptions): Record<string, any>

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 / prototype keys are ignored
  • URL decoding

stringify(obj: Record<string, any>, opts?: StringifyOptions): string

Stringify object to query string.

Options:

  • arrayFormat?: "bracket" | "repeat" — Array format (default: "bracket")
  • sort?: boolean — Sort keys (default: false)

Limitations

  • 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

About

Parse/stringify URL query strings: nested bracket notation, arrays, type coercion, prototype-pollution guard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages