obscenity / createSimpleTransformer
createSimpleTransformer(
transformer):SimpleTransformerContainer
Defined in: src/transformer/Transformers.ts:45
Creates a container holding the transformer function provided. Simple
transformers are suitable for stateless transformations, e.g., a
transformation that maps certain characters to others. For transformations
that need to keep around state, see createStatefulTransformer.
Function that applies the transformation. It should
accept one argument, the input character, and return the transformed
character. A return value of undefined indicates that the character should
be ignored.
A container holding the transformer, which can then be passed to the [[RegExpMatcher]].
function lowercaseToUppercase(char) {
return isLowercase(char) ? char - 32 : char;
}
const transformer = createSimpleTransformer(lowercaseToUppercase);
const matcher = new RegExpMatcher({ ..., blacklistMatcherTransformers: [transformer] });function ignoreAllNonDigitChars(char) {
return isDigit(char) ? char : undefined;
}
const transformer = createSimpleTransformer(ignoreAllNonDigitChars);
const matcher = new RegExpMatcher({ ..., blacklistMatcherTransformers: [transformer] });