@startinblox/core 0.0.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.
Files changed (157) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -0
  3. package/dist/_snowpack/pkg/autolinker.js +4429 -0
  4. package/dist/_snowpack/pkg/autolinker.js.map +1 -0
  5. package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js +353 -0
  6. package/dist/_snowpack/pkg/common/_baseUnary-c1edb653.js.map +1 -0
  7. package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js +26 -0
  8. package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +1 -0
  9. package/dist/_snowpack/pkg/common/decode-26fbf385.js +185 -0
  10. package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +1 -0
  11. package/dist/_snowpack/pkg/common/lit-html-3647afce.js +1104 -0
  12. package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +1 -0
  13. package/dist/_snowpack/pkg/delta-markdown-for-quill.js +26198 -0
  14. package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +1 -0
  15. package/dist/_snowpack/pkg/dialog-polyfill.js +827 -0
  16. package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -0
  17. package/dist/_snowpack/pkg/fusejs.js +1593 -0
  18. package/dist/_snowpack/pkg/fusejs.js.map +1 -0
  19. package/dist/_snowpack/pkg/import-map.json +24 -0
  20. package/dist/_snowpack/pkg/jsonld-context-parser.js +836 -0
  21. package/dist/_snowpack/pkg/jsonld-context-parser.js.map +1 -0
  22. package/dist/_snowpack/pkg/leaflet/dist/leaflet.css +640 -0
  23. package/dist/_snowpack/pkg/leaflet/dist/leaflet.css.proxy.js +10 -0
  24. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css +60 -0
  25. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +10 -0
  26. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css +14 -0
  27. package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +10 -0
  28. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +39 -0
  29. package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +1 -0
  30. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +48 -0
  31. package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +1 -0
  32. package/dist/_snowpack/pkg/lit-html/directives/until.js +87 -0
  33. package/dist/_snowpack/pkg/lit-html/directives/until.js.map +1 -0
  34. package/dist/_snowpack/pkg/lit-html.js +94 -0
  35. package/dist/_snowpack/pkg/lit-html.js.map +1 -0
  36. package/dist/_snowpack/pkg/markdown-it-link-attributes.js +68 -0
  37. package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +1 -0
  38. package/dist/_snowpack/pkg/markdown-it.js +11307 -0
  39. package/dist/_snowpack/pkg/markdown-it.js.map +1 -0
  40. package/dist/_snowpack/pkg/quill/dist/quill.snow.css +945 -0
  41. package/dist/_snowpack/pkg/quill/dist/quill.snow.css.proxy.js +10 -0
  42. package/dist/_snowpack/pkg/quill-delta-to-markdown.js +971 -0
  43. package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +1 -0
  44. package/dist/_snowpack/pkg/quill.js +14442 -0
  45. package/dist/_snowpack/pkg/quill.js.map +1 -0
  46. package/dist/_snowpack/pkg/slim-select.js +714 -0
  47. package/dist/_snowpack/pkg/slim-select.js.map +1 -0
  48. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +1149 -0
  49. package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +10 -0
  50. package/dist/_snowpack/pkg/tui-calendar.js +46507 -0
  51. package/dist/_snowpack/pkg/tui-calendar.js.map +1 -0
  52. package/dist/components/solid-ac-checker.js +45 -0
  53. package/dist/components/solid-calendar.js +66 -0
  54. package/dist/components/solid-delete.js +96 -0
  55. package/dist/components/solid-display.js +150 -0
  56. package/dist/components/solid-form-search.js +177 -0
  57. package/dist/components/solid-form.js +259 -0
  58. package/dist/components/solid-lang.js +35 -0
  59. package/dist/components/solid-map.js +204 -0
  60. package/dist/components/solid-table.js +181 -0
  61. package/dist/components/solid-widget.js +72 -0
  62. package/dist/import.css +4 -0
  63. package/dist/index.js +49 -0
  64. package/dist/libs/Component.js +13 -0
  65. package/dist/libs/ComponentFactory.js +168 -0
  66. package/dist/libs/Compositor.js +96 -0
  67. package/dist/libs/Sib.js +44 -0
  68. package/dist/libs/filter.js +184 -0
  69. package/dist/libs/helpers.js +194 -0
  70. package/dist/libs/interfaces.js +6 -0
  71. package/dist/libs/lit-helpers.js +142 -0
  72. package/dist/libs/polyfills.js +37 -0
  73. package/dist/libs/store/server-pagination.js +22 -0
  74. package/dist/libs/store/server-search.js +35 -0
  75. package/dist/libs/store/store.js +814 -0
  76. package/dist/locales/en.json +10 -0
  77. package/dist/locales/en.json.proxy.js +2 -0
  78. package/dist/locales/fr.json +10 -0
  79. package/dist/locales/fr.json.proxy.js +2 -0
  80. package/dist/mixins/attributeBinderMixin.js +116 -0
  81. package/dist/mixins/contextMixin.js +26 -0
  82. package/dist/mixins/counterMixin.js +54 -0
  83. package/dist/mixins/federationMixin.js +51 -0
  84. package/dist/mixins/filterMixin.js +155 -0
  85. package/dist/mixins/grouperMixin.js +73 -0
  86. package/dist/mixins/highlighterMixin.js +36 -0
  87. package/dist/mixins/interfaces.js +6 -0
  88. package/dist/mixins/listMixin.js +105 -0
  89. package/dist/mixins/nextMixin.js +23 -0
  90. package/dist/mixins/paginateMixin.js +97 -0
  91. package/dist/mixins/requiredMixin.js +26 -0
  92. package/dist/mixins/serverPaginationMixin.js +122 -0
  93. package/dist/mixins/sorterMixin.js +131 -0
  94. package/dist/mixins/storeMixin.js +109 -0
  95. package/dist/mixins/translationMixin.js +58 -0
  96. package/dist/mixins/validationMixin.js +95 -0
  97. package/dist/mixins/widgetMixin.js +351 -0
  98. package/dist/new-widgets/attributeMixins/actionMixin.js +13 -0
  99. package/dist/new-widgets/attributeMixins/blankMixin.js +7 -0
  100. package/dist/new-widgets/attributeMixins/booleanMixin.js +7 -0
  101. package/dist/new-widgets/attributeMixins/index.js +19 -0
  102. package/dist/new-widgets/attributeMixins/mailtoMixin.js +7 -0
  103. package/dist/new-widgets/attributeMixins/multipleMixin.js +27 -0
  104. package/dist/new-widgets/attributeMixins/numberMixin.js +7 -0
  105. package/dist/new-widgets/attributeMixins/placeholderMixin.js +16 -0
  106. package/dist/new-widgets/attributeMixins/telMixin.js +7 -0
  107. package/dist/new-widgets/baseWidgetMixin.js +109 -0
  108. package/dist/new-widgets/callbackMixins/autocompletionMixin.js +96 -0
  109. package/dist/new-widgets/callbackMixins/index.js +7 -0
  110. package/dist/new-widgets/callbackMixins/richtextMixin.js +37 -0
  111. package/dist/new-widgets/callbackMixins/slimselect.css +2 -0
  112. package/dist/new-widgets/callbackMixins/slimselect.css.proxy.js +10 -0
  113. package/dist/new-widgets/interfaces.js +1 -0
  114. package/dist/new-widgets/new-widget-factory.js +91 -0
  115. package/dist/new-widgets/templateAdditionMixins/addableMixin.js +26 -0
  116. package/dist/new-widgets/templateAdditionMixins/index.js +13 -0
  117. package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +16 -0
  118. package/dist/new-widgets/templateAdditionMixins/labelMixin.js +18 -0
  119. package/dist/new-widgets/templates/defaultTemplatesDirectory.js +29 -0
  120. package/dist/new-widgets/templates/displayTemplatesDirectory.js +54 -0
  121. package/dist/new-widgets/templates/formTemplatesDirectory.js +432 -0
  122. package/dist/new-widgets/templates/groupTemplatesDirectory.js +11 -0
  123. package/dist/new-widgets/templates/index.js +6 -0
  124. package/dist/new-widgets/templates/setTemplatesDirectory.js +16 -0
  125. package/dist/new-widgets/templatesDependencies/altMixin.js +12 -0
  126. package/dist/new-widgets/templatesDependencies/editableMixin.js +60 -0
  127. package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +34 -0
  128. package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +10 -0
  129. package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +41 -0
  130. package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +56 -0
  131. package/dist/new-widgets/templatesDependencies/formFileMixin.js +82 -0
  132. package/dist/new-widgets/templatesDependencies/formLengthMixin.js +18 -0
  133. package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +18 -0
  134. package/dist/new-widgets/templatesDependencies/formMixin.js +56 -0
  135. package/dist/new-widgets/templatesDependencies/formNumberMixin.js +10 -0
  136. package/dist/new-widgets/templatesDependencies/formRadioMixin.js +12 -0
  137. package/dist/new-widgets/templatesDependencies/formStepMixin.js +12 -0
  138. package/dist/new-widgets/templatesDependencies/linkTextMixin.js +13 -0
  139. package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +112 -0
  140. package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +65 -0
  141. package/dist/new-widgets/templatesDependencies/patternMixin.js +18 -0
  142. package/dist/new-widgets/templatesDependencies/rangeMixin.js +100 -0
  143. package/dist/new-widgets/templatesDependencies/setMixin.js +9 -0
  144. package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +9 -0
  145. package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +14 -0
  146. package/dist/new-widgets/valueTransformationMixins/dateMixin.js +29 -0
  147. package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +12 -0
  148. package/dist/new-widgets/valueTransformationMixins/index.js +15 -0
  149. package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +30 -0
  150. package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +13 -0
  151. package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +21 -0
  152. package/dist/solid-template-element.js +144 -0
  153. package/dist/style/default-theme.css +24 -0
  154. package/dist/style/default-theme.css.proxy.js +10 -0
  155. package/dist/widgets/baseWidget.js +268 -0
  156. package/dist/widgets/widget-factory.js +22 -0
  157. package/package.json +117 -0
@@ -0,0 +1,1593 @@
1
+ /**
2
+ * Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
3
+ *
4
+ * Copyright (c) 2022 Kiro Risk (http://kiro.me)
5
+ * All Rights Reserved. Apache Software License 2.0
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ */
9
+
10
+ function isArray(value) {
11
+ return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value);
12
+ }
13
+
14
+ // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
15
+ const INFINITY = 1 / 0;
16
+ function baseToString(value) {
17
+ // Exit early for strings to avoid a performance hit in some environments.
18
+ if (typeof value == 'string') {
19
+ return value;
20
+ }
21
+ let result = value + '';
22
+ return result == '0' && 1 / value == -INFINITY ? '-0' : result;
23
+ }
24
+ function toString(value) {
25
+ return value == null ? '' : baseToString(value);
26
+ }
27
+ function isString(value) {
28
+ return typeof value === 'string';
29
+ }
30
+ function isNumber(value) {
31
+ return typeof value === 'number';
32
+ }
33
+
34
+ // Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
35
+ function isBoolean(value) {
36
+ return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]';
37
+ }
38
+ function isObject(value) {
39
+ return typeof value === 'object';
40
+ }
41
+
42
+ // Checks if `value` is object-like.
43
+ function isObjectLike(value) {
44
+ return isObject(value) && value !== null;
45
+ }
46
+ function isDefined(value) {
47
+ return value !== undefined && value !== null;
48
+ }
49
+ function isBlank(value) {
50
+ return !value.trim().length;
51
+ }
52
+
53
+ // Gets the `toStringTag` of `value`.
54
+ // Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
55
+ function getTag(value) {
56
+ return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value);
57
+ }
58
+ const EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available';
59
+ const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
60
+ const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = key => `Invalid value for key ${key}`;
61
+ const PATTERN_LENGTH_TOO_LARGE = max => `Pattern length exceeds max of ${max}.`;
62
+ const MISSING_KEY_PROPERTY = name => `Missing ${name} property in key`;
63
+ const INVALID_KEY_WEIGHT_VALUE = key => `Property 'weight' in key '${key}' must be a positive integer`;
64
+ const hasOwn = Object.prototype.hasOwnProperty;
65
+ class KeyStore {
66
+ constructor(keys) {
67
+ this._keys = [];
68
+ this._keyMap = {};
69
+ let totalWeight = 0;
70
+ keys.forEach(key => {
71
+ let obj = createKey(key);
72
+ totalWeight += obj.weight;
73
+ this._keys.push(obj);
74
+ this._keyMap[obj.id] = obj;
75
+ totalWeight += obj.weight;
76
+ });
77
+
78
+ // Normalize weights so that their sum is equal to 1
79
+ this._keys.forEach(key => {
80
+ key.weight /= totalWeight;
81
+ });
82
+ }
83
+ get(keyId) {
84
+ return this._keyMap[keyId];
85
+ }
86
+ keys() {
87
+ return this._keys;
88
+ }
89
+ toJSON() {
90
+ return JSON.stringify(this._keys);
91
+ }
92
+ }
93
+ function createKey(key) {
94
+ let path = null;
95
+ let id = null;
96
+ let src = null;
97
+ let weight = 1;
98
+ let getFn = null;
99
+ if (isString(key) || isArray(key)) {
100
+ src = key;
101
+ path = createKeyPath(key);
102
+ id = createKeyId(key);
103
+ } else {
104
+ if (!hasOwn.call(key, 'name')) {
105
+ throw new Error(MISSING_KEY_PROPERTY('name'));
106
+ }
107
+ const name = key.name;
108
+ src = name;
109
+ if (hasOwn.call(key, 'weight')) {
110
+ weight = key.weight;
111
+ if (weight <= 0) {
112
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
113
+ }
114
+ }
115
+ path = createKeyPath(name);
116
+ id = createKeyId(name);
117
+ getFn = key.getFn;
118
+ }
119
+ return {
120
+ path,
121
+ id,
122
+ weight,
123
+ src,
124
+ getFn
125
+ };
126
+ }
127
+ function createKeyPath(key) {
128
+ return isArray(key) ? key : key.split('.');
129
+ }
130
+ function createKeyId(key) {
131
+ return isArray(key) ? key.join('.') : key;
132
+ }
133
+ function get(obj, path) {
134
+ let list = [];
135
+ let arr = false;
136
+ const deepGet = (obj, path, index) => {
137
+ if (!isDefined(obj)) {
138
+ return;
139
+ }
140
+ if (!path[index]) {
141
+ // If there's no path left, we've arrived at the object we care about.
142
+ list.push(obj);
143
+ } else {
144
+ let key = path[index];
145
+ const value = obj[key];
146
+ if (!isDefined(value)) {
147
+ return;
148
+ }
149
+
150
+ // If we're at the last value in the path, and if it's a string/number/bool,
151
+ // add it to the list
152
+ if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
153
+ list.push(toString(value));
154
+ } else if (isArray(value)) {
155
+ arr = true;
156
+ // Search each item in the array.
157
+ for (let i = 0, len = value.length; i < len; i += 1) {
158
+ deepGet(value[i], path, index + 1);
159
+ }
160
+ } else if (path.length) {
161
+ // An object. Recurse further.
162
+ deepGet(value, path, index + 1);
163
+ }
164
+ }
165
+ };
166
+
167
+ // Backwards compatibility (since path used to be a string)
168
+ deepGet(obj, isString(path) ? path.split('.') : path, 0);
169
+ return arr ? list : list[0];
170
+ }
171
+ const MatchOptions = {
172
+ // Whether the matches should be included in the result set. When `true`, each record in the result
173
+ // set will include the indices of the matched characters.
174
+ // These can consequently be used for highlighting purposes.
175
+ includeMatches: false,
176
+ // When `true`, the matching function will continue to the end of a search pattern even if
177
+ // a perfect match has already been located in the string.
178
+ findAllMatches: false,
179
+ // Minimum number of characters that must be matched before a result is considered a match
180
+ minMatchCharLength: 1
181
+ };
182
+ const BasicOptions = {
183
+ // When `true`, the algorithm continues searching to the end of the input even if a perfect
184
+ // match is found before the end of the same input.
185
+ isCaseSensitive: false,
186
+ // When true, the matching function will continue to the end of a search pattern even if
187
+ includeScore: false,
188
+ // List of properties that will be searched. This also supports nested properties.
189
+ keys: [],
190
+ // Whether to sort the result list, by score
191
+ shouldSort: true,
192
+ // Default sort function: sort by ascending score, ascending index
193
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
194
+ };
195
+ const FuzzyOptions = {
196
+ // Approximately where in the text is the pattern expected to be found?
197
+ location: 0,
198
+ // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
199
+ // (of both letters and location), a threshold of '1.0' would match anything.
200
+ threshold: 0.6,
201
+ // Determines how close the match must be to the fuzzy location (specified above).
202
+ // An exact letter match which is 'distance' characters away from the fuzzy location
203
+ // would score as a complete mismatch. A distance of '0' requires the match be at
204
+ // the exact location specified, a threshold of '1000' would require a perfect match
205
+ // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
206
+ distance: 100
207
+ };
208
+ const AdvancedOptions = {
209
+ // When `true`, it enables the use of unix-like search commands
210
+ useExtendedSearch: false,
211
+ // The get function to use when fetching an object's properties.
212
+ // The default will search nested paths *ie foo.bar.baz*
213
+ getFn: get,
214
+ // When `true`, search will ignore `location` and `distance`, so it won't matter
215
+ // where in the string the pattern appears.
216
+ // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
217
+ ignoreLocation: false,
218
+ // When `true`, the calculation for the relevance score (used for sorting) will
219
+ // ignore the field-length norm.
220
+ // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
221
+ ignoreFieldNorm: false,
222
+ // The weight to determine how much field length norm effects scoring.
223
+ fieldNormWeight: 1
224
+ };
225
+ var Config = {
226
+ ...BasicOptions,
227
+ ...MatchOptions,
228
+ ...FuzzyOptions,
229
+ ...AdvancedOptions
230
+ };
231
+ const SPACE = /[^ ]+/g;
232
+
233
+ // Field-length norm: the shorter the field, the higher the weight.
234
+ // Set to 3 decimals to reduce index size.
235
+ function norm(weight = 1, mantissa = 3) {
236
+ const cache = new Map();
237
+ const m = Math.pow(10, mantissa);
238
+ return {
239
+ get(value) {
240
+ const numTokens = value.match(SPACE).length;
241
+ if (cache.has(numTokens)) {
242
+ return cache.get(numTokens);
243
+ }
244
+
245
+ // Default function is 1/sqrt(x), weight makes that variable
246
+ const norm = 1 / Math.pow(numTokens, 0.5 * weight);
247
+
248
+ // In place of `toFixed(mantissa)`, for faster computation
249
+ const n = parseFloat(Math.round(norm * m) / m);
250
+ cache.set(numTokens, n);
251
+ return n;
252
+ },
253
+ clear() {
254
+ cache.clear();
255
+ }
256
+ };
257
+ }
258
+ class FuseIndex {
259
+ constructor({
260
+ getFn = Config.getFn,
261
+ fieldNormWeight = Config.fieldNormWeight
262
+ } = {}) {
263
+ this.norm = norm(fieldNormWeight, 3);
264
+ this.getFn = getFn;
265
+ this.isCreated = false;
266
+ this.setIndexRecords();
267
+ }
268
+ setSources(docs = []) {
269
+ this.docs = docs;
270
+ }
271
+ setIndexRecords(records = []) {
272
+ this.records = records;
273
+ }
274
+ setKeys(keys = []) {
275
+ this.keys = keys;
276
+ this._keysMap = {};
277
+ keys.forEach((key, idx) => {
278
+ this._keysMap[key.id] = idx;
279
+ });
280
+ }
281
+ create() {
282
+ if (this.isCreated || !this.docs.length) {
283
+ return;
284
+ }
285
+ this.isCreated = true;
286
+
287
+ // List is Array<String>
288
+ if (isString(this.docs[0])) {
289
+ this.docs.forEach((doc, docIndex) => {
290
+ this._addString(doc, docIndex);
291
+ });
292
+ } else {
293
+ // List is Array<Object>
294
+ this.docs.forEach((doc, docIndex) => {
295
+ this._addObject(doc, docIndex);
296
+ });
297
+ }
298
+ this.norm.clear();
299
+ }
300
+ // Adds a doc to the end of the index
301
+ add(doc) {
302
+ const idx = this.size();
303
+ if (isString(doc)) {
304
+ this._addString(doc, idx);
305
+ } else {
306
+ this._addObject(doc, idx);
307
+ }
308
+ }
309
+ // Removes the doc at the specified index of the index
310
+ removeAt(idx) {
311
+ this.records.splice(idx, 1);
312
+
313
+ // Change ref index of every subsquent doc
314
+ for (let i = idx, len = this.size(); i < len; i += 1) {
315
+ this.records[i].i -= 1;
316
+ }
317
+ }
318
+ getValueForItemAtKeyId(item, keyId) {
319
+ return item[this._keysMap[keyId]];
320
+ }
321
+ size() {
322
+ return this.records.length;
323
+ }
324
+ _addString(doc, docIndex) {
325
+ if (!isDefined(doc) || isBlank(doc)) {
326
+ return;
327
+ }
328
+ let record = {
329
+ v: doc,
330
+ i: docIndex,
331
+ n: this.norm.get(doc)
332
+ };
333
+ this.records.push(record);
334
+ }
335
+ _addObject(doc, docIndex) {
336
+ let record = {
337
+ i: docIndex,
338
+ $: {}
339
+ };
340
+
341
+ // Iterate over every key (i.e, path), and fetch the value at that key
342
+ this.keys.forEach((key, keyIndex) => {
343
+ let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
344
+ if (!isDefined(value)) {
345
+ return;
346
+ }
347
+ if (isArray(value)) {
348
+ let subRecords = [];
349
+ const stack = [{
350
+ nestedArrIndex: -1,
351
+ value
352
+ }];
353
+ while (stack.length) {
354
+ const {
355
+ nestedArrIndex,
356
+ value
357
+ } = stack.pop();
358
+ if (!isDefined(value)) {
359
+ continue;
360
+ }
361
+ if (isString(value) && !isBlank(value)) {
362
+ let subRecord = {
363
+ v: value,
364
+ i: nestedArrIndex,
365
+ n: this.norm.get(value)
366
+ };
367
+ subRecords.push(subRecord);
368
+ } else if (isArray(value)) {
369
+ value.forEach((item, k) => {
370
+ stack.push({
371
+ nestedArrIndex: k,
372
+ value: item
373
+ });
374
+ });
375
+ } else ;
376
+ }
377
+ record.$[keyIndex] = subRecords;
378
+ } else if (isString(value) && !isBlank(value)) {
379
+ let subRecord = {
380
+ v: value,
381
+ n: this.norm.get(value)
382
+ };
383
+ record.$[keyIndex] = subRecord;
384
+ }
385
+ });
386
+ this.records.push(record);
387
+ }
388
+ toJSON() {
389
+ return {
390
+ keys: this.keys,
391
+ records: this.records
392
+ };
393
+ }
394
+ }
395
+ function createIndex(keys, docs, {
396
+ getFn = Config.getFn,
397
+ fieldNormWeight = Config.fieldNormWeight
398
+ } = {}) {
399
+ const myIndex = new FuseIndex({
400
+ getFn,
401
+ fieldNormWeight
402
+ });
403
+ myIndex.setKeys(keys.map(createKey));
404
+ myIndex.setSources(docs);
405
+ myIndex.create();
406
+ return myIndex;
407
+ }
408
+ function parseIndex(data, {
409
+ getFn = Config.getFn,
410
+ fieldNormWeight = Config.fieldNormWeight
411
+ } = {}) {
412
+ const {
413
+ keys,
414
+ records
415
+ } = data;
416
+ const myIndex = new FuseIndex({
417
+ getFn,
418
+ fieldNormWeight
419
+ });
420
+ myIndex.setKeys(keys);
421
+ myIndex.setIndexRecords(records);
422
+ return myIndex;
423
+ }
424
+ function computeScore$1(pattern, {
425
+ errors = 0,
426
+ currentLocation = 0,
427
+ expectedLocation = 0,
428
+ distance = Config.distance,
429
+ ignoreLocation = Config.ignoreLocation
430
+ } = {}) {
431
+ const accuracy = errors / pattern.length;
432
+ if (ignoreLocation) {
433
+ return accuracy;
434
+ }
435
+ const proximity = Math.abs(expectedLocation - currentLocation);
436
+ if (!distance) {
437
+ // Dodge divide by zero error.
438
+ return proximity ? 1.0 : accuracy;
439
+ }
440
+ return accuracy + proximity / distance;
441
+ }
442
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
443
+ let indices = [];
444
+ let start = -1;
445
+ let end = -1;
446
+ let i = 0;
447
+ for (let len = matchmask.length; i < len; i += 1) {
448
+ let match = matchmask[i];
449
+ if (match && start === -1) {
450
+ start = i;
451
+ } else if (!match && start !== -1) {
452
+ end = i - 1;
453
+ if (end - start + 1 >= minMatchCharLength) {
454
+ indices.push([start, end]);
455
+ }
456
+ start = -1;
457
+ }
458
+ }
459
+
460
+ // (i-1 - start) + 1 => i - start
461
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
462
+ indices.push([start, i - 1]);
463
+ }
464
+ return indices;
465
+ }
466
+
467
+ // Machine word size
468
+ const MAX_BITS = 32;
469
+ function search(text, pattern, patternAlphabet, {
470
+ location = Config.location,
471
+ distance = Config.distance,
472
+ threshold = Config.threshold,
473
+ findAllMatches = Config.findAllMatches,
474
+ minMatchCharLength = Config.minMatchCharLength,
475
+ includeMatches = Config.includeMatches,
476
+ ignoreLocation = Config.ignoreLocation
477
+ } = {}) {
478
+ if (pattern.length > MAX_BITS) {
479
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
480
+ }
481
+ const patternLen = pattern.length;
482
+ // Set starting location at beginning text and initialize the alphabet.
483
+ const textLen = text.length;
484
+ // Handle the case when location > text.length
485
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
486
+ // Highest score beyond which we give up.
487
+ let currentThreshold = threshold;
488
+ // Is there a nearby exact match? (speedup)
489
+ let bestLocation = expectedLocation;
490
+
491
+ // Performance: only computer matches when the minMatchCharLength > 1
492
+ // OR if `includeMatches` is true.
493
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
494
+ // A mask of the matches, used for building the indices
495
+ const matchMask = computeMatches ? Array(textLen) : [];
496
+ let index;
497
+
498
+ // Get all exact matches, here for speed up
499
+ while ((index = text.indexOf(pattern, bestLocation)) > -1) {
500
+ let score = computeScore$1(pattern, {
501
+ currentLocation: index,
502
+ expectedLocation,
503
+ distance,
504
+ ignoreLocation
505
+ });
506
+ currentThreshold = Math.min(score, currentThreshold);
507
+ bestLocation = index + patternLen;
508
+ if (computeMatches) {
509
+ let i = 0;
510
+ while (i < patternLen) {
511
+ matchMask[index + i] = 1;
512
+ i += 1;
513
+ }
514
+ }
515
+ }
516
+
517
+ // Reset the best location
518
+ bestLocation = -1;
519
+ let lastBitArr = [];
520
+ let finalScore = 1;
521
+ let binMax = patternLen + textLen;
522
+ const mask = 1 << patternLen - 1;
523
+ for (let i = 0; i < patternLen; i += 1) {
524
+ // Scan for the best match; each iteration allows for one more error.
525
+ // Run a binary search to determine how far from the match location we can stray
526
+ // at this error level.
527
+ let binMin = 0;
528
+ let binMid = binMax;
529
+ while (binMin < binMid) {
530
+ const score = computeScore$1(pattern, {
531
+ errors: i,
532
+ currentLocation: expectedLocation + binMid,
533
+ expectedLocation,
534
+ distance,
535
+ ignoreLocation
536
+ });
537
+ if (score <= currentThreshold) {
538
+ binMin = binMid;
539
+ } else {
540
+ binMax = binMid;
541
+ }
542
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
543
+ }
544
+
545
+ // Use the result from this iteration as the maximum for the next.
546
+ binMax = binMid;
547
+ let start = Math.max(1, expectedLocation - binMid + 1);
548
+ let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
549
+
550
+ // Initialize the bit array
551
+ let bitArr = Array(finish + 2);
552
+ bitArr[finish + 1] = (1 << i) - 1;
553
+ for (let j = finish; j >= start; j -= 1) {
554
+ let currentLocation = j - 1;
555
+ let charMatch = patternAlphabet[text.charAt(currentLocation)];
556
+ if (computeMatches) {
557
+ // Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
558
+ matchMask[currentLocation] = +!!charMatch;
559
+ }
560
+
561
+ // First pass: exact match
562
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
563
+
564
+ // Subsequent passes: fuzzy match
565
+ if (i) {
566
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
567
+ }
568
+ if (bitArr[j] & mask) {
569
+ finalScore = computeScore$1(pattern, {
570
+ errors: i,
571
+ currentLocation,
572
+ expectedLocation,
573
+ distance,
574
+ ignoreLocation
575
+ });
576
+
577
+ // This match will almost certainly be better than any existing match.
578
+ // But check anyway.
579
+ if (finalScore <= currentThreshold) {
580
+ // Indeed it is
581
+ currentThreshold = finalScore;
582
+ bestLocation = currentLocation;
583
+
584
+ // Already passed `loc`, downhill from here on in.
585
+ if (bestLocation <= expectedLocation) {
586
+ break;
587
+ }
588
+
589
+ // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
590
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
591
+ }
592
+ }
593
+ }
594
+
595
+ // No hope for a (better) match at greater error levels.
596
+ const score = computeScore$1(pattern, {
597
+ errors: i + 1,
598
+ currentLocation: expectedLocation,
599
+ expectedLocation,
600
+ distance,
601
+ ignoreLocation
602
+ });
603
+ if (score > currentThreshold) {
604
+ break;
605
+ }
606
+ lastBitArr = bitArr;
607
+ }
608
+ const result = {
609
+ isMatch: bestLocation >= 0,
610
+ // Count exact matches (those with a score of 0) to be "almost" exact
611
+ score: Math.max(0.001, finalScore)
612
+ };
613
+ if (computeMatches) {
614
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
615
+ if (!indices.length) {
616
+ result.isMatch = false;
617
+ } else if (includeMatches) {
618
+ result.indices = indices;
619
+ }
620
+ }
621
+ return result;
622
+ }
623
+ function createPatternAlphabet(pattern) {
624
+ let mask = {};
625
+ for (let i = 0, len = pattern.length; i < len; i += 1) {
626
+ const char = pattern.charAt(i);
627
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
628
+ }
629
+ return mask;
630
+ }
631
+ class BitapSearch {
632
+ constructor(pattern, {
633
+ location = Config.location,
634
+ threshold = Config.threshold,
635
+ distance = Config.distance,
636
+ includeMatches = Config.includeMatches,
637
+ findAllMatches = Config.findAllMatches,
638
+ minMatchCharLength = Config.minMatchCharLength,
639
+ isCaseSensitive = Config.isCaseSensitive,
640
+ ignoreLocation = Config.ignoreLocation
641
+ } = {}) {
642
+ this.options = {
643
+ location,
644
+ threshold,
645
+ distance,
646
+ includeMatches,
647
+ findAllMatches,
648
+ minMatchCharLength,
649
+ isCaseSensitive,
650
+ ignoreLocation
651
+ };
652
+ this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
653
+ this.chunks = [];
654
+ if (!this.pattern.length) {
655
+ return;
656
+ }
657
+ const addChunk = (pattern, startIndex) => {
658
+ this.chunks.push({
659
+ pattern,
660
+ alphabet: createPatternAlphabet(pattern),
661
+ startIndex
662
+ });
663
+ };
664
+ const len = this.pattern.length;
665
+ if (len > MAX_BITS) {
666
+ let i = 0;
667
+ const remainder = len % MAX_BITS;
668
+ const end = len - remainder;
669
+ while (i < end) {
670
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
671
+ i += MAX_BITS;
672
+ }
673
+ if (remainder) {
674
+ const startIndex = len - MAX_BITS;
675
+ addChunk(this.pattern.substr(startIndex), startIndex);
676
+ }
677
+ } else {
678
+ addChunk(this.pattern, 0);
679
+ }
680
+ }
681
+ searchIn(text) {
682
+ const {
683
+ isCaseSensitive,
684
+ includeMatches
685
+ } = this.options;
686
+ if (!isCaseSensitive) {
687
+ text = text.toLowerCase();
688
+ }
689
+
690
+ // Exact match
691
+ if (this.pattern === text) {
692
+ let result = {
693
+ isMatch: true,
694
+ score: 0
695
+ };
696
+ if (includeMatches) {
697
+ result.indices = [[0, text.length - 1]];
698
+ }
699
+ return result;
700
+ }
701
+
702
+ // Otherwise, use Bitap algorithm
703
+ const {
704
+ location,
705
+ distance,
706
+ threshold,
707
+ findAllMatches,
708
+ minMatchCharLength,
709
+ ignoreLocation
710
+ } = this.options;
711
+ let allIndices = [];
712
+ let totalScore = 0;
713
+ let hasMatches = false;
714
+ this.chunks.forEach(({
715
+ pattern,
716
+ alphabet,
717
+ startIndex
718
+ }) => {
719
+ const {
720
+ isMatch,
721
+ score,
722
+ indices
723
+ } = search(text, pattern, alphabet, {
724
+ location: location + startIndex,
725
+ distance,
726
+ threshold,
727
+ findAllMatches,
728
+ minMatchCharLength,
729
+ includeMatches,
730
+ ignoreLocation
731
+ });
732
+ if (isMatch) {
733
+ hasMatches = true;
734
+ }
735
+ totalScore += score;
736
+ if (isMatch && indices) {
737
+ allIndices = [...allIndices, ...indices];
738
+ }
739
+ });
740
+ let result = {
741
+ isMatch: hasMatches,
742
+ score: hasMatches ? totalScore / this.chunks.length : 1
743
+ };
744
+ if (hasMatches && includeMatches) {
745
+ result.indices = allIndices;
746
+ }
747
+ return result;
748
+ }
749
+ }
750
+ class BaseMatch {
751
+ constructor(pattern) {
752
+ this.pattern = pattern;
753
+ }
754
+ static isMultiMatch(pattern) {
755
+ return getMatch(pattern, this.multiRegex);
756
+ }
757
+ static isSingleMatch(pattern) {
758
+ return getMatch(pattern, this.singleRegex);
759
+ }
760
+ search( /*text*/) {}
761
+ }
762
+ function getMatch(pattern, exp) {
763
+ const matches = pattern.match(exp);
764
+ return matches ? matches[1] : null;
765
+ }
766
+
767
+ // Token: 'file
768
+
769
+ class ExactMatch extends BaseMatch {
770
+ constructor(pattern) {
771
+ super(pattern);
772
+ }
773
+ static get type() {
774
+ return 'exact';
775
+ }
776
+ static get multiRegex() {
777
+ return /^="(.*)"$/;
778
+ }
779
+ static get singleRegex() {
780
+ return /^=(.*)$/;
781
+ }
782
+ search(text) {
783
+ const isMatch = text === this.pattern;
784
+ return {
785
+ isMatch,
786
+ score: isMatch ? 0 : 1,
787
+ indices: [0, this.pattern.length - 1]
788
+ };
789
+ }
790
+ }
791
+
792
+ // Token: !fire
793
+
794
+ class InverseExactMatch extends BaseMatch {
795
+ constructor(pattern) {
796
+ super(pattern);
797
+ }
798
+ static get type() {
799
+ return 'inverse-exact';
800
+ }
801
+ static get multiRegex() {
802
+ return /^!"(.*)"$/;
803
+ }
804
+ static get singleRegex() {
805
+ return /^!(.*)$/;
806
+ }
807
+ search(text) {
808
+ const index = text.indexOf(this.pattern);
809
+ const isMatch = index === -1;
810
+ return {
811
+ isMatch,
812
+ score: isMatch ? 0 : 1,
813
+ indices: [0, text.length - 1]
814
+ };
815
+ }
816
+ }
817
+
818
+ // Token: ^file
819
+
820
+ class PrefixExactMatch extends BaseMatch {
821
+ constructor(pattern) {
822
+ super(pattern);
823
+ }
824
+ static get type() {
825
+ return 'prefix-exact';
826
+ }
827
+ static get multiRegex() {
828
+ return /^\^"(.*)"$/;
829
+ }
830
+ static get singleRegex() {
831
+ return /^\^(.*)$/;
832
+ }
833
+ search(text) {
834
+ const isMatch = text.startsWith(this.pattern);
835
+ return {
836
+ isMatch,
837
+ score: isMatch ? 0 : 1,
838
+ indices: [0, this.pattern.length - 1]
839
+ };
840
+ }
841
+ }
842
+
843
+ // Token: !^fire
844
+
845
+ class InversePrefixExactMatch extends BaseMatch {
846
+ constructor(pattern) {
847
+ super(pattern);
848
+ }
849
+ static get type() {
850
+ return 'inverse-prefix-exact';
851
+ }
852
+ static get multiRegex() {
853
+ return /^!\^"(.*)"$/;
854
+ }
855
+ static get singleRegex() {
856
+ return /^!\^(.*)$/;
857
+ }
858
+ search(text) {
859
+ const isMatch = !text.startsWith(this.pattern);
860
+ return {
861
+ isMatch,
862
+ score: isMatch ? 0 : 1,
863
+ indices: [0, text.length - 1]
864
+ };
865
+ }
866
+ }
867
+
868
+ // Token: .file$
869
+
870
+ class SuffixExactMatch extends BaseMatch {
871
+ constructor(pattern) {
872
+ super(pattern);
873
+ }
874
+ static get type() {
875
+ return 'suffix-exact';
876
+ }
877
+ static get multiRegex() {
878
+ return /^"(.*)"\$$/;
879
+ }
880
+ static get singleRegex() {
881
+ return /^(.*)\$$/;
882
+ }
883
+ search(text) {
884
+ const isMatch = text.endsWith(this.pattern);
885
+ return {
886
+ isMatch,
887
+ score: isMatch ? 0 : 1,
888
+ indices: [text.length - this.pattern.length, text.length - 1]
889
+ };
890
+ }
891
+ }
892
+
893
+ // Token: !.file$
894
+
895
+ class InverseSuffixExactMatch extends BaseMatch {
896
+ constructor(pattern) {
897
+ super(pattern);
898
+ }
899
+ static get type() {
900
+ return 'inverse-suffix-exact';
901
+ }
902
+ static get multiRegex() {
903
+ return /^!"(.*)"\$$/;
904
+ }
905
+ static get singleRegex() {
906
+ return /^!(.*)\$$/;
907
+ }
908
+ search(text) {
909
+ const isMatch = !text.endsWith(this.pattern);
910
+ return {
911
+ isMatch,
912
+ score: isMatch ? 0 : 1,
913
+ indices: [0, text.length - 1]
914
+ };
915
+ }
916
+ }
917
+ class FuzzyMatch extends BaseMatch {
918
+ constructor(pattern, {
919
+ location = Config.location,
920
+ threshold = Config.threshold,
921
+ distance = Config.distance,
922
+ includeMatches = Config.includeMatches,
923
+ findAllMatches = Config.findAllMatches,
924
+ minMatchCharLength = Config.minMatchCharLength,
925
+ isCaseSensitive = Config.isCaseSensitive,
926
+ ignoreLocation = Config.ignoreLocation
927
+ } = {}) {
928
+ super(pattern);
929
+ this._bitapSearch = new BitapSearch(pattern, {
930
+ location,
931
+ threshold,
932
+ distance,
933
+ includeMatches,
934
+ findAllMatches,
935
+ minMatchCharLength,
936
+ isCaseSensitive,
937
+ ignoreLocation
938
+ });
939
+ }
940
+ static get type() {
941
+ return 'fuzzy';
942
+ }
943
+ static get multiRegex() {
944
+ return /^"(.*)"$/;
945
+ }
946
+ static get singleRegex() {
947
+ return /^(.*)$/;
948
+ }
949
+ search(text) {
950
+ return this._bitapSearch.searchIn(text);
951
+ }
952
+ }
953
+
954
+ // Token: 'file
955
+
956
+ class IncludeMatch extends BaseMatch {
957
+ constructor(pattern) {
958
+ super(pattern);
959
+ }
960
+ static get type() {
961
+ return 'include';
962
+ }
963
+ static get multiRegex() {
964
+ return /^'"(.*)"$/;
965
+ }
966
+ static get singleRegex() {
967
+ return /^'(.*)$/;
968
+ }
969
+ search(text) {
970
+ let location = 0;
971
+ let index;
972
+ const indices = [];
973
+ const patternLen = this.pattern.length;
974
+
975
+ // Get all exact matches
976
+ while ((index = text.indexOf(this.pattern, location)) > -1) {
977
+ location = index + patternLen;
978
+ indices.push([index, location - 1]);
979
+ }
980
+ const isMatch = !!indices.length;
981
+ return {
982
+ isMatch,
983
+ score: isMatch ? 0 : 1,
984
+ indices
985
+ };
986
+ }
987
+ }
988
+
989
+ // ❗Order is important. DO NOT CHANGE.
990
+ const searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
991
+ const searchersLen = searchers.length;
992
+
993
+ // Regex to split by spaces, but keep anything in quotes together
994
+ const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
995
+ const OR_TOKEN = '|';
996
+
997
+ // Return a 2D array representation of the query, for simpler parsing.
998
+ // Example:
999
+ // "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
1000
+ function parseQuery(pattern, options = {}) {
1001
+ return pattern.split(OR_TOKEN).map(item => {
1002
+ let query = item.trim().split(SPACE_RE).filter(item => item && !!item.trim());
1003
+ let results = [];
1004
+ for (let i = 0, len = query.length; i < len; i += 1) {
1005
+ const queryItem = query[i];
1006
+
1007
+ // 1. Handle multiple query match (i.e, once that are quoted, like `"hello world"`)
1008
+ let found = false;
1009
+ let idx = -1;
1010
+ while (!found && ++idx < searchersLen) {
1011
+ const searcher = searchers[idx];
1012
+ let token = searcher.isMultiMatch(queryItem);
1013
+ if (token) {
1014
+ results.push(new searcher(token, options));
1015
+ found = true;
1016
+ }
1017
+ }
1018
+ if (found) {
1019
+ continue;
1020
+ }
1021
+
1022
+ // 2. Handle single query matches (i.e, once that are *not* quoted)
1023
+ idx = -1;
1024
+ while (++idx < searchersLen) {
1025
+ const searcher = searchers[idx];
1026
+ let token = searcher.isSingleMatch(queryItem);
1027
+ if (token) {
1028
+ results.push(new searcher(token, options));
1029
+ break;
1030
+ }
1031
+ }
1032
+ }
1033
+ return results;
1034
+ });
1035
+ }
1036
+
1037
+ // These extended matchers can return an array of matches, as opposed
1038
+ // to a singl match
1039
+ const MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]);
1040
+
1041
+ /**
1042
+ * Command-like searching
1043
+ * ======================
1044
+ *
1045
+ * Given multiple search terms delimited by spaces.e.g. `^jscript .python$ ruby !java`,
1046
+ * search in a given text.
1047
+ *
1048
+ * Search syntax:
1049
+ *
1050
+ * | Token | Match type | Description |
1051
+ * | ----------- | -------------------------- | -------------------------------------- |
1052
+ * | `jscript` | fuzzy-match | Items that fuzzy match `jscript` |
1053
+ * | `=scheme` | exact-match | Items that are `scheme` |
1054
+ * | `'python` | include-match | Items that include `python` |
1055
+ * | `!ruby` | inverse-exact-match | Items that do not include `ruby` |
1056
+ * | `^java` | prefix-exact-match | Items that start with `java` |
1057
+ * | `!^earlang` | inverse-prefix-exact-match | Items that do not start with `earlang` |
1058
+ * | `.js$` | suffix-exact-match | Items that end with `.js` |
1059
+ * | `!.go$` | inverse-suffix-exact-match | Items that do not end with `.go` |
1060
+ *
1061
+ * A single pipe character acts as an OR operator. For example, the following
1062
+ * query matches entries that start with `core` and end with either`go`, `rb`,
1063
+ * or`py`.
1064
+ *
1065
+ * ```
1066
+ * ^core go$ | rb$ | py$
1067
+ * ```
1068
+ */
1069
+ class ExtendedSearch {
1070
+ constructor(pattern, {
1071
+ isCaseSensitive = Config.isCaseSensitive,
1072
+ includeMatches = Config.includeMatches,
1073
+ minMatchCharLength = Config.minMatchCharLength,
1074
+ ignoreLocation = Config.ignoreLocation,
1075
+ findAllMatches = Config.findAllMatches,
1076
+ location = Config.location,
1077
+ threshold = Config.threshold,
1078
+ distance = Config.distance
1079
+ } = {}) {
1080
+ this.query = null;
1081
+ this.options = {
1082
+ isCaseSensitive,
1083
+ includeMatches,
1084
+ minMatchCharLength,
1085
+ findAllMatches,
1086
+ ignoreLocation,
1087
+ location,
1088
+ threshold,
1089
+ distance
1090
+ };
1091
+ this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
1092
+ this.query = parseQuery(this.pattern, this.options);
1093
+ }
1094
+ static condition(_, options) {
1095
+ return options.useExtendedSearch;
1096
+ }
1097
+ searchIn(text) {
1098
+ const query = this.query;
1099
+ if (!query) {
1100
+ return {
1101
+ isMatch: false,
1102
+ score: 1
1103
+ };
1104
+ }
1105
+ const {
1106
+ includeMatches,
1107
+ isCaseSensitive
1108
+ } = this.options;
1109
+ text = isCaseSensitive ? text : text.toLowerCase();
1110
+ let numMatches = 0;
1111
+ let allIndices = [];
1112
+ let totalScore = 0;
1113
+
1114
+ // ORs
1115
+ for (let i = 0, qLen = query.length; i < qLen; i += 1) {
1116
+ const searchers = query[i];
1117
+
1118
+ // Reset indices
1119
+ allIndices.length = 0;
1120
+ numMatches = 0;
1121
+
1122
+ // ANDs
1123
+ for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
1124
+ const searcher = searchers[j];
1125
+ const {
1126
+ isMatch,
1127
+ indices,
1128
+ score
1129
+ } = searcher.search(text);
1130
+ if (isMatch) {
1131
+ numMatches += 1;
1132
+ totalScore += score;
1133
+ if (includeMatches) {
1134
+ const type = searcher.constructor.type;
1135
+ if (MultiMatchSet.has(type)) {
1136
+ allIndices = [...allIndices, ...indices];
1137
+ } else {
1138
+ allIndices.push(indices);
1139
+ }
1140
+ }
1141
+ } else {
1142
+ totalScore = 0;
1143
+ numMatches = 0;
1144
+ allIndices.length = 0;
1145
+ break;
1146
+ }
1147
+ }
1148
+
1149
+ // OR condition, so if TRUE, return
1150
+ if (numMatches) {
1151
+ let result = {
1152
+ isMatch: true,
1153
+ score: totalScore / numMatches
1154
+ };
1155
+ if (includeMatches) {
1156
+ result.indices = allIndices;
1157
+ }
1158
+ return result;
1159
+ }
1160
+ }
1161
+
1162
+ // Nothing was matched
1163
+ return {
1164
+ isMatch: false,
1165
+ score: 1
1166
+ };
1167
+ }
1168
+ }
1169
+ const registeredSearchers = [];
1170
+ function register(...args) {
1171
+ registeredSearchers.push(...args);
1172
+ }
1173
+ function createSearcher(pattern, options) {
1174
+ for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
1175
+ let searcherClass = registeredSearchers[i];
1176
+ if (searcherClass.condition(pattern, options)) {
1177
+ return new searcherClass(pattern, options);
1178
+ }
1179
+ }
1180
+ return new BitapSearch(pattern, options);
1181
+ }
1182
+ const LogicalOperator = {
1183
+ AND: '$and',
1184
+ OR: '$or'
1185
+ };
1186
+ const KeyType = {
1187
+ PATH: '$path',
1188
+ PATTERN: '$val'
1189
+ };
1190
+ const isExpression = query => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
1191
+ const isPath = query => !!query[KeyType.PATH];
1192
+ const isLeaf = query => !isArray(query) && isObject(query) && !isExpression(query);
1193
+ const convertToExplicit = query => ({
1194
+ [LogicalOperator.AND]: Object.keys(query).map(key => ({
1195
+ [key]: query[key]
1196
+ }))
1197
+ });
1198
+
1199
+ // When `auto` is `true`, the parse function will infer and initialize and add
1200
+ // the appropriate `Searcher` instance
1201
+ function parse(query, options, {
1202
+ auto = true
1203
+ } = {}) {
1204
+ const next = query => {
1205
+ let keys = Object.keys(query);
1206
+ const isQueryPath = isPath(query);
1207
+ if (!isQueryPath && keys.length > 1 && !isExpression(query)) {
1208
+ return next(convertToExplicit(query));
1209
+ }
1210
+ if (isLeaf(query)) {
1211
+ const key = isQueryPath ? query[KeyType.PATH] : keys[0];
1212
+ const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
1213
+ if (!isString(pattern)) {
1214
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
1215
+ }
1216
+ const obj = {
1217
+ keyId: createKeyId(key),
1218
+ pattern
1219
+ };
1220
+ if (auto) {
1221
+ obj.searcher = createSearcher(pattern, options);
1222
+ }
1223
+ return obj;
1224
+ }
1225
+ let node = {
1226
+ children: [],
1227
+ operator: keys[0]
1228
+ };
1229
+ keys.forEach(key => {
1230
+ const value = query[key];
1231
+ if (isArray(value)) {
1232
+ value.forEach(item => {
1233
+ node.children.push(next(item));
1234
+ });
1235
+ }
1236
+ });
1237
+ return node;
1238
+ };
1239
+ if (!isExpression(query)) {
1240
+ query = convertToExplicit(query);
1241
+ }
1242
+ return next(query);
1243
+ }
1244
+
1245
+ // Practical scoring function
1246
+ function computeScore(results, {
1247
+ ignoreFieldNorm = Config.ignoreFieldNorm
1248
+ }) {
1249
+ results.forEach(result => {
1250
+ let totalScore = 1;
1251
+ result.matches.forEach(({
1252
+ key,
1253
+ norm,
1254
+ score
1255
+ }) => {
1256
+ const weight = key ? key.weight : null;
1257
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
1258
+ });
1259
+ result.score = totalScore;
1260
+ });
1261
+ }
1262
+ function transformMatches(result, data) {
1263
+ const matches = result.matches;
1264
+ data.matches = [];
1265
+ if (!isDefined(matches)) {
1266
+ return;
1267
+ }
1268
+ matches.forEach(match => {
1269
+ if (!isDefined(match.indices) || !match.indices.length) {
1270
+ return;
1271
+ }
1272
+ const {
1273
+ indices,
1274
+ value
1275
+ } = match;
1276
+ let obj = {
1277
+ indices,
1278
+ value
1279
+ };
1280
+ if (match.key) {
1281
+ obj.key = match.key.src;
1282
+ }
1283
+ if (match.idx > -1) {
1284
+ obj.refIndex = match.idx;
1285
+ }
1286
+ data.matches.push(obj);
1287
+ });
1288
+ }
1289
+ function transformScore(result, data) {
1290
+ data.score = result.score;
1291
+ }
1292
+ function format(results, docs, {
1293
+ includeMatches = Config.includeMatches,
1294
+ includeScore = Config.includeScore
1295
+ } = {}) {
1296
+ const transformers = [];
1297
+ if (includeMatches) transformers.push(transformMatches);
1298
+ if (includeScore) transformers.push(transformScore);
1299
+ return results.map(result => {
1300
+ const {
1301
+ idx
1302
+ } = result;
1303
+ const data = {
1304
+ item: docs[idx],
1305
+ refIndex: idx
1306
+ };
1307
+ if (transformers.length) {
1308
+ transformers.forEach(transformer => {
1309
+ transformer(result, data);
1310
+ });
1311
+ }
1312
+ return data;
1313
+ });
1314
+ }
1315
+ class Fuse {
1316
+ constructor(docs, options = {}, index) {
1317
+ this.options = {
1318
+ ...Config,
1319
+ ...options
1320
+ };
1321
+ if (this.options.useExtendedSearch && !true) {
1322
+ throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
1323
+ }
1324
+ this._keyStore = new KeyStore(this.options.keys);
1325
+ this.setCollection(docs, index);
1326
+ }
1327
+ setCollection(docs, index) {
1328
+ this._docs = docs;
1329
+ if (index && !(index instanceof FuseIndex)) {
1330
+ throw new Error(INCORRECT_INDEX_TYPE);
1331
+ }
1332
+ this._myIndex = index || createIndex(this.options.keys, this._docs, {
1333
+ getFn: this.options.getFn,
1334
+ fieldNormWeight: this.options.fieldNormWeight
1335
+ });
1336
+ }
1337
+ add(doc) {
1338
+ if (!isDefined(doc)) {
1339
+ return;
1340
+ }
1341
+ this._docs.push(doc);
1342
+ this._myIndex.add(doc);
1343
+ }
1344
+ remove(predicate = ( /* doc, idx */) => false) {
1345
+ const results = [];
1346
+ for (let i = 0, len = this._docs.length; i < len; i += 1) {
1347
+ const doc = this._docs[i];
1348
+ if (predicate(doc, i)) {
1349
+ this.removeAt(i);
1350
+ i -= 1;
1351
+ len -= 1;
1352
+ results.push(doc);
1353
+ }
1354
+ }
1355
+ return results;
1356
+ }
1357
+ removeAt(idx) {
1358
+ this._docs.splice(idx, 1);
1359
+ this._myIndex.removeAt(idx);
1360
+ }
1361
+ getIndex() {
1362
+ return this._myIndex;
1363
+ }
1364
+ search(query, {
1365
+ limit = -1
1366
+ } = {}) {
1367
+ const {
1368
+ includeMatches,
1369
+ includeScore,
1370
+ shouldSort,
1371
+ sortFn,
1372
+ ignoreFieldNorm
1373
+ } = this.options;
1374
+ let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
1375
+ computeScore(results, {
1376
+ ignoreFieldNorm
1377
+ });
1378
+ if (shouldSort) {
1379
+ results.sort(sortFn);
1380
+ }
1381
+ if (isNumber(limit) && limit > -1) {
1382
+ results = results.slice(0, limit);
1383
+ }
1384
+ return format(results, this._docs, {
1385
+ includeMatches,
1386
+ includeScore
1387
+ });
1388
+ }
1389
+ _searchStringList(query) {
1390
+ const searcher = createSearcher(query, this.options);
1391
+ const {
1392
+ records
1393
+ } = this._myIndex;
1394
+ const results = [];
1395
+
1396
+ // Iterate over every string in the index
1397
+ records.forEach(({
1398
+ v: text,
1399
+ i: idx,
1400
+ n: norm
1401
+ }) => {
1402
+ if (!isDefined(text)) {
1403
+ return;
1404
+ }
1405
+ const {
1406
+ isMatch,
1407
+ score,
1408
+ indices
1409
+ } = searcher.searchIn(text);
1410
+ if (isMatch) {
1411
+ results.push({
1412
+ item: text,
1413
+ idx,
1414
+ matches: [{
1415
+ score,
1416
+ value: text,
1417
+ norm,
1418
+ indices
1419
+ }]
1420
+ });
1421
+ }
1422
+ });
1423
+ return results;
1424
+ }
1425
+ _searchLogical(query) {
1426
+ const expression = parse(query, this.options);
1427
+ const evaluate = (node, item, idx) => {
1428
+ if (!node.children) {
1429
+ const {
1430
+ keyId,
1431
+ searcher
1432
+ } = node;
1433
+ const matches = this._findMatches({
1434
+ key: this._keyStore.get(keyId),
1435
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
1436
+ searcher
1437
+ });
1438
+ if (matches && matches.length) {
1439
+ return [{
1440
+ idx,
1441
+ item,
1442
+ matches
1443
+ }];
1444
+ }
1445
+ return [];
1446
+ }
1447
+ const res = [];
1448
+ for (let i = 0, len = node.children.length; i < len; i += 1) {
1449
+ const child = node.children[i];
1450
+ const result = evaluate(child, item, idx);
1451
+ if (result.length) {
1452
+ res.push(...result);
1453
+ } else if (node.operator === LogicalOperator.AND) {
1454
+ return [];
1455
+ }
1456
+ }
1457
+ return res;
1458
+ };
1459
+ const records = this._myIndex.records;
1460
+ const resultMap = {};
1461
+ const results = [];
1462
+ records.forEach(({
1463
+ $: item,
1464
+ i: idx
1465
+ }) => {
1466
+ if (isDefined(item)) {
1467
+ let expResults = evaluate(expression, item, idx);
1468
+ if (expResults.length) {
1469
+ // Dedupe when adding
1470
+ if (!resultMap[idx]) {
1471
+ resultMap[idx] = {
1472
+ idx,
1473
+ item,
1474
+ matches: []
1475
+ };
1476
+ results.push(resultMap[idx]);
1477
+ }
1478
+ expResults.forEach(({
1479
+ matches
1480
+ }) => {
1481
+ resultMap[idx].matches.push(...matches);
1482
+ });
1483
+ }
1484
+ }
1485
+ });
1486
+ return results;
1487
+ }
1488
+ _searchObjectList(query) {
1489
+ const searcher = createSearcher(query, this.options);
1490
+ const {
1491
+ keys,
1492
+ records
1493
+ } = this._myIndex;
1494
+ const results = [];
1495
+
1496
+ // List is Array<Object>
1497
+ records.forEach(({
1498
+ $: item,
1499
+ i: idx
1500
+ }) => {
1501
+ if (!isDefined(item)) {
1502
+ return;
1503
+ }
1504
+ let matches = [];
1505
+
1506
+ // Iterate over every key (i.e, path), and fetch the value at that key
1507
+ keys.forEach((key, keyIndex) => {
1508
+ matches.push(...this._findMatches({
1509
+ key,
1510
+ value: item[keyIndex],
1511
+ searcher
1512
+ }));
1513
+ });
1514
+ if (matches.length) {
1515
+ results.push({
1516
+ idx,
1517
+ item,
1518
+ matches
1519
+ });
1520
+ }
1521
+ });
1522
+ return results;
1523
+ }
1524
+ _findMatches({
1525
+ key,
1526
+ value,
1527
+ searcher
1528
+ }) {
1529
+ if (!isDefined(value)) {
1530
+ return [];
1531
+ }
1532
+ let matches = [];
1533
+ if (isArray(value)) {
1534
+ value.forEach(({
1535
+ v: text,
1536
+ i: idx,
1537
+ n: norm
1538
+ }) => {
1539
+ if (!isDefined(text)) {
1540
+ return;
1541
+ }
1542
+ const {
1543
+ isMatch,
1544
+ score,
1545
+ indices
1546
+ } = searcher.searchIn(text);
1547
+ if (isMatch) {
1548
+ matches.push({
1549
+ score,
1550
+ key,
1551
+ value: text,
1552
+ idx,
1553
+ norm,
1554
+ indices
1555
+ });
1556
+ }
1557
+ });
1558
+ } else {
1559
+ const {
1560
+ v: text,
1561
+ n: norm
1562
+ } = value;
1563
+ const {
1564
+ isMatch,
1565
+ score,
1566
+ indices
1567
+ } = searcher.searchIn(text);
1568
+ if (isMatch) {
1569
+ matches.push({
1570
+ score,
1571
+ key,
1572
+ value: text,
1573
+ norm,
1574
+ indices
1575
+ });
1576
+ }
1577
+ }
1578
+ return matches;
1579
+ }
1580
+ }
1581
+ Fuse.version = '6.6.2';
1582
+ Fuse.createIndex = createIndex;
1583
+ Fuse.parseIndex = parseIndex;
1584
+ Fuse.config = Config;
1585
+ {
1586
+ Fuse.parseQuery = parse;
1587
+ }
1588
+ {
1589
+ register(ExtendedSearch);
1590
+ }
1591
+
1592
+ export default Fuse;
1593
+ //# sourceMappingURL=fusejs.js.map