UNPKG

obscenity

Version:

Robust, extensible profanity filter.

37 lines (36 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.skipNonAlphabeticTransformer = void 0; const Char_1 = require("../../util/Char"); const Transformers_1 = require("../Transformers"); /** * Creates a transformer that skips non-alphabetic characters (`a`-`z`, * `A`-`Z`). This is useful when matching text on patterns that are solely * comprised of alphabetic characters (the pattern `hello` does not match * `h.e.l.l.o` by default, but does with this transformer). * * **Warning** * * This transformation is not part of the default set of transformations, as * there are some known rough edges with false negatives; see * [#23](https://github.com/jo3-l/obscenity/issues/23) and * [#46](https://github.com/jo3-l/obscenity/issues/46) on the GitHub issue * tracker. * * **Application order** * * It is recommended that this transformer be applied near the end of the * transformer chain, if at all. * * @example * ```typescript * const transformer = skipNonAlphabeticTransformer(); * const matcher = new RegExpMatcher({ ..., blacklistMatcherTransformers: [transformer] }); * ``` * @returns A container holding the transformer, which can then be passed to the * [[RegExpMatcher]]. */ function skipNonAlphabeticTransformer() { return (0, Transformers_1.createSimpleTransformer)((c) => ((0, Char_1.isAlphabetic)(c) ? c : undefined)); } exports.skipNonAlphabeticTransformer = skipNonAlphabeticTransformer;