Skip to content

ensureString

function ensureString(source?): string | undefined;

Defined in: string.ts:15

Normalize a value that could be a string, array of strings, null, or undefined into a single string or undefined.

Useful for handling query params, headers, and other values that may come as arrays.

Parameter Type
source? string | string[] | null

string | undefined

ensureString("hello"); // "hello"
ensureString(["a", "b"]); // "a"
ensureString(null); // undefined
ensureString(undefined); // undefined