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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source? |
string | string[] | null |
Returns
Section titled “Returns”string | undefined
Example
Section titled “Example”ensureString("hello"); // "hello"ensureString(["a", "b"]); // "a"ensureString(null); // undefinedensureString(undefined); // undefined