@push.rocks/smartmatch 2.0.0 → 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 +50 -0
- package/dist_bundle/bundle.js +50 -95
- package/dist_bundle/bundle.js.map +1 -7
- package/dist_ts/00_commitinfo_data.d.ts +1 -1
- package/dist_ts/00_commitinfo_data.js +5 -5
- package/dist_ts/index.js +66 -3
- package/dist_ts/smartmatch.plugins.d.ts +1 -2
- package/dist_ts/smartmatch.plugins.js +2 -4
- package/package.json +26 -18
- package/readme.md +101 -31
- package/ts/00_commitinfo_data.ts +4 -4
- package/ts/index.ts +71 -2
- package/ts/smartmatch.plugins.ts +1 -4
- package/npmextra.json +0 -18
- /package/{license → license.md} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@git.zone/cli": {
|
|
3
|
+
"projectType": "npm",
|
|
4
|
+
"module": {
|
|
5
|
+
"githost": "code.foss.global",
|
|
6
|
+
"gitscope": "push.rocks",
|
|
7
|
+
"gitrepo": "smartmatch",
|
|
8
|
+
"description": "A minimal, linear-time library for case-insensitive wildcard string matching.",
|
|
9
|
+
"npmPackagename": "@push.rocks/smartmatch",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"projectDomain": "push.rocks",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"match",
|
|
14
|
+
"matching library",
|
|
15
|
+
"string matching",
|
|
16
|
+
"wildcards",
|
|
17
|
+
"typescript",
|
|
18
|
+
"npm package"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"release": {
|
|
22
|
+
"targets": {
|
|
23
|
+
"git": {
|
|
24
|
+
"enabled": true,
|
|
25
|
+
"remote": "origin",
|
|
26
|
+
"pushBranch": true,
|
|
27
|
+
"pushTags": true
|
|
28
|
+
},
|
|
29
|
+
"npm": {
|
|
30
|
+
"enabled": true,
|
|
31
|
+
"registries": [
|
|
32
|
+
"https://verdaccio.lossless.digital",
|
|
33
|
+
"https://registry.npmjs.org"
|
|
34
|
+
],
|
|
35
|
+
"accessLevel": "public",
|
|
36
|
+
"alreadyPublished": "success"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"schemaVersion": 2
|
|
41
|
+
},
|
|
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
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"@ship.zone/szci": {
|
|
48
|
+
"npmGlobalTools": []
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist_bundle/bundle.js
CHANGED
|
@@ -1,112 +1,67 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// node_modules/matcher/index.js
|
|
8
|
-
var matcher_exports = {};
|
|
9
|
-
__export(matcher_exports, {
|
|
10
|
-
isMatch: () => isMatch,
|
|
11
|
-
matcher: () => matcher
|
|
12
|
-
});
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
3
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// node_modules/matcher/index.js
|
|
23
|
-
var regexpCache = /* @__PURE__ */ new Map();
|
|
24
|
-
var sanitizeArray = (input, inputName) => {
|
|
25
|
-
if (!Array.isArray(input)) {
|
|
26
|
-
switch (typeof input) {
|
|
27
|
-
case "string":
|
|
28
|
-
input = [input];
|
|
29
|
-
break;
|
|
30
|
-
case "undefined":
|
|
31
|
-
input = [];
|
|
32
|
-
break;
|
|
33
|
-
default:
|
|
34
|
-
throw new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);
|
|
35
|
-
}
|
|
11
|
+
const upper = String.fromCharCode(codeUnit).toUpperCase();
|
|
12
|
+
if (upper.length !== 1) {
|
|
13
|
+
return codeUnit;
|
|
36
14
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
var makeRegexp = (pattern, options) => {
|
|
48
|
-
options = {
|
|
49
|
-
caseSensitive: false,
|
|
50
|
-
...options
|
|
51
|
-
};
|
|
52
|
-
const cacheKey = pattern + JSON.stringify(options);
|
|
53
|
-
if (regexpCache.has(cacheKey)) {
|
|
54
|
-
return regexpCache.get(cacheKey);
|
|
55
|
-
}
|
|
56
|
-
const negated = pattern[0] === "!";
|
|
57
|
-
if (negated) {
|
|
58
|
-
pattern = pattern.slice(1);
|
|
59
|
-
}
|
|
60
|
-
pattern = escapeStringRegexp(pattern).replace(/\\\*/g, "[\\s\\S]*");
|
|
61
|
-
const regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? "" : "i");
|
|
62
|
-
regexp.negated = negated;
|
|
63
|
-
regexpCache.set(cacheKey, regexp);
|
|
64
|
-
return regexp;
|
|
65
|
-
};
|
|
66
|
-
var baseMatcher = (inputs, patterns, options, firstMatchOnly) => {
|
|
67
|
-
inputs = sanitizeArray(inputs, "inputs");
|
|
68
|
-
patterns = sanitizeArray(patterns, "patterns");
|
|
69
|
-
if (patterns.length === 0) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
patterns = patterns.map((pattern) => makeRegexp(pattern, options));
|
|
73
|
-
const { allPatterns } = options || {};
|
|
74
|
-
const result = [];
|
|
75
|
-
for (const input of inputs) {
|
|
76
|
-
let matches;
|
|
77
|
-
const didFit = [...patterns].fill(false);
|
|
78
|
-
for (const [index, pattern] of patterns.entries()) {
|
|
79
|
-
if (pattern.test(input)) {
|
|
80
|
-
didFit[index] = true;
|
|
81
|
-
matches = !pattern.negated;
|
|
82
|
-
if (!matches) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
35
|
+
if (codeUnitsMatch(patternUnit, input.charCodeAt(inputIndex))) {
|
|
36
|
+
patternIndex++;
|
|
37
|
+
inputIndex++;
|
|
38
|
+
continue;
|
|
85
39
|
}
|
|
86
40
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
if (firstMatchOnly) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
41
|
+
if (starPatternIndex === -1) {
|
|
42
|
+
return false;
|
|
92
43
|
}
|
|
44
|
+
patternIndex = starPatternIndex + 1;
|
|
45
|
+
starInputIndex++;
|
|
46
|
+
inputIndex = starInputIndex;
|
|
93
47
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
function isMatch(inputs, patterns, options) {
|
|
100
|
-
return baseMatcher(inputs, patterns, options, true).length > 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// ts/index.ts
|
|
48
|
+
while (patternIndex < patternEnd && wildcard.charCodeAt(patternIndex) === STAR) {
|
|
49
|
+
patternIndex++;
|
|
50
|
+
}
|
|
51
|
+
return patternIndex === patternEnd;
|
|
52
|
+
}, "matchWildcard");
|
|
104
53
|
var SmartMatch = class {
|
|
54
|
+
static {
|
|
55
|
+
__name(this, "SmartMatch");
|
|
56
|
+
}
|
|
105
57
|
constructor(wildcardArg) {
|
|
106
58
|
this.wildcard = wildcardArg;
|
|
107
59
|
}
|
|
108
60
|
match(matchStringArg) {
|
|
109
|
-
|
|
61
|
+
const wildcard = this.wildcard;
|
|
62
|
+
const negated = wildcard.charCodeAt(0) === BANG;
|
|
63
|
+
const matches = matchWildcard(wildcard, negated ? 1 : 0, `${matchStringArg}`);
|
|
64
|
+
return negated ? !matches : matches;
|
|
110
65
|
}
|
|
111
66
|
};
|
|
112
67
|
export {
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../node_modules/matcher/index.js", "../node_modules/matcher/node_modules/escape-string-regexp/index.js", "../ts/index.ts"],
|
|
4
|
-
"sourcesContent": ["import escapeStringRegexp from 'escape-string-regexp';\n\nconst regexpCache = new Map();\n\nconst sanitizeArray = (input, inputName) => {\n\tif (!Array.isArray(input)) {\n\t\tswitch (typeof input) {\n\t\t\tcase 'string':\n\t\t\t\tinput = [input];\n\t\t\t\tbreak;\n\t\t\tcase 'undefined':\n\t\t\t\tinput = [];\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new TypeError(`Expected '${inputName}' to be a string or an array, but got a type of '${typeof input}'`);\n\t\t}\n\t}\n\n\treturn input.filter(string => {\n\t\tif (typeof string !== 'string') {\n\t\t\tif (typeof string === 'undefined') {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tthrow new TypeError(`Expected '${inputName}' to be an array of strings, but found a type of '${typeof string}' in the array`);\n\t\t}\n\n\t\treturn true;\n\t});\n};\n\nconst makeRegexp = (pattern, options) => {\n\toptions = {\n\t\tcaseSensitive: false,\n\t\t...options,\n\t};\n\n\tconst cacheKey = pattern + JSON.stringify(options);\n\n\tif (regexpCache.has(cacheKey)) {\n\t\treturn regexpCache.get(cacheKey);\n\t}\n\n\tconst negated = pattern[0] === '!';\n\n\tif (negated) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tpattern = escapeStringRegexp(pattern).replace(/\\\\\\*/g, '[\\\\s\\\\S]*');\n\n\tconst regexp = new RegExp(`^${pattern}$`, options.caseSensitive ? '' : 'i');\n\tregexp.negated = negated;\n\tregexpCache.set(cacheKey, regexp);\n\n\treturn regexp;\n};\n\nconst baseMatcher = (inputs, patterns, options, firstMatchOnly) => {\n\tinputs = sanitizeArray(inputs, 'inputs');\n\tpatterns = sanitizeArray(patterns, 'patterns');\n\n\tif (patterns.length === 0) {\n\t\treturn [];\n\t}\n\n\tpatterns = patterns.map(pattern => makeRegexp(pattern, options));\n\n\tconst {allPatterns} = options || {};\n\tconst result = [];\n\n\tfor (const input of inputs) {\n\t\t// String is included only if it matches at least one non-negated pattern supplied.\n\t\t// Note: the `allPatterns` option requires every non-negated pattern to be matched once.\n\t\t// Matching a negated pattern excludes the string.\n\t\tlet matches;\n\t\tconst didFit = [...patterns].fill(false);\n\n\t\tfor (const [index, pattern] of patterns.entries()) {\n\t\t\tif (pattern.test(input)) {\n\t\t\t\tdidFit[index] = true;\n\t\t\t\tmatches = !pattern.negated;\n\n\t\t\t\tif (!matches) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\t!(\n\t\t\t\tmatches === false\n\t\t\t\t|| (matches === undefined && patterns.some(pattern => !pattern.negated))\n\t\t\t\t|| (allPatterns && didFit.some((yes, index) => !yes && !patterns[index].negated))\n\t\t\t)\n\t\t) {\n\t\t\tresult.push(input);\n\n\t\t\tif (firstMatchOnly) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n};\n\nexport function matcher(inputs, patterns, options) {\n\treturn baseMatcher(inputs, patterns, options, false);\n}\n\nexport function isMatch(inputs, patterns, options) {\n\treturn baseMatcher(inputs, patterns, options, true).length > 0;\n}\n", "export default function escapeStringRegexp(string) {\n\tif (typeof string !== 'string') {\n\t\tthrow new TypeError('Expected a string');\n\t}\n\n\t// Escape characters with special meaning either inside or outside character sets.\n\t// Use a simple backslash escape when it\u2019s always valid, and a `\\xnn` escape when the simpler form would be disallowed by Unicode patterns\u2019 stricter grammar.\n\treturn string\n\t\t.replace(/[|\\\\{}()[\\]^$+*?.]/g, '\\\\$&')\n\t\t.replace(/-/g, '\\\\x2d');\n}\n", "import * as plugins from './smartmatch.plugins.js';\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 return plugins.matcher.isMatch(matchStringArg, this.wildcard);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAe,SAAR,mBAAoC,QAAQ;AAClD,MAAI,OAAO,WAAW,UAAU;AAC/B,UAAM,IAAI,UAAU,mBAAmB;AAAA,EACxC;AAIA,SAAO,OACL,QAAQ,uBAAuB,MAAM,EACrC,QAAQ,MAAM,OAAO;AACxB;;;ADRA,IAAM,cAAc,oBAAI,IAAI;AAE5B,IAAM,gBAAgB,CAAC,OAAO,cAAc;AAC3C,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AAC1B,YAAQ,OAAO;AAAA,WACT;AACJ,gBAAQ,CAAC,KAAK;AACd;AAAA,WACI;AACJ,gBAAQ,CAAC;AACT;AAAA;AAEA,cAAM,IAAI,UAAU,aAAa,6DAA6D,OAAO,QAAQ;AAAA;AAAA,EAEhH;AAEA,SAAO,MAAM,OAAO,YAAU;AAC7B,QAAI,OAAO,WAAW,UAAU;AAC/B,UAAI,OAAO,WAAW,aAAa;AAClC,eAAO;AAAA,MACR;AAEA,YAAM,IAAI,UAAU,aAAa,8DAA8D,OAAO,sBAAsB;AAAA,IAC7H;AAEA,WAAO;AAAA,EACR,CAAC;AACF;AAEA,IAAM,aAAa,CAAC,SAAS,YAAY;AACxC,YAAU;AAAA,IACT,eAAe;AAAA,IACf,GAAG;AAAA,EACJ;AAEA,QAAM,WAAW,UAAU,KAAK,UAAU,OAAO;AAEjD,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC9B,WAAO,YAAY,IAAI,QAAQ;AAAA,EAChC;AAEA,QAAM,UAAU,QAAQ,OAAO;AAE/B,MAAI,SAAS;AACZ,cAAU,QAAQ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,IAAI,EAAE,SAAS;AAC9D;;;AE/GO,IAAM,aAAN,MAAiB;AAAA,EAEtB,YAAY,aAAqB;AAC/B,SAAK,WAAW;AAAA,EAClB;AAAA,EAEO,MAAM,gBAAiC;AAC5C,WAAe,gBAAQ,QAAQ,gBAAgB,KAAK,QAAQ;AAAA,EAC9D;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* autocreated commitinfo by @
|
|
2
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
|
-
name: '@
|
|
6
|
-
version: '2.0.
|
|
7
|
-
description: '
|
|
5
|
+
name: '@push.rocks/smartmatch',
|
|
6
|
+
version: '2.0.3',
|
|
7
|
+
description: 'A minimal, linear-time library for case-insensitive wildcard string matching.'
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLCtFQUErRTtDQUM3RixDQUFBIn0=
|
package/dist_ts/index.js
CHANGED
|
@@ -1,10 +1,73 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
2
61
|
export class SmartMatch {
|
|
3
62
|
constructor(wildcardArg) {
|
|
4
63
|
this.wildcard = wildcardArg;
|
|
5
64
|
}
|
|
6
65
|
match(matchStringArg) {
|
|
7
|
-
|
|
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}`);
|
|
70
|
+
return negated ? !matches : matches;
|
|
8
71
|
}
|
|
9
72
|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
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { matcher };
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRtYXRjaC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRtYXRjaC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLG9CQUFvQjtBQUNwQixPQUFPLEtBQUssT0FBTyxNQUFNLFNBQVMsQ0FBQztBQUVuQyxPQUFPLEVBQUUsT0FBTyxFQUFFLENBQUMifQ==
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRtYXRjaC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRtYXRjaC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxDQUFDIn0=
|
package/package.json
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartmatch",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
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
|
-
"scripts": {
|
|
12
|
-
"test": "(tstest test/)",
|
|
13
|
-
"build": "(tsbuild && tsbundle npm)",
|
|
14
|
-
"format": "(gitzone format)",
|
|
15
|
-
"buildDocs": "tsdoc"
|
|
16
|
-
},
|
|
17
11
|
"devDependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@gitzone/tstest": "^1.0.73",
|
|
21
|
-
"@pushrocks/tapbundle": "^5.0.4",
|
|
22
|
-
"@types/node": "^18.6.5"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"matcher": "^5.0.0"
|
|
12
|
+
"@git.zone/tsrepo": "^2.2.0",
|
|
13
|
+
"@types/node": "26.6.6"
|
|
26
14
|
},
|
|
15
|
+
"dependencies": {},
|
|
27
16
|
"files": [
|
|
28
17
|
"ts/**/*",
|
|
29
18
|
"ts_web/**/*",
|
|
@@ -33,10 +22,29 @@
|
|
|
33
22
|
"dist_ts_web/**/*",
|
|
34
23
|
"assets/**/*",
|
|
35
24
|
"cli.js",
|
|
36
|
-
"
|
|
25
|
+
".smartconfig.json",
|
|
37
26
|
"readme.md"
|
|
38
27
|
],
|
|
39
28
|
"browserslist": [
|
|
40
29
|
"last 1 chrome versions"
|
|
41
|
-
]
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"match",
|
|
33
|
+
"matching library",
|
|
34
|
+
"string matching",
|
|
35
|
+
"wildcards",
|
|
36
|
+
"typescript",
|
|
37
|
+
"npm package"
|
|
38
|
+
],
|
|
39
|
+
"homepage": "https://code.foss.global/push.rocks/smartmatch",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://code.foss.global/push.rocks/smartmatch.git"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "(tsrepo test test/)",
|
|
46
|
+
"build": "(tsrepo build && tsrepo bundle npm)",
|
|
47
|
+
"format": "(gitzone format)",
|
|
48
|
+
"buildDocs": "(tsrepo docs)"
|
|
49
|
+
}
|
|
42
50
|
}
|
package/readme.md
CHANGED
|
@@ -1,39 +1,109 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Snyk | [](https://lossless.cloud)
|
|
18
|
-
TypeScript Support | [](https://lossless.cloud)
|
|
19
|
-
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
20
|
-
Code Style | [](https://lossless.cloud)
|
|
21
|
-
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
22
|
-
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
23
|
-
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
24
|
-
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
1
|
+
# @push.rocks/smartmatch
|
|
2
|
+
A minimal, linear-time library for case-insensitive wildcard string matching.
|
|
3
|
+
|
|
4
|
+
## Issue Reporting and Security
|
|
5
|
+
|
|
6
|
+
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
Install `@push.rocks/smartmatch` with pnpm:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @push.rocks/smartmatch
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
This will add `@push.rocks/smartmatch` to your project's dependencies and you're ready to start using it in your application.
|
|
25
17
|
|
|
26
18
|
## Usage
|
|
27
19
|
|
|
28
|
-
|
|
20
|
+
`SmartMatch` matches an entire string case-insensitively. `*` matches zero or more characters, including newlines. A leading `!` negates the result. All other characters, including `?`, brackets, braces and backslashes, are literal; a backslash does not escape a wildcard.
|
|
21
|
+
|
|
22
|
+
### Getting Started with @push.rocks/smartmatch
|
|
23
|
+
|
|
24
|
+
Firstly, ensure that you import `@push.rocks/smartmatch` into your project:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { SmartMatch } from '@push.rocks/smartmatch';
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Creating a Matcher Instance
|
|
31
|
+
|
|
32
|
+
The `SmartMatch` class is the entry point to the library's functionality. You create an instance of `SmartMatch` by providing a wildcard pattern to its constructor. This pattern will be used for matching against the strings.
|
|
33
|
+
|
|
34
|
+
Here’s an example:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const myMatcher = new SmartMatch('*.ts');
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This matcher will be used to determine if a given string matches the wildcard pattern `*.ts`, meaning it should end with `.ts`.
|
|
41
|
+
|
|
42
|
+
### Matching Strings
|
|
43
|
+
|
|
44
|
+
To match a string against the pattern, use the `match` method on your `SmartMatch` instance. This method takes a string as an argument and returns a boolean indicating whether the string matches the pattern.
|
|
45
|
+
|
|
46
|
+
Example usage:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// Assuming myMatcher is instantiated with '*.ts' as shown above.
|
|
50
|
+
|
|
51
|
+
const fileName = 'example.ts';
|
|
52
|
+
|
|
53
|
+
if (myMatcher.match(fileName)) {
|
|
54
|
+
console.log(`${fileName} matches the pattern!`);
|
|
55
|
+
} else {
|
|
56
|
+
console.log(`${fileName} does not match the pattern.`);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Advanced Use Cases
|
|
61
|
+
|
|
62
|
+
`@push.rocks/smartmatch` is designed to be minimal, but you can create multiple instances of `SmartMatch` with different patterns to support more complex matching logic in your application. This is particularly useful for applications that deal with various types of files, names, or identifiers that follow different naming conventions.
|
|
63
|
+
|
|
64
|
+
For example:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const scriptMatcher = new SmartMatch('*.js');
|
|
68
|
+
const typeScriptMatcher = new SmartMatch('*.ts');
|
|
69
|
+
|
|
70
|
+
const checkFileType = (fileName: string) => {
|
|
71
|
+
if (scriptMatcher.match(fileName)) {
|
|
72
|
+
console.log(`${fileName} is a JavaScript file.`);
|
|
73
|
+
} else if (typeScriptMatcher.match(fileName)) {
|
|
74
|
+
console.log(`${fileName} is a TypeScript file.`);
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`${fileName} is of an unknown type.`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Test the function
|
|
81
|
+
checkFileType('test.js'); // Output: test.js is a JavaScript file.
|
|
82
|
+
checkFileType('module.ts'); // Output: module.ts is a TypeScript file.
|
|
83
|
+
checkFileType('image.png'); // Output: image.png is of an unknown type.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This makes `@push.rocks/smartmatch` a versatile library suitable for various applications that require simple yet efficient matching logic.
|
|
87
|
+
|
|
88
|
+
### Conclusion
|
|
89
|
+
|
|
90
|
+
`@push.rocks/smartmatch` offers an elegant solution for matching strings against wildcard patterns. Whether you are developing a file utility tool, a project management app, or any software that needs to filter or categorize data based on naming patterns, `@push.rocks/smartmatch` could be the library you need. Its simplicity and effectiveness make it a valuable tool for developers looking for a minimal matching library.
|
|
91
|
+
|
|
92
|
+
## License and Legal Information
|
|
93
|
+
|
|
94
|
+
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in [license.md](./license.md).
|
|
95
|
+
|
|
96
|
+
**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.
|
|
97
|
+
|
|
98
|
+
### Trademarks
|
|
29
99
|
|
|
30
|
-
|
|
100
|
+
This 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.
|
|
31
101
|
|
|
32
|
-
|
|
102
|
+
### Company Information
|
|
33
103
|
|
|
34
|
-
|
|
104
|
+
Task Venture Capital GmbH
|
|
105
|
+
Registered at District court Bremen HRB 35230 HB, Germany
|
|
35
106
|
|
|
36
|
-
|
|
37
|
-
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
107
|
+
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
|
38
108
|
|
|
39
|
-
|
|
109
|
+
By 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.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* autocreated commitinfo by @
|
|
2
|
+
* autocreated commitinfo by @push.rocks/commitinfo
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
|
-
name: '@
|
|
6
|
-
version: '2.0.
|
|
7
|
-
description: '
|
|
5
|
+
name: '@push.rocks/smartmatch',
|
|
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,4 +1,69 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
2
67
|
|
|
3
68
|
export class SmartMatch {
|
|
4
69
|
public wildcard: string;
|
|
@@ -7,6 +72,10 @@ export class SmartMatch {
|
|
|
7
72
|
}
|
|
8
73
|
|
|
9
74
|
public match(matchStringArg: string): boolean {
|
|
10
|
-
|
|
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}`);
|
|
79
|
+
return negated ? !matches : matches;
|
|
11
80
|
}
|
|
12
81
|
}
|
package/ts/smartmatch.plugins.ts
CHANGED
package/npmextra.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"gitzone": {
|
|
3
|
-
"projectType": "npm",
|
|
4
|
-
"module": {
|
|
5
|
-
"githost": "gitlab.com",
|
|
6
|
-
"gitscope": "pushrocks",
|
|
7
|
-
"gitrepo": "smartmatch",
|
|
8
|
-
"description": "a minimal matching library using picomatch",
|
|
9
|
-
"npmPackagename": "@pushrocks/smartmatch",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"projectDomain": "push.rocks"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"npmci": {
|
|
15
|
-
"npmGlobalTools": [],
|
|
16
|
-
"npmAccessLevel": "public"
|
|
17
|
-
}
|
|
18
|
-
}
|
/package/{license → license.md}
RENAMED
|
File without changes
|