Skip to content

Commit

Permalink
Allow BigInt as stringifiable value in the types (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
bug-brain authored Feb 3, 2024
1 parent c5c2efc commit 7f84490
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7f84490

Please sign in to comment.