Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qss

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qss

A tiny (294B) browser utility for stringifying a query Object.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56K
decreased by-28.54%
Maintainers
1
Weekly downloads
 
Created
Source

qss Build Status

A tiny (294B) browser utility for stringifying a query Object.

You should only consider using this within a browser context since Node's built-in querystring.stringify is much faster and should be used in a Node environment! An ideal use case is serializing a query object before an API request is sent.

This module exposes three module definitions:

  • ES Module: dist/qss.mjs
  • CommonJS: dist/qss.js
  • UMD: dist/qss.min.js

Install

$ npm install --save qss

Usage

import { encode, decode } from 'qss';

encode({ foo:'hello', bar:[1,2,3], baz:true });
//=> 'foo=hello&bar=1&bar=2&bar=3&baz=true'

encode({ foo:123 }, '?');
//=> '?foo=123'

encode({ bar:'world' }, 'foo=hello&');
//=> 'foo=hello&bar=world'

decode('foo=hello&bar=1&bar=2&bar=3&baz=true');
//=> { foo:'hello', bar:[1,2,3], baz:true };

API

qss.encode(params, prefix)

Returns: String

Returns the formatted querystring.

params

Type: Object

The object that contains all query parameter keys & their values.

prefix

Type: String
Default: ''

An optional prefix. The stringified params will be appended to this value, so it must end with your desired joiner; eg ?.

Important: No checks or validations will run on your prefix. Similarly, no character is used to "glue" the query string to your prefix string.

qss.decode(query)

Returns: Object

Returns an Object with decoded keys and values.

Repetitive keys will form an Array of its values. Also, qss will attempt to typecast Boolean and Number values.

query

Type: String

The query string, without its leading ? character.

qss.decode(
  location.search.substring(1) // removes the "?"
);

Benchmarks

Running Node v10.13.0

Encode

qss             x 1,114,662 ops/sec ±0.23% (94 runs sampled)
native          x 5,329,564 ops/sec ±0.56% (91 runs sampled)
query-string    x   345,668 ops/sec ±1.18% (97 runs sampled)
querystringify  x   922,295 ops/sec ±0.73% (93 runs sampled)

Decode

qss             x 456,666 ops/sec ±0.86% (95 runs sampled)
native          x 195,820 ops/sec ±0.47% (91 runs sampled)
query-string    x 200,192 ops/sec ±0.25% (98 runs sampled)
querystringify  x 301,697 ops/sec ±0.69% (96 runs sampled)

License

MIT © Luke Edwards

Keywords

FAQs

Package last updated on 29 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc