@powerlines/plugin-automd 0.1.128 → 0.1.129

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 (80) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +2 -0
  2. package/dist/_virtual/rolldown_runtime.mjs +32 -0
  3. package/dist/index.cjs +5 -5
  4. package/dist/index.d.mts +1 -1
  5. package/dist/index.mjs +7 -7
  6. package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +78 -0
  7. package/dist/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +77 -0
  8. package/dist/node_modules/.pnpm/acorn@8.15.0/node_modules/acorn/dist/acorn.cjs +5032 -0
  9. package/dist/node_modules/.pnpm/acorn@8.15.0/node_modules/acorn/dist/acorn.mjs +5031 -0
  10. package/dist/node_modules/.pnpm/automd@0.4.2_patch_hash_0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/shared/automd.CjwUz8DJ.cjs +593 -0
  11. package/dist/node_modules/.pnpm/automd@0.4.2_patch_hash_0fe864a2d6fa1461e144747e5f0fbc0a5fb51435ec6b3217ffb18ff2d7058778_magicast@0.5.1/node_modules/automd/dist/shared/automd.CjwUz8DJ.mjs +590 -0
  12. package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DA7CpUDY.cjs +23 -0
  13. package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DA7CpUDY.mjs +22 -0
  14. package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DnMsyigM.cjs +405 -0
  15. package/dist/node_modules/.pnpm/confbox@0.2.2/node_modules/confbox/dist/shared/confbox.DnMsyigM.mjs +404 -0
  16. package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.cjs +46 -0
  17. package/dist/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs +45 -0
  18. package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.cjs +204 -0
  19. package/dist/node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs +202 -0
  20. package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.cjs +1013 -0
  21. package/dist/node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs +1007 -0
  22. package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.cjs +128 -0
  23. package/dist/node_modules/.pnpm/fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs +123 -0
  24. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.cjs +41464 -0
  25. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/babel.mjs +41461 -0
  26. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.cjs +4387 -0
  27. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/dist/jiti.mjs +4384 -0
  28. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.cjs +26 -0
  29. package/dist/node_modules/.pnpm/jiti@2.4.2/node_modules/jiti/lib/jiti.mjs +26 -0
  30. package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.cjs +370 -0
  31. package/dist/node_modules/.pnpm/lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs +367 -0
  32. package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +939 -0
  33. package/dist/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +939 -0
  34. package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.cjs +67 -0
  35. package/dist/node_modules/.pnpm/mdbox@0.1.1/node_modules/mdbox/dist/index.mjs +64 -0
  36. package/dist/node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.cjs +1292 -0
  37. package/dist/node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.mjs +1284 -0
  38. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.cjs +179 -0
  39. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/chunks/multipart-parser.mjs +179 -0
  40. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.cjs +20 -0
  41. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/index.mjs +18 -0
  42. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.cjs +3975 -0
  43. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/node.mjs +3961 -0
  44. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.cjs +16 -0
  45. package/dist/node_modules/.pnpm/node-fetch-native@1.6.7/node_modules/node-fetch-native/dist/shared/node-fetch-native.DfbY2q-x.mjs +14 -0
  46. package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.cjs +36 -0
  47. package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/node.mjs +33 -0
  48. package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.cjs +227 -0
  49. package/dist/node_modules/.pnpm/ofetch@1.5.1/node_modules/ofetch/dist/shared/ofetch.CWycOUEr.mjs +225 -0
  50. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +139 -0
  51. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +133 -0
  52. package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.cjs +77 -0
  53. package/dist/node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.mjs +76 -0
  54. package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.cjs +72 -0
  55. package/dist/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs +69 -0
  56. package/dist/node_modules/.pnpm/ufo@1.6.2/node_modules/ufo/dist/index.cjs +178 -0
  57. package/dist/node_modules/.pnpm/ufo@1.6.2/node_modules/ufo/dist/index.mjs +175 -0
  58. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.cjs +12337 -0
  59. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/babel.mjs +12337 -0
  60. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.cjs +19 -0
  61. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/loader/loader.mjs +18 -0
  62. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.cjs +71 -0
  63. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.BTwOq8Jl.mjs +71 -0
  64. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.cjs +110 -0
  65. package/dist/node_modules/.pnpm/untyped@2.0.0/node_modules/untyped/dist/shared/untyped.Br_uXjZG.mjs +100 -0
  66. package/dist/types/plugin.d.mts +3 -3
  67. package/package.json +4 -5
  68. /package/dist/{powerlines → packages/powerlines}/src/internal/helpers/hooks.d.mts +0 -0
  69. /package/dist/{powerlines → packages/powerlines}/src/types/api.d.mts +0 -0
  70. /package/dist/{powerlines → packages/powerlines}/src/types/babel.d.mts +0 -0
  71. /package/dist/{powerlines → packages/powerlines}/src/types/build.d.mts +0 -0
  72. /package/dist/{powerlines → packages/powerlines}/src/types/commands.d.mts +0 -0
  73. /package/dist/{powerlines → packages/powerlines}/src/types/config.d.mts +0 -0
  74. /package/dist/{powerlines → packages/powerlines}/src/types/context.d.mts +0 -0
  75. /package/dist/{powerlines → packages/powerlines}/src/types/fs.d.mts +0 -0
  76. /package/dist/{powerlines → packages/powerlines}/src/types/hooks.d.mts +0 -0
  77. /package/dist/{powerlines → packages/powerlines}/src/types/plugin.d.mts +0 -0
  78. /package/dist/{powerlines → packages/powerlines}/src/types/resolved.d.mts +0 -0
  79. /package/dist/{powerlines → packages/powerlines}/src/types/tsconfig.d.mts +0 -0
  80. /package/dist/{powerlines → packages/powerlines}/src/types/unplugin.d.mts +0 -0
@@ -0,0 +1,202 @@
1
+ import { __toESM } from "../../../../../../_virtual/rolldown_runtime.mjs";
2
+ import { require_fastest_levenshtein } from "../../../../fastest-levenshtein@1.0.16/node_modules/fastest-levenshtein/mod.mjs";
3
+ import { require_lodash } from "../../../../lodash.deburr@4.1.0/node_modules/lodash.deburr/index.mjs";
4
+
5
+ //#region ../../node_modules/.pnpm/didyoumean2@7.0.4/node_modules/didyoumean2/dist/index.mjs
6
+ var import_fastest_levenshtein = require_fastest_levenshtein();
7
+ var import_lodash = /* @__PURE__ */ __toESM(require_lodash(), 1);
8
+ let ReturnTypeEnums = /* @__PURE__ */ function(ReturnTypeEnums$1) {
9
+ ReturnTypeEnums$1["ALL_CLOSEST_MATCHES"] = "all-closest-matches";
10
+ ReturnTypeEnums$1["ALL_MATCHES"] = "all-matches";
11
+ ReturnTypeEnums$1["ALL_SORTED_MATCHES"] = "all-sorted-matches";
12
+ ReturnTypeEnums$1["FIRST_CLOSEST_MATCH"] = "first-closest-match";
13
+ ReturnTypeEnums$1["FIRST_MATCH"] = "first-match";
14
+ return ReturnTypeEnums$1;
15
+ }({});
16
+ let ThresholdTypeEnums = /* @__PURE__ */ function(ThresholdTypeEnums$1) {
17
+ ThresholdTypeEnums$1["EDIT_DISTANCE"] = "edit-distance";
18
+ ThresholdTypeEnums$1["SIMILARITY"] = "similarity";
19
+ return ThresholdTypeEnums$1;
20
+ }({});
21
+ const fillDefaultOptions = (options) => {
22
+ const optionsWithDefaultValues = {
23
+ caseSensitive: false,
24
+ deburr: true,
25
+ matchPath: [],
26
+ returnType: ReturnTypeEnums.FIRST_CLOSEST_MATCH,
27
+ thresholdType: ThresholdTypeEnums.SIMILARITY,
28
+ trimSpaces: true,
29
+ ...options
30
+ };
31
+ if (!Object.values(ReturnTypeEnums).includes(optionsWithDefaultValues.returnType)) throw new TypeError("unknown returnType");
32
+ if (!Object.values(ThresholdTypeEnums).includes(optionsWithDefaultValues.thresholdType)) throw new TypeError("unknown thresholdType");
33
+ switch (optionsWithDefaultValues.thresholdType) {
34
+ case ThresholdTypeEnums.EDIT_DISTANCE: return {
35
+ threshold: 20,
36
+ ...optionsWithDefaultValues
37
+ };
38
+ case ThresholdTypeEnums.SIMILARITY: return {
39
+ threshold: .4,
40
+ ...optionsWithDefaultValues
41
+ };
42
+ }
43
+ };
44
+ /**
45
+ * Using edit distance between `a` and `b` to calculate similarity
46
+ *
47
+ * @param {string} a - `input`
48
+ * @param {string} b - String from `matchList`
49
+ * @returns {number} similarity between `a` and `b`
50
+ */
51
+ const getSimilarity = (a, b) => {
52
+ if (!a || !b) return 0;
53
+ if (a === b) return 1;
54
+ const editDistance = (0, import_fastest_levenshtein.distance)(a, b);
55
+ const longestLength = Math.max(a.length, b.length);
56
+ return (longestLength - editDistance) / longestLength;
57
+ };
58
+ /**
59
+ * Normalize a string
60
+ *
61
+ * @param {string} str - any string
62
+ * @param {object} options - options that allows you to modify the behavior
63
+ * @returns {string} - normalized string
64
+ */
65
+ const normalizeString = (str, options) => {
66
+ let s = str;
67
+ if (options.trimSpaces) s = s.trim().replaceAll(/\s+/gu, " ");
68
+ if (options.deburr) s = (0, import_lodash.default)(s);
69
+ if (!options.caseSensitive) s = s.toLowerCase();
70
+ return s;
71
+ };
72
+ const getMatchItemStr = (matchItem, matchPath) => {
73
+ const matchItemStr = matchPath.length > 0 ? matchPath.reduce((acc, prop) => {
74
+ return acc?.[prop];
75
+ }, matchItem) : matchItem;
76
+ if (typeof matchItemStr !== "string") return "";
77
+ return matchItemStr;
78
+ };
79
+ /**
80
+ * Process matchItem according to options
81
+ *
82
+ * @param {object | string} matchItem - Item for matching with `input`
83
+ * @param {object} options - options that allows you to modify the behavior
84
+ * @returns {string} - processed matchItem
85
+ */
86
+ const matchItemProcessor = (matchItem, options) => {
87
+ const { matchPath } = options;
88
+ return normalizeString(getMatchItemStr(matchItem, matchPath), options);
89
+ };
90
+ /**
91
+ * Generate result
92
+ *
93
+ * @param {object[] | string[]} matchList - List for matching with `input`
94
+ * @param {number[]} matchedIndexes - indexes of matchList that need to be returned as result
95
+ * @param {ReturnTypeEnums} returnType - how the result will response to user
96
+ * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
97
+ */
98
+ const resultProcessor = (matchList, matchedIndexes, returnType) => {
99
+ switch (returnType) {
100
+ case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
101
+ case ReturnTypeEnums.ALL_MATCHES:
102
+ case ReturnTypeEnums.ALL_SORTED_MATCHES: return matchedIndexes.map((matchedIndex) => matchList[matchedIndex]);
103
+ case ReturnTypeEnums.FIRST_CLOSEST_MATCH:
104
+ case ReturnTypeEnums.FIRST_MATCH: {
105
+ const matchedIndex = matchedIndexes[0];
106
+ if (matchedIndex === void 0) return null;
107
+ return matchList[matchedIndex];
108
+ }
109
+ }
110
+ };
111
+ /**
112
+ * Main function for didyoumean2
113
+ *
114
+ * @param {string} input - string that you are not sure and want to match with `matchList`
115
+ * @param {object[] | string[]} matchList - List for matching with `input`
116
+ * @param {null | object | undefined} options - options that allows you to modify the behavior
117
+ * @returns {Array | null | object | string} - matched result(s), return object if `match` is `{Object[]}`
118
+ */
119
+ function didYouMean(input, matchList, options) {
120
+ const optionsWithDefaults = fillDefaultOptions(options);
121
+ const { returnType, threshold, thresholdType } = optionsWithDefaults;
122
+ const normalizedInput = normalizeString(input, optionsWithDefaults);
123
+ let checkIfMatched;
124
+ let scoreProcessor;
125
+ switch (thresholdType) {
126
+ case ThresholdTypeEnums.EDIT_DISTANCE:
127
+ checkIfMatched = (score) => score <= threshold;
128
+ scoreProcessor = (matchItem) => (0, import_fastest_levenshtein.distance)(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
129
+ break;
130
+ case ThresholdTypeEnums.SIMILARITY:
131
+ checkIfMatched = (score) => score >= threshold;
132
+ scoreProcessor = (matchItem) => getSimilarity(normalizedInput, matchItemProcessor(matchItem, optionsWithDefaults));
133
+ break;
134
+ }
135
+ const matchedIndexes = [];
136
+ switch (returnType) {
137
+ case ReturnTypeEnums.ALL_CLOSEST_MATCHES:
138
+ case ReturnTypeEnums.FIRST_CLOSEST_MATCH: {
139
+ const scores = [];
140
+ let marginValue;
141
+ switch (thresholdType) {
142
+ case ThresholdTypeEnums.EDIT_DISTANCE:
143
+ marginValue = Number.POSITIVE_INFINITY;
144
+ for (const matchItem of matchList) {
145
+ const score = scoreProcessor(matchItem);
146
+ if (marginValue > score) marginValue = score;
147
+ scores.push(score);
148
+ }
149
+ break;
150
+ case ThresholdTypeEnums.SIMILARITY:
151
+ marginValue = 0;
152
+ for (const matchItem of matchList) {
153
+ const score = scoreProcessor(matchItem);
154
+ if (marginValue < score) marginValue = score;
155
+ scores.push(score);
156
+ }
157
+ break;
158
+ }
159
+ for (const [i, score] of scores.entries()) if (checkIfMatched(score) && score === marginValue) matchedIndexes.push(i);
160
+ break;
161
+ }
162
+ case ReturnTypeEnums.ALL_MATCHES:
163
+ for (const [i, matchItem] of matchList.entries()) {
164
+ const score = scoreProcessor(matchItem);
165
+ if (checkIfMatched(score)) matchedIndexes.push(i);
166
+ }
167
+ break;
168
+ case ReturnTypeEnums.ALL_SORTED_MATCHES: {
169
+ const unsortedResults = [];
170
+ for (const [i, matchItem] of matchList.entries()) {
171
+ const score = scoreProcessor(matchItem);
172
+ if (checkIfMatched(score)) unsortedResults.push({
173
+ score,
174
+ index: i
175
+ });
176
+ }
177
+ switch (thresholdType) {
178
+ case ThresholdTypeEnums.EDIT_DISTANCE:
179
+ unsortedResults.sort((a, b) => a.score - b.score);
180
+ break;
181
+ case ThresholdTypeEnums.SIMILARITY:
182
+ unsortedResults.sort((a, b) => b.score - a.score);
183
+ break;
184
+ }
185
+ for (const unsortedResult of unsortedResults) matchedIndexes.push(unsortedResult.index);
186
+ break;
187
+ }
188
+ case ReturnTypeEnums.FIRST_MATCH:
189
+ for (const [i, matchItem] of matchList.entries()) {
190
+ const score = scoreProcessor(matchItem);
191
+ if (checkIfMatched(score)) {
192
+ matchedIndexes.push(i);
193
+ break;
194
+ }
195
+ }
196
+ break;
197
+ }
198
+ return resultProcessor(matchList, matchedIndexes, returnType);
199
+ }
200
+
201
+ //#endregion
202
+ export { ReturnTypeEnums, ThresholdTypeEnums, didYouMean as default };