@powerlines/plugin-automd 0.1.237 → 0.1.239

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 (59) hide show
  1. package/dist/chunk-BrXtsOCC.cjs +41 -0
  2. package/dist/{_virtual/rolldown_runtime.cjs → chunk-CS8OKu3y.mjs} +5 -2
  3. package/dist/dist-8g8frrZv.cjs +246 -0
  4. package/dist/dist-BavrV299.cjs +682 -0
  5. package/dist/dist-DVv98dZY.cjs +87 -0
  6. package/dist/dist-Jfd0GR_C.mjs +223 -0
  7. package/dist/dist-Jfd0GR_C.mjs.map +1 -0
  8. package/dist/dist-PRh64A_O.mjs +70 -0
  9. package/dist/dist-PRh64A_O.mjs.map +1 -0
  10. package/dist/dist-PXnBmevt.mjs +681 -0
  11. package/dist/dist-PXnBmevt.mjs.map +1 -0
  12. package/dist/index-B8OHl-c_.d.mts +1 -0
  13. package/dist/index-CmCelmEL.d.cts +1 -0
  14. package/dist/index.cjs +9607 -15
  15. package/dist/index.d.cts +5 -4
  16. package/dist/index.d.cts.map +1 -0
  17. package/dist/index.d.mts +5 -4
  18. package/dist/index.d.mts.map +1 -0
  19. package/dist/index.mjs +9600 -12
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/loader-BRhKFmUn.mjs +58373 -0
  22. package/dist/loader-BRhKFmUn.mjs.map +1 -0
  23. package/dist/loader-DNEbMIIe.cjs +58372 -0
  24. package/dist/multipart-parser-C_EjwsED.cjs +178 -0
  25. package/dist/multipart-parser-CglOohoL.mjs +179 -0
  26. package/dist/multipart-parser-CglOohoL.mjs.map +1 -0
  27. package/dist/node-CsMhpAoX.cjs +269 -0
  28. package/dist/node-DapIDpAC.cjs +4024 -0
  29. package/dist/node-Du1vi9nA.mjs +3974 -0
  30. package/dist/node-Du1vi9nA.mjs.map +1 -0
  31. package/dist/node-d_BpkPSt.mjs +267 -0
  32. package/dist/node-d_BpkPSt.mjs.map +1 -0
  33. package/dist/plugin-BVD0UMjp.d.cts +52 -0
  34. package/dist/plugin-BVD0UMjp.d.cts.map +1 -0
  35. package/dist/plugin-C6jB5e_j.d.mts +52 -0
  36. package/dist/plugin-C6jB5e_j.d.mts.map +1 -0
  37. package/dist/plugin-Ckx8qAq8.cjs +0 -0
  38. package/dist/plugin-jZ9N9Mz-.mjs +1 -0
  39. package/dist/toc-BN2Ji9Yo.d.mts +35 -0
  40. package/dist/toc-BN2Ji9Yo.d.mts.map +1 -0
  41. package/dist/toc-BQgoCyR1.cjs +0 -0
  42. package/dist/toc-BrayIFG6.d.cts +35 -0
  43. package/dist/toc-BrayIFG6.d.cts.map +1 -0
  44. package/dist/toc-CBjybXug.mjs +1 -0
  45. package/dist/types/index.cjs +3 -0
  46. package/dist/types/index.d.cts +3 -2
  47. package/dist/types/index.d.mts +3 -2
  48. package/dist/types/index.mjs +4 -0
  49. package/dist/types/plugin.cjs +1 -0
  50. package/dist/types/plugin.d.cts +2 -50
  51. package/dist/types/plugin.d.mts +2 -50
  52. package/dist/types/plugin.mjs +2 -0
  53. package/dist/types/toc.cjs +1 -0
  54. package/dist/types/toc.d.cts +1 -33
  55. package/dist/types/toc.d.mts +1 -33
  56. package/dist/types/toc.mjs +2 -0
  57. package/dist/types--fVOUYBq.mjs +1 -0
  58. package/dist/types-D208vOSb.cjs +0 -0
  59. package/package.json +4 -4
@@ -0,0 +1,681 @@
1
+ import { r as __toESM, t as __commonJSMin } from "./chunk-CS8OKu3y.mjs";
2
+
3
+ //#region ../../node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.js
4
+ var require_fastest_levenshtein = /* @__PURE__ */ __commonJSMin(((exports) => {
5
+ exports.__esModule = true;
6
+ exports.distance = exports.closest = void 0;
7
+ var peq = new Uint32Array(65536);
8
+ var myers_32 = function(a, b) {
9
+ var n = a.length;
10
+ var m = b.length;
11
+ var lst = 1 << n - 1;
12
+ var pv = -1;
13
+ var mv = 0;
14
+ var sc = n;
15
+ var i = n;
16
+ while (i--) peq[a.charCodeAt(i)] |= 1 << i;
17
+ for (i = 0; i < m; i++) {
18
+ var eq = peq[b.charCodeAt(i)];
19
+ var xv = eq | mv;
20
+ eq |= (eq & pv) + pv ^ pv;
21
+ mv |= ~(eq | pv);
22
+ pv &= eq;
23
+ if (mv & lst) sc++;
24
+ if (pv & lst) sc--;
25
+ mv = mv << 1 | 1;
26
+ pv = pv << 1 | ~(xv | mv);
27
+ mv &= xv;
28
+ }
29
+ i = n;
30
+ while (i--) peq[a.charCodeAt(i)] = 0;
31
+ return sc;
32
+ };
33
+ var myers_x = function(b, a) {
34
+ var n = a.length;
35
+ var m = b.length;
36
+ var mhc = [];
37
+ var phc = [];
38
+ var hsize = Math.ceil(n / 32);
39
+ var vsize = Math.ceil(m / 32);
40
+ for (var i = 0; i < hsize; i++) {
41
+ phc[i] = -1;
42
+ mhc[i] = 0;
43
+ }
44
+ var j = 0;
45
+ for (; j < vsize - 1; j++) {
46
+ var mv_1 = 0;
47
+ var pv_1 = -1;
48
+ var start_1 = j * 32;
49
+ var vlen_1 = Math.min(32, m) + start_1;
50
+ for (var k = start_1; k < vlen_1; k++) peq[b.charCodeAt(k)] |= 1 << k;
51
+ for (var i = 0; i < n; i++) {
52
+ var eq = peq[a.charCodeAt(i)];
53
+ var pb = phc[i / 32 | 0] >>> i & 1;
54
+ var mb = mhc[i / 32 | 0] >>> i & 1;
55
+ var xv = eq | mv_1;
56
+ var xh = ((eq | mb) & pv_1) + pv_1 ^ pv_1 | eq | mb;
57
+ var ph = mv_1 | ~(xh | pv_1);
58
+ var mh = pv_1 & xh;
59
+ if (ph >>> 31 ^ pb) phc[i / 32 | 0] ^= 1 << i;
60
+ if (mh >>> 31 ^ mb) mhc[i / 32 | 0] ^= 1 << i;
61
+ ph = ph << 1 | pb;
62
+ mh = mh << 1 | mb;
63
+ pv_1 = mh | ~(xv | ph);
64
+ mv_1 = ph & xv;
65
+ }
66
+ for (var k = start_1; k < vlen_1; k++) peq[b.charCodeAt(k)] = 0;
67
+ }
68
+ var mv = 0;
69
+ var pv = -1;
70
+ var start = j * 32;
71
+ var vlen = Math.min(32, m - start) + start;
72
+ for (var k = start; k < vlen; k++) peq[b.charCodeAt(k)] |= 1 << k;
73
+ var score = m;
74
+ for (var i = 0; i < n; i++) {
75
+ var eq = peq[a.charCodeAt(i)];
76
+ var pb = phc[i / 32 | 0] >>> i & 1;
77
+ var mb = mhc[i / 32 | 0] >>> i & 1;
78
+ var xv = eq | mv;
79
+ var xh = ((eq | mb) & pv) + pv ^ pv | eq | mb;
80
+ var ph = mv | ~(xh | pv);
81
+ var mh = pv & xh;
82
+ score += ph >>> m - 1 & 1;
83
+ score -= mh >>> m - 1 & 1;
84
+ if (ph >>> 31 ^ pb) phc[i / 32 | 0] ^= 1 << i;
85
+ if (mh >>> 31 ^ mb) mhc[i / 32 | 0] ^= 1 << i;
86
+ ph = ph << 1 | pb;
87
+ mh = mh << 1 | mb;
88
+ pv = mh | ~(xv | ph);
89
+ mv = ph & xv;
90
+ }
91
+ for (var k = start; k < vlen; k++) peq[b.charCodeAt(k)] = 0;
92
+ return score;
93
+ };
94
+ var distance$1 = function(a, b) {
95
+ if (a.length < b.length) {
96
+ var tmp = b;
97
+ b = a;
98
+ a = tmp;
99
+ }
100
+ if (b.length === 0) return a.length;
101
+ if (a.length <= 32) return myers_32(a, b);
102
+ return myers_x(a, b);
103
+ };
104
+ exports.distance = distance$1;
105
+ var closest = function(str, arr) {
106
+ var min_distance = Infinity;
107
+ var min_index = 0;
108
+ for (var i = 0; i < arr.length; i++) {
109
+ var dist = distance$1(str, arr[i]);
110
+ if (dist < min_distance) {
111
+ min_distance = dist;
112
+ min_index = i;
113
+ }
114
+ }
115
+ return arr[min_index];
116
+ };
117
+ exports.closest = closest;
118
+ }));
119
+
120
+ //#endregion
121
+ //#region ../../node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.js
122
+ var require_lodash = /* @__PURE__ */ __commonJSMin(((exports, module) => {
123
+ /**
124
+ * lodash (Custom Build) <https://lodash.com/>
125
+ * Build: `lodash modularize exports="npm" -o ./`
126
+ * Copyright jQuery Foundation and other contributors <https://jquery.org/>
127
+ * Released under MIT license <https://lodash.com/license>
128
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
129
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
130
+ */
131
+ /** Used as references for various `Number` constants. */
132
+ var INFINITY = Infinity;
133
+ /** `Object#toString` result references. */
134
+ var symbolTag = "[object Symbol]";
135
+ /** Used to match Latin Unicode letters (excluding mathematical operators). */
136
+ var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
137
+ /**
138
+ * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
139
+ * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
140
+ */
141
+ var reComboMark = RegExp("[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]", "g");
142
+ /** Used to map Latin Unicode letters to basic Latin letters. */
143
+ var deburredLetters = {
144
+ "À": "A",
145
+ "Á": "A",
146
+ "Â": "A",
147
+ "Ã": "A",
148
+ "Ä": "A",
149
+ "Å": "A",
150
+ "à": "a",
151
+ "á": "a",
152
+ "â": "a",
153
+ "ã": "a",
154
+ "ä": "a",
155
+ "å": "a",
156
+ "Ç": "C",
157
+ "ç": "c",
158
+ "Ð": "D",
159
+ "ð": "d",
160
+ "È": "E",
161
+ "É": "E",
162
+ "Ê": "E",
163
+ "Ë": "E",
164
+ "è": "e",
165
+ "é": "e",
166
+ "ê": "e",
167
+ "ë": "e",
168
+ "Ì": "I",
169
+ "Í": "I",
170
+ "Î": "I",
171
+ "Ï": "I",
172
+ "ì": "i",
173
+ "í": "i",
174
+ "î": "i",
175
+ "ï": "i",
176
+ "Ñ": "N",
177
+ "ñ": "n",
178
+ "Ò": "O",
179
+ "Ó": "O",
180
+ "Ô": "O",
181
+ "Õ": "O",
182
+ "Ö": "O",
183
+ "Ø": "O",
184
+ "ò": "o",
185
+ "ó": "o",
186
+ "ô": "o",
187
+ "õ": "o",
188
+ "ö": "o",
189
+ "ø": "o",
190
+ "Ù": "U",
191
+ "Ú": "U",
192
+ "Û": "U",
193
+ "Ü": "U",
194
+ "ù": "u",
195
+ "ú": "u",
196
+ "û": "u",
197
+ "ü": "u",
198
+ "Ý": "Y",
199
+ "ý": "y",
200
+ "ÿ": "y",
201
+ "Æ": "Ae",
202
+ "æ": "ae",
203
+ "Þ": "Th",
204
+ "þ": "th",
205
+ "ß": "ss",
206
+ "Ā": "A",
207
+ "Ă": "A",
208
+ "Ą": "A",
209
+ "ā": "a",
210
+ "ă": "a",
211
+ "ą": "a",
212
+ "Ć": "C",
213
+ "Ĉ": "C",
214
+ "Ċ": "C",
215
+ "Č": "C",
216
+ "ć": "c",
217
+ "ĉ": "c",
218
+ "ċ": "c",
219
+ "č": "c",
220
+ "Ď": "D",
221
+ "Đ": "D",
222
+ "ď": "d",
223
+ "đ": "d",
224
+ "Ē": "E",
225
+ "Ĕ": "E",
226
+ "Ė": "E",
227
+ "Ę": "E",
228
+ "Ě": "E",
229
+ "ē": "e",
230
+ "ĕ": "e",
231
+ "ė": "e",
232
+ "ę": "e",
233
+ "ě": "e",
234
+ "Ĝ": "G",
235
+ "Ğ": "G",
236
+ "Ġ": "G",
237
+ "Ģ": "G",
238
+ "ĝ": "g",
239
+ "ğ": "g",
240
+ "ġ": "g",
241
+ "ģ": "g",
242
+ "Ĥ": "H",
243
+ "Ħ": "H",
244
+ "ĥ": "h",
245
+ "ħ": "h",
246
+ "Ĩ": "I",
247
+ "Ī": "I",
248
+ "Ĭ": "I",
249
+ "Į": "I",
250
+ "İ": "I",
251
+ "ĩ": "i",
252
+ "ī": "i",
253
+ "ĭ": "i",
254
+ "į": "i",
255
+ "ı": "i",
256
+ "Ĵ": "J",
257
+ "ĵ": "j",
258
+ "Ķ": "K",
259
+ "ķ": "k",
260
+ "ĸ": "k",
261
+ "Ĺ": "L",
262
+ "Ļ": "L",
263
+ "Ľ": "L",
264
+ "Ŀ": "L",
265
+ "Ł": "L",
266
+ "ĺ": "l",
267
+ "ļ": "l",
268
+ "ľ": "l",
269
+ "ŀ": "l",
270
+ "ł": "l",
271
+ "Ń": "N",
272
+ "Ņ": "N",
273
+ "Ň": "N",
274
+ "Ŋ": "N",
275
+ "ń": "n",
276
+ "ņ": "n",
277
+ "ň": "n",
278
+ "ŋ": "n",
279
+ "Ō": "O",
280
+ "Ŏ": "O",
281
+ "Ő": "O",
282
+ "ō": "o",
283
+ "ŏ": "o",
284
+ "ő": "o",
285
+ "Ŕ": "R",
286
+ "Ŗ": "R",
287
+ "Ř": "R",
288
+ "ŕ": "r",
289
+ "ŗ": "r",
290
+ "ř": "r",
291
+ "Ś": "S",
292
+ "Ŝ": "S",
293
+ "Ş": "S",
294
+ "Š": "S",
295
+ "ś": "s",
296
+ "ŝ": "s",
297
+ "ş": "s",
298
+ "š": "s",
299
+ "Ţ": "T",
300
+ "Ť": "T",
301
+ "Ŧ": "T",
302
+ "ţ": "t",
303
+ "ť": "t",
304
+ "ŧ": "t",
305
+ "Ũ": "U",
306
+ "Ū": "U",
307
+ "Ŭ": "U",
308
+ "Ů": "U",
309
+ "Ű": "U",
310
+ "Ų": "U",
311
+ "ũ": "u",
312
+ "ū": "u",
313
+ "ŭ": "u",
314
+ "ů": "u",
315
+ "ű": "u",
316
+ "ų": "u",
317
+ "Ŵ": "W",
318
+ "ŵ": "w",
319
+ "Ŷ": "Y",
320
+ "ŷ": "y",
321
+ "Ÿ": "Y",
322
+ "Ź": "Z",
323
+ "Ż": "Z",
324
+ "Ž": "Z",
325
+ "ź": "z",
326
+ "ż": "z",
327
+ "ž": "z",
328
+ "IJ": "IJ",
329
+ "ij": "ij",
330
+ "Œ": "Oe",
331
+ "œ": "oe",
332
+ "ʼn": "'n",
333
+ "ſ": "ss"
334
+ };
335
+ /** Detect free variable `global` from Node.js. */
336
+ var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
337
+ /** Detect free variable `self`. */
338
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
339
+ /** Used as a reference to the global object. */
340
+ var root = freeGlobal || freeSelf || Function("return this")();
341
+ /**
342
+ * The base implementation of `_.propertyOf` without support for deep paths.
343
+ *
344
+ * @private
345
+ * @param {Object} object The object to query.
346
+ * @returns {Function} Returns the new accessor function.
347
+ */
348
+ function basePropertyOf(object) {
349
+ return function(key) {
350
+ return object == null ? void 0 : object[key];
351
+ };
352
+ }
353
+ /**
354
+ * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
355
+ * letters to basic Latin letters.
356
+ *
357
+ * @private
358
+ * @param {string} letter The matched letter to deburr.
359
+ * @returns {string} Returns the deburred letter.
360
+ */
361
+ var deburrLetter = basePropertyOf(deburredLetters);
362
+ /**
363
+ * Used to resolve the
364
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
365
+ * of values.
366
+ */
367
+ var objectToString = Object.prototype.toString;
368
+ /** Built-in value references. */
369
+ var Symbol = root.Symbol;
370
+ /** Used to convert symbols to primitives and strings. */
371
+ var symbolProto = Symbol ? Symbol.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
372
+ /**
373
+ * The base implementation of `_.toString` which doesn't convert nullish
374
+ * values to empty strings.
375
+ *
376
+ * @private
377
+ * @param {*} value The value to process.
378
+ * @returns {string} Returns the string.
379
+ */
380
+ function baseToString(value) {
381
+ if (typeof value == "string") return value;
382
+ if (isSymbol(value)) return symbolToString ? symbolToString.call(value) : "";
383
+ var result = value + "";
384
+ return result == "0" && 1 / value == -INFINITY ? "-0" : result;
385
+ }
386
+ /**
387
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
388
+ * and has a `typeof` result of "object".
389
+ *
390
+ * @static
391
+ * @memberOf _
392
+ * @since 4.0.0
393
+ * @category Lang
394
+ * @param {*} value The value to check.
395
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
396
+ * @example
397
+ *
398
+ * _.isObjectLike({});
399
+ * // => true
400
+ *
401
+ * _.isObjectLike([1, 2, 3]);
402
+ * // => true
403
+ *
404
+ * _.isObjectLike(_.noop);
405
+ * // => false
406
+ *
407
+ * _.isObjectLike(null);
408
+ * // => false
409
+ */
410
+ function isObjectLike(value) {
411
+ return !!value && typeof value == "object";
412
+ }
413
+ /**
414
+ * Checks if `value` is classified as a `Symbol` primitive or object.
415
+ *
416
+ * @static
417
+ * @memberOf _
418
+ * @since 4.0.0
419
+ * @category Lang
420
+ * @param {*} value The value to check.
421
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
422
+ * @example
423
+ *
424
+ * _.isSymbol(Symbol.iterator);
425
+ * // => true
426
+ *
427
+ * _.isSymbol('abc');
428
+ * // => false
429
+ */
430
+ function isSymbol(value) {
431
+ return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
432
+ }
433
+ /**
434
+ * Converts `value` to a string. An empty string is returned for `null`
435
+ * and `undefined` values. The sign of `-0` is preserved.
436
+ *
437
+ * @static
438
+ * @memberOf _
439
+ * @since 4.0.0
440
+ * @category Lang
441
+ * @param {*} value The value to process.
442
+ * @returns {string} Returns the string.
443
+ * @example
444
+ *
445
+ * _.toString(null);
446
+ * // => ''
447
+ *
448
+ * _.toString(-0);
449
+ * // => '-0'
450
+ *
451
+ * _.toString([1, 2, 3]);
452
+ * // => '1,2,3'
453
+ */
454
+ function toString(value) {
455
+ return value == null ? "" : baseToString(value);
456
+ }
457
+ /**
458
+ * Deburrs `string` by converting
459
+ * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
460
+ * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
461
+ * letters to basic Latin letters and removing
462
+ * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
463
+ *
464
+ * @static
465
+ * @memberOf _
466
+ * @since 3.0.0
467
+ * @category String
468
+ * @param {string} [string=''] The string to deburr.
469
+ * @returns {string} Returns the deburred string.
470
+ * @example
471
+ *
472
+ * _.deburr('déjà vu');
473
+ * // => 'deja vu'
474
+ */
475
+ function deburr$1(string) {
476
+ string = toString(string);
477
+ return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
478
+ }
479
+ module.exports = deburr$1;
480
+ }));
481
+
482
+ //#endregion
483
+ //#region ../../node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs
484
+ var import_fastest_levenshtein = require_fastest_levenshtein();
485
+ var import_lodash = /* @__PURE__ */ __toESM(require_lodash(), 1);
486
+ let ReturnTypeEnums = /* @__PURE__ */ function(ReturnTypeEnums$1) {
487
+ ReturnTypeEnums$1["ALL_CLOSEST_MATCHES"] = "all-closest-matches";
488
+ ReturnTypeEnums$1["ALL_MATCHES"] = "all-matches";
489
+ ReturnTypeEnums$1["ALL_SORTED_MATCHES"] = "all-sorted-matches";
490
+ ReturnTypeEnums$1["FIRST_CLOSEST_MATCH"] = "first-closest-match";
491
+ ReturnTypeEnums$1["FIRST_MATCH"] = "first-match";
492
+ return ReturnTypeEnums$1;
493
+ }({});
494
+ let ThresholdTypeEnums = /* @__PURE__ */ function(ThresholdTypeEnums$1) {
495
+ ThresholdTypeEnums$1["EDIT_DISTANCE"] = "edit-distance";
496
+ ThresholdTypeEnums$1["SIMILARITY"] = "similarity";
497
+ return ThresholdTypeEnums$1;
498
+ }({});
499
+ const fillDefaultOptions = (options) => {
500
+ const optionsWithDefaultValues = {
501
+ caseSensitive: false,
502
+ deburr: true,
503
+ matchPath: [],
504
+ returnType: ReturnTypeEnums.FIRST_CLOSEST_MATCH,
505
+ thresholdType: ThresholdTypeEnums.SIMILARITY,
506
+ trimSpaces: true,
507
+ ...options
508
+ };
509
+ if (!Object.values(ReturnTypeEnums).includes(optionsWithDefaultValues.returnType)) throw new TypeError("unknown returnType");
510
+ if (!Object.values(ThresholdTypeEnums).includes(optionsWithDefaultValues.thresholdType)) throw new TypeError("unknown thresholdType");
511
+ switch (optionsWithDefaultValues.thresholdType) {
512
+ case ThresholdTypeEnums.EDIT_DISTANCE: return {
513
+ threshold: 20,
514
+ ...optionsWithDefaultValues
515
+ };
516
+ case ThresholdTypeEnums.SIMILARITY: return {
517
+ threshold: .4,
518
+ ...optionsWithDefaultValues
519
+ };
520
+ }
521
+ };
522
+ /**
523
+ * Using edit distance between `a` and `b` to calculate similarity
524
+ *
525
+ * @param {string} a - `input`
526
+ * @param {string} b - String from `matchList`
527
+ * @returns {number} similarity between `a` and `b`
528
+ */
529
+ const getSimilarity = (a, b) => {
530
+ if (!a || !b) return 0;
531
+ if (a === b) return 1;
532
+ const editDistance = (0, import_fastest_levenshtein.distance)(a, b);
533
+ const longestLength = Math.max(a.length, b.length);
534
+ return (longestLength - editDistance) / longestLength;
535
+ };
536
+ /**
537
+ * Normalize a string
538
+ *
539
+ * @param {string} str - any string
540
+ * @param {object} options - options that allows you to modify the behavior
541
+ * @returns {string} - normalized string
542
+ */
543
+ const normalizeString = (str, options) => {
544
+ let s = str;
545
+ if (options.trimSpaces) s = s.trim().replaceAll(/\s+/gu, " ");
546
+ if (options.deburr) s = (0, import_lodash.default)(s);
547
+ if (!options.caseSensitive) s = s.toLowerCase();
548
+ return s;
549
+ };
550
+ const getMatchItemStr = (matchItem, matchPath) => {
551
+ const matchItemStr = matchPath.length > 0 ? matchPath.reduce((acc, prop) => {
552
+ return acc?.[prop];
553
+ }, matchItem) : matchItem;
554
+ if (typeof matchItemStr !== "string") return "";
555
+ return matchItemStr;
556
+ };
557
+ /**
558
+ * Process matchItem according to options
559
+ *
560
+ * @param {object | string} matchItem - Item for matching with `input`
561
+ * @param {object} options - options that allows you to modify the behavior
562
+ * @returns {string} - processed matchItem
563
+ */
564
+ const matchItemProcessor = (matchItem, options) => {
565
+ const { matchPath } = options;
566
+ return normalizeString(getMatchItemStr(matchItem, matchPath), options);
567
+ };
568
+ /**
569
+ * Generate result
570
+ *
571
+ * @param {object[] | string[]} matchList - List for matching with `input`
572
+ * @param {number[]} matchedIndexes - indexes of matchList that need to be returned as result
573
+ * @param {ReturnTypeEnums} returnType - how the result will response to user
574
+ * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
575
+ */
576
+ const resultProcessor = (matchList, matchedIndexes, returnType) => {
577
+ switch (returnType) {
578
+ case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
579
+ case ReturnTypeEnums.ALL_MATCHES:
580
+ case ReturnTypeEnums.ALL_SORTED_MATCHES: return matchedIndexes.map((matchedIndex) => matchList[matchedIndex]);
581
+ case ReturnTypeEnums.FIRST_CLOSEST_MATCH:
582
+ case ReturnTypeEnums.FIRST_MATCH: {
583
+ const matchedIndex = matchedIndexes[0];
584
+ if (matchedIndex === void 0) return null;
585
+ return matchList[matchedIndex];
586
+ }
587
+ }
588
+ };
589
+ /**
590
+ * Main function for didyoumean2
591
+ *
592
+ * @param {string} input - string that you are not sure and want to match with `matchList`
593
+ * @param {object[] | string[]} matchList - List for matching with `input`
594
+ * @param {null | object | undefined} options - options that allows you to modify the behavior
595
+ * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
596
+ */
597
+ function didYouMean(input, matchList, options) {
598
+ const optionsWithDefaults = fillDefaultOptions(options);
599
+ const { returnType, threshold, thresholdType } = optionsWithDefaults;
600
+ const normalizedInput = normalizeString(input, optionsWithDefaults);
601
+ let checkIfMatched;
602
+ let scoreProcessor;
603
+ switch (thresholdType) {
604
+ case ThresholdTypeEnums.EDIT_DISTANCE:
605
+ checkIfMatched = (score) => score <= threshold;
606
+ scoreProcessor = (matchItem) => (0, import_fastest_levenshtein.distance)(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
607
+ break;
608
+ case ThresholdTypeEnums.SIMILARITY:
609
+ checkIfMatched = (score) => score >= threshold;
610
+ scoreProcessor = (matchItem) => getSimilarity(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
611
+ break;
612
+ }
613
+ const matchedIndexes = [];
614
+ switch (returnType) {
615
+ case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
616
+ case ReturnTypeEnums.FIRST_CLOSEST_MATCH: {
617
+ const scores = [];
618
+ let marginValue;
619
+ switch (thresholdType) {
620
+ case ThresholdTypeEnums.EDIT_DISTANCE:
621
+ marginValue = Number.POSITIVE_INFINITY;
622
+ for (const matchItem of matchList) {
623
+ const score = scoreProcessor(matchItem);
624
+ if (marginValue > score) marginValue = score;
625
+ scores.push(score);
626
+ }
627
+ break;
628
+ case ThresholdTypeEnums.SIMILARITY:
629
+ marginValue = 0;
630
+ for (const matchItem of matchList) {
631
+ const score = scoreProcessor(matchItem);
632
+ if (marginValue < score) marginValue = score;
633
+ scores.push(score);
634
+ }
635
+ break;
636
+ }
637
+ for (const [i, score] of scores.entries()) if (checkIfMatched(score) && score === marginValue) matchedIndexes.push(i);
638
+ break;
639
+ }
640
+ case ReturnTypeEnums.ALL_MATCHES:
641
+ for (const [i, matchItem] of matchList.entries()) {
642
+ const score = scoreProcessor(matchItem);
643
+ if (checkIfMatched(score)) matchedIndexes.push(i);
644
+ }
645
+ break;
646
+ case ReturnTypeEnums.ALL_SORTED_MATCHES: {
647
+ const unsortedResults = [];
648
+ for (const [i, matchItem] of matchList.entries()) {
649
+ const score = scoreProcessor(matchItem);
650
+ if (checkIfMatched(score)) unsortedResults.push({
651
+ score,
652
+ index: i
653
+ });
654
+ }
655
+ switch (thresholdType) {
656
+ case ThresholdTypeEnums.EDIT_DISTANCE:
657
+ unsortedResults.sort((a, b) => a.score - b.score);
658
+ break;
659
+ case ThresholdTypeEnums.SIMILARITY:
660
+ unsortedResults.sort((a, b) => b.score - a.score);
661
+ break;
662
+ }
663
+ for (const unsortedResult of unsortedResults) matchedIndexes.push(unsortedResult.index);
664
+ break;
665
+ }
666
+ case ReturnTypeEnums.FIRST_MATCH:
667
+ for (const [i, matchItem] of matchList.entries()) {
668
+ const score = scoreProcessor(matchItem);
669
+ if (checkIfMatched(score)) {
670
+ matchedIndexes.push(i);
671
+ break;
672
+ }
673
+ }
674
+ break;
675
+ }
676
+ return resultProcessor(matchList, matchedIndexes, returnType);
677
+ }
678
+
679
+ //#endregion
680
+ export { ReturnTypeEnums, ThresholdTypeEnums, didYouMean as default };
681
+ //# sourceMappingURL=dist-PXnBmevt.mjs.map