From 4b104ddba9ffec511bed690a23bb5e218590e538 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 18:31:19 -0400 Subject: [PATCH 01/11] feat: add type declarations --- lib/index.d.ts | 4 ++++ package.json | 1 + 2 files changed, 5 insertions(+) create mode 100644 lib/index.d.ts diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..a62138b --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,4 @@ +declare namespace FastQuerystring { + export function stringify(value: string): Record; + export function parse(value: Record): string; +} diff --git a/package.json b/package.json index 46b27d6..2b1a909 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "lib/index.js", "type": "commonjs", + "types": "./lib/index.d.ts", "scripts": { "format": "rome format . --write", "format:ci": "rome format .", From 4535136e5423eb6b863033a564e8db7812d2e82d Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 18:31:29 -0400 Subject: [PATCH 02/11] chore: release 0.6.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b1a909..9327fa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fast-querystring", - "version": "0.6.1", + "version": "0.6.2", "description": "", "main": "lib/index.js", "type": "commonjs", From 1ad68b646a0bcf6fb3dd5a7c57903d9433fbe59e Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 19:08:42 -0400 Subject: [PATCH 03/11] fix: use correct types for the package --- .npmignore | 2 ++ lib/index.d.ts | 6 ++++-- lib/index.js | 11 ++++++++++- package.json | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.npmignore b/.npmignore index 5b75d98..17f3d8f 100644 --- a/.npmignore +++ b/.npmignore @@ -6,3 +6,5 @@ test benchmark .idea .github +rome.json +LICENSE diff --git a/lib/index.d.ts b/lib/index.d.ts index a62138b..426ff25 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,4 +1,6 @@ declare namespace FastQuerystring { - export function stringify(value: string): Record; - export function parse(value: Record): string; + export function stringify(value: Record): string; + export function parse(value: string): Record; } + +export default FastQuerystring; diff --git a/lib/index.js b/lib/index.js index 22da53c..feb9c3b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,16 @@ const parse = require("./parse"); const stringify = require("./stringify"); -module.exports = { +const fastQuerystring = { parse, stringify, }; + +/** + * Enable TS and JS support + * + * - `const qs = require('fast-querystring')` + * - `import qs from 'fast-querystring'` + */ +module.exports = fastQuerystring; +module.exports.default = fastQuerystring; diff --git a/package.json b/package.json index 9327fa3..13755ab 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "lib/index.js", "type": "commonjs", - "types": "./lib/index.d.ts", + "types": "lib/index.d.ts", "scripts": { "format": "rome format . --write", "format:ci": "rome format .", From 80b2c9da86783163c19ec4ea176b369a9faa6012 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 19:08:56 -0400 Subject: [PATCH 04/11] chore: release 0.6.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13755ab..f5b4d1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fast-querystring", - "version": "0.6.2", + "version": "0.6.3", "description": "", "main": "lib/index.js", "type": "commonjs", From f517380dd068ad58d7f54b8a3f5b2964675b2b0c Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 19:11:35 -0400 Subject: [PATCH 05/11] fix: handle exported function definitions --- lib/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/index.d.ts b/lib/index.d.ts index 426ff25..cac8424 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -3,4 +3,6 @@ declare namespace FastQuerystring { export function parse(value: string): Record; } +export function stringify(value: Record): string; +export function parse(value: string): Record; export default FastQuerystring; From 06f49f557bedbcbe1f3058c273d91020fce11d33 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 6 Sep 2022 19:11:47 -0400 Subject: [PATCH 06/11] chore: release 0.6.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f5b4d1c..0b0e977 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fast-querystring", - "version": "0.6.3", + "version": "0.6.4", "description": "", "main": "lib/index.js", "type": "commonjs", From 515b83d94bb4c013f17b4795d60a195ce01099bc Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 7 Sep 2022 16:53:58 +0000 Subject: [PATCH 07/11] chore(.npmignore): remove `LICENSE` `LICENSE` is always included in published module, see https://docs.npmjs.com/cli/v8/commands/npm-publish#files-included-in-package --- .npmignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.npmignore b/.npmignore index 17f3d8f..3737f78 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,3 @@ benchmark .idea .github rome.json -LICENSE From 0aba9969ab8ac273e4200552edfd4504aae132b2 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 8 Sep 2022 09:27:35 -0400 Subject: [PATCH 08/11] build: update rome to fix improve ci errors --- package.json | 4 ++-- pnpm-lock.yaml | 62 +++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 0b0e977..196a7ac 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "types": "lib/index.d.ts", "scripts": { "format": "rome format . --write", - "format:ci": "rome format .", + "format:ci": "rome ci .", "test": "vitest", "test:watch": "vitest --watch", "coverage": "vitest run --coverage", @@ -29,7 +29,7 @@ "qs": "^6.11.0", "query-string": "^7.1.1", "querystringify": "^2.2.0", - "rome": "0.9.0-next", + "rome": "0.9.1-next", "vitest": "^0.23.1" }, "repository": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6370af4..725d614 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ specifiers: qs: ^6.11.0 query-string: ^7.1.1 querystringify: ^2.2.0 - rome: 0.9.0-next + rome: 0.9.1-next vitest: ^0.23.1 dependencies: @@ -23,7 +23,7 @@ devDependencies: qs: 6.11.0 query-string: 7.1.1 querystringify: 2.2.0 - rome: 0.9.0-next + rome: 0.9.1-next vitest: 0.23.1 packages: @@ -54,68 +54,68 @@ packages: dev: true optional: true - /@rometools/cli-darwin-arm64/0.9.0-next: - resolution: {integrity: sha512-DoqyJZoDI2lOFEJP8fIKLOGd+vG6cGvqsb5SnEBtyx6utumO1HeFhBXfhFS1zOU8A4eNE1eTdFVDeGjs6J/hYQ==} + /@rometools/cli-darwin-arm64/0.9.1-next: + resolution: {integrity: sha512-eunRhR1I+pHYK3IUx8+Wm64OD5i1zoli+2WNlXAdjJpebue9slC3AMuq1o1yx0FS43gstnkrK8ddmMgaieOvgw==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /@rometools/cli-darwin-x64/0.9.0-next: - resolution: {integrity: sha512-Imt1C/lwltDQMC0GUt/DfOeCa6tjkfvO94oXKf0WmzXzPXAOP1wT4vxne9A6pSH5h35yfW+abrByLRkro1SDPw==} + /@rometools/cli-darwin-x64/0.9.1-next: + resolution: {integrity: sha512-AZLQQl/5Qhjxig9MNTJ54MYSdZDNJt92gvDwAKtKmukCfeJ62TXFXPMlvWHWezRC72aN8QXJxZrbN4b5U+Tnqg==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /@rometools/cli-linux-arm64/0.9.0-next: - resolution: {integrity: sha512-d0KPHo7cK84ZrEqwXOXHg6LNYLACcezZyxZwzEyNnia4eRtpA3kG5EXdoayR0rFpfIMwTzUUWqSmYhfppMDcvA==} + /@rometools/cli-linux-arm64/0.9.1-next: + resolution: {integrity: sha512-5esFEUs7DC5tM5tnNl6fSdmN79ryt5VUOdOoPKqH6FbfnCr8/vnhWk0yGkwIsvv1JjApJM93IoAA+MMopB1KDA==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@rometools/cli-linux-x64/0.9.0-next: - resolution: {integrity: sha512-m1E/kGvSAexdaSwhDmTLjKBLawHEtY/bxgVCwyVaPG+sk4QCB7/4YZyQzLQxMJ1cJ+RFUYESdh1CP/KN0ZWtFw==} + /@rometools/cli-linux-x64/0.9.1-next: + resolution: {integrity: sha512-HAIREqsunGiN280yqsOrAc5sO0BpMjqp4wx2Q4OEPB7eqtOMoW5bWlAQO8Lcki1zXRRJlDAXUqRRaz5ZHzWQbQ==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@rometools/cli-win32-arm64/0.9.0-next: - resolution: {integrity: sha512-7lTx/l/EqF7ecntugjK0LCICFTyXnswZ/h2WT8chctkPjLJvlimqXWlC9Sem4KbNIjNPpO8gW3pmvNQlUGyWag==} + /@rometools/cli-win32-arm64/0.9.1-next: + resolution: {integrity: sha512-W8MEctDRofZMGeeYK3EY4lBypkUpPIVItPj/0ZLOcT1tcuUIdAP3YMDyB9hLCDGkpIQX6ElGld9jyX+JXGmCEQ==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /@rometools/cli-win32-x64/0.9.0-next: - resolution: {integrity: sha512-Xey8/xIaSq9i9TS11L4osUIRUiA7qwmRiu86CPwACclzcucWa2ySf11jWmjiZKxgDl1O1YaxcZDHef88zZcGPA==} + /@rometools/cli-win32-x64/0.9.1-next: + resolution: {integrity: sha512-vRJVtoQ0TyZb7LN6sbkyUDsyJ2AcqR05sqs7KLW9WFGtZaDMxEJLromtC7CaPL7pZzFzM/osF5DPlUgdki2GSA==} cpu: [x64] os: [win32] requiresBuild: true dev: true optional: true - /@rometools/wasm-bundler/0.9.0-next: - resolution: {integrity: sha512-ieC7g99orV/WLqvC1pupu1O5WMyE0YggT2mvmjXn5CUXh+iNI7ZD4d2XfFiiGNQFUs96FrNaypK7M1Nc1kC65w==} + /@rometools/wasm-bundler/0.9.1-next: + resolution: {integrity: sha512-goYzCBSJeomHcFbsUuEqH22kjVxoEId9gXLhUonr/mV6A0bN6qZVIxGkR7TxEvu0IgvTm0uxxgffJAKFQbbjwg==} requiresBuild: true dev: true optional: true - /@rometools/wasm-nodejs/0.9.0-next: - resolution: {integrity: sha512-zTZLVALA/tm7D1SeW08t9TytB4Rx9s++pYU8/yc7wN/sEnWuE2QbHvnfrzRlMsw6K+k27HLCyJOfak3rAZOpvw==} + /@rometools/wasm-nodejs/0.9.1-next: + resolution: {integrity: sha512-adqqDjMnnEYZgO0meOvhAYZgBFunbu3yqR03ucuTSc6SoRqDzIRq3h/lb+TB/cnmeZ/+z3CaC3aAUriyq8t2og==} requiresBuild: true dev: true optional: true - /@rometools/wasm-web/0.9.0-next: - resolution: {integrity: sha512-8mRIbOtK+XWLbMBJoERHZ/RKyZSiOOquPK2DrMuKxzPnW8bGuK/4EvIImPGgoGYzTXNJFSprboQpaE+gvBmB8w==} + /@rometools/wasm-web/0.9.1-next: + resolution: {integrity: sha512-2slMIuHMbgMCExvzsJ8Nz2tUtJXxXEA8NrVS8qJbmG93l/q2NC+Nfn8IUwqYXOHRglS4i4KzC1UZTfPW5hfBLA==} requiresBuild: true dev: true optional: true @@ -639,21 +639,21 @@ packages: fsevents: 2.3.2 dev: true - /rome/0.9.0-next: - resolution: {integrity: sha512-Ggk0vGhYmeFEAMdd9gTtsmGKGIGa5ldet/GJDRgtW/7gZYP7HYNizJcf5N4uwZHn0/hjgFvguWB2BEHsHGTivA==} + /rome/0.9.1-next: + resolution: {integrity: sha512-kPqIL1szBNFd3PQxO7Jg+68oDdgQ4vdxr2xvBjWhOG1p0aoa6BTlGSmRmcs8KQl94mt63qN+QEavIpmCiP+nsA==} engines: {node: '>=14.*'} hasBin: true requiresBuild: true optionalDependencies: - '@rometools/cli-darwin-arm64': 0.9.0-next - '@rometools/cli-darwin-x64': 0.9.0-next - '@rometools/cli-linux-arm64': 0.9.0-next - '@rometools/cli-linux-x64': 0.9.0-next - '@rometools/cli-win32-arm64': 0.9.0-next - '@rometools/cli-win32-x64': 0.9.0-next - '@rometools/wasm-bundler': 0.9.0-next - '@rometools/wasm-nodejs': 0.9.0-next - '@rometools/wasm-web': 0.9.0-next + '@rometools/cli-darwin-arm64': 0.9.1-next + '@rometools/cli-darwin-x64': 0.9.1-next + '@rometools/cli-linux-arm64': 0.9.1-next + '@rometools/cli-linux-x64': 0.9.1-next + '@rometools/cli-win32-arm64': 0.9.1-next + '@rometools/cli-win32-x64': 0.9.1-next + '@rometools/wasm-bundler': 0.9.1-next + '@rometools/wasm-nodejs': 0.9.1-next + '@rometools/wasm-web': 0.9.1-next dev: true /side-channel/1.0.4: From 405da62a03d9851e003478526f003fd5e7fff597 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 8 Sep 2022 11:00:32 -0400 Subject: [PATCH 09/11] perf: improve parse performance by 12% --- README.md | 16 ++++++++-------- lib/parse.js | 44 +++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b6a6ab5..ce2fb35 100644 --- a/README.md +++ b/README.md @@ -48,17 +48,17 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] })) ╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗ ║ Slower tests │ Samples │ Result │ Tolerance ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ qs │ 10000 │ 317841.53 op/sec │ ± 1.18 % ║ -║ query-string │ 10000 │ 341009.91 op/sec │ ± 1.06 % ║ -║ querystringify │ 1000 │ 451609.79 op/sec │ ± 0.61 % ║ -║ @aws-sdk/querystring-parser │ 1000 │ 477241.09 op/sec │ ± 0.69 % ║ -║ URLSearchParams-with-Object.fromEntries │ 10000 │ 870095.07 op/sec │ ± 3.29 % ║ -║ URLSearchParams-with-construct │ 10000 │ 1232650.60 op/sec │ ± 2.95 % ║ -║ node:querystring │ 10000 │ 1462802.04 op/sec │ ± 3.69 % ║ +║ qs │ 10000 │ 290743.91 op/sec │ ± 1.87 % ║ +║ query-string │ 1500 │ 333025.25 op/sec │ ± 0.98 % ║ +║ querystringify │ 10000 │ 430382.40 op/sec │ ± 1.95 % ║ +║ @aws-sdk/querystring-parser │ 3000 │ 452331.29 op/sec │ ± 0.87 % ║ +║ URLSearchParams-with-Object.fromEntries │ 2000 │ 862635.26 op/sec │ ± 0.87 % ║ +║ URLSearchParams-with-construct │ 10000 │ 1216331.19 op/sec │ ± 3.19 % ║ +║ node:querystring │ 10000 │ 1453849.93 op/sec │ ± 4.50 % ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ ║ Fastest test │ Samples │ Result │ Tolerance ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ fast-querystring │ 10000 │ 1809816.84 op/sec │ ± 3.19 % ║ +║ fast-querystring │ 10000 │ 2047629.50 op/sec │ ± 3.72 % ║ ╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝ ``` diff --git a/lib/parse.js b/lib/parse.js index 4f72bd1..268c0ca 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,21 +1,23 @@ -"use strict"; - const fastDecode = require("fast-decode-uri-component"); const plusRegex = /\+/g; +const Empty = function () {}; +Empty.prototype = Object.create(null); /** * @callback parse * @param {string} input */ function parse(input) { - const result = Object.create(null); + // Optimization: Use new Empty() instead of Object.create(null) for performance + // v8 has a better optimization for initializing functions compared to Object + const result = new Empty(); if (typeof input !== "string") { return result; } - const inputLength = input.length; + let inputLength = input.length; let key = ""; let value = ""; let startingIndex = -1; @@ -37,13 +39,8 @@ function parse(input) { keyEndingIndex = hasBothKeyValuePair ? equalityIndex : i; key = input.slice(startingIndex + 1, keyEndingIndex); - // Only update value if '=' exists in the current range - if (hasBothKeyValuePair) { - value = input.slice(equalityIndex + 1, i); - } - // Add key/value pair only if the range size is greater than 1; a.k.a. contains at least "=" - if (hasBothKeyValuePair || i - startingIndex > 1) { + if (hasBothKeyValuePair || key.length > 0) { // Optimization: Replace '+' with space if (keyHasPlus) { key = key.replace(plusRegex, " "); @@ -55,6 +52,8 @@ function parse(input) { } if (hasBothKeyValuePair) { + value = input.slice(equalityIndex + 1, i); + if (valueHasPlus) { value = value.replace(plusRegex, " "); } @@ -63,12 +62,11 @@ function parse(input) { value = fastDecode(value) || value; } } + const currentValue = result[key]; - if (result[key] === undefined) { + if (currentValue === undefined) { result[key] = value; } else { - const currentValue = result[key]; - // Optimization: value.pop is faster than Array.isArray(value) if (currentValue.pop) { currentValue.push(value); @@ -86,31 +84,31 @@ function parse(input) { shouldDecodeValue = false; keyHasPlus = false; valueHasPlus = false; - hasBothKeyValuePair = false; } // Check '=' else if (c === 61) { + if (equalityIndex <= startingIndex) { + equalityIndex = i; + } // If '=' character occurs again, we should decode the input. - if (equalityIndex > startingIndex) { + else { shouldDecodeValue = true; - } else { - equalityIndex = i; } } // Check '+', and remember to replace it with empty space. else if (c === 43) { - if (equalityIndex <= startingIndex) { - keyHasPlus = true; - } else { + if (equalityIndex > startingIndex) { valueHasPlus = true; + } else { + keyHasPlus = true; } } // Check '%' character for encoding else if (c === 37) { - if (equalityIndex <= startingIndex) { - shouldDecodeKey = true; - } else { + if (equalityIndex > startingIndex) { shouldDecodeValue = true; + } else { + shouldDecodeKey = true; } } } From c2b2fbfe4cbfc5fa686b288b9e618d7a0ffe824e Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 8 Sep 2022 11:20:48 -0400 Subject: [PATCH 10/11] docs: add more benchmarks --- README.md | 47 ++++++++++++++++++++++------------------- benchmark/parse.mjs | 4 ++++ benchmark/stringify.mjs | 8 +++++++ package.json | 2 ++ pnpm-lock.yaml | 24 +++++++++++++++++++++ 5 files changed, 63 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index ce2fb35..cf92994 100644 --- a/README.md +++ b/README.md @@ -48,17 +48,18 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] })) ╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗ ║ Slower tests │ Samples │ Result │ Tolerance ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ qs │ 10000 │ 290743.91 op/sec │ ± 1.87 % ║ -║ query-string │ 1500 │ 333025.25 op/sec │ ± 0.98 % ║ -║ querystringify │ 10000 │ 430382.40 op/sec │ ± 1.95 % ║ -║ @aws-sdk/querystring-parser │ 3000 │ 452331.29 op/sec │ ± 0.87 % ║ -║ URLSearchParams-with-Object.fromEntries │ 2000 │ 862635.26 op/sec │ ± 0.87 % ║ -║ URLSearchParams-with-construct │ 10000 │ 1216331.19 op/sec │ ± 3.19 % ║ -║ node:querystring │ 10000 │ 1453849.93 op/sec │ ± 4.50 % ║ +║ qs │ 10000 │ 302595.31 op/sec │ ± 1.22 % ║ +║ query-string │ 9500 │ 334820.82 op/sec │ ± 0.99 % ║ +║ querystringify │ 1000 │ 437899.50 op/sec │ ± 0.73 % ║ +║ @aws-sdk/querystring-parser │ 1000 │ 454836.96 op/sec │ ± 0.69 % ║ +║ URLSearchParams-with-Object.fromEntries │ 1500 │ 849572.92 op/sec │ ± 0.89 % ║ +║ URLSearchParams-with-construct │ 10000 │ 1190835.28 op/sec │ ± 3.22 % ║ +║ node:querystring │ 10000 │ 1384717.43 op/sec │ ± 2.99 % ║ +║ querystringparser │ 3500 │ 1735544.65 op/sec │ ± 0.95 % ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ ║ Fastest test │ Samples │ Result │ Tolerance ║ ╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ fast-querystring │ 10000 │ 2047629.50 op/sec │ ± 3.72 % ║ +║ fast-querystring │ 10000 │ 2023187.35 op/sec │ ± 2.67 % ║ ╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝ ``` @@ -67,18 +68,20 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] })) ``` > node benchmark/stringify.mjs -╔════════════════════════════╤═════════╤═══════════════════╤═══════════╗ -║ Slower tests │ Samples │ Result │ Tolerance ║ -╟────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ query-string │ 10000 │ 284130.63 op/sec │ ± 1.62 % ║ -║ qs │ 10000 │ 334799.48 op/sec │ ± 1.93 % ║ -║ http-querystring-stringify │ 10000 │ 482642.49 op/sec │ ± 1.72 % ║ -║ URLSearchParams │ 10000 │ 587274.65 op/sec │ ± 1.88 % ║ -║ querystringify │ 10000 │ 753960.35 op/sec │ ± 2.20 % ║ -║ node:querystring │ 10000 │ 1796993.95 op/sec │ ± 5.34 % ║ -╟────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ Fastest test │ Samples │ Result │ Tolerance ║ -╟────────────────────────────┼─────────┼───────────────────┼───────────╢ -║ fast-querystring │ 10000 │ 2051022.89 op/sec │ ± 4.52 % ║ -╚════════════════════════════╧═════════╧═══════════════════╧═══════════╝ +╔══════════════════════════════╤═════════╤═══════════════════╤═══════════╗ +║ Slower tests │ Samples │ Result │ Tolerance ║ +╟──────────────────────────────┼─────────┼───────────────────┼───────────╢ +║ query-string │ 10000 │ 294354.42 op/sec │ ± 1.25 % ║ +║ qs │ 10000 │ 349992.31 op/sec │ ± 1.45 % ║ +║ @aws-sdk/querystring-builder │ 10000 │ 380426.03 op/sec │ ± 1.69 % ║ +║ http-querystring-stringify │ 10000 │ 489248.93 op/sec │ ± 1.54 % ║ +║ URLSearchParams │ 10000 │ 579241.21 op/sec │ ± 1.92 % ║ +║ querystringparser │ 1500 │ 667303.72 op/sec │ ± 0.77 % ║ +║ querystringify │ 10000 │ 780283.61 op/sec │ ± 2.43 % ║ +║ node:querystring │ 10000 │ 1779241.34 op/sec │ ± 6.49 % ║ +╟──────────────────────────────┼─────────┼───────────────────┼───────────╢ +║ Fastest test │ Samples │ Result │ Tolerance ║ +╟──────────────────────────────┼─────────┼───────────────────┼───────────╢ +║ fast-querystring │ 10000 │ 2125769.45 op/sec │ ± 3.93 % ║ +╚══════════════════════════════╧═════════╧═══════════════════╧═══════════╝ ``` diff --git a/benchmark/parse.mjs b/benchmark/parse.mjs index a4c50f1..d5c2113 100644 --- a/benchmark/parse.mjs +++ b/benchmark/parse.mjs @@ -5,6 +5,7 @@ import native from "node:querystring"; import queryString from "query-string"; import querystringify from "querystringify"; import awsQueryStringParser from "@aws-sdk/querystring-parser"; +import querystringparser from "querystringparser"; const input = "frappucino=muffin&goat=scone&pond=moose&foo=bar&foo=baz"; @@ -46,6 +47,9 @@ await benchmark( "@aws-sdk/querystring-parser"() { return awsQueryStringParser.parseQueryString(input); }, + querystringparser() { + return querystringparser.parse(input); + }, }, { warmup: true }, ); diff --git a/benchmark/stringify.mjs b/benchmark/stringify.mjs index 1ae179e..c6c10cb 100644 --- a/benchmark/stringify.mjs +++ b/benchmark/stringify.mjs @@ -5,6 +5,8 @@ import native from "node:querystring"; import queryString from "query-string"; import querystringify from "querystringify"; import httpQuerystringStringify from "http-querystring-stringify"; +import awsQueryStringBuilder from "@aws-sdk/querystring-builder"; +import querystringparser from "querystringparser"; const value = { frappucino: "muffin", @@ -40,6 +42,12 @@ await benchmark( "http-querystring-stringify"() { return httpQuerystringStringify(value); }, + "@aws-sdk/querystring-builder"() { + return awsQueryStringBuilder.buildQueryString(value); + }, + querystringparser() { + return querystringparser.stringify(value); + }, }, { warmup: true }, ); diff --git a/package.json b/package.json index 196a7ac..c79a546 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "author": "Yagiz Nizipli ", "license": "MIT", "devDependencies": { + "@aws-sdk/querystring-builder": "^3.162.0", "@aws-sdk/querystring-parser": "^3.162.0", "@types/node": "^18.7.15", "cronometro": "^1.1.2", @@ -29,6 +30,7 @@ "qs": "^6.11.0", "query-string": "^7.1.1", "querystringify": "^2.2.0", + "querystringparser": "^0.1.1", "rome": "0.9.1-next", "vitest": "^0.23.1" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 725d614..4530f62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,7 @@ lockfileVersion: 5.4 specifiers: + '@aws-sdk/querystring-builder': ^3.162.0 '@aws-sdk/querystring-parser': ^3.162.0 '@types/node': ^18.7.15 cronometro: ^1.1.2 @@ -9,6 +10,7 @@ specifiers: qs: ^6.11.0 query-string: ^7.1.1 querystringify: ^2.2.0 + querystringparser: ^0.1.1 rome: 0.9.1-next vitest: ^0.23.1 @@ -16,6 +18,7 @@ dependencies: fast-decode-uri-component: 1.0.1 devDependencies: + '@aws-sdk/querystring-builder': 3.162.0 '@aws-sdk/querystring-parser': 3.162.0 '@types/node': 18.7.15 cronometro: 1.1.2 @@ -23,6 +26,7 @@ devDependencies: qs: 6.11.0 query-string: 7.1.1 querystringify: 2.2.0 + querystringparser: 0.1.1 rome: 0.9.1-next vitest: 0.23.1 @@ -32,6 +36,15 @@ packages: resolution: {integrity: sha512-ulkCYfFbYj01ie1MDOyxv2F6SpRN1TOj7fQxbP07D6HmeR+gr2JLSmINKjga2emB+b1L2KGrFKBTc+e00p54nw==} dev: true + /@aws-sdk/querystring-builder/3.162.0: + resolution: {integrity: sha512-3urwxCEpnQwa1B6fKmcr8R2Qmzr8VDttRSay5CgD/stbZ4XUzNsA6G1V36+EL1Vq4vMr1aZhriARioLDlhcz+g==} + engines: {node: '>= 12.0.0'} + dependencies: + '@aws-sdk/types': 3.162.0 + '@aws-sdk/util-uri-escape': 3.55.0 + tslib: 2.4.0 + dev: true + /@aws-sdk/querystring-parser/3.162.0: resolution: {integrity: sha512-0ccaGsR1O7e3BsprdYBMwGf8gmycTv1Dfz2EB5R6MiTqzcuQJ/lxpIcRh3jhUJaD1TPlUziyrBEAxtLka3HDDQ==} engines: {node: '>= 12.0.0'} @@ -45,6 +58,13 @@ packages: engines: {node: '>= 12.0.0'} dev: true + /@aws-sdk/util-uri-escape/3.55.0: + resolution: {integrity: sha512-mmdDLUpFCN2nkfwlLdOM54lTD528GiGSPN1qb8XtGLgZsJUmg3uJSFIN2lPeSbEwJB3NFjVas/rnQC48i7mV8w==} + engines: {node: '>= 12.0.0'} + dependencies: + tslib: 2.4.0 + dev: true + /@esbuild/linux-loong64/0.14.54: resolution: {integrity: sha512-bZBrLAIX1kpWelV0XemxBZllyRmM6vgFQQG2GdNb+r3Fkp0FOh1NJSvekXDs7jq70k4euu1cryLMfU+mTXlEpw==} engines: {node: '>=12'} @@ -617,6 +637,10 @@ packages: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} dev: true + /querystringparser/0.1.1: + resolution: {integrity: sha512-dvvDKF+ZuUd0N9DZ0C59TTt2/aztGfRrNzbn6SiqSQq/uwCKoMpLEMAb08DNd0ozbyhJfrrGJFWGLHeoL7ESag==} + dev: true + /require-from-string/2.0.2: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} From 962df0972d6b8a49b2986fff0a935d2b21a0b4bf Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 8 Sep 2022 14:41:33 -0400 Subject: [PATCH 11/11] chore: release 0.7.0 --- README.md | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cf92994..759050d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fast-querystring -Fast query-string parser to replace the legacy `node:querystring` parse & stringify functions. +Fast query-string parser and stringifier to replace the legacy `node:querystring` module. ### Installation diff --git a/package.json b/package.json index c79a546..4ff5733 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fast-querystring", - "version": "0.6.4", - "description": "", + "version": "0.7.0", + "description": "A fast alternative to legacy querystring module", "main": "lib/index.js", "type": "commonjs", "types": "lib/index.d.ts",