nested-query-params
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Nested Query Params

A TypeScript implementation of Rack's query string parser.

Overview

A TypeScript implementation of Rack's query string parser. Allows query strings to be expanded into "structural" types; objects, arrays, and string values are supported.

Installation

npm i -D nested-query-params

Usage

import { parseQuery, printQuery } from "nested-query-params";

// maps
const map = parseQuery("?foo[bar]=baz");
console.debug(map.foo.bar); // prints "baz"

// arrays
const list = parseQuery("?foo[]=bar&foo[]=baz");
console.debug(list.foo); // prints ["bar", "baz"]

// mixed
const mixed = parseQuery("?bar=baz&foo[bar][]=baz&foo[bar][]=42");
console.debug(mixed); // prints { bar: "baz", foo: { bar: ["baz", "42"] } }

// print
const simple = parseQuery("?foo[bar]=baz");
console.debug(printQuery(simple)); // prints "?foo[bar]=baz"

// print valid
const edited = { ...simple, foo: "bar" };
console.debug(printQuery(edited)); // prints "?foo=bar"

/nested-query-params/

    Package Sidebar

    Install

    npm i nested-query-params

    Weekly Downloads

    183

    Version

    1.1.1

    License

    MIT

    Unpacked Size

    22.4 kB

    Total Files

    18

    Last publish

    Collaborators

    • jamesdphillips