@orchidjs/sifter 1.0.2 → 1.1.0
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/dist/cjs/package.json +1 -0
- package/dist/cjs/sifter.d.ts +72 -0
- package/dist/cjs/sifter.js +290 -1110
- package/dist/cjs/sifter.js.map +1 -1
- package/dist/cjs/types.d.ts +57 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +48 -0
- package/dist/cjs/utils.js +102 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/sifter.d.ts +72 -0
- package/dist/esm/sifter.js +267 -330
- package/dist/esm/sifter.js.map +1 -1
- package/dist/esm/types.d.ts +57 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +48 -0
- package/dist/esm/utils.js +54 -56
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/sifter.d.ts +3 -2
- package/dist/types/types.d.ts +12 -12
- package/dist/types/utils.d.ts +2 -2
- package/dist/umd/package.json +1 -0
- package/dist/umd/sifter.js +794 -1043
- package/dist/umd/sifter.js.map +1 -1
- package/dist/umd/sifter.min.js +72 -77
- package/dist/umd/sifter.min.js.map +1 -1
- package/lib/sifter.ts +3 -2
- package/lib/types.ts +1 -1
- package/lib/utils.ts +1 -1
- package/package.json +31 -21
- package/dist/esm/lib/sifter.js +0 -368
- package/dist/esm/lib/sifter.js.map +0 -1
- package/dist/esm/lib/utils.js +0 -95
- package/dist/esm/lib/utils.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js +0 -556
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/index.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js +0 -113
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/regex.js.map +0 -1
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js +0 -29
- package/dist/esm/node_modules/@orchidjs/unicode-variants/dist/esm/strings.js.map +0 -1
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */
|
|
2
|
-
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Convert array of strings to a regular expression
|
|
6
|
-
* ex ['ab','a'] => (?:ab|a)
|
|
7
|
-
* ex ['a','b'] => [ab]
|
|
8
|
-
* @param {string[]} chars
|
|
9
|
-
* @return {string}
|
|
10
|
-
*/
|
|
11
|
-
const arrayToPattern = chars => {
|
|
12
|
-
chars = chars.filter(Boolean);
|
|
13
|
-
|
|
14
|
-
if (chars.length < 2) {
|
|
15
|
-
return chars[0] || '';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return maxValueLength(chars) == 1 ? '[' + chars.join('') + ']' : '(?:' + chars.join('|') + ')';
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* @param {string[]} array
|
|
22
|
-
* @return {string}
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const sequencePattern = array => {
|
|
27
|
-
if (!hasDuplicates(array)) {
|
|
28
|
-
return array.join('');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let pattern = '';
|
|
32
|
-
let prev_char_count = 0;
|
|
33
|
-
|
|
34
|
-
const prev_pattern = () => {
|
|
35
|
-
if (prev_char_count > 1) {
|
|
36
|
-
pattern += '{' + prev_char_count + '}';
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
array.forEach((char, i) => {
|
|
41
|
-
if (char === array[i - 1]) {
|
|
42
|
-
prev_char_count++;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
prev_pattern();
|
|
47
|
-
pattern += char;
|
|
48
|
-
prev_char_count = 1;
|
|
49
|
-
});
|
|
50
|
-
prev_pattern();
|
|
51
|
-
return pattern;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Convert array of strings to a regular expression
|
|
55
|
-
* ex ['ab','a'] => (?:ab|a)
|
|
56
|
-
* ex ['a','b'] => [ab]
|
|
57
|
-
* @param {Set<string>} chars
|
|
58
|
-
* @return {string}
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const setToPattern = chars => {
|
|
63
|
-
let array = toArray(chars);
|
|
64
|
-
return arrayToPattern(array);
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
* https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values
|
|
69
|
-
* @param {any[]} array
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const hasDuplicates = array => {
|
|
74
|
-
return new Set(array).size !== array.length;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error
|
|
78
|
-
* @param {string} str
|
|
79
|
-
* @return {string}
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const escape_regex = str => {
|
|
84
|
-
return (str + '').replace(/([\$\(-\+\.\?\[-\^\{-\}])/g, '\\$1');
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Return the max length of array values
|
|
88
|
-
* @param {string[]} array
|
|
89
|
-
*
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const maxValueLength = array => {
|
|
94
|
-
return array.reduce((longest, value) => Math.max(longest, unicodeLength(value)), 0);
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* @param {string} str
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const unicodeLength = str => {
|
|
102
|
-
return toArray(str).length;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* @param {any} p
|
|
106
|
-
* @return {any[]}
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const toArray = p => Array.from(p);
|
|
111
|
-
|
|
112
|
-
export { arrayToPattern, escape_regex, hasDuplicates, maxValueLength, sequencePattern, setToPattern, toArray, unicodeLength };
|
|
113
|
-
//# sourceMappingURL=regex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex.js","sources":["../../../../../../../node_modules/@orchidjs/unicode-variants/dist/esm/regex.js"],"sourcesContent":["/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n * @param {string[]} chars\n * @return {string}\n */\nconst arrayToPattern = chars => {\n chars = chars.filter(Boolean);\n\n if (chars.length < 2) {\n return chars[0] || '';\n }\n\n return maxValueLength(chars) == 1 ? '[' + chars.join('') + ']' : '(?:' + chars.join('|') + ')';\n};\n/**\n * @param {string[]} array\n * @return {string}\n */\n\nconst sequencePattern = array => {\n if (!hasDuplicates(array)) {\n return array.join('');\n }\n\n let pattern = '';\n let prev_char_count = 0;\n\n const prev_pattern = () => {\n if (prev_char_count > 1) {\n pattern += '{' + prev_char_count + '}';\n }\n };\n\n array.forEach((char, i) => {\n if (char === array[i - 1]) {\n prev_char_count++;\n return;\n }\n\n prev_pattern();\n pattern += char;\n prev_char_count = 1;\n });\n prev_pattern();\n return pattern;\n};\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n * @param {Set<string>} chars\n * @return {string}\n */\n\nconst setToPattern = chars => {\n let array = toArray(chars);\n return arrayToPattern(array);\n};\n/**\n *\n * https://stackoverflow.com/questions/7376598/in-javascript-how-do-i-check-if-an-array-has-duplicate-values\n * @param {any[]} array\n */\n\nconst hasDuplicates = array => {\n return new Set(array).size !== array.length;\n};\n/**\n * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error\n * @param {string} str\n * @return {string}\n */\n\nconst escape_regex = str => {\n return (str + '').replace(/([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}\\\\])/gu, '\\\\$1');\n};\n/**\n * Return the max length of array values\n * @param {string[]} array\n *\n */\n\nconst maxValueLength = array => {\n return array.reduce((longest, value) => Math.max(longest, unicodeLength(value)), 0);\n};\n/**\n * @param {string} str\n */\n\nconst unicodeLength = str => {\n return toArray(str).length;\n};\n/**\n * @param {any} p\n * @return {any[]}\n */\n\nconst toArray = p => Array.from(p);\n\nexport { arrayToPattern, escape_regex, hasDuplicates, maxValueLength, sequencePattern, setToPattern, toArray, unicodeLength };\n//# sourceMappingURL=regex.js.map\n"],"names":["arrayToPattern","chars","maxValueLength","sequencePattern","array","hasDuplicates","pattern","prev_char_count","prev_pattern","char","i","setToPattern","toArray","escape_regex","str","Math","unicodeLength","p","Array"],"mappings":";;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,cAAc,GAAIC,KAAD,IAAU;AAEvCA,EAAAA,KAAK,GAAGA,KAAK,CAALA,MAAAA,CAARA,OAAQA,CAARA;;AAEA,MAAIA,KAAK,CAALA,MAAAA,GAAJ,CAAA,EAAsB;AACrB,WAAOA,KAAK,CAALA,CAAK,CAALA,IAAP,EAAA;AACA;;AAED,SAAQC,cAAc,CAAdA,KAAc,CAAdA,IAAD,CAACA,GAA8B,MAAID,KAAK,CAALA,IAAAA,CAAJ,EAAIA,CAAJ,GAA/B,GAACC,GAAuD,QAAMD,KAAK,CAALA,IAAAA,CAAN,GAAMA,CAAN,GAA/D,GAAA;AARM;AAWP;AACA;AACA;AACA;;;MACaE,eAAe,GAAIC,KAAD,IAAS;AAEvC,MAAI,CAACC,aAAa,CAAlB,KAAkB,CAAlB,EAA2B;AAC1B,WAAOD,KAAK,CAALA,IAAAA,CAAP,EAAOA,CAAP;AACA;;AAED,MAA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aY,aAAa,GAAIF,GAAD,IAAS;AACrC,SAAOF,OAAO,CAAPA,GAAO,CAAPA,CAAP,MAAA;AADM;AAIP;AACA;AACA;AACA;;;MACaA,OAAO,GAAIK,CAAD,IAAOC,KAAK,CAALA,IAAAA,CAAAA,CAAAA;;;;"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */
|
|
2
|
-
/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Get all possible combinations of substrings that add up to the given string
|
|
6
|
-
* https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string
|
|
7
|
-
* @param {string} input
|
|
8
|
-
* @return {string[][]}
|
|
9
|
-
*/
|
|
10
|
-
const allSubstrings = input => {
|
|
11
|
-
if (input.length === 1) return [[input]];
|
|
12
|
-
/** @type {string[][]} */
|
|
13
|
-
|
|
14
|
-
let result = [];
|
|
15
|
-
const start = input.substring(1);
|
|
16
|
-
const suba = allSubstrings(start);
|
|
17
|
-
suba.forEach(function (subresult) {
|
|
18
|
-
let tmp = subresult.slice(0);
|
|
19
|
-
tmp[0] = input.charAt(0) + tmp[0];
|
|
20
|
-
result.push(tmp);
|
|
21
|
-
tmp = subresult.slice(0);
|
|
22
|
-
tmp.unshift(input.charAt(0));
|
|
23
|
-
result.push(tmp);
|
|
24
|
-
});
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { allSubstrings };
|
|
29
|
-
//# sourceMappingURL=strings.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strings.js","sources":["../../../../../../../node_modules/@orchidjs/unicode-variants/dist/esm/strings.js"],"sourcesContent":["/*! @orchidjs/unicode-variants | https://github.com/orchidjs/unicode-variants | Apache License (v2) */\n/**\n * Get all possible combinations of substrings that add up to the given string\n * https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string\n * @param {string} input\n * @return {string[][]}\n */\nconst allSubstrings = input => {\n if (input.length === 1) return [[input]];\n /** @type {string[][]} */\n\n let result = [];\n const start = input.substring(1);\n const suba = allSubstrings(start);\n suba.forEach(function (subresult) {\n let tmp = subresult.slice(0);\n tmp[0] = input.charAt(0) + tmp[0];\n result.push(tmp);\n tmp = subresult.slice(0);\n tmp.unshift(input.charAt(0));\n result.push(tmp);\n });\n return result;\n};\n\nexport { allSubstrings };\n//# sourceMappingURL=strings.js.map\n"],"names":["allSubstrings","input","result","start","suba","tmp","subresult"],"mappings":";;;AAGA;AACA;AACA;AACA;AACA;AACA;MACaA,aAAa,GAAIC,KAAD,IAAW;AAEpC,MAAIA,KAAK,CAALA,MAAAA,KAAJ,CAAA,EAAwB,OAAO,CAAC,CAAR,KAAQ,CAAD,CAAP;AAE3B;;AACG,MAAIC,MAAM,GAAV,EAAA;AAEH,QAAMC,KAAK,GAAGF,KAAK,CAALA,SAAAA,CAAd,CAAcA,CAAd;AACG,QAAMG,IAAI,GAAGJ,aAAa,CAA1B,KAA0B,CAA1B;AAEHI,EAAAA,IAAI,CAAJA,OAAAA,CAAa,UAAA,SAAA,EAAoB;AAC1B,QAAIC,GAAG,GAAGC,SAAS,CAATA,KAAAA,CAAV,CAAUA,CAAV;AACAD,IAAAA,GAAG,CAAHA,CAAG,CAAHA,GAASJ,KAAK,CAALA,MAAAA,CAAAA,CAAAA,IAAkBI,GAAG,CAA9BA,CAA8B,CAA9BA;AACAH,IAAAA,MAAM,CAANA,IAAAA,CAAAA,GAAAA;AAEAG,IAAAA,GAAG,GAAGC,SAAS,CAATA,KAAAA,CAAND,CAAMC,CAAND;AACAA,IAAAA,GAAG,CAAHA,OAAAA,CAAYJ,KAAK,CAALA,MAAAA,CAAZI,CAAYJ,CAAZI;AACAH,IAAAA,MAAM,CAANA,IAAAA,CAAAA,GAAAA;AAPPE,GAAAA;AAUG,SAAA,MAAA;AACH;;;;"}
|