qss: Tiny Query String Serializer

3.0.0 · active · verified Sun Apr 19

qss (query string stringify) is a minimalist, 305-byte browser utility designed for efficiently serializing JavaScript objects into URL query strings and parsing query strings back into objects. The current stable version is 3.0.0. It distinguishes itself by its extreme lightness and strong performance for decoding compared to other libraries like `qs`, `query-string`, and even Node.js's native `querystring.decode` in browser contexts. While suitable for browsers, its `encode` function is significantly slower than Node.js's native `querystring.stringify`, making it less ideal for server-side encoding. qss ships with TypeScript type definitions, providing a robust development experience. Releases are feature-driven rather than on a strict cadence, with major versions introducing breaking changes as needed for improvements or modernizations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to encode JavaScript objects into query strings and decode query strings back into objects, including usage with prefixes and array values.

import { encode, decode } from 'qss';

// Example 1: Basic object encoding
const params1 = { foo: 'hello world', bar: [1, 2, 3], baz: true };
const queryString1 = encode(params1);
console.log('Encoded 1:', queryString1);
// Expected: 'foo=hello%20world&bar=1&bar=2&bar=3&baz=true'

// Example 2: Encoding with a custom prefix
const params2 = { limit: 10, offset: 0 };
const queryString2 = encode(params2, '?');
console.log('Encoded 2 with prefix:', queryString2);
// Expected: '?limit=10&offset=0'

// Example 3: Decoding a query string
const decodedParams1 = decode('foo=hello%20world&bar=1&bar=2&bar=3&baz=true');
console.log('Decoded 1:', decodedParams1);
// Expected: { foo: 'hello world', bar: [1, 2, 3], baz: true }

// Example 4: Decoding from location.search (browser context)
// In a browser, you might do:
// const browserQueryString = location.search.substring(1);
// const decodedBrowserParams = decode(browserQueryString);
// console.log('Decoded from browser search:', decodedBrowserParams);

view raw JSON →