From c8c2053618ae3ab15ef289e128e779f4927cc39a Mon Sep 17 00:00:00 2001 From: bug-brain <40305896+bug-brain@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:16:17 +0100 Subject: [PATCH 1/3] recognize bigint as stringifiable --- base.d.ts | 2 +- test/stringify.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base.d.ts b/base.d.ts index 0803e2a..f6bbd9a 100644 --- a/base.d.ts +++ b/base.d.ts @@ -412,7 +412,7 @@ export type StringifyOptions = { readonly skipEmptyString?: boolean; }; -export type Stringifiable = string | boolean | number | null | undefined; // eslint-disable-line @typescript-eslint/ban-types +export type Stringifiable = string | boolean | number | bigint | null | undefined; // eslint-disable-line @typescript-eslint/ban-types export type StringifiableRecord = Record< string, diff --git a/test/stringify.js b/test/stringify.js index d68f097..0cbdb49 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -14,6 +14,13 @@ test('different types', t => { t.is(queryString.stringify(0), ''); }); +test('primitive types', t => { + t.is(queryString.stringify({a: 'string'}), 'a=string'); + t.is(queryString.stringify({a: true, b: false}), 'a=true&b=false'); + t.is(queryString.stringify({a: 0, b: 1n}), 'a=0&b=1'); + t.is(queryString.stringify({a: null, b: undefined}), 'a'); +}); + test('URI encode', t => { t.is(queryString.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz'); t.is(queryString.stringify({'foo bar': 'baz\'faz'}), 'foo%20bar=baz%27faz'); From 6f2a6a508748880232f983d9ca6b3e7eeef0fb77 Mon Sep 17 00:00:00 2001 From: bug-brain <40305896+bug-brain@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:56:17 +0100 Subject: [PATCH 2/3] update xo because 0.53.1 crashes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 910e36c..41dc0e4 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "deep-equal": "^2.1.0", "fast-check": "^3.4.0", "tsd": "^0.25.0", - "xo": "^0.53.1" + "xo": "^0.54.2" }, "tsd": { "compilerOptions": { From db5e73bb707b093885d321a01b7f359dff7bc5c3 Mon Sep 17 00:00:00 2001 From: bug-brain <40305896+bug-brain@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:57:18 +0100 Subject: [PATCH 3/3] replace if/else with ternary for xo --- base.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/base.js b/base.js index 0ca95bb..d20872c 100644 --- a/base.js +++ b/base.js @@ -385,13 +385,7 @@ export function parse(query, options) { // eslint-disable-next-line unicorn/no-array-reduce return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce((result, key) => { const value = returnValue[key]; - if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { - // Sort object keys, not values - result[key] = keysSorter(value); - } else { - result[key] = value; - } - + result[key] = Boolean(value) && typeof value === 'object' && !Array.isArray(value) ? keysSorter(value) : value; return result; }, Object.create(null)); }