Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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