Methods
escapeRegExp(input) → {String}
Escapes RegExp characters in a string.
Parameters:
Name | Type | Description |
---|---|---|
input |
String |
- Source:
Returns:
- Type
- String
sanitize()
An alias for the transliterate method
- Source:
- See:
transliterate(stringopt, substitutionsopt) → {String}
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 | Attributes | Default | Description |
---|---|---|---|---|
string |
String |
<optional> |
`` | The string to transliterate or sanitize. |
substitutions |
Object |
<optional> |
new Map | 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 |
- Source:
Returns:
Returns a new string with all substitutions made.
- Type
- String
Example
{@lang javascript}
const substitutions = {
tʼ: `d`,
ts: `c`,
};
const input = `tsatʼ`;
const output = transliterate(input, substitutions);
console.log(output); // --> "cad"