CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
README.md115 linesDownload Raw Back to fast-querystring
1# fast-querystring2 3![Test](https://github.com/anonrig/fast-querystring/workflows/test/badge.svg)4[![codecov](https://codecov.io/gh/anonrig/fast-querystring/branch/main/graph/badge.svg?token=4ZDJA2BMOH)](https://codecov.io/gh/anonrig/fast-querystring)5[![NPM version](https://img.shields.io/npm/v/fast-querystring.svg?style=flat)](https://www.npmjs.com/package/fast-querystring)6 7Fast query-string parser and stringifier to replace the legacy `node:querystring` module.8 9### Installation10 11```12npm i fast-querystring13```14 15### Features16 17- Supports both `parse` and `stringify` methods from `node:querystring` module18- Parsed object does not have prototype methods19- Uses `&` separator as default20- Supports only input of type `string`21- Supports repeating keys in query string22  - `foo=bar&foo=baz` parses into `{foo: ['bar', 'baz']}`23- Supports pairs with missing values24  - `foo=bar&hola` parses into `{foo: 'bar', hola: ''}`25- Stringify does not support nested values (just like `node:querystring`)26 27### Usage28 29```javascript30const qs = require('fast-querystring')31 32// Parsing a querystring33console.log(qs.parse('hello=world&foo=bar&values=v1&values=v2'))34// {35//   hello: 'world',36//   foo: 'bar',37//   values: ['v1', 'v2']38// }39 40// Stringifying an object41console.log(qs.stringify({ foo: ['bar', 'baz'] }))42// 'foo=bar&foo=baz'43```44 45### Benchmark46 47All benchmarks are run using Node.js v20.2.0 running on M1 Max.48 49- Parsing a query-string50 51```52> node benchmark/parse.mjs53 54╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗55║ Slower tests                            │ Samples │            Result │ Tolerance ║56╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢57║ query-string                            │   10000 │  273968.62 op/sec │  ± 1.48 % ║58║ qs                                      │    9999 │  324118.68 op/sec │  ± 0.99 % ║59║ querystringify                          │    1000 │  410157.64 op/sec │  ± 0.68 % ║60║ @aws-sdk/querystring-parser             │    1000 │  431465.20 op/sec │  ± 0.83 % ║61║ URLSearchParams-with-Object.fromEntries │    5000 │  833939.19 op/sec │  ± 0.97 % ║62║ URLSearchParams-with-construct          │   10000 │  980017.92 op/sec │  ± 2.42 % ║63║ node:querystring                        │   10000 │ 1068165.86 op/sec │  ± 3.41 % ║64║ querystringparser                       │    3000 │ 1384001.31 op/sec │  ± 0.95 % ║65╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢66║ Fastest test                            │ Samples │            Result │ Tolerance ║67╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢68║ fast-querystring                        │   10000 │ 1584458.62 op/sec │  ± 2.64 % ║69╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝70```71 72- Stringify a query-string73 74```75> node benchmark/stringify.mjs76 77╔══════════════════════════════╤═════════╤═══════════════════╤═══════════╗78║ Slower tests                 │ Samples │            Result │ Tolerance ║79╟──────────────────────────────┼─────────┼───────────────────┼───────────╢80║ query-string                 │   10000 │  314662.25 op/sec │  ± 1.08 % ║81║ qs                           │    9500 │  353621.74 op/sec │  ± 0.98 % ║82║ http-querystring-stringify   │   10000 │  372189.04 op/sec │  ± 1.48 % ║83║ @aws-sdk/querystring-builder │   10000 │  411658.63 op/sec │  ± 1.67 % ║84║ URLSearchParams              │   10000 │  454438.85 op/sec │  ± 1.32 % ║85║ querystringparser            │   10000 │  455615.18 op/sec │  ± 4.22 % ║86║ querystringify               │   10000 │  879020.96 op/sec │  ± 2.12 % ║87║ querystringify-ts            │   10000 │  879134.48 op/sec │  ± 2.19 % ║88║ node:querystring             │   10000 │ 1244505.97 op/sec │  ± 2.12 % ║89╟──────────────────────────────┼─────────┼───────────────────┼───────────╢90║ Fastest test                 │ Samples │            Result │ Tolerance ║91╟──────────────────────────────┼─────────┼───────────────────┼───────────╢92║ fast-querystring             │   10000 │ 1953717.60 op/sec │  ± 3.16 % ║93╚══════════════════════════════╧═════════╧═══════════════════╧═══════════╝94```95 96- Importing package.97 98```99> node benchmark/import.mjs100 101╔═════════════════════════════╤═════════╤═════════════════╤═══════════╗102║ Slower tests                │ Samples │          Result │ Tolerance ║103╟─────────────────────────────┼─────────┼─────────────────┼───────────╢104║ @aws-sdk/querystring-parser │    1000 │ 12360.51 op/sec │  ± 0.57 % ║105║ qs                          │    1000 │ 14507.74 op/sec │  ± 0.36 % ║106║ querystringify              │    1000 │ 14750.53 op/sec │  ± 0.39 % ║107║ query-string                │    1000 │ 16335.05 op/sec │  ± 0.87 % ║108║ querystringparser           │    1000 │ 17018.50 op/sec │  ± 0.42 % ║109╟─────────────────────────────┼─────────┼─────────────────┼───────────╢110║ Fastest test                │ Samples │          Result │ Tolerance ║111╟─────────────────────────────┼─────────┼─────────────────┼───────────╢112║ fast-querystring            │    2500 │ 74605.83 op/sec │  ± 0.91 % ║113╚═════════════════════════════╧═════════╧═════════════════╧═══════════╝114```115