Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.67 KB

File metadata and controls

54 lines (36 loc) · 1.67 KB

obscenity


obscenity / createSimpleTransformer

Function: 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.

Parameters

transformer

TransformerFn

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.

Returns

SimpleTransformerContainer

A container holding the transformer, which can then be passed to the [[RegExpMatcher]].

Examples

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] });