Small, simple but powerful query string parser for JavaScript applications.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
querystringify is a lightweight JavaScript library that provides a simple, JSON-compatible interface for parsing query strings into objects and converting objects back into query strings. It features built-in security protection against prototype pollution and graceful error handling for malformed input.
npm install querystringifyvar qs = require('querystringify');For ES modules (if available):
import { parse, stringify } from 'querystringify';var qs = require('querystringify');
// Parse query strings into objects
var result = qs.parse('?foo=bar&baz=qux');
// Result: { foo: 'bar', baz: 'qux' }
// Convert objects into query strings
var queryString = qs.stringify({ foo: 'bar', baz: 'qux' });
// Result: 'foo=bar&baz=qux'
// Add prefix to query string
var withPrefix = qs.stringify({ foo: 'bar' }, true);
// Result: '?foo=bar'Parses query strings into JavaScript objects with automatic URL decoding and security protections.
/**
* Parse a query string into an object
* @param {string} query - The query string to parse (can include ?, #, or no prefix)
* @returns {object} Object with key-value pairs from the query string
*/
function parse(query);Features:
? or # prefixesUsage Examples:
var qs = require('querystringify');
// Basic parsing
qs.parse('foo=bar&baz=qux');
// { foo: 'bar', baz: 'qux' }
// Works with prefixes
qs.parse('?foo=bar&baz=qux');
// { foo: 'bar', baz: 'qux' }
qs.parse('#foo=bar&baz=qux');
// { foo: 'bar', baz: 'qux' }
// Parameters without values
qs.parse('foo&bar=baz');
// { foo: '', bar: 'baz' }
// URL decoding including plus signs
qs.parse('name=John+Doe&city=New%20York');
// { name: 'John Doe', city: 'New York' }
// Duplicate keys - first wins
qs.parse('foo=first&foo=second');
// { foo: 'first' }
// Malformed input is handled gracefully
qs.parse('?%&validkey=validvalue');
// { validkey: 'validvalue' }Converts JavaScript objects into properly encoded query strings with optional prefix support.
/**
* Convert an object into a query string
* @param {object} obj - Object to convert to query string
* @param {string|boolean} [prefix] - Optional prefix. If true, uses '?'. If string, uses that string. Default: no prefix
* @returns {string} Query string representation, or empty string if no valid pairs
*/
function stringify(obj, prefix);Features:
?, or custom string)Object.create(null)Usage Examples:
var qs = require('querystringify');
// Basic stringification
qs.stringify({ foo: 'bar', baz: 'qux' });
// 'foo=bar&baz=qux'
// With question mark prefix
qs.stringify({ foo: 'bar', baz: 'qux' }, true);
// '?foo=bar&baz=qux'
// With custom prefix
qs.stringify({ foo: 'bar', baz: 'qux' }, '#');
// '#foo=bar&baz=qux'
// Empty values
qs.stringify({ foo: '' });
// 'foo='
// Null, undefined, NaN become empty strings
qs.stringify({ foo: null, bar: undefined, baz: NaN });
// 'foo=&bar=&baz='
// URL encoding
qs.stringify({ name: 'John Doe', city: 'New York' });
// 'name=John%20Doe&city=New%20York'
// Empty objects
qs.stringify({});
// ''
qs.stringify({}, true);
// ''
// Works with nulled objects
var obj = Object.create(null);
obj.foo = 'bar';
qs.stringify(obj);
// 'foo=bar'querystringify is designed to handle malformed input gracefully:
toString and __proto__ cannot be overriddenquerystringify works in both browser and Node.js environments without external dependencies. It uses standard JavaScript APIs (encodeURIComponent, decodeURIComponent) available in all modern environments.
Install with Tessl CLI
npx tessl i tessl/npm-querystringify