Skip to content

Commit 7f84490

Browse files
authored
Allow BigInt as stringifiable value in the types (#377)
1 parent c5c2efc commit 7f84490

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

base.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export type StringifyOptions = {
412412
readonly skipEmptyString?: boolean;
413413
};
414414

415-
export type Stringifiable = string | boolean | number | null | undefined; // eslint-disable-line @typescript-eslint/ban-types
415+
export type Stringifiable = string | boolean | number | bigint | null | undefined; // eslint-disable-line @typescript-eslint/ban-types
416416

417417
export type StringifiableRecord = Record<
418418
string,

base.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,7 @@ export function parse(query, options) {
385385
// eslint-disable-next-line unicorn/no-array-reduce
386386
return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce((result, key) => {
387387
const value = returnValue[key];
388-
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
389-
// Sort object keys, not values
390-
result[key] = keysSorter(value);
391-
} else {
392-
result[key] = value;
393-
}
394-
388+
result[key] = Boolean(value) && typeof value === 'object' && !Array.isArray(value) ? keysSorter(value) : value;
395389
return result;
396390
}, Object.create(null));
397391
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"deep-equal": "^2.1.0",
5656
"fast-check": "^3.4.0",
5757
"tsd": "^0.25.0",
58-
"xo": "^0.53.1"
58+
"xo": "^0.54.2"
5959
},
6060
"tsd": {
6161
"compilerOptions": {

test/stringify.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ test('different types', t => {
1414
t.is(queryString.stringify(0), '');
1515
});
1616

17+
test('primitive types', t => {
18+
t.is(queryString.stringify({a: 'string'}), 'a=string');
19+
t.is(queryString.stringify({a: true, b: false}), 'a=true&b=false');
20+
t.is(queryString.stringify({a: 0, b: 1n}), 'a=0&b=1');
21+
t.is(queryString.stringify({a: null, b: undefined}), 'a');
22+
});
23+
1724
test('URI encode', t => {
1825
t.is(queryString.stringify({'foo bar': 'baz faz'}), 'foo%20bar=baz%20faz');
1926
t.is(queryString.stringify({'foo bar': 'baz\'faz'}), 'foo%20bar=baz%27faz');

0 commit comments

Comments
 (0)