Global

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 "s": "z" will replace all s characters with z. 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 of ts from the string (but leave individual instances of t and s that do not appear in sequence).

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"