Skip to content

encodeUri

encodeUri(obj, options?): string

Defined in: uri/encode.ts:37

Encodes an object into a URI query string. The function ignores any properties with a null or undefined value.

Parameters

obj

EncodeUriObject

The object to encode.

options?

EncodeUriOptions = {}

Returns

string

The encoded URI query string.

Example

const query = encodeUri({ name: "John Doe", age: 30, active: true });
// query === "name=John%20Doe&age=30&active=true"
const queryWithQuestionMark = encodeUri(
{ search: "test", page: 2 },
{ includeQuestionMark: true }
);
// queryWithQuestionMark === "?search=test&page=2"