@push.rocks/smartmatch 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.smartconfig.json +5 -4
- package/dist_bundle/bundle.js +51 -4
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/index.js +65 -8
- package/package.json +7 -10
- package/readme.md +1 -1
- package/ts/00_commitinfo_data.ts +2 -2
- package/ts/index.ts +71 -7
package/.smartconfig.json
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
"githost": "code.foss.global",
|
|
6
6
|
"gitscope": "push.rocks",
|
|
7
7
|
"gitrepo": "smartmatch",
|
|
8
|
-
"description": "A minimal
|
|
8
|
+
"description": "A minimal, linear-time library for case-insensitive wildcard string matching.",
|
|
9
9
|
"npmPackagename": "@push.rocks/smartmatch",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"projectDomain": "push.rocks",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"match",
|
|
14
|
-
"regexp",
|
|
15
14
|
"matching library",
|
|
16
15
|
"string matching",
|
|
17
16
|
"wildcards",
|
|
@@ -40,8 +39,10 @@
|
|
|
40
39
|
},
|
|
41
40
|
"schemaVersion": 2
|
|
42
41
|
},
|
|
43
|
-
"@git.zone/
|
|
44
|
-
"
|
|
42
|
+
"@git.zone/tsrepo": {
|
|
43
|
+
"docs": {
|
|
44
|
+
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license.md](./license.md) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
|
45
|
+
}
|
|
45
46
|
},
|
|
46
47
|
"@ship.zone/szci": {
|
|
47
48
|
"npmGlobalTools": []
|
package/dist_bundle/bundle.js
CHANGED
|
@@ -2,6 +2,54 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// ts/index.ts
|
|
5
|
+
var STAR = 42;
|
|
6
|
+
var BANG = 33;
|
|
7
|
+
var canonicalize = /* @__PURE__ */ __name((codeUnit) => {
|
|
8
|
+
if (codeUnit < 128) {
|
|
9
|
+
return codeUnit >= 97 && codeUnit <= 122 ? codeUnit - 32 : codeUnit;
|
|
10
|
+
}
|
|
11
|
+
const upper = String.fromCharCode(codeUnit).toUpperCase();
|
|
12
|
+
if (upper.length !== 1) {
|
|
13
|
+
return codeUnit;
|
|
14
|
+
}
|
|
15
|
+
const upperCodeUnit = upper.charCodeAt(0);
|
|
16
|
+
return upperCodeUnit < 128 ? codeUnit : upperCodeUnit;
|
|
17
|
+
}, "canonicalize");
|
|
18
|
+
var codeUnitsMatch = /* @__PURE__ */ __name((patternUnit, inputUnit) => patternUnit === inputUnit || canonicalize(patternUnit) === canonicalize(inputUnit), "codeUnitsMatch");
|
|
19
|
+
var matchWildcard = /* @__PURE__ */ __name((wildcard, start, input) => {
|
|
20
|
+
const patternEnd = wildcard.length;
|
|
21
|
+
const inputEnd = input.length;
|
|
22
|
+
let patternIndex = start;
|
|
23
|
+
let inputIndex = 0;
|
|
24
|
+
let starPatternIndex = -1;
|
|
25
|
+
let starInputIndex = 0;
|
|
26
|
+
while (inputIndex < inputEnd) {
|
|
27
|
+
if (patternIndex < patternEnd) {
|
|
28
|
+
const patternUnit = wildcard.charCodeAt(patternIndex);
|
|
29
|
+
if (patternUnit === STAR) {
|
|
30
|
+
starPatternIndex = patternIndex;
|
|
31
|
+
starInputIndex = inputIndex;
|
|
32
|
+
patternIndex++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (codeUnitsMatch(patternUnit, input.charCodeAt(inputIndex))) {
|
|
36
|
+
patternIndex++;
|
|
37
|
+
inputIndex++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (starPatternIndex === -1) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
patternIndex = starPatternIndex + 1;
|
|
45
|
+
starInputIndex++;
|
|
46
|
+
inputIndex = starInputIndex;
|
|
47
|
+
}
|
|
48
|
+
while (patternIndex < patternEnd && wildcard.charCodeAt(patternIndex) === STAR) {
|
|
49
|
+
patternIndex++;
|
|
50
|
+
}
|
|
51
|
+
return patternIndex === patternEnd;
|
|
52
|
+
}, "matchWildcard");
|
|
5
53
|
var SmartMatch = class {
|
|
6
54
|
static {
|
|
7
55
|
__name(this, "SmartMatch");
|
|
@@ -10,10 +58,9 @@ var SmartMatch = class {
|
|
|
10
58
|
this.wildcard = wildcardArg;
|
|
11
59
|
}
|
|
12
60
|
match(matchStringArg) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const matches = new RegExp(`^${pattern}$`, "i").test(matchStringArg);
|
|
61
|
+
const wildcard = this.wildcard;
|
|
62
|
+
const negated = wildcard.charCodeAt(0) === BANG;
|
|
63
|
+
const matches = matchWildcard(wildcard, negated ? 1 : 0, `${matchStringArg}`);
|
|
17
64
|
return negated ? !matches : matches;
|
|
18
65
|
}
|
|
19
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../ts/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../ts/index.ts"],"sourcesContent":["const STAR = 0x2a;\nconst BANG = 0x21;\n\n/**\n * Case-folds one UTF-16 code unit exactly like ECMA-262's Canonicalize for a\n * RegExp with the `i` flag and without `u` or `v`: upper-case the code unit,\n * keep it when the upper-case form is not a single code unit, and keep it when\n * a code unit at or above U+0080 would fold below U+0080.\n */\nconst canonicalize = (codeUnit: number): number => {\n if (codeUnit < 0x80) {\n return codeUnit >= 0x61 && codeUnit <= 0x7a ? codeUnit - 0x20 : codeUnit;\n }\n const upper = String.fromCharCode(codeUnit).toUpperCase();\n if (upper.length !== 1) {\n return codeUnit;\n }\n const upperCodeUnit = upper.charCodeAt(0);\n return upperCodeUnit < 0x80 ? codeUnit : upperCodeUnit;\n};\n\nconst codeUnitsMatch = (patternUnit: number, inputUnit: number): boolean =>\n patternUnit === inputUnit || canonicalize(patternUnit) === canonicalize(inputUnit);\n\n/**\n * Matches the whole input against a wildcard in which `*` matches any sequence\n * of code units and every other code unit is literal. Iterative, with a single\n * restart point for the most recent `*`: O(pattern x input) time and constant\n * extra memory.\n */\nconst matchWildcard = (wildcard: string, start: number, input: string): boolean => {\n const patternEnd = wildcard.length;\n const inputEnd = input.length;\n let patternIndex = start;\n let inputIndex = 0;\n let starPatternIndex = -1;\n let starInputIndex = 0;\n\n while (inputIndex < inputEnd) {\n if (patternIndex < patternEnd) {\n const patternUnit = wildcard.charCodeAt(patternIndex);\n if (patternUnit === STAR) {\n starPatternIndex = patternIndex;\n starInputIndex = inputIndex;\n patternIndex++;\n continue;\n }\n if (codeUnitsMatch(patternUnit, input.charCodeAt(inputIndex))) {\n patternIndex++;\n inputIndex++;\n continue;\n }\n }\n if (starPatternIndex === -1) {\n return false;\n }\n patternIndex = starPatternIndex + 1;\n starInputIndex++;\n inputIndex = starInputIndex;\n }\n\n while (patternIndex < patternEnd && wildcard.charCodeAt(patternIndex) === STAR) {\n patternIndex++;\n }\n return patternIndex === patternEnd;\n};\n\nexport class SmartMatch {\n public wildcard: string;\n constructor(wildcardArg: string) {\n this.wildcard = wildcardArg;\n }\n\n public match(matchStringArg: string): boolean {\n const wildcard = this.wildcard;\n const negated = wildcard.charCodeAt(0) === BANG;\n // A plain-JavaScript caller may pass a non-string; convert it as the RegExp engine did (ToString).\n const matches = matchWildcard(wildcard, negated ? 1 : 0, `${matchStringArg}`);\n return negated ? !matches : matches;\n }\n}\n"],"mappings":";;;;AAAA,IAAM,OAAO;AACb,IAAM,OAAO;AAQb,IAAM,eAAe,wBAAC,aAA6B;AACjD,MAAI,WAAW,KAAM;AACnB,WAAO,YAAY,MAAQ,YAAY,MAAO,WAAW,KAAO;AAAA,EAClE;AACA,QAAM,QAAQ,OAAO,aAAa,QAAQ,EAAE,YAAY;AACxD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AACA,QAAM,gBAAgB,MAAM,WAAW,CAAC;AACxC,SAAO,gBAAgB,MAAO,WAAW;AAC3C,GAVqB;AAYrB,IAAM,iBAAiB,wBAAC,aAAqB,cAC3C,gBAAgB,aAAa,aAAa,WAAW,MAAM,aAAa,SAAS,GAD5D;AASvB,IAAM,gBAAgB,wBAAC,UAAkB,OAAe,UAA2B;AACjF,QAAM,aAAa,SAAS;AAC5B,QAAM,WAAW,MAAM;AACvB,MAAI,eAAe;AACnB,MAAI,aAAa;AACjB,MAAI,mBAAmB;AACvB,MAAI,iBAAiB;AAErB,SAAO,aAAa,UAAU;AAC5B,QAAI,eAAe,YAAY;AAC7B,YAAM,cAAc,SAAS,WAAW,YAAY;AACpD,UAAI,gBAAgB,MAAM;AACxB,2BAAmB;AACnB,yBAAiB;AACjB;AACA;AAAA,MACF;AACA,UAAI,eAAe,aAAa,MAAM,WAAW,UAAU,CAAC,GAAG;AAC7D;AACA;AACA;AAAA,MACF;AAAA,IACF;AACA,QAAI,qBAAqB,IAAI;AAC3B,aAAO;AAAA,IACT;AACA,mBAAe,mBAAmB;AAClC;AACA,iBAAa;AAAA,EACf;AAEA,SAAO,eAAe,cAAc,SAAS,WAAW,YAAY,MAAM,MAAM;AAC9E;AAAA,EACF;AACA,SAAO,iBAAiB;AAC1B,GAnCsB;AAqCf,IAAM,aAAN,MAAiB;AAAA,EAnExB,OAmEwB;AAAA;AAAA;AAAA,EAEtB,YAAY,aAAqB;AAC/B,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,MAAM,gBAAiC;AAC5C,UAAM,WAAW,KAAK;AACtB,UAAM,UAAU,SAAS,WAAW,CAAC,MAAM;AAE3C,UAAM,UAAU,cAAc,UAAU,UAAU,IAAI,GAAG,GAAG,cAAc,EAAE;AAC5E,WAAO,UAAU,CAAC,UAAU;AAAA,EAC9B;AACF;","names":[],"file":"bundle.js"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartmatch',
|
|
6
|
-
version: '2.0.
|
|
7
|
-
description: 'A minimal
|
|
6
|
+
version: '2.0.3',
|
|
7
|
+
description: 'A minimal, linear-time library for case-insensitive wildcard string matching.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtFQUErRTtDQUM3RixDQUFBIn0=
|
package/dist_ts/index.js
CHANGED
|
@@ -1,16 +1,73 @@
|
|
|
1
|
+
const STAR = 0x2a;
|
|
2
|
+
const BANG = 0x21;
|
|
3
|
+
/**
|
|
4
|
+
* Case-folds one UTF-16 code unit exactly like ECMA-262's Canonicalize for a
|
|
5
|
+
* RegExp with the `i` flag and without `u` or `v`: upper-case the code unit,
|
|
6
|
+
* keep it when the upper-case form is not a single code unit, and keep it when
|
|
7
|
+
* a code unit at or above U+0080 would fold below U+0080.
|
|
8
|
+
*/
|
|
9
|
+
const canonicalize = (codeUnit) => {
|
|
10
|
+
if (codeUnit < 0x80) {
|
|
11
|
+
return codeUnit >= 0x61 && codeUnit <= 0x7a ? codeUnit - 0x20 : codeUnit;
|
|
12
|
+
}
|
|
13
|
+
const upper = String.fromCharCode(codeUnit).toUpperCase();
|
|
14
|
+
if (upper.length !== 1) {
|
|
15
|
+
return codeUnit;
|
|
16
|
+
}
|
|
17
|
+
const upperCodeUnit = upper.charCodeAt(0);
|
|
18
|
+
return upperCodeUnit < 0x80 ? codeUnit : upperCodeUnit;
|
|
19
|
+
};
|
|
20
|
+
const codeUnitsMatch = (patternUnit, inputUnit) => patternUnit === inputUnit || canonicalize(patternUnit) === canonicalize(inputUnit);
|
|
21
|
+
/**
|
|
22
|
+
* Matches the whole input against a wildcard in which `*` matches any sequence
|
|
23
|
+
* of code units and every other code unit is literal. Iterative, with a single
|
|
24
|
+
* restart point for the most recent `*`: O(pattern x input) time and constant
|
|
25
|
+
* extra memory.
|
|
26
|
+
*/
|
|
27
|
+
const matchWildcard = (wildcard, start, input) => {
|
|
28
|
+
const patternEnd = wildcard.length;
|
|
29
|
+
const inputEnd = input.length;
|
|
30
|
+
let patternIndex = start;
|
|
31
|
+
let inputIndex = 0;
|
|
32
|
+
let starPatternIndex = -1;
|
|
33
|
+
let starInputIndex = 0;
|
|
34
|
+
while (inputIndex < inputEnd) {
|
|
35
|
+
if (patternIndex < patternEnd) {
|
|
36
|
+
const patternUnit = wildcard.charCodeAt(patternIndex);
|
|
37
|
+
if (patternUnit === STAR) {
|
|
38
|
+
starPatternIndex = patternIndex;
|
|
39
|
+
starInputIndex = inputIndex;
|
|
40
|
+
patternIndex++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (codeUnitsMatch(patternUnit, input.charCodeAt(inputIndex))) {
|
|
44
|
+
patternIndex++;
|
|
45
|
+
inputIndex++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (starPatternIndex === -1) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
patternIndex = starPatternIndex + 1;
|
|
53
|
+
starInputIndex++;
|
|
54
|
+
inputIndex = starInputIndex;
|
|
55
|
+
}
|
|
56
|
+
while (patternIndex < patternEnd && wildcard.charCodeAt(patternIndex) === STAR) {
|
|
57
|
+
patternIndex++;
|
|
58
|
+
}
|
|
59
|
+
return patternIndex === patternEnd;
|
|
60
|
+
};
|
|
1
61
|
export class SmartMatch {
|
|
2
62
|
constructor(wildcardArg) {
|
|
3
63
|
this.wildcard = wildcardArg;
|
|
4
64
|
}
|
|
5
65
|
match(matchStringArg) {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.replace(/-/g, '\\x2d')
|
|
11
|
-
.replace(/\\\*/g, '[\\s\\S]*');
|
|
12
|
-
const matches = new RegExp(`^${pattern}$`, 'i').test(matchStringArg);
|
|
66
|
+
const wildcard = this.wildcard;
|
|
67
|
+
const negated = wildcard.charCodeAt(0) === BANG;
|
|
68
|
+
// A plain-JavaScript caller may pass a non-string; convert it as the RegExp engine did (ToString).
|
|
69
|
+
const matches = matchWildcard(wildcard, negated ? 1 : 0, `${matchStringArg}`);
|
|
13
70
|
return negated ? !matches : matches;
|
|
14
71
|
}
|
|
15
72
|
}
|
|
16
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmd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QsT0FBTyxZQUFZLEdBQUcsVUFBVSxJQUFJLFFBQVEsQ0FBQyxVQUFVLENBQUMsWUFBWSxDQUFDLEtBQUssSUFBSSxFQUFFLENBQUM7UUFDL0UsWUFBWSxFQUFFLENBQUM7SUFDakIsQ0FBQztJQUNELE9BQU8sWUFBWSxLQUFLLFVBQVUsQ0FBQztBQUNyQyxDQUFDLENBQUM7QUFFRixNQUFNLE9BQU8sVUFBVTtJQUVyQixZQUFZLFdBQW1CO1FBQzdCLElBQUksQ0FBQyxRQUFRLEdBQUcsV0FBVyxDQUFDO0lBQzlCLENBQUM7SUFFTSxLQUFLLENBQUMsY0FBc0I7UUFDakMsTUFBTSxRQUFRLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQztRQUMvQixNQUFNLE9BQU8sR0FBRyxRQUFRLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQyxLQUFLLElBQUksQ0FBQztRQUNoRCxtR0FBbUc7UUFDbkcsTUFBTSxPQUFPLEdBQUcsYUFBYSxDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxFQUFFLEdBQUcsY0FBYyxFQUFFLENBQUMsQ0FBQztRQUM5RSxPQUFPLE9BQU8sQ0FBQyxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLE9BQU8sQ0FBQztJQUN0QyxDQUFDO0NBQ0YifQ==
|
package/package.json
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartmatch",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "A minimal
|
|
5
|
+
"description": "A minimal, linear-time library for case-insensitive wildcard string matching.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
|
7
7
|
"typings": "dist_ts/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"author": "Lossless GmbH",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@git.zone/
|
|
13
|
-
"@
|
|
14
|
-
"@git.zone/tstest": "^7.2.0",
|
|
15
|
-
"@types/node": "26.6.4"
|
|
12
|
+
"@git.zone/tsrepo": "^2.2.0",
|
|
13
|
+
"@types/node": "26.6.6"
|
|
16
14
|
},
|
|
17
15
|
"dependencies": {},
|
|
18
16
|
"files": [
|
|
@@ -32,7 +30,6 @@
|
|
|
32
30
|
],
|
|
33
31
|
"keywords": [
|
|
34
32
|
"match",
|
|
35
|
-
"regexp",
|
|
36
33
|
"matching library",
|
|
37
34
|
"string matching",
|
|
38
35
|
"wildcards",
|
|
@@ -45,9 +42,9 @@
|
|
|
45
42
|
"url": "https://code.foss.global/push.rocks/smartmatch.git"
|
|
46
43
|
},
|
|
47
44
|
"scripts": {
|
|
48
|
-
"test": "(
|
|
49
|
-
"build": "(
|
|
45
|
+
"test": "(tsrepo test test/)",
|
|
46
|
+
"build": "(tsrepo build && tsrepo bundle npm)",
|
|
50
47
|
"format": "(gitzone format)",
|
|
51
|
-
"buildDocs": "
|
|
48
|
+
"buildDocs": "(tsrepo docs)"
|
|
52
49
|
}
|
|
53
50
|
}
|
package/readme.md
CHANGED
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartmatch',
|
|
6
|
-
version: '2.0.
|
|
7
|
-
description: 'A minimal
|
|
6
|
+
version: '2.0.3',
|
|
7
|
+
description: 'A minimal, linear-time library for case-insensitive wildcard string matching.'
|
|
8
8
|
}
|
package/ts/index.ts
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
+
const STAR = 0x2a;
|
|
2
|
+
const BANG = 0x21;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Case-folds one UTF-16 code unit exactly like ECMA-262's Canonicalize for a
|
|
6
|
+
* RegExp with the `i` flag and without `u` or `v`: upper-case the code unit,
|
|
7
|
+
* keep it when the upper-case form is not a single code unit, and keep it when
|
|
8
|
+
* a code unit at or above U+0080 would fold below U+0080.
|
|
9
|
+
*/
|
|
10
|
+
const canonicalize = (codeUnit: number): number => {
|
|
11
|
+
if (codeUnit < 0x80) {
|
|
12
|
+
return codeUnit >= 0x61 && codeUnit <= 0x7a ? codeUnit - 0x20 : codeUnit;
|
|
13
|
+
}
|
|
14
|
+
const upper = String.fromCharCode(codeUnit).toUpperCase();
|
|
15
|
+
if (upper.length !== 1) {
|
|
16
|
+
return codeUnit;
|
|
17
|
+
}
|
|
18
|
+
const upperCodeUnit = upper.charCodeAt(0);
|
|
19
|
+
return upperCodeUnit < 0x80 ? codeUnit : upperCodeUnit;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const codeUnitsMatch = (patternUnit: number, inputUnit: number): boolean =>
|
|
23
|
+
patternUnit === inputUnit || canonicalize(patternUnit) === canonicalize(inputUnit);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Matches the whole input against a wildcard in which `*` matches any sequence
|
|
27
|
+
* of code units and every other code unit is literal. Iterative, with a single
|
|
28
|
+
* restart point for the most recent `*`: O(pattern x input) time and constant
|
|
29
|
+
* extra memory.
|
|
30
|
+
*/
|
|
31
|
+
const matchWildcard = (wildcard: string, start: number, input: string): boolean => {
|
|
32
|
+
const patternEnd = wildcard.length;
|
|
33
|
+
const inputEnd = input.length;
|
|
34
|
+
let patternIndex = start;
|
|
35
|
+
let inputIndex = 0;
|
|
36
|
+
let starPatternIndex = -1;
|
|
37
|
+
let starInputIndex = 0;
|
|
38
|
+
|
|
39
|
+
while (inputIndex < inputEnd) {
|
|
40
|
+
if (patternIndex < patternEnd) {
|
|
41
|
+
const patternUnit = wildcard.charCodeAt(patternIndex);
|
|
42
|
+
if (patternUnit === STAR) {
|
|
43
|
+
starPatternIndex = patternIndex;
|
|
44
|
+
starInputIndex = inputIndex;
|
|
45
|
+
patternIndex++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (codeUnitsMatch(patternUnit, input.charCodeAt(inputIndex))) {
|
|
49
|
+
patternIndex++;
|
|
50
|
+
inputIndex++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (starPatternIndex === -1) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
patternIndex = starPatternIndex + 1;
|
|
58
|
+
starInputIndex++;
|
|
59
|
+
inputIndex = starInputIndex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
while (patternIndex < patternEnd && wildcard.charCodeAt(patternIndex) === STAR) {
|
|
63
|
+
patternIndex++;
|
|
64
|
+
}
|
|
65
|
+
return patternIndex === patternEnd;
|
|
66
|
+
};
|
|
67
|
+
|
|
1
68
|
export class SmartMatch {
|
|
2
69
|
public wildcard: string;
|
|
3
70
|
constructor(wildcardArg: string) {
|
|
@@ -5,13 +72,10 @@ export class SmartMatch {
|
|
|
5
72
|
}
|
|
6
73
|
|
|
7
74
|
public match(matchStringArg: string): boolean {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.replace(/-/g, '\\x2d')
|
|
13
|
-
.replace(/\\\*/g, '[\\s\\S]*');
|
|
14
|
-
const matches = new RegExp(`^${pattern}$`, 'i').test(matchStringArg);
|
|
75
|
+
const wildcard = this.wildcard;
|
|
76
|
+
const negated = wildcard.charCodeAt(0) === BANG;
|
|
77
|
+
// A plain-JavaScript caller may pass a non-string; convert it as the RegExp engine did (ToString).
|
|
78
|
+
const matches = matchWildcard(wildcard, negated ? 1 : 0, `${matchStringArg}`);
|
|
15
79
|
return negated ? !matches : matches;
|
|
16
80
|
}
|
|
17
81
|
}
|