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
13 changes: 10 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,18 @@ export interface StringifyOptions {
readonly skipEmptyString?: boolean;
}

export type Stringifiable = string | boolean | number;

export type StringifiableRecord = Record<
string,
Stringifiable | Stringifiable[] | null | undefined
>;

/**
Stringify an object into a query string and sort the keys.
*/
export function stringify(
object: {[key: string]: any},
object: StringifiableRecord,
options?: StringifyOptions
): string;

Expand All @@ -358,9 +365,9 @@ export interface UrlObject {
readonly url: string;

/**
Qverrides queries in the `url` property.
Overrides queries in the `url` property.
*/
readonly query: Record<string, string | undefined | null>;
readonly query: StringifiableRecord;

/**
Overrides the fragment identifier in the `url` property.
Expand Down
17 changes: 16 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,19 @@ expectType<queryString.ParsedUrl>(
// Extract
expectType<string>(queryString.extract('http://foo.bar/?abc=def&hij=klm'));

expectType<string>(queryString.stringifyUrl({url: 'https://sindresorhus.com', query: {foo: undefined}}));
expectType<string>(
queryString.stringifyUrl({
url: 'https://sindresorhus.com',
query: {
fooArray: [
'a',
'b'
],
fooNumber: 1,
fooBoolean: true,
fooNull: null,
fooUndefined: undefined,
fooString: 'hi'
},
})
);