requireStringLength()function

requireStringLength(value: PossibleString, min?: number, max?: number, caller: AnyCaller = requireString): string
ParamType
valuePossibleString
The value to convert. required
minnumber
The minimum allowed length.
maxnumber
The maximum allowed length.
callerAnyCaller
Function to attribute a thrown error to (defaults to requireString). Defaults to requireString
Return
string
The string representation of value.
Throws
RequiredError
If value cannot be converted to a string within the length bounds.

Convert a possible string to a string with min/max length, or throw RequiredError if conversion fails.

Examples

requireStringLength("abc", 1, 5) // "abc"