* Constructs a normalizer to pass to functions in matches.js * @param {boolean|undefined} trim The user-specified value for `trim`, without * any defaulting having been applied * @param {boolean|undefined} collapseWhitespace The user-specified value for * `collapseWhitespace`, without any defaul
({
trim,
collapseWhitespace,
normalizer,
}: NormalizerOptions)
| 87 | */ |
| 88 | |
| 89 | function makeNormalizer({ |
| 90 | trim, |
| 91 | collapseWhitespace, |
| 92 | normalizer, |
| 93 | }: NormalizerOptions) { |
| 94 | if (!normalizer) { |
| 95 | // No custom normalizer specified. Just use default. |
| 96 | return getDefaultNormalizer({trim, collapseWhitespace}) |
| 97 | } |
| 98 | |
| 99 | if ( |
| 100 | typeof trim !== 'undefined' || |
| 101 | typeof collapseWhitespace !== 'undefined' |
| 102 | ) { |
| 103 | // They've also specified a value for trim or collapseWhitespace |
| 104 | throw new Error( |
| 105 | 'trim and collapseWhitespace are not supported with a normalizer. ' + |
| 106 | 'If you want to use the default trim and collapseWhitespace logic in your normalizer, ' + |
| 107 | 'use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer', |
| 108 | ) |
| 109 | } |
| 110 | |
| 111 | return normalizer |
| 112 | } |
| 113 | |
| 114 | function matchRegExp(matcher: RegExp, text: string) { |
| 115 | const match = matcher.test(text) |
no test coverage detected