-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
26 lines (25 loc) · 963 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { isAlphabetic } from '../../util/Char';
import { createSimpleTransformer } from '../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).
*
* **Application order**
*
* It is recommended that this transformer be applied near the end of the
* transformer chain.
*
* @example
* ```typescript
* const transformer = resolveLeetSpeakTransformer();
* const matcher = new RegExpMatcher({ ..., blacklistMatcherTransformers: [transformer] });
* ```
*
* @returns A container holding the transformer, which can then be passed to the
* [[RegExpMatcher]] or the [[NfaMatcher]].
*/
export function skipNonAlphabeticTransformer() {
return createSimpleTransformer((c) => (isAlphabetic(c) ? c : undefined));
}