Detalhes do pacote

fast-querystring

anonrig18.1mMIT1.1.2

A fast alternative to legacy querystring module

querystring, qs, parser

readme (leia-me)

fast-querystring

Test codecov NPM version

Fast query-string parser and stringifier to replace the legacy node:querystring module.

Installation

npm i fast-querystring

Features

  • Supports both parse and stringify methods from node:querystring module
  • Parsed object does not have prototype methods
  • Uses & separator as default
  • Supports only input of type string
  • Supports repeating keys in query string
    • foo=bar&foo=baz parses into {foo: ['bar', 'baz']}
  • Supports pairs with missing values
    • foo=bar&hola parses into {foo: 'bar', hola: ''}
  • Stringify does not support nested values (just like node:querystring)

Usage

const qs = require('fast-querystring')

// Parsing a querystring
console.log(qs.parse('hello=world&foo=bar&values=v1&values=v2'))
// {
//   hello: 'world',
//   foo: 'bar',
//   values: ['v1', 'v2']
// }

// Stringifying an object
console.log(qs.stringify({ foo: ['bar', 'baz'] }))
// 'foo=bar&foo=baz'

Benchmark

All benchmarks are run using Node.js v20.2.0 running on M1 Max.

  • Parsing a query-string
> node benchmark/parse.mjs

╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗
║ Slower tests                            │ Samples │            Result │ Tolerance ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ query-string10000273968.62 op/sec │  ± 1.48 % ║
║ qs                                      │    9999324118.68 op/sec │  ± 0.99 % ║
║ querystringify                          │    1000410157.64 op/sec │  ± 0.68 % ║
║ @aws-sdk/querystring-parser             │    1000431465.20 op/sec │  ± 0.83 % ║
║ URLSearchParams-with-Object.fromEntries │    5000833939.19 op/sec │  ± 0.97 % ║
║ URLSearchParams-with-construct          │   10000980017.92 op/sec │  ± 2.42 % ║
║ node:querystring                        │   100001068165.86 op/sec │  ± 3.41 % ║
║ querystringparser                       │    30001384001.31 op/sec │  ± 0.95 % ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ Fastest test                            │ Samples │            Result │ Tolerance ║
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
║ fast-querystring                        │   100001584458.62 op/sec │  ± 2.64 % ║
╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝
  • Stringify a query-string
> node benchmark/stringify.mjs

╔══════════════════════════════╤═════════╤═══════════════════╤═══════════╗
║ Slower tests                 │ Samples │            Result │ Tolerance ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ query-string10000314662.25 op/sec │  ± 1.08 % ║
║ qs                           │    9500353621.74 op/sec │  ± 0.98 % ║
║ http-querystring-stringify   │   10000372189.04 op/sec │  ± 1.48 % ║
║ @aws-sdk/querystring-builder │   10000411658.63 op/sec │  ± 1.67 % ║
║ URLSearchParams              │   10000454438.85 op/sec │  ± 1.32 % ║
║ querystringparser            │   10000455615.18 op/sec │  ± 4.22 % ║
║ querystringify               │   10000879020.96 op/sec │  ± 2.12 % ║
║ querystringify-ts            │   10000879134.48 op/sec │  ± 2.19 % ║
║ node:querystring             │   100001244505.97 op/sec │  ± 2.12 % ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ Fastest test                 │ Samples │            Result │ Tolerance ║
╟──────────────────────────────┼─────────┼───────────────────┼───────────╢
║ fast-querystring             │   100001953717.60 op/sec │  ± 3.16 % ║
╚══════════════════════════════╧═════════╧═══════════════════╧═══════════╝
  • Importing package.
> node benchmark/import.mjs

╔═════════════════════════════╤═════════╤═════════════════╤═══════════╗
║ Slower tests                │ Samples │          Result │ Tolerance ║
╟─────────────────────────────┼─────────┼─────────────────┼───────────╢
║ @aws-sdk/querystring-parser │    100012360.51 op/sec │  ± 0.57 % ║
║ qs                          │    100014507.74 op/sec │  ± 0.36 % ║
║ querystringify              │    100014750.53 op/sec │  ± 0.39 % ║
║ query-string100016335.05 op/sec │  ± 0.87 % ║
║ querystringparser           │    100017018.50 op/sec │  ± 0.42 % ║
╟─────────────────────────────┼─────────┼─────────────────┼───────────╢
║ Fastest test                │ Samples │          Result │ Tolerance ║
╟─────────────────────────────┼─────────┼─────────────────┼───────────╢
║ fast-querystring            │    250074605.83 op/sec │  ± 0.91 % ║
╚═════════════════════════════╧═════════╧═════════════════╧═══════════╝