1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.matchAnyPattern = exports.extractTerms = exports.repeatedTimeunitPattern = void 0;
|
4 | function repeatedTimeunitPattern(prefix, singleTimeunitPattern) {
|
5 | const singleTimeunitPatternNoCapture = singleTimeunitPattern.replace(/\((?!\?)/g, "(?:");
|
6 | return `${prefix}${singleTimeunitPatternNoCapture}\\s{0,5}(?:,?\\s{0,5}${singleTimeunitPatternNoCapture}){0,10}`;
|
7 | }
|
8 | exports.repeatedTimeunitPattern = repeatedTimeunitPattern;
|
9 | function extractTerms(dictionary) {
|
10 | let keys;
|
11 | if (dictionary instanceof Array) {
|
12 | keys = [...dictionary];
|
13 | }
|
14 | else if (dictionary instanceof Map) {
|
15 | keys = Array.from(dictionary.keys());
|
16 | }
|
17 | else {
|
18 | keys = Object.keys(dictionary);
|
19 | }
|
20 | return keys;
|
21 | }
|
22 | exports.extractTerms = extractTerms;
|
23 | function matchAnyPattern(dictionary) {
|
24 | const joinedTerms = extractTerms(dictionary)
|
25 | .sort((a, b) => b.length - a.length)
|
26 | .join("|")
|
27 | .replace(/\./g, "\\.");
|
28 | return `(?:${joinedTerms})`;
|
29 | }
|
30 | exports.matchAnyPattern = matchAnyPattern;
|