requireStringLength()function
requireStringLength(value: PossibleString, min?: number, max?: number, caller: AnyCaller = requireString): string
| Param | Type | |
|---|---|---|
value | PossibleString | The value to convert. required |
min | number | The minimum allowed length. |
max | number | The maximum allowed length. |
caller | AnyCaller | 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"