@orchidjs/sifter 0.9.0 → 0.9.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/README.md +6 -6
- package/dist/cjs/diacritics.js +46 -37
- package/dist/cjs/diacritics.js.map +1 -1
- package/dist/cjs/sifter.js +20 -24
- package/dist/cjs/sifter.js.map +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/diacritics.js +46 -37
- package/dist/esm/diacritics.js.map +1 -1
- package/dist/esm/sifter.js +20 -24
- package/dist/esm/sifter.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/diacritics.d.ts +2 -7
- package/dist/types/utils.d.ts +1 -1
- package/dist/umd/sifter.js +63 -60
- package/dist/umd/sifter.js.map +1 -1
- package/dist/umd/sifter.min.js +34 -36
- package/dist/umd/sifter.min.js.map +1 -1
- package/lib/diacritics.ts +65 -220
- package/lib/sifter.ts +27 -31
- package/lib/utils.ts +3 -3
- package/package.json +8 -7
package/dist/umd/sifter.js
CHANGED
|
@@ -5,24 +5,20 @@
|
|
|
5
5
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.sifter = factory());
|
|
6
6
|
}(this, (function () { 'use strict';
|
|
7
7
|
|
|
8
|
+
// @ts-ignore TS2691 "An import path cannot end with a '.ts' extension"
|
|
8
9
|
// https://github.com/andrewrk/node-diacritics/blob/master/index.js
|
|
9
10
|
var latin_pat;
|
|
10
11
|
const accent_pat = '[\u0300-\u036F\u{b7}\u{2be}]'; // \u{2bc}
|
|
11
12
|
|
|
12
|
-
const accent_reg = new RegExp(accent_pat, '
|
|
13
|
+
const accent_reg = new RegExp(accent_pat, 'gu');
|
|
13
14
|
var diacritic_patterns;
|
|
14
15
|
const latin_convert = {
|
|
15
16
|
'æ': 'ae',
|
|
16
17
|
'ⱥ': 'a',
|
|
17
18
|
'ø': 'o'
|
|
18
19
|
};
|
|
19
|
-
const convert_pat = new RegExp(Object.keys(latin_convert).join('|'), '
|
|
20
|
-
|
|
21
|
-
* code points generated from toCodePoints();
|
|
22
|
-
* removed 65339 to 65345
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const code_points = [[67, 67], [160, 160], [192, 438], [452, 652], [961, 961], [1019, 1019], [1083, 1083], [1281, 1289], [1984, 1984], [5095, 5095], [7429, 7441], [7545, 7549], [7680, 7935], [8580, 8580], [9398, 9449], [11360, 11391], [42792, 42793], [42802, 42851], [42873, 42897], [42912, 42922], [64256, 64260], [65313, 65338], [65345, 65370]];
|
|
20
|
+
const convert_pat = new RegExp(Object.keys(latin_convert).join('|'), 'gu');
|
|
21
|
+
const code_points = [[0, 65535]];
|
|
26
22
|
/**
|
|
27
23
|
* Remove accents
|
|
28
24
|
* via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
|
|
@@ -31,7 +27,7 @@
|
|
|
31
27
|
|
|
32
28
|
const asciifold = str => {
|
|
33
29
|
return str.normalize('NFKD').replace(accent_reg, '').toLowerCase().replace(convert_pat, function (foreignletter) {
|
|
34
|
-
return latin_convert[foreignletter];
|
|
30
|
+
return latin_convert[foreignletter] || foreignletter;
|
|
35
31
|
});
|
|
36
32
|
};
|
|
37
33
|
/**
|
|
@@ -41,9 +37,8 @@
|
|
|
41
37
|
*
|
|
42
38
|
*/
|
|
43
39
|
|
|
44
|
-
|
|
45
40
|
const arrayToPattern = (chars, glue = '|') => {
|
|
46
|
-
if (chars.length
|
|
41
|
+
if (chars.length === 1 && chars[0] != undefined) {
|
|
47
42
|
return chars[0];
|
|
48
43
|
}
|
|
49
44
|
|
|
@@ -58,6 +53,10 @@
|
|
|
58
53
|
|
|
59
54
|
return '(?:' + chars.join(glue) + ')';
|
|
60
55
|
};
|
|
56
|
+
const escapeToPattern = chars => {
|
|
57
|
+
const escaped = chars.map(diacritic => escape_regex(diacritic));
|
|
58
|
+
return arrayToPattern(escaped);
|
|
59
|
+
};
|
|
61
60
|
/**
|
|
62
61
|
* Get all possible combinations of substrings that add up to the given string
|
|
63
62
|
* https://stackoverflow.com/questions/30169587/find-all-the-combination-of-substrings-that-add-up-to-the-given-string
|
|
@@ -82,7 +81,7 @@
|
|
|
82
81
|
*
|
|
83
82
|
*/
|
|
84
83
|
|
|
85
|
-
const generateDiacritics =
|
|
84
|
+
const generateDiacritics = code_points => {
|
|
86
85
|
var diacritics = {};
|
|
87
86
|
code_points.forEach(code_range => {
|
|
88
87
|
for (let i = code_range[0]; i <= code_range[1]; i++) {
|
|
@@ -91,27 +90,42 @@
|
|
|
91
90
|
|
|
92
91
|
if (latin == diacritic.toLowerCase()) {
|
|
93
92
|
continue;
|
|
94
|
-
}
|
|
93
|
+
} // skip when latin is a string longer than 3 characters long
|
|
94
|
+
// bc the resulting regex patterns will be long
|
|
95
|
+
// eg:
|
|
96
|
+
// latin صلى الله عليه وسلم length 18 code point 65018
|
|
97
|
+
// latin جل جلاله length 8 code point 65019
|
|
98
|
+
|
|
95
99
|
|
|
96
|
-
if (
|
|
97
|
-
|
|
100
|
+
if (latin.length > 3) {
|
|
101
|
+
continue;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
const latin_diacritics = diacritics[latin] || [latin];
|
|
105
|
+
const patt = new RegExp(escapeToPattern(latin_diacritics), 'iu');
|
|
101
106
|
|
|
102
107
|
if (diacritic.match(patt)) {
|
|
103
108
|
continue;
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
latin_diacritics.push(diacritic);
|
|
112
|
+
diacritics[latin] = latin_diacritics;
|
|
107
113
|
}
|
|
108
|
-
});
|
|
109
|
-
|
|
114
|
+
}); // filter out if there's only one character in the list
|
|
115
|
+
// todo: this may not be needed
|
|
116
|
+
|
|
117
|
+
Object.keys(diacritics).forEach(latin => {
|
|
118
|
+
const latin_diacritics = diacritics[latin] || [];
|
|
119
|
+
|
|
120
|
+
if (latin_diacritics.length < 2) {
|
|
121
|
+
delete diacritics[latin];
|
|
122
|
+
}
|
|
123
|
+
}); // latin character pattern
|
|
110
124
|
// match longer substrings first
|
|
111
125
|
|
|
112
|
-
latin_chars =
|
|
113
|
-
latin_pat = new RegExp('(' +
|
|
114
|
-
// ae needs:
|
|
126
|
+
let latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length);
|
|
127
|
+
latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns
|
|
128
|
+
// ae needs:
|
|
115
129
|
// (?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))
|
|
116
130
|
|
|
117
131
|
var diacritic_patterns = {};
|
|
@@ -120,7 +134,7 @@
|
|
|
120
134
|
var pattern = substrings.map(sub_pat => {
|
|
121
135
|
sub_pat = sub_pat.map(l => {
|
|
122
136
|
if (diacritics.hasOwnProperty(l)) {
|
|
123
|
-
return
|
|
137
|
+
return escapeToPattern(diacritics[l]);
|
|
124
138
|
}
|
|
125
139
|
|
|
126
140
|
return l;
|
|
@@ -139,27 +153,20 @@
|
|
|
139
153
|
|
|
140
154
|
const diacriticRegexPoints = regex => {
|
|
141
155
|
if (diacritic_patterns === undefined) {
|
|
142
|
-
diacritic_patterns = generateDiacritics();
|
|
156
|
+
diacritic_patterns = generateDiacritics(code_points);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
const decomposed = regex.normalize('NFKD').toLowerCase();
|
|
146
160
|
return decomposed.split(latin_pat).map(part => {
|
|
147
|
-
|
|
148
|
-
return '';
|
|
149
|
-
} // "ffl" or "ffl"
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
// "ffl" or "ffl"
|
|
152
162
|
const no_accent = asciifold(part);
|
|
153
163
|
|
|
164
|
+
if (no_accent == '') {
|
|
165
|
+
return '';
|
|
166
|
+
}
|
|
167
|
+
|
|
154
168
|
if (diacritic_patterns.hasOwnProperty(no_accent)) {
|
|
155
169
|
return diacritic_patterns[no_accent];
|
|
156
|
-
} // 'أهلا' (\u{623}\u{647}\u{644}\u{627}) or 'أهلا' (\u{627}\u{654}\u{647}\u{644}\u{627})
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const composed_part = part.normalize('NFC');
|
|
160
|
-
|
|
161
|
-
if (composed_part != part) {
|
|
162
|
-
return arrayToPattern([part, composed_part]);
|
|
163
170
|
}
|
|
164
171
|
|
|
165
172
|
return part;
|
|
@@ -325,10 +332,10 @@
|
|
|
325
332
|
}
|
|
326
333
|
|
|
327
334
|
if (word.length > 0) {
|
|
328
|
-
regex = escape_regex(word);
|
|
329
|
-
|
|
330
335
|
if (this.settings.diacritics) {
|
|
331
|
-
regex = diacriticRegexPoints(
|
|
336
|
+
regex = diacriticRegexPoints(word);
|
|
337
|
+
} else {
|
|
338
|
+
regex = escape_regex(word);
|
|
332
339
|
}
|
|
333
340
|
|
|
334
341
|
if (respect_word_boundaries) regex = "\\b" + regex;
|
|
@@ -512,10 +519,6 @@
|
|
|
512
519
|
break;
|
|
513
520
|
}
|
|
514
521
|
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
for (i = 0, n = sort_flds.length; i < n; i++) {
|
|
518
|
-
multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1);
|
|
519
522
|
} // build function
|
|
520
523
|
|
|
521
524
|
|
|
@@ -523,25 +526,25 @@
|
|
|
523
526
|
|
|
524
527
|
if (!sort_flds_count) {
|
|
525
528
|
return null;
|
|
526
|
-
}
|
|
527
|
-
const sort_fld = sort_flds[0].field;
|
|
528
|
-
const multiplier = multipliers[0];
|
|
529
|
-
return function (a, b) {
|
|
530
|
-
return multiplier * cmp(get_field(sort_fld, a), get_field(sort_fld, b));
|
|
531
|
-
};
|
|
532
|
-
} else {
|
|
533
|
-
return function (a, b) {
|
|
534
|
-
var i, result, field;
|
|
529
|
+
}
|
|
535
530
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
531
|
+
return function (a, b) {
|
|
532
|
+
var i, result, field;
|
|
533
|
+
|
|
534
|
+
for (i = 0; i < sort_flds_count; i++) {
|
|
535
|
+
field = sort_flds[i].field;
|
|
536
|
+
let multiplier = multipliers[i];
|
|
537
|
+
|
|
538
|
+
if (multiplier == undefined) {
|
|
539
|
+
multiplier = sort_flds[i].direction === 'desc' ? -1 : 1;
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
542
|
+
result = multiplier * cmp(get_field(field, a), get_field(field, b));
|
|
543
|
+
if (result) return result;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return 0;
|
|
547
|
+
};
|
|
545
548
|
}
|
|
546
549
|
|
|
547
550
|
/**
|
|
@@ -611,7 +614,7 @@
|
|
|
611
614
|
}
|
|
612
615
|
});
|
|
613
616
|
} else {
|
|
614
|
-
iterate(self.items, (
|
|
617
|
+
iterate(self.items, (_, id) => {
|
|
615
618
|
search.items.push({
|
|
616
619
|
'score': 1,
|
|
617
620
|
'id': id
|
package/dist/umd/sifter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sifter.js","sources":["../../lib/diacritics.ts","../../lib/utils.ts","../../lib/sifter.ts"],"sourcesContent":["\ntype TDiacraticList = {[key:string]:string};\n\n// https://github.com/andrewrk/node-diacritics/blob/master/index.js\n\nvar latin_pat:RegExp;\nconst accent_pat = '[\\u0300-\\u036F\\u{b7}\\u{2be}]'; // \\u{2bc}\nconst accent_reg = new RegExp(accent_pat,'g');\nvar diacritic_patterns:TDiacraticList;\n\nconst latin_convert:TDiacraticList = {\n\t'æ': 'ae',\n\t'ⱥ': 'a',\n\t'ø': 'o',\n};\n\nconst convert_pat = new RegExp(Object.keys(latin_convert).join('|'),'g');\n\n\nexport const DIACRITICS:TDiacraticList = {\n\t\" \":\" \",\n\t0:\"߀\",\n\tA:\"ⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ\",\n\tAA:\"Ꜳ\",\n\tAE:\"ÆǼǢ\",\n\tAO:\"Ꜵ\",\n\tAU:\"Ꜷ\",\n\tAV:\"ꜸꜺ\",\n\tAY:\"Ꜽ\",\n\tB:\"ⒷBḂḄḆɃƁ\",\n\tC:\"ⒸCꜾḈĆCĈĊČÇƇȻ\",\n\tD:\"ⒹDḊĎḌḐḒḎĐƊƉᴅꝹ\",\n\tDh:\"Ð\",\n\tDZ:\"DZDŽ\",\n\tDz:\"DzDž\",\n\tE:\"ɛⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎᴇ\",\n\tF:\"ꝼⒻFḞƑꝻ\",\n\tG:\"ⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾɢ\",\n\tH:\"ⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ\",\n\tI:\"ⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ\",\n\tJ:\"ⒿJĴɈȷ\",\n\tK:\"ⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ\",\n\tL:\"ⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ\",\n\tLJ:\"LJ\",\n\tLj:\"Lj\",\n\tM:\"ⓂMḾṀṂⱮƜϻ\",\n\tN:\"ꞤȠⓃNǸŃÑṄŇṆŅṊṈƝꞐᴎ\",\n\tNJ:\"NJ\",\n\tNj:\"Nj\",\n\tO:\"ⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ\",\n\tOE:\"Œ\",\n\tOI:\"Ƣ\",\n\tOO:\"Ꝏ\",\n\tOU:\"Ȣ\",\n\tP:\"ⓅPṔṖƤⱣꝐꝒꝔ\",\n\tQ:\"ⓆQꝖꝘɊ\",\n\tR:\"ⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ\",\n\tS:\"ⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ\",\n\tT:\"ⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ\",\n\tTh:\"Þ\",\n\tTZ:\"Ꜩ\",\n\tU:\"ⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ\",\n\tV:\"ⓋVṼṾƲꝞɅ\",\n\tVY:\"Ꝡ\",\n\tW:\"ⓌWẀẂŴẆẄẈⱲ\",\n\tX:\"ⓍXẊẌ\",\n\tY:\"ⓎYỲÝŶỸȲẎŸỶỴƳɎỾ\",\n\tZ:\"ⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ\",\n\ta:\"ⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑ\",\n\taa:\"ꜳ\",\n\tae:\"æǽǣ\",\n\tao:\"ꜵ\",\n\tau:\"ꜷ\",\n\tav:\"ꜹꜻ\",\n\tay:\"ꜽ\",\n\tb:\"ⓑbḃḅḇƀƃɓƂ\",\n\tc:\"cⓒćĉċčçḉƈȼꜿↄ\",\n\td:\"ⓓdḋďḍḑḓḏđƌɖɗƋᏧԁꞪ\",\n\tdh:\"ð\",\n\tdz:\"dzdž\",\n\te:\"ⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇǝ\",\n\tf:\"ⓕfḟƒ\",\n\tff:\"ff\",\n\tfi:\"fi\",\n\tfl:\"fl\",\n\tffi:\"ffi\",\n\tffl:\"ffl\",\n\tg:\"ⓖgǵĝḡğġǧģǥɠꞡꝿᵹ\",\n\th:\"ⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ\",\n\thv:\"ƕ\",\n\ti:\"ⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı\",\n\tj:\"ⓙjĵǰɉ\",\n\tk:\"ⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ\",\n\tl:\"ⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇɭ\",\n\tlj:\"lj\",\n\tm:\"ⓜmḿṁṃɱɯ\",\n\tn:\"ⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥлԉ\",\n\tnj:\"nj\",\n\to:\"ⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿꝋꝍɵɔᴑ\",\n\toe:\"œ\",\n\toi:\"ƣ\",\n\too:\"ꝏ\",\n\tou:\"ȣ\",\n\tp:\"ⓟpṕṗƥᵽꝑꝓꝕρ\",\n\tq:\"ⓠqɋꝗꝙ\",\n\tr:\"ⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ\",\n\ts:\"ⓢsśṥŝṡšṧṣṩșşȿꞩꞅẛʂ\",\n\tss:\"ß\",\n\tt:\"ⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ\",\n\tth:\"þ\",\n\ttz:\"ꜩ\",\n\tu:\"ⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ\",\n\tv:\"ⓥvṽṿʋꝟʌ\",\n\tvy:\"ꝡ\",\n\tw:\"ⓦwẁẃŵẇẅẘẉⱳ\",\n\tx:\"ⓧxẋẍ\",\n\ty:\"ⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ\",\n\tz:\"ⓩzźẑżžẓẕƶȥɀⱬꝣ\"\n}\n\n/**\n * code points generated from toCodePoints();\n * removed 65339 to 65345\n */\nexport const code_points = [\n\t[ 67, 67 ],\n\t[ 160, 160 ],\n\t[ 192, 438 ],\n\t[ 452, 652 ],\n\t[ 961, 961 ],\n\t[ 1019, 1019 ],\n\t[ 1083, 1083 ],\n\t[ 1281, 1289 ],\n\t[ 1984, 1984 ],\n\t[ 5095, 5095 ],\n\t[ 7429, 7441 ],\n\t[ 7545, 7549 ],\n\t[ 7680, 7935 ],\n\t[ 8580, 8580 ],\n\t[ 9398, 9449 ],\n\t[ 11360, 11391 ],\n\t[ 42792, 42793 ],\n\t[ 42802, 42851 ],\n\t[ 42873, 42897 ],\n\t[ 42912, 42922 ],\n\t[ 64256, 64260 ],\n\t[ 65313, 65338 ],\n\t[ 65345, 65370 ]\n];\n\n/**\n * Remove accents\n * via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703\n *\n */\nexport const asciifold = (str:string):string => {\n\treturn str\n\t\t.normalize('NFKD')\n\t\t.replace(accent_reg, '')\n\t\t.toLowerCase()\n\t\t.replace(convert_pat,function(foreignletter) {\n\t\t\treturn latin_convert[foreignletter];\n\t\t});\n};\n\n\n/**\n * Convert list of diacritics to array of code points\n *\n */\n// @ts-ignore\nfunction toCodePoints(tolerance=8){\n\tvar char_codes:number[] = [];\n\n\tfor( let letter in DIACRITICS ){\n\t\tlet _diacritics = DIACRITICS[letter];\n\t\tfor( let n = 0; n < _diacritics.length; n++ ){\n\t\t\tvar code_point = _diacritics.codePointAt(n);\n\t\t\tif( code_point ) char_codes.push( code_point );\n\t\t}\n\t}\n\n\t//https://stackoverflow.com/questions/40431572/is-there-a-simple-way-to-group-js-array-values-by-range\n\tchar_codes.sort((a, b) => a - b);\n\tvar accumulator: number[][] = [];\n\tchar_codes.reduce(function (accumulator, currentValue, index, source) {\n\n\t\tif( !index ){\n\t\t\taccumulator.push( [currentValue,currentValue] );\n\n\t\t}else if( currentValue - source[index - 1] > tolerance ){\n\t\t\taccumulator.push( [currentValue,currentValue] );\n\n\t\t}else{\n\n\t\t\tlet range = accumulator.pop();\n\t\t\tif( range ){\n\t\t\t\taccumulator.push( [range[0],currentValue]);\n\t\t\t}\n\t\t}\n\n\t\treturn accumulator;\n\t}, accumulator);\n\n}\n\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n *\n */\nexport const arrayToPattern = (chars:string[],glue:string='|'):string =>{\n\t\n\tif( chars.length == 1 ){\n\t\treturn chars[0];\n\t}\n\t\n\tvar longest = 1;\n\tchars.forEach((a)=>{longest = Math.max(longest,a.length)});\n\n\tif( longest == 1 ){\n\t\treturn '['+chars.join('')+']';\n\t}\n\n\treturn '(?:'+chars.join(glue)+')';\t\n};\n\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 *\n */\nexport const allSubstrings = (input:string):string[][] => {\n\n if( input.length === 1) return [[input]];\n\n var result:string[][] = [];\n allSubstrings(input.substring(1)).forEach(function(subresult) {\n var tmp = subresult.slice(0);\n tmp[0] = input.charAt(0) + tmp[0];\n result.push(tmp);\n\n tmp = subresult.slice(0);\n tmp.unshift(input.charAt(0));\n result.push(tmp);\n });\n \n return result;\n}\n\n/**\n * Generate a list of diacritics from the list of code points\n *\n */\nexport const generateDiacritics = ():TDiacraticList => {\t\n\n\tvar diacritics:{[key:string]:string[]} = {};\n\tcode_points.forEach((code_range)=>{\n\n\t\tfor(let i = code_range[0]; i <= code_range[1]; i++){\n\t\t\t\n\t\t\tlet diacritic\t= String.fromCharCode(i);\n\t\t\tlet\tlatin\t\t= asciifold(diacritic);\n\n\t\t\tif( latin == diacritic.toLowerCase() ){\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif( !(latin in diacritics) ){\n\t\t\t\tdiacritics[latin] = [latin];\n\t\t\t}\n\t\t\t\n\t\t\tvar patt = new RegExp( arrayToPattern(diacritics[latin]),'iu');\n\t\t\tif( diacritic.match(patt) ){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tdiacritics[latin].push(diacritic);\n\t\t}\n\t});\n\t\t\n\tvar latin_chars = Object.keys(diacritics);\n\t\n\t\n\t// latin character pattern\n\t// match longer substrings first\n\tlatin_chars\t\t= latin_chars.sort((a, b) => b.length - a.length );\n\tlatin_pat\t\t= new RegExp('('+ arrayToPattern(latin_chars) + accent_pat + '*)','g');\n\t\n\t\n\t// build diacritic patterns\n\t// ae needs: \n\t//\t(?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))\n\tvar diacritic_patterns:TDiacraticList = {};\n\tlatin_chars.sort((a,b) => a.length -b.length).forEach((latin)=>{\n\t\t\n\t\tvar substrings\t= allSubstrings(latin);\n\t\tvar pattern = substrings.map((sub_pat)=>{\n\t\t\t\n\t\t\tsub_pat = sub_pat.map((l)=>{\n\t\t\t\tif( diacritics.hasOwnProperty(l) ){\n\t\t\t\t\treturn arrayToPattern(diacritics[l]);\n\t\t\t\t}\n\t\t\t\treturn l;\n\t\t\t});\n\t\t\t\n\t\t\treturn arrayToPattern(sub_pat,'');\n\t\t});\n\t\t\n\t\tdiacritic_patterns[latin] = arrayToPattern(pattern);\t\t\n\t});\n\t\t\t\n\treturn diacritic_patterns;\n}\n\n/**\n * Expand a regular expression pattern to include diacritics\n * \teg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/\n *\n */\nexport const diacriticRegexPoints = (regex:string):string => {\n\n\tif( diacritic_patterns === undefined ){\n\t\tdiacritic_patterns = generateDiacritics();\n\t}\n\t\n\tconst decomposed\t\t= regex.normalize('NFKD').toLowerCase();\n\t\n\treturn decomposed.split(latin_pat).map((part:string)=>{\n\t\t\n\t\tif( part == '' ){\n\t\t\treturn '';\n\t\t}\n\t\t\n\t\t// \"ffl\" or \"ffl\"\n\t\tconst no_accent = asciifold(part);\t\t\t\t\n\t\tif( diacritic_patterns.hasOwnProperty(no_accent) ){\n\t\t\treturn diacritic_patterns[no_accent];\n\t\t}\n\t\t\n\t\t// 'أهلا' (\\u{623}\\u{647}\\u{644}\\u{627}) or 'أهلا' (\\u{627}\\u{654}\\u{647}\\u{644}\\u{627})\n\t\tconst composed_part = part.normalize('NFC');\n\t\tif( composed_part != part ){\n\t\t\treturn arrayToPattern([part,composed_part]);\n\t\t}\n\t\t\t\t\n\t\treturn part;\n\t}).join('');\n\t\n}\n","\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { asciifold } from './diacritics.ts';\n\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport * as T from './types.ts';\n\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\nexport const getAttr = (obj:{[key:string]:any}, name:string ) => {\n if (!obj ) return;\n return obj[name];\n};\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\nexport const getAttrNesting = (obj:{[key:string]:any}, name:string ) => {\n if (!obj ) return;\n var part, names = name.split(\".\");\n\twhile( (part = names.shift()) && (obj = obj[part]));\n return obj;\n};\n\n/**\n * Calculates how close of a match the\n * given value is against a search token.\n *\n */\nexport const scoreValue = (value:string, token:T.Token, weight:number ):number => {\n\tvar score, pos;\n\n\tif (!value) return 0;\n\n\tvalue = value + '';\n\tpos = value.search(token.regex);\n\tif (pos === -1) return 0;\n\n\tscore = token.string.length / value.length;\n\tif (pos === 0) score += 0.5;\n\n\treturn score * weight;\n};\n\n/**\n *\n * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error\n */\nexport const escape_regex = (str:string):string => {\t\n\treturn (str + '').replace(/([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}\\\\])/gu, '\\\\$1');\n};\n\n\n/**\n * Cast object property to an array if it exists and has a value\n *\n */\nexport const propToArray = (obj:{[key:string]:any}, key:string) => {\n\tvar value = obj[key];\n\t\n\tif( typeof value == 'function' ) return value;\n\t\n\tif( value && !Array.isArray(value) ){\n\t\tobj[key] = [value];\n\t}\n}\n\n\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\nexport const iterate = (object:[]|{[key:string]:any}, callback:(value:any,key:number|string)=>any) => {\n\n\tif ( Array.isArray(object)) {\n\t\tobject.forEach(callback);\n\n\t}else{\n\n\t\tfor (var key in object) {\n\t\t\tif (object.hasOwnProperty(key)) {\n\t\t\t\tcallback(object[key], key);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\n\nexport const cmp = (a:number|string, b:number|string) => {\n\tif (typeof a === 'number' && typeof b === 'number') {\n\t\treturn a > b ? 1 : (a < b ? -1 : 0);\n\t}\n\ta = asciifold(a + '').toLowerCase();\n\tb = asciifold(b + '').toLowerCase();\n\tif (a > b) return 1;\n\tif (b > a) return -1;\n\treturn 0;\n};\n","/**\n * sifter.js\n * Copyright (c) 2013–2020 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis <brian@thirdroute.com>\n */\n\n // @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { scoreValue, getAttr, getAttrNesting, escape_regex, propToArray, iterate, cmp } from './utils.ts';\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { diacriticRegexPoints } from './diacritics.ts';\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport * as T from 'types.ts';\n\nexport default class Sifter{\n\n\tpublic items; // []|{};\n\tpublic settings: T.Settings;\n\n\t/**\n\t * Textually searches arrays and hashes of objects\n\t * by property (or multiple properties). Designed\n\t * specifically for autocomplete.\n\t *\n\t */\n\tconstructor(items:any, settings:T.Settings) {\n\t\tthis.items = items;\n\t\tthis.settings = settings || {diacritics: true};\n\t};\n\n\t/**\n\t * Splits a search string into an array of individual\n\t * regexps to be used to match results.\n\t *\n\t */\n\ttokenize(query:string, respect_word_boundaries?:boolean, weights?:T.Weights ):T.Token[] {\n\t\tif (!query || !query.length) return [];\n\n\t\tconst tokens:T.Token[]\t= [];\n\t\tconst words\t\t\t\t= query.split(/\\s+/);\n\t\tvar field_regex:RegExp;\n\n\t\tif( weights ){\n\t\t\tfield_regex = new RegExp( '^('+ Object.keys(weights).map(escape_regex).join('|')+')\\:(.*)$');\n\t\t}\n\n\t\twords.forEach((word:string) => {\n\t\t\tlet field_match;\n\t\t\tlet field:null|string\t= null;\n\t\t\tlet regex:null|string\t= null;\n\n\t\t\t// look for \"field:query\" tokens\n\t\t\tif( field_regex && (field_match = word.match(field_regex)) ){\n\t\t\t\tfield\t= field_match[1];\n\t\t\t\tword\t= field_match[2];\n\t\t\t}\n\n\t\t\tif( word.length > 0 ){\n\t\t\t\tregex = escape_regex(word);\n\t\t\t\tif( this.settings.diacritics ){\n\t\t\t\t\tregex = diacriticRegexPoints(regex);\n\t\t\t\t}\n\t\t\t\tif( respect_word_boundaries ) regex = \"\\\\b\"+regex;\n\t\t\t}\n\n\t\t\ttokens.push({\n\t\t\t\tstring : word,\n\t\t\t\tregex : regex ? new RegExp(regex,'iu') : null,\n\t\t\t\tfield : field,\n\t\t\t});\n\t\t});\n\n\t\treturn tokens;\n\t};\n\n\n\t/**\n\t * Returns a function to be used to score individual results.\n\t *\n\t * Good matches will have a higher score than poor matches.\n\t * If an item is not a match, 0 will be returned by the function.\n\t *\n\t * @returns {function}\n\t */\n\tgetScoreFunction(query:string, options:T.Options ){\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getScoreFunction(search);\n\t}\n\n\t_getScoreFunction(search:T.PrepareObj ){\n\t\tconst tokens\t\t= search.tokens,\n\t\ttoken_count\t\t\t= tokens.length;\n\n\t\tif (!token_count) {\n\t\t\treturn function() { return 0; };\n\t\t}\n\n\t\tconst fields\t= search.options.fields,\n\t\tweights\t\t\t= search.weights,\n\t\tfield_count\t\t= fields.length,\n\t\tgetAttrFn\t\t= search.getAttrFn;\n\n\t\tif (!field_count) {\n\t\t\treturn function() { return 1; };\n\t\t}\n\n\n\t\t/**\n\t\t * Calculates the score of an object\n\t\t * against the search query.\n\t\t *\n\t\t */\n\t\tconst scoreObject = (function() {\n\n\n\t\t\tif (field_count === 1) {\n\t\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\t\tconst field = fields[0].field;\n\t\t\t\t\treturn scoreValue(getAttrFn(data, field), token, weights[field]);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\tvar sum = 0;\n\n\t\t\t\t// is the token specific to a field?\n\t\t\t\tif( token.field ){\n\n\t\t\t\t\tconst value = getAttrFn(data, token.field);\n\n\t\t\t\t\tif( !token.regex && value ){\n\t\t\t\t\t\tsum += (1/field_count);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tsum += scoreValue(value, token, 1);\n\t\t\t\t\t}\n\n\n\n\t\t\t\t}else{\n\t\t\t\t\titerate(weights, (weight:number, field:string) => {\n\t\t\t\t\t\tsum += scoreValue(getAttrFn(data, field), token, weight);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn sum / field_count;\n\t\t\t};\n\t\t})();\n\n\t\tif (token_count === 1) {\n\t\t\treturn function(data:{}) {\n\t\t\t\treturn scoreObject(tokens[0], data);\n\t\t\t};\n\t\t}\n\n\t\tif (search.options.conjunction === 'and') {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar i = 0, score, sum = 0;\n\t\t\t\tfor (; i < token_count; i++) {\n\t\t\t\t\tscore = scoreObject(tokens[i], data);\n\t\t\t\t\tif (score <= 0) return 0;\n\t\t\t\t\tsum += score;\n\t\t\t\t}\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar sum = 0;\n\t\t\t\titerate(tokens,(token:T.Token)=>{\n\t\t\t\t\tsum += scoreObject(token, data);\n\t\t\t\t});\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Returns a function that can be used to compare two\n\t * results, for sorting purposes. If no sorting should\n\t * be performed, `null` will be returned.\n\t *\n\t * @return function(a,b)\n\t */\n\tgetSortFunction(query:string, options:T.Options) {\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getSortFunction(search);\n\t}\n\n\t_getSortFunction(search:T.PrepareObj){\n\t\tvar i, n, implicit_score;\n\n\t\tconst self\t= this,\n\t\toptions\t\t= search.options,\n\t\tsort\t\t= (!search.query && options.sort_empty) ? options.sort_empty : options.sort,\n\t\tsort_flds:T.Sort[]\t\t= [],\n\t\tmultipliers:number[]\t= [];\n\n\n\t\tif( typeof sort == 'function' ){\n\t\t\treturn sort.bind(this);\n\t\t}\t\t\t\n\n\t\t/**\n\t\t * Fetches the specified sort field value\n\t\t * from a search result item.\n\t\t *\n\t\t */\n\t\tconst get_field = function(name:string, result:T.ResultItem):string|number {\n\t\t\tif (name === '$score') return result.score;\n\t\t\treturn search.getAttrFn(self.items[result.id], name);\n\t\t};\n\n\t\t// parse options\n\t\tif (sort) {\n\t\t\tfor (i = 0, n = sort.length; i < n; i++) {\n\t\t\t\tif (search.query || sort[i].field !== '$score') {\n\t\t\t\t\tsort_flds.push(sort[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// the \"$score\" field is implied to be the primary\n\t\t// sort field, unless it's manually specified\n\t\tif (search.query) {\n\t\t\timplicit_score = true;\n\t\t\tfor (i = 0, n = sort_flds.length; i < n; i++) {\n\t\t\t\tif (sort_flds[i].field === '$score') {\n\t\t\t\t\timplicit_score = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (implicit_score) {\n\t\t\t\tsort_flds.unshift({field: '$score', direction: 'desc'});\n\t\t\t}\n\t\t} else {\n\t\t\tfor (i = 0, n = sort_flds.length; i < n; i++) {\n\t\t\t\tif (sort_flds[i].field === '$score') {\n\t\t\t\t\tsort_flds.splice(i, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (i = 0, n = sort_flds.length; i < n; i++) {\n\t\t\tmultipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1);\n\t\t}\n\n\t\t// build function\n\t\tconst sort_flds_count = sort_flds.length;\n\t\tif (!sort_flds_count) {\n\t\t\treturn null;\n\t\t} else if (sort_flds_count === 1) {\n\t\t\tconst sort_fld = sort_flds[0].field;\n\t\t\tconst multiplier = multipliers[0];\n\t\t\treturn function(a:T.ResultItem, b:T.ResultItem) {\n\t\t\t\treturn multiplier * cmp(\n\t\t\t\t\tget_field(sort_fld, a),\n\t\t\t\t\tget_field(sort_fld, b)\n\t\t\t\t);\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(a:T.ResultItem, b:T.ResultItem) {\n\t\t\t\tvar i, result, field;\n\t\t\t\tfor (i = 0; i < sort_flds_count; i++) {\n\t\t\t\t\tfield = sort_flds[i].field;\n\t\t\t\t\tresult = multipliers[i] * cmp(\n\t\t\t\t\t\tget_field(field, a),\n\t\t\t\t\t\tget_field(field, b)\n\t\t\t\t\t);\n\t\t\t\t\tif (result) return result;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Parses a search query and returns an object\n\t * with tokens and fields ready to be populated\n\t * with results.\n\t *\n\t */\n\tprepareSearch(query:string, optsUser:Partial<T.Options>):T.PrepareObj {\n\t\tconst weights:T.Weights = {};\n\t\tvar options\t\t= Object.assign({},optsUser);\n\n\t\tpropToArray(options,'sort');\n\t\tpropToArray(options,'sort_empty');\n\n\t\t// convert fields to new format\n\t\tif( options.fields ){\n\t\t\tpropToArray(options,'fields');\n\t\t\tconst fields:T.Field[] = [];\n\t\t\toptions.fields.forEach((field:string|T.Field) => {\n\t\t\t\tif( typeof field == 'string' ){\n\t\t\t\t\tfield = {field:field,weight:1};\n\t\t\t\t}\n\t\t\t\tfields.push(field);\n\t\t\t\tweights[field.field] = ('weight' in field) ? field.weight : 1;\n\t\t\t});\n\t\t\toptions.fields = fields;\n\t\t}\n\n\n\t\treturn {\n\t\t\toptions\t\t: options,\n\t\t\tquery\t\t: query.toLowerCase().trim(),\n\t\t\ttokens\t\t: this.tokenize(query, options.respect_word_boundaries, weights),\n\t\t\ttotal\t\t: 0,\n\t\t\titems\t\t: [],\n\t\t\tweights\t\t: weights,\n\t\t\tgetAttrFn\t: (options.nesting) ? getAttrNesting : getAttr,\n\t\t};\n\t};\n\n\t/**\n\t * Searches through all items and returns a sorted array of matches.\n\t *\n\t */\n\tsearch(query:string, options:T.Options) : T.PrepareObj {\n\t\tvar self = this, score, search:T.PrepareObj;\n\n\t\tsearch = this.prepareSearch(query, options);\n\t\toptions = search.options;\n\t\tquery = search.query;\n\n\t\t// generate result scoring function\n\t\tconst fn_score = options.score || self._getScoreFunction(search);\n\n\t\t// perform search and sort\n\t\tif (query.length) {\n\t\t\titerate(self.items, (item:T.ResultItem, id:string|number) => {\n\t\t\t\tscore = fn_score(item);\n\t\t\t\tif (options.filter === false || score > 0) {\n\t\t\t\t\tsearch.items.push({'score': score, 'id': id});\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\titerate(self.items, (item:T.ResultItem, id:string|number) => {\n\t\t\t\tsearch.items.push({'score': 1, 'id': id});\n\t\t\t});\n\t\t}\n\n\t\tconst fn_sort = self._getSortFunction(search);\n\t\tif (fn_sort) search.items.sort(fn_sort);\n\n\t\t// apply limits\n\t\tsearch.total = search.items.length;\n\t\tif (typeof options.limit === 'number') {\n\t\t\tsearch.items = search.items.slice(0, options.limit);\n\t\t}\n\n\t\treturn search;\n\t};\n}\n"],"names":["latin_pat","accent_pat","accent_reg","RegExp","diacritic_patterns","latin_convert","convert_pat","Object","keys","join","code_points","asciifold","str","normalize","replace","toLowerCase","foreignletter","arrayToPattern","chars","glue","length","longest","forEach","a","Math","max","allSubstrings","input","result","substring","subresult","tmp","slice","charAt","push","unshift","generateDiacritics","diacritics","code_range","i","diacritic","String","fromCharCode","latin","patt","match","latin_chars","sort","b","substrings","pattern","map","sub_pat","l","hasOwnProperty","diacriticRegexPoints","regex","undefined","decomposed","split","part","no_accent","composed_part","getAttr","obj","name","getAttrNesting","names","shift","scoreValue","value","token","weight","score","pos","search","string","escape_regex","propToArray","key","Array","isArray","iterate","object","callback","cmp","Sifter","constructor","items","settings","tokenize","query","respect_word_boundaries","weights","tokens","words","field_regex","word","field_match","field","getScoreFunction","options","prepareSearch","_getScoreFunction","token_count","fields","field_count","getAttrFn","scoreObject","data","sum","conjunction","getSortFunction","_getSortFunction","n","implicit_score","self","sort_empty","sort_flds","multipliers","bind","get_field","id","direction","splice","sort_flds_count","sort_fld","multiplier","optsUser","assign","trim","total","nesting","fn_score","item","filter","fn_sort","limit"],"mappings":";;;;;;;CAGA;CAEA,IAAIA,SAAJ;CACA,MAAMC,UAAU,GAAG,8BAAnB;;CACA,MAAMC,UAAU,GAAG,IAAIC,MAAJ,CAAWF,UAAX,EAAsB,GAAtB,CAAnB;CACA,IAAIG,kBAAJ;CAEA,MAAMC,aAA4B,GAAG;CACpC,OAAK,IAD+B;CAEpC,OAAK,GAF+B;CAGpC,OAAK;CAH+B,CAArC;CAMA,MAAMC,WAAW,GAAG,IAAIH,MAAJ,CAAWI,MAAM,CAACC,IAAP,CAAYH,aAAZ,EAA2BI,IAA3B,CAAgC,GAAhC,CAAX,EAAgD,GAAhD,CAApB;CAwGA;CACA;CACA;CACA;;CACO,MAAMC,WAAW,GAAG,CAC1B,CAAE,EAAF,EAAM,EAAN,CAD0B,EAE1B,CAAE,GAAF,EAAO,GAAP,CAF0B,EAG1B,CAAE,GAAF,EAAO,GAAP,CAH0B,EAI1B,CAAE,GAAF,EAAO,GAAP,CAJ0B,EAK1B,CAAE,GAAF,EAAO,GAAP,CAL0B,EAM1B,CAAE,IAAF,EAAQ,IAAR,CAN0B,EAO1B,CAAE,IAAF,EAAQ,IAAR,CA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AACoC,KAA9B,CAAf;CACA;;CAED,WAAO9D,MAAP;CACA;;CAlVyB;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"sifter.js","sources":["../../lib/diacritics.ts","../../lib/utils.ts","../../lib/sifter.ts"],"sourcesContent":["\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { escape_regex } from './utils.ts';\n\ntype TDiacraticList = {[key:string]:string};\n\n// https://github.com/andrewrk/node-diacritics/blob/master/index.js\n\nvar latin_pat:RegExp;\nconst accent_pat = '[\\u0300-\\u036F\\u{b7}\\u{2be}]'; // \\u{2bc}\nconst accent_reg = new RegExp(accent_pat,'gu');\nvar diacritic_patterns:TDiacraticList;\n\nconst latin_convert:TDiacraticList = {\n\t'æ': 'ae',\n\t'ⱥ': 'a',\n\t'ø': 'o',\n};\n\nconst convert_pat = new RegExp(Object.keys(latin_convert).join('|'),'gu');\n\nconst code_points:[[number,number]] = [[ 0, 65535 ]];\n\n/**\n * Remove accents\n * via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703\n *\n */\nexport const asciifold = (str:string):string => {\n\treturn str\n\t\t.normalize('NFKD')\n\t\t.replace(accent_reg, '')\n\t\t.toLowerCase()\n\t\t.replace(convert_pat,function(foreignletter) {\n\t\t\treturn latin_convert[foreignletter] || foreignletter;\n\t\t});\n};\n\n/**\n * Convert array of strings to a regular expression\n *\tex ['ab','a'] => (?:ab|a)\n * \tex ['a','b'] => [ab]\n *\n */\nexport const arrayToPattern = (chars:string[],glue:string='|'):string =>{\n\n\tif( chars.length === 1 && chars[0] != undefined ){\n\t\treturn chars[0];\n\t}\n\n\tvar longest = 1;\n\tchars.forEach((a)=>{longest = Math.max(longest,a.length)});\n\n\tif( longest == 1 ){\n\t\treturn '['+chars.join('')+']';\n\t}\n\n\treturn '(?:'+chars.join(glue)+')';\n};\n\nexport const escapeToPattern = (chars:string[]):string =>{\n\tconst escaped = chars.map((diacritic) => escape_regex(diacritic));\n\treturn arrayToPattern(escaped);\n};\n\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 *\n */\nexport const allSubstrings = (input:string):string[][] => {\n\n if( input.length === 1) return [[input]];\n\n var result:string[][] = [];\n allSubstrings(input.substring(1)).forEach(function(subresult) {\n var tmp = subresult.slice(0);\n tmp[0] = input.charAt(0) + tmp[0];\n result.push(tmp);\n\n tmp = subresult.slice(0);\n tmp.unshift(input.charAt(0));\n result.push(tmp);\n });\n\n return result;\n}\n\n/**\n * Generate a list of diacritics from the list of code points\n *\n */\nexport const generateDiacritics = (code_points:[[number,number]]):TDiacraticList => {\n\n\tvar diacritics:{[key:string]:string[]} = {};\n\tcode_points.forEach((code_range)=>{\n\n\t\tfor(let i = code_range[0]; i <= code_range[1]; i++){\n\n\t\t\tlet diacritic\t= String.fromCharCode(i);\n\t\t\tlet\tlatin\t\t= asciifold(diacritic);\n\n\t\t\tif( latin == diacritic.toLowerCase() ){\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// skip when latin is a string longer than 3 characters long\n\t\t\t// bc the resulting regex patterns will be long\n\t\t\t// eg:\n\t\t\t// latin صلى الله عليه وسلم length 18 code point 65018\n\t\t\t// latin جل جلاله length 8 code point 65019\n\t\t\tif( latin.length > 3 ){\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst latin_diacritics:string[] = diacritics[latin] || [latin];\n\t\t\tconst patt = new RegExp( escapeToPattern(latin_diacritics),'iu');\n\t\t\tif( diacritic.match(patt) ){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlatin_diacritics.push(diacritic);\n\t\t\tdiacritics[latin] = latin_diacritics;\n\t\t}\n\t});\n\n\t// filter out if there's only one character in the list\n\t// todo: this may not be needed\n\tObject.keys(diacritics).forEach(latin => {\n\t\tconst latin_diacritics = diacritics[latin] || [];\n\t\tif( latin_diacritics.length < 2 ){\n\t\t\tdelete diacritics[latin];\n\t\t}\n\t});\n\n\n\t// latin character pattern\n\t// match longer substrings first\n\tlet latin_chars\t= Object.keys(diacritics).sort((a, b) => b.length - a.length );\n\tlatin_pat\t\t= new RegExp('('+ escapeToPattern(latin_chars) + accent_pat + '*)','gu');\n\n\n\t// build diacritic patterns\n\t// ae needs:\n\t//\t(?:(?:ae|Æ|Ǽ|Ǣ)|(?:A|Ⓐ|A...)(?:E|ɛ|Ⓔ...))\n\tvar diacritic_patterns:TDiacraticList = {};\n\tlatin_chars.sort((a,b) => a.length -b.length).forEach((latin)=>{\n\n\t\tvar substrings\t= allSubstrings(latin);\n\t\tvar pattern = substrings.map((sub_pat)=>{\n\n\t\t\tsub_pat = sub_pat.map((l)=>{\n\t\t\t\tif( diacritics.hasOwnProperty(l) ){\n\t\t\t\t\treturn escapeToPattern(diacritics[l]!);\n\t\t\t\t}\n\t\t\t\treturn l;\n\t\t\t});\n\n\t\t\treturn arrayToPattern(sub_pat,'');\n\t\t});\n\n\t\tdiacritic_patterns[latin] = arrayToPattern(pattern);\n\t});\n\n\n\treturn diacritic_patterns;\n}\n\n/**\n * Expand a regular expression pattern to include diacritics\n * \teg /a/ becomes /aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐɑAⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ/\n *\n */\nexport const diacriticRegexPoints = (regex:string):string => {\n\n\tif( diacritic_patterns === undefined ){\n\t\tdiacritic_patterns = generateDiacritics(code_points);\n\t}\n\n\tconst decomposed\t\t= regex.normalize('NFKD').toLowerCase();\n\n\treturn decomposed.split(latin_pat).map((part:string)=>{\n\n\t\t// \"ffl\" or \"ffl\"\n\t\tconst no_accent = asciifold(part);\n\t\tif( no_accent == '' ){\n\t\t\treturn '';\n\t\t}\n\n\t\tif( diacritic_patterns.hasOwnProperty(no_accent) ){\n\t\t\treturn diacritic_patterns[no_accent];\n\t\t}\n\n\t\treturn part;\n\t}).join('');\n\n}\n","\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { asciifold } from './diacritics.ts';\n\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport * as T from './types.ts';\n\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\nexport const getAttr = (obj:{[key:string]:any}, name:string ) => {\n if (!obj ) return;\n return obj[name];\n};\n\n/**\n * A property getter resolving dot-notation\n * @param {Object} obj The root object to fetch property on\n * @param {String} name The optionally dotted property name to fetch\n * @return {Object} The resolved property value\n */\nexport const getAttrNesting = (obj:{[key:string]:any}, name:string ) => {\n if (!obj ) return;\n var part, names = name.split(\".\");\n\twhile( (part = names.shift()) && (obj = obj[part]));\n return obj;\n};\n\n/**\n * Calculates how close of a match the\n * given value is against a search token.\n *\n */\nexport const scoreValue = (value:string, token:T.Token, weight:number ):number => {\n\tvar score, pos;\n\n\tif (!value) return 0;\n\n\tvalue = value + '';\n\tpos = value.search(token.regex);\n\tif (pos === -1) return 0;\n\n\tscore = token.string.length / value.length;\n\tif (pos === 0) score += 0.5;\n\n\treturn score * weight;\n};\n\n/**\n *\n * https://stackoverflow.com/questions/63006601/why-does-u-throw-an-invalid-escape-error\n */\nexport const escape_regex = (str:string):string => {\n\treturn (str + '').replace(/([\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\|\\}\\\\])/gu, '\\\\$1');\n};\n\n\n/**\n * Cast object property to an array if it exists and has a value\n *\n */\nexport const propToArray = (obj:{[key:string]:any}, key:string) => {\n\tvar value = obj[key];\n\n\tif( typeof value == 'function' ) return value;\n\n\tif( value && !Array.isArray(value) ){\n\t\tobj[key] = [value];\n\t}\n}\n\n\n/**\n * Iterates over arrays and hashes.\n *\n * ```\n * iterate(this.items, function(item, id) {\n * // invoked for each item\n * });\n * ```\n *\n */\nexport const iterate = (object:[]|{[key:string]:any}, callback:(value:any,key:number|string)=>any) => {\n\n\tif ( Array.isArray(object)) {\n\t\tobject.forEach(callback);\n\n\t}else{\n\n\t\tfor (var key in object) {\n\t\t\tif (object.hasOwnProperty(key)) {\n\t\t\t\tcallback(object[key], key);\n\t\t\t}\n\t\t}\n\t}\n};\n\n\n\nexport const cmp = (a:number|string, b:number|string) => {\n\tif (typeof a === 'number' && typeof b === 'number') {\n\t\treturn a > b ? 1 : (a < b ? -1 : 0);\n\t}\n\ta = asciifold(a + '').toLowerCase();\n\tb = asciifold(b + '').toLowerCase();\n\tif (a > b) return 1;\n\tif (b > a) return -1;\n\treturn 0;\n};\n","/**\n * sifter.js\n * Copyright (c) 2013–2020 Brian Reavis & contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this\n * file except in compliance with the License. You may obtain a copy of the License at:\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n * ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n *\n * @author Brian Reavis <brian@thirdroute.com>\n */\n\n // @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { scoreValue, getAttr, getAttrNesting, escape_regex, propToArray, iterate, cmp } from './utils.ts';\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport { diacriticRegexPoints } from './diacritics.ts';\n// @ts-ignore TS2691 \"An import path cannot end with a '.ts' extension\"\nimport * as T from 'types.ts';\n\nexport default class Sifter{\n\n\tpublic items; // []|{};\n\tpublic settings: T.Settings;\n\n\t/**\n\t * Textually searches arrays and hashes of objects\n\t * by property (or multiple properties). Designed\n\t * specifically for autocomplete.\n\t *\n\t */\n\tconstructor(items:any, settings:T.Settings) {\n\t\tthis.items = items;\n\t\tthis.settings = settings || {diacritics: true};\n\t};\n\n\t/**\n\t * Splits a search string into an array of individual\n\t * regexps to be used to match results.\n\t *\n\t */\n\ttokenize(query:string, respect_word_boundaries?:boolean, weights?:T.Weights ):T.Token[] {\n\t\tif (!query || !query.length) return [];\n\n\t\tconst tokens:T.Token[]\t= [];\n\t\tconst words\t\t\t\t= query.split(/\\s+/);\n\t\tvar field_regex:RegExp;\n\n\t\tif( weights ){\n\t\t\tfield_regex = new RegExp( '^('+ Object.keys(weights).map(escape_regex).join('|')+')\\:(.*)$');\n\t\t}\n\n\t\twords.forEach((word:string) => {\n\t\t\tlet field_match;\n\t\t\tlet field:null|string\t= null;\n\t\t\tlet regex:null|string\t= null;\n\n\t\t\t// look for \"field:query\" tokens\n\t\t\tif( field_regex && (field_match = word.match(field_regex)) ){\n\t\t\t\tfield\t= field_match[1]!;\n\t\t\t\tword\t= field_match[2]!;\n\t\t\t}\n\n\t\t\tif( word.length > 0 ){\n\t\t\t\tif( this.settings.diacritics ){\n\t\t\t\t\tregex = diacriticRegexPoints(word);\n\t\t\t\t}else{\n\t\t\t\t\tregex = escape_regex(word);\n\t\t\t\t}\n\t\t\t\tif( respect_word_boundaries ) regex = \"\\\\b\"+regex;\n\t\t\t}\n\n\t\t\ttokens.push({\n\t\t\t\tstring : word,\n\t\t\t\tregex : regex ? new RegExp(regex,'iu') : null,\n\t\t\t\tfield : field,\n\t\t\t});\n\t\t});\n\n\t\treturn tokens;\n\t};\n\n\n\t/**\n\t * Returns a function to be used to score individual results.\n\t *\n\t * Good matches will have a higher score than poor matches.\n\t * If an item is not a match, 0 will be returned by the function.\n\t *\n\t * @returns {function}\n\t */\n\tgetScoreFunction(query:string, options:T.Options ){\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getScoreFunction(search);\n\t}\n\n\t_getScoreFunction(search:T.PrepareObj ){\n\t\tconst tokens\t\t= search.tokens,\n\t\ttoken_count\t\t\t= tokens.length;\n\n\t\tif (!token_count) {\n\t\t\treturn function() { return 0; };\n\t\t}\n\n\t\tconst fields\t= search.options.fields,\n\t\tweights\t\t\t= search.weights,\n\t\tfield_count\t\t= fields.length,\n\t\tgetAttrFn\t\t= search.getAttrFn;\n\n\t\tif (!field_count) {\n\t\t\treturn function() { return 1; };\n\t\t}\n\n\n\t\t/**\n\t\t * Calculates the score of an object\n\t\t * against the search query.\n\t\t *\n\t\t */\n\t\tconst scoreObject = (function() {\n\n\n\t\t\tif (field_count === 1) {\n\t\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\t\tconst field = fields[0].field;\n\t\t\t\t\treturn scoreValue(getAttrFn(data, field), token, weights[field]);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn function(token:T.Token, data:{}) {\n\t\t\t\tvar sum = 0;\n\n\t\t\t\t// is the token specific to a field?\n\t\t\t\tif( token.field ){\n\n\t\t\t\t\tconst value = getAttrFn(data, token.field);\n\n\t\t\t\t\tif( !token.regex && value ){\n\t\t\t\t\t\tsum += (1/field_count);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tsum += scoreValue(value, token, 1);\n\t\t\t\t\t}\n\n\n\n\t\t\t\t}else{\n\t\t\t\t\titerate(weights, (weight:number, field:string) => {\n\t\t\t\t\t\tsum += scoreValue(getAttrFn(data, field), token, weight);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\treturn sum / field_count;\n\t\t\t};\n\t\t})();\n\n\t\tif (token_count === 1) {\n\t\t\treturn function(data:{}) {\n\t\t\t\treturn scoreObject(tokens[0], data);\n\t\t\t};\n\t\t}\n\n\t\tif (search.options.conjunction === 'and') {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar i = 0, score, sum = 0;\n\t\t\t\tfor (; i < token_count; i++) {\n\t\t\t\t\tscore = scoreObject(tokens[i], data);\n\t\t\t\t\tif (score <= 0) return 0;\n\t\t\t\t\tsum += score;\n\t\t\t\t}\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t} else {\n\t\t\treturn function(data:{}) {\n\t\t\t\tvar sum = 0;\n\t\t\t\titerate(tokens,(token:T.Token)=>{\n\t\t\t\t\tsum += scoreObject(token, data);\n\t\t\t\t});\n\t\t\t\treturn sum / token_count;\n\t\t\t};\n\t\t}\n\t};\n\n\t/**\n\t * Returns a function that can be used to compare two\n\t * results, for sorting purposes. If no sorting should\n\t * be performed, `null` will be returned.\n\t *\n\t * @return function(a,b)\n\t */\n\tgetSortFunction(query:string, options:T.Options) {\n\t\tvar search = this.prepareSearch(query, options);\n\t\treturn this._getSortFunction(search);\n\t}\n\n\t_getSortFunction(search:T.PrepareObj){\n\t\tvar i, n, implicit_score;\n\n\t\tconst self\t= this,\n\t\toptions\t\t= search.options,\n\t\tsort\t\t= (!search.query && options.sort_empty) ? options.sort_empty : options.sort,\n\t\tsort_flds:T.Sort[]\t\t= [],\n\t\tmultipliers:number[]\t= [];\n\n\n\t\tif( typeof sort == 'function' ){\n\t\t\treturn sort.bind(this);\n\t\t}\n\n\t\t/**\n\t\t * Fetches the specified sort field value\n\t\t * from a search result item.\n\t\t *\n\t\t */\n\t\tconst get_field = function(name:string, result:T.ResultItem):string|number {\n\t\t\tif (name === '$score') return result.score;\n\t\t\treturn search.getAttrFn(self.items[result.id], name);\n\t\t};\n\n\t\t// parse options\n\t\tif (sort) {\n\t\t\tfor (i = 0, n = sort.length; i < n; i++) {\n\t\t\t\tif (search.query || sort[i].field !== '$score') {\n\t\t\t\t\tsort_flds.push(sort[i]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// the \"$score\" field is implied to be the primary\n\t\t// sort field, unless it's manually specified\n\t\tif (search.query) {\n\t\t\timplicit_score = true;\n\t\t\tfor (i = 0, n = sort_flds.length; i < n; i++) {\n\t\t\t\tif (sort_flds[i].field === '$score') {\n\t\t\t\t\timplicit_score = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (implicit_score) {\n\t\t\t\tsort_flds.unshift({field: '$score', direction: 'desc'});\n\t\t\t}\n\t\t} else {\n\t\t\tfor (i = 0, n = sort_flds.length; i < n; i++) {\n\t\t\t\tif (sort_flds[i].field === '$score') {\n\t\t\t\t\tsort_flds.splice(i, 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t\t// build function\n\t\tconst sort_flds_count = sort_flds.length;\n\t\tif (!sort_flds_count) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn function(a:T.ResultItem, b:T.ResultItem) {\n\t\t\tvar i, result, field;\n\t\t\tfor (i = 0; i < sort_flds_count; i++) {\n\t\t\t\tfield = sort_flds[i].field;\n\n\t\t\t\tlet multiplier = multipliers[i];\n\t\t\t\tif( multiplier == undefined ){\n\t\t\t\t\tmultiplier = sort_flds[i].direction === 'desc' ? -1 : 1;\n\t\t\t\t}\n\n\t\t\t\tresult = multiplier * cmp(\n\t\t\t\t\tget_field(field, a),\n\t\t\t\t\tget_field(field, b)\n\t\t\t\t);\n\t\t\t\tif (result) return result;\n\t\t\t}\n\t\t\treturn 0;\n\t\t};\n\t\t\n\t};\n\n\t/**\n\t * Parses a search query and returns an object\n\t * with tokens and fields ready to be populated\n\t * with results.\n\t *\n\t */\n\tprepareSearch(query:string, optsUser:Partial<T.Options>):T.PrepareObj {\n\t\tconst weights:T.Weights = {};\n\t\tvar options\t\t= Object.assign({},optsUser);\n\n\t\tpropToArray(options,'sort');\n\t\tpropToArray(options,'sort_empty');\n\n\t\t// convert fields to new format\n\t\tif( options.fields ){\n\t\t\tpropToArray(options,'fields');\n\t\t\tconst fields:T.Field[] = [];\n\t\t\toptions.fields.forEach((field:string|T.Field) => {\n\t\t\t\tif( typeof field == 'string' ){\n\t\t\t\t\tfield = {field:field,weight:1};\n\t\t\t\t}\n\t\t\t\tfields.push(field);\n\t\t\t\tweights[field.field] = ('weight' in field) ? field.weight : 1;\n\t\t\t});\n\t\t\toptions.fields = fields;\n\t\t}\n\n\n\t\treturn {\n\t\t\toptions\t\t: options,\n\t\t\tquery\t\t: query.toLowerCase().trim(),\n\t\t\ttokens\t\t: this.tokenize(query, options.respect_word_boundaries, weights),\n\t\t\ttotal\t\t: 0,\n\t\t\titems\t\t: [],\n\t\t\tweights\t\t: weights,\n\t\t\tgetAttrFn\t: (options.nesting) ? getAttrNesting : getAttr,\n\t\t};\n\t};\n\n\t/**\n\t * Searches through all items and returns a sorted array of matches.\n\t *\n\t */\n\tsearch(query:string, options:T.Options) : T.PrepareObj {\n\t\tvar self = this, score, search:T.PrepareObj;\n\n\t\tsearch = this.prepareSearch(query, options);\n\t\toptions = search.options;\n\t\tquery = search.query;\n\n\t\t// generate result scoring function\n\t\tconst fn_score = options.score || self._getScoreFunction(search);\n\n\t\t// perform search and sort\n\t\tif (query.length) {\n\t\t\titerate(self.items, (item:T.ResultItem, id:string|number) => {\n\t\t\t\tscore = fn_score(item);\n\t\t\t\tif (options.filter === false || score > 0) {\n\t\t\t\t\tsearch.items.push({'score': score, 'id': id});\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\titerate(self.items, (_:T.ResultItem, id:string|number) => {\n\t\t\t\tsearch.items.push({'score': 1, 'id': id});\n\t\t\t});\n\t\t}\n\n\t\tconst fn_sort = self._getSortFunction(search);\n\t\tif (fn_sort) search.items.sort(fn_sort);\n\n\t\t// apply limits\n\t\tsearch.total = search.items.length;\n\t\tif (typeof options.limit === 'number') {\n\t\t\tsearch.items = search.items.slice(0, options.limit);\n\t\t}\n\n\t\treturn search;\n\t};\n}\n"],"names":["latin_pat","accent_pat","accent_reg","RegExp","diacritic_patterns","latin_convert","convert_pat","Object","keys","join","code_points","asciifold","str","normalize","replace","toLowerCase","foreignletter","arrayToPattern","chars","glue","length","undefined","longest","forEach","a","Math","max","escapeToPattern","escaped","map","diacritic","escape_regex","allSubstrings","input","result","substring","subresult","tmp","slice","charAt","push","unshift","generateDiacritics","diacritics","code_range","i","String","fromCharCode","latin","latin_diacritics","patt","match","latin_chars","sort","b","substrings","pattern","sub_pat","l","hasOwnProperty","diacriticRegexPoints","regex","decomposed","split","part","no_accent","getAttr","obj","name","getAttrNesting","names","shift","scoreValue","value","token","weight","score","pos","search","string","propToArray","key","Array","isArray","iterate","object","callback","cmp","Sifter","constructor","items","settings","tokenize","query","respect_word_boundaries","weights","tokens","words","field_regex","word","field_match","field","getScoreFunction","options","prepareSearch","_getScoreFunction","token_count","fields","field_count","getAttrFn","scoreObject","data","sum","conjunction","getSortFunction","_getSortFunction","n","implicit_score","self","sort_empty","sort_flds","multipliers","bind","get_field","id","direction","splice","sort_flds_count","multiplier","optsUser","assign","trim","total","nesting","fn_score","item","filter","_","fn_sort","limit"],"mappings":";;;;;;;CACA;CAKA;CAEA,IAAIA,SAAJ;CACA,MAAMC,UAAU,GAAG,8BAAnB;;CACA,MAAMC,UAAU,GAAG,IAAIC,MAAJ,CAAWF,UAAX,EAAsB,IAAtB,CAAnB;CACA,IAAIG,kBAAJ;CAEA,MAAMC,aAA4B,GAAG;CACpC,OAAK,IAD+B;CAEpC,OAAK,GAF+B;CAGpC,OAAK;CAH+B,CAArC;CAMA,MAAMC,WAAW,GAAG,IAAIH,MAAJ,CAAWI,MAAM,CAACC,IAAP,CAAYH,aAAZ,EAA2BI,IAA3B,CAAgC,GAAhC,CAAX,EAAgD,IAAhD,CAApB;CAEA,MAAMC,WAA6B,GAAG,CAAC,CAAE,CAAF,EAAK,KAAL,CAAD,CAAtC;CAEA;CACA;CACA;CACA;CACA;;CACO,MAAMC,SAAS,GAAIC,GAAD,IAAuB;CAC/C,SAAOA,GAAG,CACRC,SADK,CACK,MADL,EAELC,OAFK,CAEGZ,UAFH,EAEe,EAFf,EAGLa,WAHK,GAILD,OAJK,CAIGR,WAJH,EAIe,UAASU,aAAT,EAAwB;CAC5C,WAAOX,aAAa,CAACW,aAAD,CAAb,IAAgCA,aAAvC;CACA,GANK,CAAP;CAOA,CARM;CAUP;CACA;CACA;CACA;CACA;CACA;;CACO,MAAMC,cAAc,GAAG,CAACC,KAAD,EAAgBC,IAAW,GAAC,GAA5B,KAA0C;CAEvE,MAAID,KAAK,CAACE,MAAN,KAAiB,CAAjB,IAAsBF,KAAK,CAAC,CAAD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,KAAP,CAAapD,KAAb,CAAmB,CAAnB,EAAsBiE,OAAO,CAACoC,KAA9B,CAAf;CACA;;CAED,WAAO7D,MAAP;CACA;;CA9UyB;;;;;;;;"}
|
package/dist/umd/sifter.min.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).sifter=t()}(this,(function(){"use strict"
|
|
2
2
|
var e
|
|
3
|
-
const t="[̀-ͯ·ʾ]",r=new RegExp(t,"
|
|
3
|
+
const t="[̀-ͯ·ʾ]",r=new RegExp(t,"gu")
|
|
4
4
|
var n
|
|
5
|
-
const i={"æ":"ae","ⱥ":"a","ø":"o"},o=new RegExp(Object.keys(i).join("|"),"
|
|
5
|
+
const i={"æ":"ae","ⱥ":"a","ø":"o"},o=new RegExp(Object.keys(i).join("|"),"gu"),s=[[0,65535]],c=e=>e.normalize("NFKD").replace(r,"").toLowerCase().replace(o,(function(e){return i[e]||e})),u=(e,t="|")=>{if(1===e.length&&null!=e[0])return e[0]
|
|
6
6
|
var r=1
|
|
7
|
-
return e.forEach((e=>{r=Math.max(r,e.length)})),1==r?"["+e.join("")+"]":"(?:"+e.join(t)+")"},f=e=>{
|
|
7
|
+
return e.forEach((e=>{r=Math.max(r,e.length)})),1==r?"["+e.join("")+"]":"(?:"+e.join(t)+")"},f=e=>{const t=e.map((e=>d(e)))
|
|
8
|
+
return u(t)},a=e=>{if(1===e.length)return[[e]]
|
|
8
9
|
var t=[]
|
|
9
|
-
return
|
|
10
|
-
n[0]=e.charAt(0)+n[0],t.push(n),(n=r.slice(0)).unshift(e.charAt(0)),t.push(n)})),t},
|
|
11
|
-
|
|
12
|
-
if(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
n
|
|
20
|
-
|
|
21
|
-
const t=c(e)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return r!=e?u([e,r]):e})).join("")},l=(e,t)=>{if(e)return e[t]},h=(e,t)=>{if(e){for(var r,n=t.split(".");(r=n.shift())&&(e=e[r]););return e}},g=(e,t,r)=>{var n,i
|
|
25
|
-
return e?-1===(i=(e+="").search(t.regex))?0:(n=t.string.length/e.length,0===i&&(n+=.5),n*r):0},p=e=>(e+"").replace(/([\$\(-\+\.\?\[-\^\{-\}])/g,"\\$1"),d=(e,t)=>{var r=e[t]
|
|
10
|
+
return a(e.substring(1)).forEach((function(r){var n=r.slice(0)
|
|
11
|
+
n[0]=e.charAt(0)+n[0],t.push(n),(n=r.slice(0)).unshift(e.charAt(0)),t.push(n)})),t},l=t=>{void 0===n&&(n=(t=>{var r={}
|
|
12
|
+
t.forEach((e=>{for(let t=e[0];t<=e[1];t++){let e=String.fromCharCode(t),n=c(e)
|
|
13
|
+
if(n==e.toLowerCase())continue
|
|
14
|
+
if(n.length>3)continue
|
|
15
|
+
const i=r[n]||[n],o=new RegExp(f(i),"iu")
|
|
16
|
+
e.match(o)||(i.push(e),r[n]=i)}})),Object.keys(r).forEach((e=>{(r[e]||[]).length<2&&delete r[e]}))
|
|
17
|
+
let n=Object.keys(r).sort(((e,t)=>t.length-e.length))
|
|
18
|
+
e=new RegExp("("+f(n)+"[̀-ͯ·ʾ]*)","gu")
|
|
19
|
+
var i={}
|
|
20
|
+
return n.sort(((e,t)=>e.length-t.length)).forEach((e=>{var t=a(e).map((e=>(e=e.map((e=>r.hasOwnProperty(e)?f(r[e]):e)),u(e,""))))
|
|
21
|
+
i[e]=u(t)})),i})(s))
|
|
22
|
+
return t.normalize("NFKD").toLowerCase().split(e).map((e=>{const t=c(e)
|
|
23
|
+
return""==t?"":n.hasOwnProperty(t)?n[t]:e})).join("")},h=(e,t)=>{if(e)return e[t]},g=(e,t)=>{if(e){for(var r,n=t.split(".");(r=n.shift())&&(e=e[r]););return e}},p=(e,t,r)=>{var n,i
|
|
24
|
+
return e?-1===(i=(e+="").search(t.regex))?0:(n=t.string.length/e.length,0===i&&(n+=.5),n*r):0},d=e=>(e+"").replace(/([\$\(-\+\.\?\[-\^\{-\}])/g,"\\$1"),m=(e,t)=>{var r=e[t]
|
|
26
25
|
if("function"==typeof r)return r
|
|
27
|
-
r&&!Array.isArray(r)&&(e[t]=[r])},
|
|
28
|
-
else for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)},
|
|
26
|
+
r&&!Array.isArray(r)&&(e[t]=[r])},y=(e,t)=>{if(Array.isArray(e))e.forEach(t)
|
|
27
|
+
else for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)},v=(e,t)=>"number"==typeof e&&"number"==typeof t?e>t?1:e<t?-1:0:(e=c(e+"").toLowerCase())>(t=c(t+"").toLowerCase())?1:t>e?-1:0
|
|
29
28
|
|
|
30
29
|
;/**
|
|
31
30
|
* sifter.js
|
|
@@ -45,20 +44,20 @@ else for(var r in e)e.hasOwnProperty(r)&&t(e[r],r)},y=(e,t)=>"number"==typeof e&
|
|
|
45
44
|
return class{constructor(e,t){this.items=void 0,this.settings=void 0,this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,r){if(!e||!e.length)return[]
|
|
46
45
|
const n=[],i=e.split(/\s+/)
|
|
47
46
|
var o
|
|
48
|
-
return r&&(o=new RegExp("^("+Object.keys(r).map(
|
|
49
|
-
o&&(r=e.match(o))&&(i=r[1],e=r[2]),e.length>0&&(s=
|
|
47
|
+
return r&&(o=new RegExp("^("+Object.keys(r).map(d).join("|")+"):(.*)$")),i.forEach((e=>{let r,i=null,s=null
|
|
48
|
+
o&&(r=e.match(o))&&(i=r[1],e=r[2]),e.length>0&&(s=this.settings.diacritics?l(e):d(e),t&&(s="\\b"+s)),n.push({string:e,regex:s?new RegExp(s,"iu"):null,field:i})})),n}getScoreFunction(e,t){var r=this.prepareSearch(e,t)
|
|
50
49
|
return this._getScoreFunction(r)}_getScoreFunction(e){const t=e.tokens,r=t.length
|
|
51
50
|
if(!r)return function(){return 0}
|
|
52
51
|
const n=e.options.fields,i=e.weights,o=n.length,s=e.getAttrFn
|
|
53
52
|
if(!o)return function(){return 1}
|
|
54
53
|
const c=1===o?function(e,t){const r=n[0].field
|
|
55
|
-
return
|
|
54
|
+
return p(s(t,r),e,i[r])}:function(e,t){var r=0
|
|
56
55
|
if(e.field){const n=s(t,e.field)
|
|
57
|
-
!e.regex&&n?r+=1/o:r+=
|
|
56
|
+
!e.regex&&n?r+=1/o:r+=p(n,e,1)}else y(i,((n,i)=>{r+=p(s(t,i),e,n)}))
|
|
58
57
|
return r/o}
|
|
59
58
|
return 1===r?function(e){return c(t[0],e)}:"and"===e.options.conjunction?function(e){for(var n,i=0,o=0;i<r;i++){if((n=c(t[i],e))<=0)return 0
|
|
60
59
|
o+=n}return o/r}:function(e){var n=0
|
|
61
|
-
return
|
|
60
|
+
return y(t,(t=>{n+=c(t,e)})),n/r}}getSortFunction(e,t){var r=this.prepareSearch(e,t)
|
|
62
61
|
return this._getSortFunction(r)}_getSortFunction(e){var t,r,n
|
|
63
62
|
const i=this,o=e.options,s=!e.query&&o.sort_empty?o.sort_empty:o.sort,c=[],u=[]
|
|
64
63
|
if("function"==typeof s)return s.bind(this)
|
|
@@ -66,19 +65,18 @@ const f=function(t,r){return"$score"===t?r.score:e.getAttrFn(i.items[r.id],t)}
|
|
|
66
65
|
if(s)for(t=0,r=s.length;t<r;t++)(e.query||"$score"!==s[t].field)&&c.push(s[t])
|
|
67
66
|
if(e.query){for(n=!0,t=0,r=c.length;t<r;t++)if("$score"===c[t].field){n=!1
|
|
68
67
|
break}n&&c.unshift({field:"$score",direction:"desc"})}else for(t=0,r=c.length;t<r;t++)if("$score"===c[t].field){c.splice(t,1)
|
|
69
|
-
break}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return 0}}return null}prepareSearch(e,t){const r={}
|
|
68
|
+
break}const a=c.length
|
|
69
|
+
return a?function(e,t){var r,n,i
|
|
70
|
+
for(r=0;r<a;r++){i=c[r].field
|
|
71
|
+
let o=u[r]
|
|
72
|
+
if(null==o&&(o="desc"===c[r].direction?-1:1),n=o*v(f(i,e),f(i,t)))return n}return 0}:null}prepareSearch(e,t){const r={}
|
|
75
73
|
var n=Object.assign({},t)
|
|
76
|
-
if(
|
|
74
|
+
if(m(n,"sort"),m(n,"sort_empty"),n.fields){m(n,"fields")
|
|
77
75
|
const e=[]
|
|
78
|
-
n.fields.forEach((t=>{"string"==typeof t&&(t={field:t,weight:1}),e.push(t),r[t.field]="weight"in t?t.weight:1})),n.fields=e}return{options:n,query:e.toLowerCase().trim(),tokens:this.tokenize(e,n.respect_word_boundaries,r),total:0,items:[],weights:r,getAttrFn:n.nesting?h
|
|
76
|
+
n.fields.forEach((t=>{"string"==typeof t&&(t={field:t,weight:1}),e.push(t),r[t.field]="weight"in t?t.weight:1})),n.fields=e}return{options:n,query:e.toLowerCase().trim(),tokens:this.tokenize(e,n.respect_word_boundaries,r),total:0,items:[],weights:r,getAttrFn:n.nesting?g:h}}search(e,t){var r,n,i=this
|
|
79
77
|
n=this.prepareSearch(e,t),t=n.options,e=n.query
|
|
80
78
|
const o=t.score||i._getScoreFunction(n)
|
|
81
|
-
e.length?
|
|
79
|
+
e.length?y(i.items,((e,i)=>{r=o(e),(!1===t.filter||r>0)&&n.items.push({score:r,id:i})})):y(i.items,((e,t)=>{n.items.push({score:1,id:t})}))
|
|
82
80
|
const s=i._getSortFunction(n)
|
|
83
81
|
return s&&n.items.sort(s),n.total=n.items.length,"number"==typeof t.limit&&(n.items=n.items.slice(0,t.limit)),n}}}))
|
|
84
82
|
//# sourceMappingURL=sifter.min.js.map
|