1 | export function repeatedTimeunitPattern(prefix, singleTimeunitPattern, connectorPattern = "\\s{0,5},?\\s{0,5}") {
|
2 | const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:");
|
3 | return `${prefix}${singleTimeunitPatternNoCapture}(?:${connectorPattern}${singleTimeunitPatternNoCapture}){0,10}`;
|
4 | }
|
5 | export function extractTerms(dictionary) {
|
6 | let keys;
|
7 | if (dictionary instanceof Array) {
|
8 | keys = [...dictionary];
|
9 | }
|
10 | else if (dictionary instanceof Map) {
|
11 | keys = Array.from(dictionary.keys());
|
12 | }
|
13 | else {
|
14 | keys = Object.keys(dictionary);
|
15 | }
|
16 | return keys;
|
17 | }
|
18 | export function matchAnyPattern(dictionary) {
|
19 | const joinedTerms = extractTerms(dictionary)
|
20 | .sort((a, b) => b.length - a.length)
|
21 | .join("|")
|
22 | .replace(/\./g, "\\.");
|
23 | return `(?:${joinedTerms})`;
|
24 | }
|
25 |
|
\ | No newline at end of file |