Methods
-
sanitize()
-
An alias for the transliterate method
- See:
-
transliterate( [string] [, substitutions])
-
Makes a series of substitutions on a string. Can be used to convert a string from one writing system to another (a process known as "transliteration") or to remove unwanted characters or sequences of characters from a string (a process known as "sanitization").
Parameters:
Name Type Argument Default Description string
String <optional>
`` The string to transliterate or sanitize.
substitutions
Object <optional>
{} A hash of substitutions to make on the string. Each key in this object should be a string of characters you want to replace, and the value for that key should be the new string of characters to replace it with. For example, setting
"s": "z"
will replace alls
characters withz
. To sanitize a string, provide each unwanted character or sequence of characters as as a key, and set the value of that key to an empty string. For example, setting"ts": ""
in this object will remove all sequences ofts
from the string (but leave individual instances oft
ands
that do not appear in sequence).Returns:
Returns a new string with all substitutions made.
- Type
- String
Example
const substitutions = { tʼ: `d`, ts: `c`, }; const input = `tsatʼ`; const output = transliterate(input, substitutions); console.log(output); // --> "cad"