( matcher: TextMatch, text: string | undefined, normalizer: NormalizerFn = getDefaultNormalizer(), exact: boolean = true, )
| 7 | }; |
| 8 | |
| 9 | export function matches( |
| 10 | matcher: TextMatch, |
| 11 | text: string | undefined, |
| 12 | normalizer: NormalizerFn = getDefaultNormalizer(), |
| 13 | exact: boolean = true, |
| 14 | ): boolean { |
| 15 | if (typeof text !== 'string') { |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | const normalizedText = normalizer(text); |
| 20 | if (typeof matcher === 'string') { |
| 21 | const normalizedMatcher = normalizer(matcher); |
| 22 | return exact |
| 23 | ? normalizedText === normalizedMatcher |
| 24 | : normalizedText.toLowerCase().includes(normalizedMatcher.toLowerCase()); |
| 25 | } else { |
| 26 | // Reset state for global regexes: https://stackoverflow.com/a/1520839/484499 |
| 27 | matcher.lastIndex = 0; |
| 28 | return matcher.test(normalizedText); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | type NormalizerConfig = { |
| 33 | trim?: boolean; |
no test coverage detected
searching dependent graphs…