Skip to main content

castToString

Cast any input to a string.

Signature

castToString(input: any, default?: string): string

Parameters

NameTypeOptionalDescription
inputanyNoSpecifies the input.
defaultstringYesOptional parameter which specifies the default string if the supplied input cannot be casted.

Return value

Returns the string value.

Example

import { castToString } from "@tripetto/builder";

castToString(1); // Returns `1`
castToString(1.2); // Returns `1.2`
castToString(undefined); // Returns ``