Value to sanitize. Should be a non-nullish string
.
A string that represents a set of characters. For ranges, only values from parseableRange
are valid.
A char
(i.e. string
with length === 0
) which should replace invalid characters inside the string.
– Definies how string should be trimmed. Defaults to left
(compatibility reasons).
A type-safe string sanitizer supporting any set of chars while being capable of calculating the expected result as a static type if literal is provided as a name. Predicts the accurate output based on input types or errors (
never
) if function is guaranteed to fail in the runtime.Remarks
It is designed to be rather performant at runtime (it uses
RegExp
under-the-hood), however be aware of long compilation times as TypeScript will have to do heavy calculations for function result in case of complex strings and character sets (a lot of operations are done in char-by-char manner, usinginfer
and type recursion — there's a real chance that for very long literal strings TypeScript will just give up at calculations and end compilation with an error!).Throws
TypeError
for unresolveable charset or invalid trimMode,RangeError
for non-char values in replacement andError
for value which cannot be sanitized to the expected charset.Example
Since
v1.0.0