@n8n/utils 1.18.0 → 1.20.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 (123) hide show
  1. package/dist/assert.cjs +2 -11
  2. package/dist/assert.d.cts +2 -5
  3. package/dist/assert.d.mts +2 -0
  4. package/dist/assert.mjs +3 -0
  5. package/dist/assert2.cjs +17 -0
  6. package/dist/assert2.cjs.map +1 -0
  7. package/dist/{assert.d.ts → assert2.d.cts} +2 -2
  8. package/dist/assert2.d.mts +5 -0
  9. package/dist/{assert.js → assert2.mjs} +2 -2
  10. package/dist/assert2.mjs.map +1 -0
  11. package/dist/event-bus.cjs +2 -43
  12. package/dist/event-bus.d.cts +2 -14
  13. package/dist/event-bus.d.mts +2 -0
  14. package/dist/event-bus.mjs +3 -0
  15. package/dist/event-bus2.cjs +49 -0
  16. package/dist/event-bus2.cjs.map +1 -0
  17. package/dist/{event-bus.d.ts → event-bus2.d.cts} +2 -2
  18. package/dist/event-bus2.d.mts +14 -0
  19. package/dist/{event-bus.js → event-bus2.mjs} +2 -2
  20. package/dist/event-bus2.mjs.map +1 -0
  21. package/dist/event-queue.cjs +2 -40
  22. package/dist/event-queue.d.cts +2 -7
  23. package/dist/event-queue.d.mts +2 -0
  24. package/dist/event-queue.mjs +3 -0
  25. package/dist/event-queue2.cjs +46 -0
  26. package/dist/event-queue2.cjs.map +1 -0
  27. package/dist/{event-queue.d.ts → event-queue2.d.cts} +2 -2
  28. package/dist/event-queue2.d.mts +7 -0
  29. package/dist/{event-queue.js → event-queue2.mjs} +2 -2
  30. package/dist/event-queue2.mjs.map +1 -0
  31. package/dist/files/sanitize.cjs +3 -0
  32. package/dist/files/sanitize.d.cts +2 -0
  33. package/dist/files/sanitize.d.mts +2 -0
  34. package/dist/files/sanitize.mjs +3 -0
  35. package/dist/index.cjs +23 -0
  36. package/dist/index.d.cts +11 -0
  37. package/dist/index.d.mts +11 -0
  38. package/dist/index.mjs +12 -0
  39. package/dist/number/smartDecimal.cjs +2 -10
  40. package/dist/number/smartDecimal.d.cts +2 -5
  41. package/dist/number/smartDecimal.d.mts +2 -0
  42. package/dist/number/smartDecimal.mjs +3 -0
  43. package/dist/reRankSearchResults.cjs +25 -0
  44. package/dist/reRankSearchResults.cjs.map +1 -0
  45. package/dist/{search/reRankSearchResults.d.ts → reRankSearchResults.d.cts} +2 -2
  46. package/dist/reRankSearchResults.d.mts +13 -0
  47. package/dist/{search/reRankSearchResults.js → reRankSearchResults.mjs} +2 -2
  48. package/dist/reRankSearchResults.mjs.map +1 -0
  49. package/dist/retry.cjs +2 -39
  50. package/dist/retry.d.cts +2 -6
  51. package/dist/retry.d.mts +2 -0
  52. package/dist/retry.mjs +3 -0
  53. package/dist/retry2.cjs +45 -0
  54. package/dist/retry2.cjs.map +1 -0
  55. package/dist/{retry.d.ts → retry2.d.cts} +2 -2
  56. package/dist/retry2.d.mts +6 -0
  57. package/dist/{retry.js → retry2.mjs} +2 -2
  58. package/dist/retry2.mjs.map +1 -0
  59. package/dist/sanitize.cjs +67 -0
  60. package/dist/sanitize.cjs.map +1 -0
  61. package/dist/sanitize.d.cts +5 -0
  62. package/dist/sanitize.d.mts +5 -0
  63. package/dist/sanitize.mjs +61 -0
  64. package/dist/sanitize.mjs.map +1 -0
  65. package/dist/search/reRankSearchResults.cjs +2 -19
  66. package/dist/search/reRankSearchResults.d.cts +2 -13
  67. package/dist/search/reRankSearchResults.d.mts +2 -0
  68. package/dist/search/reRankSearchResults.mjs +3 -0
  69. package/dist/search/sublimeSearch.cjs +3 -172
  70. package/dist/search/sublimeSearch.d.cts +2 -15
  71. package/dist/search/sublimeSearch.d.mts +2 -0
  72. package/dist/search/sublimeSearch.mjs +3 -0
  73. package/dist/smartDecimal.cjs +16 -0
  74. package/dist/smartDecimal.cjs.map +1 -0
  75. package/dist/{number/smartDecimal.d.ts → smartDecimal.d.cts} +2 -2
  76. package/dist/smartDecimal.d.mts +5 -0
  77. package/dist/{number/smartDecimal.js → smartDecimal.mjs} +2 -2
  78. package/dist/smartDecimal.mjs.map +1 -0
  79. package/dist/sort/sortByProperty.cjs +2 -12
  80. package/dist/sort/sortByProperty.d.cts +2 -5
  81. package/dist/sort/sortByProperty.d.mts +2 -0
  82. package/dist/sort/sortByProperty.mjs +3 -0
  83. package/dist/sortByProperty.cjs +18 -0
  84. package/dist/sortByProperty.cjs.map +1 -0
  85. package/dist/{sort/sortByProperty.d.ts → sortByProperty.d.cts} +2 -2
  86. package/dist/sortByProperty.d.mts +5 -0
  87. package/dist/{sort/sortByProperty.js → sortByProperty.mjs} +2 -2
  88. package/dist/sortByProperty.mjs.map +1 -0
  89. package/dist/string/truncate.cjs +3 -30
  90. package/dist/string/truncate.d.cts +2 -6
  91. package/dist/string/truncate.d.mts +2 -0
  92. package/dist/string/truncate.mjs +3 -0
  93. package/dist/sublimeSearch.cjs +183 -0
  94. package/dist/sublimeSearch.cjs.map +1 -0
  95. package/dist/{search/sublimeSearch.d.ts → sublimeSearch.d.cts} +2 -2
  96. package/dist/sublimeSearch.d.mts +15 -0
  97. package/dist/{search/sublimeSearch.js → sublimeSearch.mjs} +2 -2
  98. package/dist/sublimeSearch.mjs.map +1 -0
  99. package/dist/truncate.cjs +41 -0
  100. package/dist/truncate.cjs.map +1 -0
  101. package/dist/{string/truncate.d.ts → truncate.d.cts} +2 -2
  102. package/dist/truncate.d.mts +6 -0
  103. package/dist/{string/truncate.js → truncate.mjs} +2 -2
  104. package/dist/truncate.mjs.map +1 -0
  105. package/package.json +16 -7
  106. package/dist/assert.cjs.map +0 -1
  107. package/dist/assert.js.map +0 -1
  108. package/dist/event-bus.cjs.map +0 -1
  109. package/dist/event-bus.js.map +0 -1
  110. package/dist/event-queue.cjs.map +0 -1
  111. package/dist/event-queue.js.map +0 -1
  112. package/dist/number/smartDecimal.cjs.map +0 -1
  113. package/dist/number/smartDecimal.js.map +0 -1
  114. package/dist/retry.cjs.map +0 -1
  115. package/dist/retry.js.map +0 -1
  116. package/dist/search/reRankSearchResults.cjs.map +0 -1
  117. package/dist/search/reRankSearchResults.js.map +0 -1
  118. package/dist/search/sublimeSearch.cjs.map +0 -1
  119. package/dist/search/sublimeSearch.js.map +0 -1
  120. package/dist/sort/sortByProperty.cjs.map +0 -1
  121. package/dist/sort/sortByProperty.js.map +0 -1
  122. package/dist/string/truncate.cjs.map +0 -1
  123. package/dist/string/truncate.js.map +0 -1
@@ -0,0 +1,18 @@
1
+
2
+ //#region src/sort/sortByProperty.ts
3
+ const sortByProperty = (property, arr, order = "asc") => arr.sort((a, b) => {
4
+ const result = String(a[property]).localeCompare(String(b[property]), void 0, {
5
+ numeric: true,
6
+ sensitivity: "base"
7
+ });
8
+ return order === "asc" ? result : -result;
9
+ });
10
+
11
+ //#endregion
12
+ Object.defineProperty(exports, 'sortByProperty', {
13
+ enumerable: true,
14
+ get: function () {
15
+ return sortByProperty;
16
+ }
17
+ });
18
+ //# sourceMappingURL=sortByProperty.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sortByProperty.cjs","names":[],"sources":["../src/sort/sortByProperty.ts"],"sourcesContent":["export const sortByProperty = <T>(\n\tproperty: keyof T,\n\tarr: T[],\n\torder: 'asc' | 'desc' = 'asc',\n): T[] =>\n\tarr.sort((a, b) => {\n\t\tconst result = String(a[property]).localeCompare(String(b[property]), undefined, {\n\t\t\tnumeric: true,\n\t\t\tsensitivity: 'base',\n\t\t});\n\t\treturn order === 'asc' ? result : -result;\n\t});\n"],"mappings":";;AAAA,MAAa,kBACZ,UACA,KACA,QAAwB,UAExB,IAAI,MAAM,GAAG,MAAM;CAClB,MAAM,SAAS,OAAO,EAAE,UAAU,CAAC,cAAc,OAAO,EAAE,UAAU,EAAE,QAAW;EAChF,SAAS;EACT,aAAa;EACb,CAAC;AACF,QAAO,UAAU,QAAQ,SAAS,CAAC;EAClC"}
@@ -1,5 +1,5 @@
1
1
  //#region src/sort/sortByProperty.d.ts
2
2
  declare const sortByProperty: <T>(property: keyof T, arr: T[], order?: "asc" | "desc") => T[];
3
3
  //#endregion
4
- export { sortByProperty };
5
- //# sourceMappingURL=sortByProperty.d.ts.map
4
+ export { sortByProperty as t };
5
+ //# sourceMappingURL=sortByProperty.d.cts.map
@@ -0,0 +1,5 @@
1
+ //#region src/sort/sortByProperty.d.ts
2
+ declare const sortByProperty: <T>(property: keyof T, arr: T[], order?: "asc" | "desc") => T[];
3
+ //#endregion
4
+ export { sortByProperty as t };
5
+ //# sourceMappingURL=sortByProperty.d.mts.map
@@ -8,5 +8,5 @@ const sortByProperty = (property, arr, order = "asc") => arr.sort((a, b) => {
8
8
  });
9
9
 
10
10
  //#endregion
11
- export { sortByProperty };
12
- //# sourceMappingURL=sortByProperty.js.map
11
+ export { sortByProperty as t };
12
+ //# sourceMappingURL=sortByProperty.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sortByProperty.mjs","names":[],"sources":["../src/sort/sortByProperty.ts"],"sourcesContent":["export const sortByProperty = <T>(\n\tproperty: keyof T,\n\tarr: T[],\n\torder: 'asc' | 'desc' = 'asc',\n): T[] =>\n\tarr.sort((a, b) => {\n\t\tconst result = String(a[property]).localeCompare(String(b[property]), undefined, {\n\t\t\tnumeric: true,\n\t\t\tsensitivity: 'base',\n\t\t});\n\t\treturn order === 'asc' ? result : -result;\n\t});\n"],"mappings":";AAAA,MAAa,kBACZ,UACA,KACA,QAAwB,UAExB,IAAI,MAAM,GAAG,MAAM;CAClB,MAAM,SAAS,OAAO,EAAE,UAAU,CAAC,cAAc,OAAO,EAAE,UAAU,EAAE,QAAW;EAChF,SAAS;EACT,aAAa;EACb,CAAC;AACF,QAAO,UAAU,QAAQ,SAAS,CAAC;EAClC"}
@@ -1,31 +1,4 @@
1
+ const require_truncate = require('../truncate.cjs');
1
2
 
2
- //#region src/string/truncate.ts
3
- const truncate = (text, length = 30) => text.length > length ? text.slice(0, length) + "..." : text;
4
- /**
5
- * Replace part of given text with ellipsis following the rules below:
6
- *
7
- * - Remove chars just before the last word, as long as the last word is under 15 chars
8
- * - Otherwise preserve the last 5 chars of the name and remove chars before that
9
- */
10
- function truncateBeforeLast(text, maxLength) {
11
- const chars = [];
12
- const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
13
- for (const { segment } of segmenter.segment(text)) chars.push(segment);
14
- if (chars.length <= maxLength) return text;
15
- const lastWordIndex = chars.findLastIndex((ch) => ch.match(/^\s+$/)) + 1;
16
- const lastWord = chars.slice(lastWordIndex);
17
- const ellipsis = "…";
18
- const ellipsisLength = 1;
19
- if (lastWord.length < 15) {
20
- const charsToRemove = chars.length - maxLength + ellipsisLength;
21
- const indexBeforeLastWord = lastWordIndex;
22
- const keepLength = indexBeforeLastWord - charsToRemove;
23
- if (keepLength > 0) return chars.slice(0, keepLength).join("") + ellipsis + chars.slice(indexBeforeLastWord).join("");
24
- }
25
- return chars.slice(0, maxLength - 5 - ellipsisLength).join("") + ellipsis + chars.slice(-5).join("");
26
- }
27
-
28
- //#endregion
29
- exports.truncate = truncate;
30
- exports.truncateBeforeLast = truncateBeforeLast;
31
- //# sourceMappingURL=truncate.cjs.map
3
+ exports.truncate = require_truncate.truncate;
4
+ exports.truncateBeforeLast = require_truncate.truncateBeforeLast;
@@ -1,6 +1,2 @@
1
- //#region src/string/truncate.d.ts
2
- declare const truncate: (text: string, length?: number) => string;
3
- declare function truncateBeforeLast(text: string, maxLength: number): string;
4
- //#endregion
5
- export { truncate, truncateBeforeLast };
6
- //# sourceMappingURL=truncate.d.cts.map
1
+ import { n as truncateBeforeLast, t as truncate } from "../truncate.cjs";
2
+ export { truncate, truncateBeforeLast };
@@ -0,0 +1,2 @@
1
+ import { n as truncateBeforeLast, t as truncate } from "../truncate.mjs";
2
+ export { truncate, truncateBeforeLast };
@@ -0,0 +1,3 @@
1
+ import { n as truncateBeforeLast, t as truncate } from "../truncate.mjs";
2
+
3
+ export { truncate, truncateBeforeLast };
@@ -0,0 +1,183 @@
1
+
2
+ //#region src/search/sublimeSearch.ts
3
+ const SEQUENTIAL_BONUS = 60;
4
+ const SEPARATOR_BONUS = 38;
5
+ const CAMEL_BONUS = 30;
6
+ const FIRST_LETTER_BONUS = 15;
7
+ const LEADING_LETTER_PENALTY = -20;
8
+ const MAX_LEADING_LETTER_PENALTY = -200;
9
+ const UNMATCHED_LETTER_PENALTY = -5;
10
+ const DEFAULT_KEYS = [{
11
+ key: "properties.displayName",
12
+ weight: 1.3
13
+ }, {
14
+ key: "properties.codex.alias",
15
+ weight: 1
16
+ }];
17
+ /**
18
+ * Returns true if each character in pattern is found sequentially within target
19
+ * @param {*} pattern string
20
+ * @param {*} target string
21
+ */
22
+ function fuzzyMatchSimple(pattern, target) {
23
+ let patternIdx = 0;
24
+ let strIdx = 0;
25
+ while (patternIdx < pattern.length && strIdx < target.length) {
26
+ if (pattern.charAt(patternIdx).toLowerCase() === target.charAt(strIdx).toLowerCase()) patternIdx++;
27
+ ++strIdx;
28
+ }
29
+ return pattern.length !== 0 && target.length !== 0 && patternIdx === pattern.length;
30
+ }
31
+ function fuzzyMatchRecursive(pattern, target, patternCurIndex, targetCurrIndex, targetMatches, matches, maxMatches, nextMatch, recursionCount, recursionLimit) {
32
+ let outScore = 0;
33
+ if (++recursionCount >= recursionLimit) return {
34
+ matched: false,
35
+ outScore
36
+ };
37
+ if (patternCurIndex === pattern.length || targetCurrIndex === target.length) return {
38
+ matched: false,
39
+ outScore
40
+ };
41
+ let recursiveMatch = false;
42
+ let bestRecursiveMatches = [];
43
+ let bestRecursiveScore = 0;
44
+ let firstMatch = true;
45
+ while (patternCurIndex < pattern.length && targetCurrIndex < target.length) {
46
+ if (pattern[patternCurIndex].toLowerCase() === target[targetCurrIndex].toLowerCase()) {
47
+ if (nextMatch >= maxMatches) return {
48
+ matched: false,
49
+ outScore
50
+ };
51
+ if (firstMatch && targetMatches) {
52
+ matches = [...targetMatches];
53
+ firstMatch = false;
54
+ }
55
+ const recursiveMatches = [];
56
+ const recursiveResult = fuzzyMatchRecursive(pattern, target, patternCurIndex, targetCurrIndex + 1, matches, recursiveMatches, maxMatches, nextMatch, recursionCount, recursionLimit);
57
+ const recursiveScore = recursiveResult.outScore;
58
+ if (recursiveResult.matched) {
59
+ if (!recursiveMatch || recursiveScore > bestRecursiveScore) {
60
+ bestRecursiveMatches = [...recursiveMatches];
61
+ bestRecursiveScore = recursiveScore;
62
+ }
63
+ recursiveMatch = true;
64
+ }
65
+ matches[nextMatch++] = targetCurrIndex;
66
+ ++patternCurIndex;
67
+ }
68
+ ++targetCurrIndex;
69
+ }
70
+ const matched = patternCurIndex === pattern.length;
71
+ if (matched) {
72
+ outScore = 100;
73
+ if (!target.toLowerCase().startsWith("n8n")) {
74
+ let penalty = LEADING_LETTER_PENALTY * matches[0];
75
+ penalty = penalty < MAX_LEADING_LETTER_PENALTY ? MAX_LEADING_LETTER_PENALTY : penalty;
76
+ outScore += penalty;
77
+ }
78
+ const unmatched = target.length - nextMatch;
79
+ outScore += UNMATCHED_LETTER_PENALTY * unmatched;
80
+ for (let i = 0; i < nextMatch; i++) {
81
+ const currIdx = matches[i];
82
+ if (i > 0) {
83
+ if (currIdx === matches[i - 1] + 1) outScore += SEQUENTIAL_BONUS;
84
+ }
85
+ if (currIdx > 0) {
86
+ const neighbor = target[currIdx - 1];
87
+ const curr = target[currIdx];
88
+ if (neighbor !== neighbor.toUpperCase() && curr !== curr.toLowerCase()) outScore += CAMEL_BONUS;
89
+ if (neighbor === "_" || neighbor === " ") outScore += SEPARATOR_BONUS;
90
+ } else outScore += FIRST_LETTER_BONUS;
91
+ }
92
+ if (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {
93
+ matches = [...bestRecursiveMatches];
94
+ outScore = bestRecursiveScore;
95
+ return {
96
+ matched: true,
97
+ outScore
98
+ };
99
+ } else if (matched) return {
100
+ matched: true,
101
+ outScore
102
+ };
103
+ else return {
104
+ matched: false,
105
+ outScore
106
+ };
107
+ }
108
+ return {
109
+ matched: false,
110
+ outScore
111
+ };
112
+ }
113
+ /**
114
+ * Does a fuzzy search to find pattern inside a string.
115
+ * @param {*} pattern string pattern to search for
116
+ * @param {*} target string string which is being searched
117
+ * @returns [boolean, number] a boolean which tells if pattern was
118
+ * found or not and a search score
119
+ */
120
+ function fuzzyMatch(pattern, target) {
121
+ return fuzzyMatchRecursive(pattern, target, 0, 0, null, [], 256, 0, 0, 5);
122
+ }
123
+ function getValue(obj, prop) {
124
+ if (obj.hasOwnProperty(prop)) return obj[prop];
125
+ const segments = prop.split(".");
126
+ let result = obj;
127
+ let i = 0;
128
+ while (result && i < segments.length) {
129
+ const key = segments[i];
130
+ result = result[key];
131
+ i++;
132
+ }
133
+ return result;
134
+ }
135
+ function sublimeSearch(filter, data, keys = DEFAULT_KEYS) {
136
+ const results = data.reduce((accu, item) => {
137
+ let values = [];
138
+ keys.forEach(({ key, weight }) => {
139
+ const value = getValue(item, key);
140
+ if (Array.isArray(value)) values = values.concat(value.map((v) => ({
141
+ value: v,
142
+ weight
143
+ })));
144
+ else if (typeof value === "string") values.push({
145
+ value,
146
+ weight
147
+ });
148
+ });
149
+ const itemMatch = values.reduce((result, { value, weight }) => {
150
+ if (!fuzzyMatchSimple(filter, value)) return result;
151
+ const match = fuzzyMatch(filter, value);
152
+ match.outScore *= weight;
153
+ const { matched, outScore } = match;
154
+ if (!result && matched) return match;
155
+ if (matched && result && outScore > result.outScore) return match;
156
+ return result;
157
+ }, null);
158
+ if (itemMatch) accu.push({
159
+ score: itemMatch.outScore,
160
+ item
161
+ });
162
+ return accu;
163
+ }, []);
164
+ results.sort((a, b) => {
165
+ return b.score - a.score;
166
+ });
167
+ return results;
168
+ }
169
+
170
+ //#endregion
171
+ Object.defineProperty(exports, 'DEFAULT_KEYS', {
172
+ enumerable: true,
173
+ get: function () {
174
+ return DEFAULT_KEYS;
175
+ }
176
+ });
177
+ Object.defineProperty(exports, 'sublimeSearch', {
178
+ enumerable: true,
179
+ get: function () {
180
+ return sublimeSearch;
181
+ }
182
+ });
183
+ //# sourceMappingURL=sublimeSearch.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sublimeSearch.cjs","names":["bestRecursiveMatches: number[]","recursiveMatches: number[]","values: Array<{ value: string; weight: number }>"],"sources":["../src/search/sublimeSearch.ts"],"sourcesContent":["/*\n * Constants and utility functions used for searching for node types in node creator component\n * based on https://github.com/forrestthewoods/lib_fts/blob/master/code/fts_fuzzy_match.js\n */\n\nconst SEQUENTIAL_BONUS = 60; // bonus for adjacent matches\nconst SEPARATOR_BONUS = 38; // bonus if match occurs after a separator\nconst CAMEL_BONUS = 30; // bonus if match is uppercase and prev is lower\nconst FIRST_LETTER_BONUS = 15; // bonus if the first letter is matched\n\nconst LEADING_LETTER_PENALTY = -20; // penalty applied for every letter in str before the first match\nconst MAX_LEADING_LETTER_PENALTY = -200; // maximum penalty for leading letters\nconst UNMATCHED_LETTER_PENALTY = -5;\n\nexport const DEFAULT_KEYS = [\n\t{ key: 'properties.displayName', weight: 1.3 },\n\t{ key: 'properties.codex.alias', weight: 1 },\n];\n\n/**\n * Returns true if each character in pattern is found sequentially within target\n * @param {*} pattern string\n * @param {*} target string\n */\nfunction fuzzyMatchSimple(pattern: string, target: string): boolean {\n\tlet patternIdx = 0;\n\tlet strIdx = 0;\n\n\twhile (patternIdx < pattern.length && strIdx < target.length) {\n\t\tconst patternChar = pattern.charAt(patternIdx).toLowerCase();\n\t\tconst targetChar = target.charAt(strIdx).toLowerCase();\n\t\tif (patternChar === targetChar) {\n\t\t\tpatternIdx++;\n\t\t}\n\t\t++strIdx;\n\t}\n\n\treturn pattern.length !== 0 && target.length !== 0 && patternIdx === pattern.length;\n}\n\nfunction fuzzyMatchRecursive(\n\tpattern: string,\n\ttarget: string,\n\tpatternCurIndex: number,\n\ttargetCurrIndex: number,\n\ttargetMatches: null | number[],\n\tmatches: number[],\n\tmaxMatches: number,\n\tnextMatch: number,\n\trecursionCount: number,\n\trecursionLimit: number,\n): { matched: boolean; outScore: number } {\n\tlet outScore = 0;\n\n\t// Return if recursion limit is reached.\n\tif (++recursionCount >= recursionLimit) {\n\t\treturn { matched: false, outScore };\n\t}\n\n\t// Return if we reached ends of strings.\n\tif (patternCurIndex === pattern.length || targetCurrIndex === target.length) {\n\t\treturn { matched: false, outScore };\n\t}\n\n\t// Recursion params\n\tlet recursiveMatch = false;\n\tlet bestRecursiveMatches: number[] = [];\n\tlet bestRecursiveScore = 0;\n\n\t// Loop through pattern and str looking for a match.\n\tlet firstMatch = true;\n\twhile (patternCurIndex < pattern.length && targetCurrIndex < target.length) {\n\t\t// Match found.\n\t\tif (pattern[patternCurIndex].toLowerCase() === target[targetCurrIndex].toLowerCase()) {\n\t\t\tif (nextMatch >= maxMatches) {\n\t\t\t\treturn { matched: false, outScore };\n\t\t\t}\n\n\t\t\tif (firstMatch && targetMatches) {\n\t\t\t\tmatches = [...targetMatches];\n\t\t\t\tfirstMatch = false;\n\t\t\t}\n\n\t\t\tconst recursiveMatches: number[] = [];\n\t\t\tconst recursiveResult = fuzzyMatchRecursive(\n\t\t\t\tpattern,\n\t\t\t\ttarget,\n\t\t\t\tpatternCurIndex,\n\t\t\t\ttargetCurrIndex + 1,\n\t\t\t\tmatches,\n\t\t\t\trecursiveMatches,\n\t\t\t\tmaxMatches,\n\t\t\t\tnextMatch,\n\t\t\t\trecursionCount,\n\t\t\t\trecursionLimit,\n\t\t\t);\n\n\t\t\tconst recursiveScore = recursiveResult.outScore;\n\t\t\tif (recursiveResult.matched) {\n\t\t\t\t// Pick best recursive score.\n\t\t\t\tif (!recursiveMatch || recursiveScore > bestRecursiveScore) {\n\t\t\t\t\tbestRecursiveMatches = [...recursiveMatches];\n\t\t\t\t\tbestRecursiveScore = recursiveScore;\n\t\t\t\t}\n\t\t\t\trecursiveMatch = true;\n\t\t\t}\n\n\t\t\tmatches[nextMatch++] = targetCurrIndex;\n\t\t\t++patternCurIndex;\n\t\t}\n\t\t++targetCurrIndex;\n\t}\n\n\tconst matched = patternCurIndex === pattern.length;\n\n\tif (matched) {\n\t\toutScore = 100;\n\n\t\t// Apply leading letter penalty (if not n8n-prefixed)\n\t\tif (!target.toLowerCase().startsWith('n8n')) {\n\t\t\tlet penalty = LEADING_LETTER_PENALTY * matches[0];\n\t\t\tpenalty = penalty < MAX_LEADING_LETTER_PENALTY ? MAX_LEADING_LETTER_PENALTY : penalty;\n\t\t\toutScore += penalty;\n\t\t}\n\n\t\t//Apply unmatched penalty\n\t\tconst unmatched = target.length - nextMatch;\n\t\toutScore += UNMATCHED_LETTER_PENALTY * unmatched;\n\n\t\t// Apply ordering bonuses\n\t\tfor (let i = 0; i < nextMatch; i++) {\n\t\t\tconst currIdx = matches[i];\n\n\t\t\tif (i > 0) {\n\t\t\t\tconst prevIdx = matches[i - 1];\n\t\t\t\tif (currIdx === prevIdx + 1) {\n\t\t\t\t\toutScore += SEQUENTIAL_BONUS;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check for bonuses based on neighbor character value.\n\t\t\tif (currIdx > 0) {\n\t\t\t\t// Camel case\n\t\t\t\tconst neighbor = target[currIdx - 1];\n\t\t\t\tconst curr = target[currIdx];\n\t\t\t\tif (neighbor !== neighbor.toUpperCase() && curr !== curr.toLowerCase()) {\n\t\t\t\t\toutScore += CAMEL_BONUS;\n\t\t\t\t}\n\t\t\t\tconst isNeighbourSeparator = neighbor === '_' || neighbor === ' ';\n\t\t\t\tif (isNeighbourSeparator) {\n\t\t\t\t\toutScore += SEPARATOR_BONUS;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// First letter\n\t\t\t\toutScore += FIRST_LETTER_BONUS;\n\t\t\t}\n\t\t}\n\n\t\t// Return best result\n\t\tif (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {\n\t\t\t// Recursive score is better than \"this\"\n\t\t\tmatches = [...bestRecursiveMatches];\n\t\t\toutScore = bestRecursiveScore;\n\t\t\treturn { matched: true, outScore };\n\t\t} else if (matched) {\n\t\t\t// \"this\" score is better than recursive\n\t\t\treturn { matched: true, outScore };\n\t\t} else {\n\t\t\treturn { matched: false, outScore };\n\t\t}\n\t}\n\treturn { matched: false, outScore };\n}\n\n/**\n * Does a fuzzy search to find pattern inside a string.\n * @param {*} pattern string pattern to search for\n * @param {*} target string string which is being searched\n * @returns [boolean, number] a boolean which tells if pattern was\n * found or not and a search score\n */\nfunction fuzzyMatch(pattern: string, target: string): { matched: boolean; outScore: number } {\n\tconst recursionCount = 0;\n\tconst recursionLimit = 5;\n\tconst matches: number[] = [];\n\tconst maxMatches = 256;\n\n\treturn fuzzyMatchRecursive(\n\t\tpattern,\n\t\ttarget,\n\t\t0 /* patternCurIndex */,\n\t\t0 /* strCurrIndex */,\n\t\tnull /* srcMatces */,\n\t\tmatches,\n\t\tmaxMatches,\n\t\t0 /* nextMatch */,\n\t\trecursionCount,\n\t\trecursionLimit,\n\t);\n}\n\n// prop = 'key'\n// prop = 'key1.key2'\n// prop = ['key1', 'key2']\nfunction getValue<T extends object>(obj: T, prop: string): unknown {\n\tif (obj.hasOwnProperty(prop)) {\n\t\treturn obj[prop as keyof T];\n\t}\n\n\tconst segments = prop.split('.');\n\n\tlet result = obj;\n\tlet i = 0;\n\twhile (result && i < segments.length) {\n\t\tconst key = segments[i] as keyof T;\n\t\tresult = result[key] as T;\n\t\ti++;\n\t}\n\treturn result;\n}\n\nexport function sublimeSearch<T extends object>(\n\tfilter: string,\n\tdata: readonly T[],\n\tkeys: Array<{ key: string; weight: number }> = DEFAULT_KEYS,\n): Array<{ score: number; item: T }> {\n\tconst results = data.reduce((accu: Array<{ score: number; item: T }>, item: T) => {\n\t\tlet values: Array<{ value: string; weight: number }> = [];\n\t\tkeys.forEach(({ key, weight }) => {\n\t\t\tconst value = getValue(item, key);\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tvalues = values.concat(value.map((v) => ({ value: v, weight })));\n\t\t\t} else if (typeof value === 'string') {\n\t\t\t\tvalues.push({\n\t\t\t\t\tvalue,\n\t\t\t\t\tweight,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// for each item, check every key and get maximum score\n\t\tconst itemMatch = values.reduce(\n\t\t\t(\n\t\t\t\tresult: null | { matched: boolean; outScore: number },\n\t\t\t\t{ value, weight }: { value: string; weight: number },\n\t\t\t) => {\n\t\t\t\tif (!fuzzyMatchSimple(filter, value)) {\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\n\t\t\t\tconst match = fuzzyMatch(filter, value);\n\t\t\t\tmatch.outScore *= weight;\n\n\t\t\t\tconst { matched, outScore } = match;\n\t\t\t\tif (!result && matched) {\n\t\t\t\t\treturn match;\n\t\t\t\t}\n\t\t\t\tif (matched && result && outScore > result.outScore) {\n\t\t\t\t\treturn match;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tnull,\n\t\t);\n\n\t\tif (itemMatch) {\n\t\t\taccu.push({\n\t\t\t\tscore: itemMatch.outScore,\n\t\t\t\titem,\n\t\t\t});\n\t\t}\n\n\t\treturn accu;\n\t}, []);\n\n\tresults.sort((a, b) => {\n\t\treturn b.score - a.score;\n\t});\n\n\treturn results;\n}\n"],"mappings":"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"}
@@ -11,5 +11,5 @@ declare function sublimeSearch<T extends object>(filter: string, data: readonly
11
11
  item: T;
12
12
  }>;
13
13
  //#endregion
14
- export { DEFAULT_KEYS, sublimeSearch };
15
- //# sourceMappingURL=sublimeSearch.d.ts.map
14
+ export { sublimeSearch as n, DEFAULT_KEYS as t };
15
+ //# sourceMappingURL=sublimeSearch.d.cts.map
@@ -0,0 +1,15 @@
1
+ //#region src/search/sublimeSearch.d.ts
2
+ declare const DEFAULT_KEYS: {
3
+ key: string;
4
+ weight: number;
5
+ }[];
6
+ declare function sublimeSearch<T extends object>(filter: string, data: readonly T[], keys?: Array<{
7
+ key: string;
8
+ weight: number;
9
+ }>): Array<{
10
+ score: number;
11
+ item: T;
12
+ }>;
13
+ //#endregion
14
+ export { sublimeSearch as n, DEFAULT_KEYS as t };
15
+ //# sourceMappingURL=sublimeSearch.d.mts.map
@@ -167,5 +167,5 @@ function sublimeSearch(filter, data, keys = DEFAULT_KEYS) {
167
167
  }
168
168
 
169
169
  //#endregion
170
- export { DEFAULT_KEYS, sublimeSearch };
171
- //# sourceMappingURL=sublimeSearch.js.map
170
+ export { sublimeSearch as n, DEFAULT_KEYS as t };
171
+ //# sourceMappingURL=sublimeSearch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sublimeSearch.mjs","names":["bestRecursiveMatches: number[]","recursiveMatches: number[]","values: Array<{ value: string; weight: number }>"],"sources":["../src/search/sublimeSearch.ts"],"sourcesContent":["/*\n * Constants and utility functions used for searching for node types in node creator component\n * based on https://github.com/forrestthewoods/lib_fts/blob/master/code/fts_fuzzy_match.js\n */\n\nconst SEQUENTIAL_BONUS = 60; // bonus for adjacent matches\nconst SEPARATOR_BONUS = 38; // bonus if match occurs after a separator\nconst CAMEL_BONUS = 30; // bonus if match is uppercase and prev is lower\nconst FIRST_LETTER_BONUS = 15; // bonus if the first letter is matched\n\nconst LEADING_LETTER_PENALTY = -20; // penalty applied for every letter in str before the first match\nconst MAX_LEADING_LETTER_PENALTY = -200; // maximum penalty for leading letters\nconst UNMATCHED_LETTER_PENALTY = -5;\n\nexport const DEFAULT_KEYS = [\n\t{ key: 'properties.displayName', weight: 1.3 },\n\t{ key: 'properties.codex.alias', weight: 1 },\n];\n\n/**\n * Returns true if each character in pattern is found sequentially within target\n * @param {*} pattern string\n * @param {*} target string\n */\nfunction fuzzyMatchSimple(pattern: string, target: string): boolean {\n\tlet patternIdx = 0;\n\tlet strIdx = 0;\n\n\twhile (patternIdx < pattern.length && strIdx < target.length) {\n\t\tconst patternChar = pattern.charAt(patternIdx).toLowerCase();\n\t\tconst targetChar = target.charAt(strIdx).toLowerCase();\n\t\tif (patternChar === targetChar) {\n\t\t\tpatternIdx++;\n\t\t}\n\t\t++strIdx;\n\t}\n\n\treturn pattern.length !== 0 && target.length !== 0 && patternIdx === pattern.length;\n}\n\nfunction fuzzyMatchRecursive(\n\tpattern: string,\n\ttarget: string,\n\tpatternCurIndex: number,\n\ttargetCurrIndex: number,\n\ttargetMatches: null | number[],\n\tmatches: number[],\n\tmaxMatches: number,\n\tnextMatch: number,\n\trecursionCount: number,\n\trecursionLimit: number,\n): { matched: boolean; outScore: number } {\n\tlet outScore = 0;\n\n\t// Return if recursion limit is reached.\n\tif (++recursionCount >= recursionLimit) {\n\t\treturn { matched: false, outScore };\n\t}\n\n\t// Return if we reached ends of strings.\n\tif (patternCurIndex === pattern.length || targetCurrIndex === target.length) {\n\t\treturn { matched: false, outScore };\n\t}\n\n\t// Recursion params\n\tlet recursiveMatch = false;\n\tlet bestRecursiveMatches: number[] = [];\n\tlet bestRecursiveScore = 0;\n\n\t// Loop through pattern and str looking for a match.\n\tlet firstMatch = true;\n\twhile (patternCurIndex < pattern.length && targetCurrIndex < target.length) {\n\t\t// Match found.\n\t\tif (pattern[patternCurIndex].toLowerCase() === target[targetCurrIndex].toLowerCase()) {\n\t\t\tif (nextMatch >= maxMatches) {\n\t\t\t\treturn { matched: false, outScore };\n\t\t\t}\n\n\t\t\tif (firstMatch && targetMatches) {\n\t\t\t\tmatches = [...targetMatches];\n\t\t\t\tfirstMatch = false;\n\t\t\t}\n\n\t\t\tconst recursiveMatches: number[] = [];\n\t\t\tconst recursiveResult = fuzzyMatchRecursive(\n\t\t\t\tpattern,\n\t\t\t\ttarget,\n\t\t\t\tpatternCurIndex,\n\t\t\t\ttargetCurrIndex + 1,\n\t\t\t\tmatches,\n\t\t\t\trecursiveMatches,\n\t\t\t\tmaxMatches,\n\t\t\t\tnextMatch,\n\t\t\t\trecursionCount,\n\t\t\t\trecursionLimit,\n\t\t\t);\n\n\t\t\tconst recursiveScore = recursiveResult.outScore;\n\t\t\tif (recursiveResult.matched) {\n\t\t\t\t// Pick best recursive score.\n\t\t\t\tif (!recursiveMatch || recursiveScore > bestRecursiveScore) {\n\t\t\t\t\tbestRecursiveMatches = [...recursiveMatches];\n\t\t\t\t\tbestRecursiveScore = recursiveScore;\n\t\t\t\t}\n\t\t\t\trecursiveMatch = true;\n\t\t\t}\n\n\t\t\tmatches[nextMatch++] = targetCurrIndex;\n\t\t\t++patternCurIndex;\n\t\t}\n\t\t++targetCurrIndex;\n\t}\n\n\tconst matched = patternCurIndex === pattern.length;\n\n\tif (matched) {\n\t\toutScore = 100;\n\n\t\t// Apply leading letter penalty (if not n8n-prefixed)\n\t\tif (!target.toLowerCase().startsWith('n8n')) {\n\t\t\tlet penalty = LEADING_LETTER_PENALTY * matches[0];\n\t\t\tpenalty = penalty < MAX_LEADING_LETTER_PENALTY ? MAX_LEADING_LETTER_PENALTY : penalty;\n\t\t\toutScore += penalty;\n\t\t}\n\n\t\t//Apply unmatched penalty\n\t\tconst unmatched = target.length - nextMatch;\n\t\toutScore += UNMATCHED_LETTER_PENALTY * unmatched;\n\n\t\t// Apply ordering bonuses\n\t\tfor (let i = 0; i < nextMatch; i++) {\n\t\t\tconst currIdx = matches[i];\n\n\t\t\tif (i > 0) {\n\t\t\t\tconst prevIdx = matches[i - 1];\n\t\t\t\tif (currIdx === prevIdx + 1) {\n\t\t\t\t\toutScore += SEQUENTIAL_BONUS;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check for bonuses based on neighbor character value.\n\t\t\tif (currIdx > 0) {\n\t\t\t\t// Camel case\n\t\t\t\tconst neighbor = target[currIdx - 1];\n\t\t\t\tconst curr = target[currIdx];\n\t\t\t\tif (neighbor !== neighbor.toUpperCase() && curr !== curr.toLowerCase()) {\n\t\t\t\t\toutScore += CAMEL_BONUS;\n\t\t\t\t}\n\t\t\t\tconst isNeighbourSeparator = neighbor === '_' || neighbor === ' ';\n\t\t\t\tif (isNeighbourSeparator) {\n\t\t\t\t\toutScore += SEPARATOR_BONUS;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// First letter\n\t\t\t\toutScore += FIRST_LETTER_BONUS;\n\t\t\t}\n\t\t}\n\n\t\t// Return best result\n\t\tif (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {\n\t\t\t// Recursive score is better than \"this\"\n\t\t\tmatches = [...bestRecursiveMatches];\n\t\t\toutScore = bestRecursiveScore;\n\t\t\treturn { matched: true, outScore };\n\t\t} else if (matched) {\n\t\t\t// \"this\" score is better than recursive\n\t\t\treturn { matched: true, outScore };\n\t\t} else {\n\t\t\treturn { matched: false, outScore };\n\t\t}\n\t}\n\treturn { matched: false, outScore };\n}\n\n/**\n * Does a fuzzy search to find pattern inside a string.\n * @param {*} pattern string pattern to search for\n * @param {*} target string string which is being searched\n * @returns [boolean, number] a boolean which tells if pattern was\n * found or not and a search score\n */\nfunction fuzzyMatch(pattern: string, target: string): { matched: boolean; outScore: number } {\n\tconst recursionCount = 0;\n\tconst recursionLimit = 5;\n\tconst matches: number[] = [];\n\tconst maxMatches = 256;\n\n\treturn fuzzyMatchRecursive(\n\t\tpattern,\n\t\ttarget,\n\t\t0 /* patternCurIndex */,\n\t\t0 /* strCurrIndex */,\n\t\tnull /* srcMatces */,\n\t\tmatches,\n\t\tmaxMatches,\n\t\t0 /* nextMatch */,\n\t\trecursionCount,\n\t\trecursionLimit,\n\t);\n}\n\n// prop = 'key'\n// prop = 'key1.key2'\n// prop = ['key1', 'key2']\nfunction getValue<T extends object>(obj: T, prop: string): unknown {\n\tif (obj.hasOwnProperty(prop)) {\n\t\treturn obj[prop as keyof T];\n\t}\n\n\tconst segments = prop.split('.');\n\n\tlet result = obj;\n\tlet i = 0;\n\twhile (result && i < segments.length) {\n\t\tconst key = segments[i] as keyof T;\n\t\tresult = result[key] as T;\n\t\ti++;\n\t}\n\treturn result;\n}\n\nexport function sublimeSearch<T extends object>(\n\tfilter: string,\n\tdata: readonly T[],\n\tkeys: Array<{ key: string; weight: number }> = DEFAULT_KEYS,\n): Array<{ score: number; item: T }> {\n\tconst results = data.reduce((accu: Array<{ score: number; item: T }>, item: T) => {\n\t\tlet values: Array<{ value: string; weight: number }> = [];\n\t\tkeys.forEach(({ key, weight }) => {\n\t\t\tconst value = getValue(item, key);\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tvalues = values.concat(value.map((v) => ({ value: v, weight })));\n\t\t\t} else if (typeof value === 'string') {\n\t\t\t\tvalues.push({\n\t\t\t\t\tvalue,\n\t\t\t\t\tweight,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\t// for each item, check every key and get maximum score\n\t\tconst itemMatch = values.reduce(\n\t\t\t(\n\t\t\t\tresult: null | { matched: boolean; outScore: number },\n\t\t\t\t{ value, weight }: { value: string; weight: number },\n\t\t\t) => {\n\t\t\t\tif (!fuzzyMatchSimple(filter, value)) {\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\n\t\t\t\tconst match = fuzzyMatch(filter, value);\n\t\t\t\tmatch.outScore *= weight;\n\n\t\t\t\tconst { matched, outScore } = match;\n\t\t\t\tif (!result && matched) {\n\t\t\t\t\treturn match;\n\t\t\t\t}\n\t\t\t\tif (matched && result && outScore > result.outScore) {\n\t\t\t\t\treturn match;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t},\n\t\t\tnull,\n\t\t);\n\n\t\tif (itemMatch) {\n\t\t\taccu.push({\n\t\t\t\tscore: itemMatch.outScore,\n\t\t\t\titem,\n\t\t\t});\n\t\t}\n\n\t\treturn accu;\n\t}, []);\n\n\tresults.sort((a, b) => {\n\t\treturn b.score - a.score;\n\t});\n\n\treturn results;\n}\n"],"mappings":"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"}
@@ -0,0 +1,41 @@
1
+
2
+ //#region src/string/truncate.ts
3
+ const truncate = (text, length = 30) => text.length > length ? text.slice(0, length) + "..." : text;
4
+ /**
5
+ * Replace part of given text with ellipsis following the rules below:
6
+ *
7
+ * - Remove chars just before the last word, as long as the last word is under 15 chars
8
+ * - Otherwise preserve the last 5 chars of the name and remove chars before that
9
+ */
10
+ function truncateBeforeLast(text, maxLength) {
11
+ const chars = [];
12
+ const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
13
+ for (const { segment } of segmenter.segment(text)) chars.push(segment);
14
+ if (chars.length <= maxLength) return text;
15
+ const lastWordIndex = chars.findLastIndex((ch) => ch.match(/^\s+$/)) + 1;
16
+ const lastWord = chars.slice(lastWordIndex);
17
+ const ellipsis = "…";
18
+ const ellipsisLength = 1;
19
+ if (lastWord.length < 15) {
20
+ const charsToRemove = chars.length - maxLength + ellipsisLength;
21
+ const indexBeforeLastWord = lastWordIndex;
22
+ const keepLength = indexBeforeLastWord - charsToRemove;
23
+ if (keepLength > 0) return chars.slice(0, keepLength).join("") + ellipsis + chars.slice(indexBeforeLastWord).join("");
24
+ }
25
+ return chars.slice(0, maxLength - 5 - ellipsisLength).join("") + ellipsis + chars.slice(-5).join("");
26
+ }
27
+
28
+ //#endregion
29
+ Object.defineProperty(exports, 'truncate', {
30
+ enumerable: true,
31
+ get: function () {
32
+ return truncate;
33
+ }
34
+ });
35
+ Object.defineProperty(exports, 'truncateBeforeLast', {
36
+ enumerable: true,
37
+ get: function () {
38
+ return truncateBeforeLast;
39
+ }
40
+ });
41
+ //# sourceMappingURL=truncate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.cjs","names":["chars: string[]"],"sources":["../src/string/truncate.ts"],"sourcesContent":["export const truncate = (text: string, length = 30): string =>\n\ttext.length > length ? text.slice(0, length) + '...' : text;\n\n/**\n * Replace part of given text with ellipsis following the rules below:\n *\n * - Remove chars just before the last word, as long as the last word is under 15 chars\n * - Otherwise preserve the last 5 chars of the name and remove chars before that\n */\nexport function truncateBeforeLast(text: string, maxLength: number): string {\n\tconst chars: string[] = [];\n\n\tconst segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });\n\n\tfor (const { segment } of segmenter.segment(text)) {\n\t\tchars.push(segment);\n\t}\n\n\tif (chars.length <= maxLength) {\n\t\treturn text;\n\t}\n\n\tconst lastWhitespaceIndex = chars.findLastIndex((ch) => ch.match(/^\\s+$/));\n\tconst lastWordIndex = lastWhitespaceIndex + 1;\n\tconst lastWord = chars.slice(lastWordIndex);\n\tconst ellipsis = '…';\n\tconst ellipsisLength = ellipsis.length;\n\n\tif (lastWord.length < 15) {\n\t\tconst charsToRemove = chars.length - maxLength + ellipsisLength;\n\t\tconst indexBeforeLastWord = lastWordIndex;\n\t\tconst keepLength = indexBeforeLastWord - charsToRemove;\n\n\t\tif (keepLength > 0) {\n\t\t\treturn (\n\t\t\t\tchars.slice(0, keepLength).join('') + ellipsis + chars.slice(indexBeforeLastWord).join('')\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tchars.slice(0, maxLength - 5 - ellipsisLength).join('') + ellipsis + chars.slice(-5).join('')\n\t);\n}\n"],"mappings":";;AAAA,MAAa,YAAY,MAAc,SAAS,OAC/C,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ;;;;;;;AAQxD,SAAgB,mBAAmB,MAAc,WAA2B;CAC3E,MAAMA,QAAkB,EAAE;CAE1B,MAAM,YAAY,IAAI,KAAK,UAAU,QAAW,EAAE,aAAa,YAAY,CAAC;AAE5E,MAAK,MAAM,EAAE,aAAa,UAAU,QAAQ,KAAK,CAChD,OAAM,KAAK,QAAQ;AAGpB,KAAI,MAAM,UAAU,UACnB,QAAO;CAIR,MAAM,gBADsB,MAAM,eAAe,OAAO,GAAG,MAAM,QAAQ,CAAC,GAC9B;CAC5C,MAAM,WAAW,MAAM,MAAM,cAAc;CAC3C,MAAM,WAAW;CACjB,MAAM,iBAAiB;AAEvB,KAAI,SAAS,SAAS,IAAI;EACzB,MAAM,gBAAgB,MAAM,SAAS,YAAY;EACjD,MAAM,sBAAsB;EAC5B,MAAM,aAAa,sBAAsB;AAEzC,MAAI,aAAa,EAChB,QACC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,GAAG,GAAG,WAAW,MAAM,MAAM,oBAAoB,CAAC,KAAK,GAAG;;AAK7F,QACC,MAAM,MAAM,GAAG,YAAY,IAAI,eAAe,CAAC,KAAK,GAAG,GAAG,WAAW,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG"}
@@ -2,5 +2,5 @@
2
2
  declare const truncate: (text: string, length?: number) => string;
3
3
  declare function truncateBeforeLast(text: string, maxLength: number): string;
4
4
  //#endregion
5
- export { truncate, truncateBeforeLast };
6
- //# sourceMappingURL=truncate.d.ts.map
5
+ export { truncateBeforeLast as n, truncate as t };
6
+ //# sourceMappingURL=truncate.d.cts.map
@@ -0,0 +1,6 @@
1
+ //#region src/string/truncate.d.ts
2
+ declare const truncate: (text: string, length?: number) => string;
3
+ declare function truncateBeforeLast(text: string, maxLength: number): string;
4
+ //#endregion
5
+ export { truncateBeforeLast as n, truncate as t };
6
+ //# sourceMappingURL=truncate.d.mts.map
@@ -25,5 +25,5 @@ function truncateBeforeLast(text, maxLength) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- export { truncate, truncateBeforeLast };
29
- //# sourceMappingURL=truncate.js.map
28
+ export { truncateBeforeLast as n, truncate as t };
29
+ //# sourceMappingURL=truncate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.mjs","names":["chars: string[]"],"sources":["../src/string/truncate.ts"],"sourcesContent":["export const truncate = (text: string, length = 30): string =>\n\ttext.length > length ? text.slice(0, length) + '...' : text;\n\n/**\n * Replace part of given text with ellipsis following the rules below:\n *\n * - Remove chars just before the last word, as long as the last word is under 15 chars\n * - Otherwise preserve the last 5 chars of the name and remove chars before that\n */\nexport function truncateBeforeLast(text: string, maxLength: number): string {\n\tconst chars: string[] = [];\n\n\tconst segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });\n\n\tfor (const { segment } of segmenter.segment(text)) {\n\t\tchars.push(segment);\n\t}\n\n\tif (chars.length <= maxLength) {\n\t\treturn text;\n\t}\n\n\tconst lastWhitespaceIndex = chars.findLastIndex((ch) => ch.match(/^\\s+$/));\n\tconst lastWordIndex = lastWhitespaceIndex + 1;\n\tconst lastWord = chars.slice(lastWordIndex);\n\tconst ellipsis = '…';\n\tconst ellipsisLength = ellipsis.length;\n\n\tif (lastWord.length < 15) {\n\t\tconst charsToRemove = chars.length - maxLength + ellipsisLength;\n\t\tconst indexBeforeLastWord = lastWordIndex;\n\t\tconst keepLength = indexBeforeLastWord - charsToRemove;\n\n\t\tif (keepLength > 0) {\n\t\t\treturn (\n\t\t\t\tchars.slice(0, keepLength).join('') + ellipsis + chars.slice(indexBeforeLastWord).join('')\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tchars.slice(0, maxLength - 5 - ellipsisLength).join('') + ellipsis + chars.slice(-5).join('')\n\t);\n}\n"],"mappings":";AAAA,MAAa,YAAY,MAAc,SAAS,OAC/C,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ;;;;;;;AAQxD,SAAgB,mBAAmB,MAAc,WAA2B;CAC3E,MAAMA,QAAkB,EAAE;CAE1B,MAAM,YAAY,IAAI,KAAK,UAAU,QAAW,EAAE,aAAa,YAAY,CAAC;AAE5E,MAAK,MAAM,EAAE,aAAa,UAAU,QAAQ,KAAK,CAChD,OAAM,KAAK,QAAQ;AAGpB,KAAI,MAAM,UAAU,UACnB,QAAO;CAIR,MAAM,gBADsB,MAAM,eAAe,OAAO,GAAG,MAAM,QAAQ,CAAC,GAC9B;CAC5C,MAAM,WAAW,MAAM,MAAM,cAAc;CAC3C,MAAM,WAAW;CACjB,MAAM,iBAAiB;AAEvB,KAAI,SAAS,SAAS,IAAI;EACzB,MAAM,gBAAgB,MAAM,SAAS,YAAY;EACjD,MAAM,sBAAsB;EAC5B,MAAM,aAAa,sBAAsB;AAEzC,MAAI,aAAa,EAChB,QACC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,GAAG,GAAG,WAAW,MAAM,MAAM,oBAAoB,CAAC,KAAK,GAAG;;AAK7F,QACC,MAAM,MAAM,GAAG,YAAY,IAAI,eAAe,CAAC,KAAK,GAAG,GAAG,WAAW,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG"}
package/package.json CHANGED
@@ -1,33 +1,41 @@
1
1
  {
2
2
  "name": "@n8n/utils",
3
3
  "type": "module",
4
- "version": "1.18.0",
4
+ "version": "1.20.0",
5
5
  "files": [
6
6
  "dist",
7
7
  "LICENSE.md",
8
8
  "LICENSE_EE.md"
9
9
  ],
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.mjs",
12
+ "types": "./dist/index.d.mts",
10
13
  "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.mts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.cjs"
18
+ },
11
19
  "./dist/*": {
12
- "types": "./dist/*.d.ts",
13
- "import": "./dist/*.js",
20
+ "types": "./dist/*.d.mts",
21
+ "import": "./dist/*.mjs",
14
22
  "require": "./dist/*.cjs"
15
23
  },
16
24
  "./*": {
17
- "types": "./dist/*.d.ts",
18
- "import": "./dist/*.js",
25
+ "types": "./dist/*.d.mts",
26
+ "import": "./dist/*.mjs",
19
27
  "require": "./dist/*.cjs"
20
28
  }
21
29
  },
22
30
  "devDependencies": {
23
31
  "@testing-library/jest-dom": "^6.6.3",
24
32
  "@testing-library/user-event": "^14.6.1",
25
- "tsdown": "^0.15.6",
33
+ "tsdown": "^0.16.5",
26
34
  "typescript": "5.9.2",
27
35
  "vite": "npm:rolldown-vite@latest",
28
36
  "vitest": "^3.1.3",
29
- "@n8n/eslint-config": "0.0.1",
30
37
  "@n8n/typescript-config": "1.3.0",
38
+ "@n8n/eslint-config": "0.0.1",
31
39
  "@n8n/vitest-config": "1.5.0"
32
40
  },
33
41
  "license": "SEE LICENSE IN LICENSE.md",
@@ -46,6 +54,7 @@
46
54
  "preview": "vite preview",
47
55
  "typecheck": "tsc --noEmit",
48
56
  "test": "vitest run",
57
+ "test:unit": "vitest run",
49
58
  "test:dev": "vitest --silent=false",
50
59
  "lint": "eslint src --quiet",
51
60
  "lint:fix": "eslint src --fix",
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert.cjs","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert.js","names":[],"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Asserts given condition\n */\nexport function assert(condition: unknown, message?: string): asserts condition {\n\tif (!condition) {\n\t\t// eslint-disable-next-line n8n-local-rules/no-plain-errors\n\t\tthrow new Error(message ?? 'Assertion failed');\n\t}\n}\n"],"mappings":";;;;AAGA,SAAgB,OAAO,WAAoB,SAAqC;AAC/E,KAAI,CAAC,UAEJ,OAAM,IAAI,MAAM,WAAW,mBAAmB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-bus.cjs","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-bus.js","names":["handler: typeof fn"],"sources":["../src/event-bus.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CallbackFn = (...args: any[]) => any;\n\ntype Payloads<ListenerMap> = {\n\t[E in keyof ListenerMap]: unknown;\n};\n\ntype Listener<Payload> = (payload: Payload) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface EventBus<ListenerMap extends Payloads<ListenerMap> = Record<string, any>> {\n\ton<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\tonce<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\toff<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tfn: Listener<ListenerMap[EventName]>,\n\t): void;\n\n\temit<EventName extends keyof ListenerMap & string>(\n\t\teventName: EventName,\n\t\tevent?: ListenerMap[EventName],\n\t): void;\n}\n\n/**\n * Creates an event bus with the given listener map.\n *\n * @example\n * ```ts\n * const eventBus = createEventBus<{\n * 'user-logged-in': { username: string };\n * 'user-logged-out': never;\n * }>();\n */\nexport function createEventBus<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tListenerMap extends Payloads<ListenerMap> = Record<string, any>,\n>(): EventBus<ListenerMap> {\n\tconst handlers = new Map<string, CallbackFn[]>();\n\n\treturn {\n\t\ton(eventName, fn) {\n\t\t\tlet eventFns = handlers.get(eventName);\n\t\t\tif (!eventFns) {\n\t\t\t\teventFns = [fn];\n\t\t\t} else {\n\t\t\t\teventFns.push(fn);\n\t\t\t}\n\t\t\thandlers.set(eventName, eventFns);\n\t\t},\n\n\t\tonce(eventName, fn) {\n\t\t\tconst handler: typeof fn = (payload) => {\n\t\t\t\tthis.off(eventName, handler);\n\t\t\t\tfn(payload);\n\t\t\t};\n\t\t\tthis.on(eventName, handler);\n\t\t},\n\n\t\toff(eventName, fn) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.splice(eventFns.indexOf(fn) >>> 0, 1);\n\t\t\t}\n\t\t},\n\n\t\temit(eventName, event) {\n\t\t\tconst eventFns = handlers.get(eventName);\n\t\t\tif (eventFns) {\n\t\t\t\teventFns.slice().forEach((handler) => {\n\t\t\t\t\thandler(event);\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;AA0CA,SAAgB,iBAGW;CAC1B,MAAM,2BAAW,IAAI,KAA2B;AAEhD,QAAO;EACN,GAAG,WAAW,IAAI;GACjB,IAAI,WAAW,SAAS,IAAI,UAAU;AACtC,OAAI,CAAC,SACJ,YAAW,CAAC,GAAG;OAEf,UAAS,KAAK,GAAG;AAElB,YAAS,IAAI,WAAW,SAAS;;EAGlC,KAAK,WAAW,IAAI;GACnB,MAAMA,WAAsB,YAAY;AACvC,SAAK,IAAI,WAAW,QAAQ;AAC5B,OAAG,QAAQ;;AAEZ,QAAK,GAAG,WAAW,QAAQ;;EAG5B,IAAI,WAAW,IAAI;GAClB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,SAAS,QAAQ,GAAG,KAAK,GAAG,EAAE;;EAIhD,KAAK,WAAW,OAAO;GACtB,MAAM,WAAW,SAAS,IAAI,UAAU;AACxC,OAAI,SACH,UAAS,OAAO,CAAC,SAAS,YAAY;AACrC,YAAQ,MAAM;KACb;;EAGJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-queue.cjs","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-queue.js","names":["queue: T[]"],"sources":["../src/event-queue.ts"],"sourcesContent":["/**\n * Create an event queue that processes events sequentially.\n *\n * @param processEvent - Async function that processes a single event.\n * @returns A function that enqueues events for processing.\n */\nexport function createEventQueue<T>(processEvent: (event: T) => Promise<void>) {\n\t// The internal queue holding events.\n\tconst queue: T[] = [];\n\n\t// Flag to indicate whether an event is currently being processed.\n\tlet processing = false;\n\n\t/**\n\t * Process the next event in the queue (if not already processing).\n\t */\n\tasync function processNext(): Promise<void> {\n\t\tif (processing || queue.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tprocessing = true;\n\t\tconst currentEvent = queue.shift();\n\n\t\tif (currentEvent !== undefined) {\n\t\t\ttry {\n\t\t\t\tawait processEvent(currentEvent);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error processing event:', error);\n\t\t\t}\n\t\t}\n\n\t\tprocessing = false;\n\n\t\t// Recursively process the next event.\n\t\tawait processNext();\n\t}\n\n\t/**\n\t * Enqueue an event and trigger processing.\n\t *\n\t * @param event - The event to enqueue.\n\t */\n\tfunction enqueue(event: T): void {\n\t\tqueue.push(event);\n\t\tvoid processNext();\n\t}\n\n\treturn { enqueue };\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,iBAAoB,cAA2C;CAE9E,MAAMA,QAAa,EAAE;CAGrB,IAAI,aAAa;;;;CAKjB,eAAe,cAA6B;AAC3C,MAAI,cAAc,MAAM,WAAW,EAClC;AAGD,eAAa;EACb,MAAM,eAAe,MAAM,OAAO;AAElC,MAAI,iBAAiB,OACpB,KAAI;AACH,SAAM,aAAa,aAAa;WACxB,OAAO;AACf,WAAQ,MAAM,2BAA2B,MAAM;;AAIjD,eAAa;AAGb,QAAM,aAAa;;;;;;;CAQpB,SAAS,QAAQ,OAAgB;AAChC,QAAM,KAAK,MAAM;AACjB,EAAK,aAAa;;AAGnB,QAAO,EAAE,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"smartDecimal.cjs","names":[],"sources":["../../src/number/smartDecimal.ts"],"sourcesContent":["export const smartDecimal = (value: number, decimals = 2): number => {\n\t// Check if integer\n\tif (Number.isInteger(value)) {\n\t\treturn value;\n\t}\n\n\t// Check if it has only one decimal place\n\tif (value.toString().split('.')[1].length <= decimals) {\n\t\treturn value;\n\t}\n\n\treturn Number(value.toFixed(decimals));\n};\n"],"mappings":";;AAAA,MAAa,gBAAgB,OAAe,WAAW,MAAc;AAEpE,KAAI,OAAO,UAAU,MAAM,CAC1B,QAAO;AAIR,KAAI,MAAM,UAAU,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,SAC5C,QAAO;AAGR,QAAO,OAAO,MAAM,QAAQ,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"smartDecimal.js","names":[],"sources":["../../src/number/smartDecimal.ts"],"sourcesContent":["export const smartDecimal = (value: number, decimals = 2): number => {\n\t// Check if integer\n\tif (Number.isInteger(value)) {\n\t\treturn value;\n\t}\n\n\t// Check if it has only one decimal place\n\tif (value.toString().split('.')[1].length <= decimals) {\n\t\treturn value;\n\t}\n\n\treturn Number(value.toFixed(decimals));\n};\n"],"mappings":";AAAA,MAAa,gBAAgB,OAAe,WAAW,MAAc;AAEpE,KAAI,OAAO,UAAU,MAAM,CAC1B,QAAO;AAIR,KAAI,MAAM,UAAU,CAAC,MAAM,IAAI,CAAC,GAAG,UAAU,SAC5C,QAAO;AAGR,QAAO,OAAO,MAAM,QAAQ,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.cjs","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
package/dist/retry.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"retry.js","names":[],"sources":["../src/retry.ts"],"sourcesContent":["type RetryFn = () => boolean | Promise<boolean>;\n\n/**\n * A utility that retries a function every `interval` milliseconds\n * until the function returns true or the maximum number of retries is reached.\n *\n * @param fn - A function that returns a boolean or a Promise resolving to a boolean.\n * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.\n * @param maxRetries - The maximum number of retry attempts. Defaults to 3.\n * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.\n * @returns {Promise<boolean>} - A promise that resolves to:\n * - true: If the function returns true before reaching maxRetries.\n * - false: If the function never returns true or if an error occurs.\n */\nexport async function retry(\n\tfn: RetryFn,\n\tinterval: number = 1000,\n\tmaxRetries: number = 3,\n\tbackoff: 'exponential' | 'linear' | null = 'linear',\n): Promise<boolean> {\n\tlet attempt = 0;\n\n\twhile (attempt < maxRetries) {\n\t\tattempt++;\n\t\ttry {\n\t\t\tconst result = await fn();\n\t\t\tif (result) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error('Error during retry:', error);\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Wait for the specified interval before the next attempt, if any attempts remain.\n\t\tif (attempt < maxRetries) {\n\t\t\tlet computedInterval = interval;\n\n\t\t\tif (backoff === 'linear') {\n\t\t\t\tcomputedInterval = interval * attempt;\n\t\t\t} else if (backoff === 'exponential') {\n\t\t\t\tcomputedInterval = Math.pow(2, attempt - 1) * interval;\n\t\t\t\tcomputedInterval = Math.min(computedInterval, 30000); // Cap the maximum interval to 30 seconds\n\t\t\t}\n\n\t\t\tawait new Promise<void>((resolve) => setTimeout(resolve, computedInterval));\n\t\t}\n\t}\n\n\treturn false;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,eAAsB,MACrB,IACA,WAAmB,KACnB,aAAqB,GACrB,UAA2C,UACxB;CACnB,IAAI,UAAU;AAEd,QAAO,UAAU,YAAY;AAC5B;AACA,MAAI;AAEH,OADe,MAAM,IAAI,CAExB,QAAO;WAEA,OAAO;AACf,WAAQ,MAAM,uBAAuB,MAAM;AAC3C,SAAM;;AAIP,MAAI,UAAU,YAAY;GACzB,IAAI,mBAAmB;AAEvB,OAAI,YAAY,SACf,oBAAmB,WAAW;YACpB,YAAY,eAAe;AACrC,uBAAmB,KAAK,IAAI,GAAG,UAAU,EAAE,GAAG;AAC9C,uBAAmB,KAAK,IAAI,kBAAkB,IAAM;;AAGrD,SAAM,IAAI,SAAe,YAAY,WAAW,SAAS,iBAAiB,CAAC;;;AAI7E,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"reRankSearchResults.cjs","names":[],"sources":["../../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";;AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"reRankSearchResults.js","names":[],"sources":["../../src/search/reRankSearchResults.ts"],"sourcesContent":["export function reRankSearchResults<T extends { key: string }>(\n\tsearchResults: Array<{ score: number; item: T }>,\n\tadditionalFactors: Record<string, Record<string, number>>,\n): Array<{ score: number; item: T }> {\n\treturn searchResults\n\t\t.map(({ score, item }) => {\n\t\t\t// For each additional factor, we check if it exists for the item and type,\n\t\t\t// and if so, we add the score to the item's score.\n\t\t\tconst additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {\n\t\t\t\tconst factorScore = factorScores[item.key];\n\t\t\t\tif (factorScore) {\n\t\t\t\t\treturn acc + factorScore;\n\t\t\t\t}\n\n\t\t\t\treturn acc;\n\t\t\t}, 0);\n\n\t\t\treturn {\n\t\t\t\tscore: score + additionalScore,\n\t\t\t\titem,\n\t\t\t};\n\t\t})\n\t\t.sort((a, b) => {\n\t\t\treturn b.score - a.score;\n\t\t});\n}\n"],"mappings":";AAAA,SAAgB,oBACf,eACA,mBACoC;AACpC,QAAO,cACL,KAAK,EAAE,OAAO,WAAW;AAYzB,SAAO;GACN,OAAO,QAVgB,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,KAAK,CAAC,GAAG,kBAAkB;IAC5F,MAAM,cAAc,aAAa,KAAK;AACtC,QAAI,YACH,QAAO,MAAM;AAGd,WAAO;MACL,EAAE;GAIJ;GACA;GACA,CACD,MAAM,GAAG,MAAM;AACf,SAAO,EAAE,QAAQ,EAAE;GAClB"}