@n8n/utils 1.17.0 → 1.19.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 (129) hide show
  1. package/dist/assert.cjs +2 -9
  2. package/dist/assert.d.cts +2 -3
  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/assert2.d.cts +5 -0
  8. package/dist/assert2.d.mts +5 -0
  9. package/dist/assert2.mjs +11 -0
  10. package/dist/assert2.mjs.map +1 -0
  11. package/dist/event-bus.cjs +2 -39
  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-bus2.d.cts +14 -0
  18. package/dist/event-bus2.d.mts +14 -0
  19. package/dist/event-bus2.mjs +43 -0
  20. package/dist/event-bus2.mjs.map +1 -0
  21. package/dist/event-queue.cjs +2 -29
  22. package/dist/event-queue.d.cts +2 -5
  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-queue2.d.cts +7 -0
  28. package/dist/event-queue2.d.mts +7 -0
  29. package/dist/event-queue2.mjs +40 -0
  30. package/dist/event-queue2.mjs.map +1 -0
  31. package/dist/index.cjs +21 -0
  32. package/dist/index.d.cts +10 -0
  33. package/dist/index.d.mts +10 -0
  34. package/dist/index.mjs +11 -0
  35. package/dist/number/smartDecimal.cjs +2 -13
  36. package/dist/number/smartDecimal.d.cts +2 -3
  37. package/dist/number/smartDecimal.d.mts +2 -0
  38. package/dist/number/smartDecimal.mjs +3 -0
  39. package/dist/reRankSearchResults.cjs +25 -0
  40. package/dist/reRankSearchResults.cjs.map +1 -0
  41. package/dist/reRankSearchResults.d.cts +13 -0
  42. package/dist/reRankSearchResults.d.mts +13 -0
  43. package/dist/reRankSearchResults.mjs +19 -0
  44. package/dist/reRankSearchResults.mjs.map +1 -0
  45. package/dist/retry.cjs +2 -30
  46. package/dist/retry.d.cts +2 -4
  47. package/dist/retry.d.mts +2 -0
  48. package/dist/retry.mjs +3 -0
  49. package/dist/retry2.cjs +45 -0
  50. package/dist/retry2.cjs.map +1 -0
  51. package/dist/{retry.d.ts → retry2.d.cts} +4 -2
  52. package/dist/retry2.d.mts +6 -0
  53. package/dist/retry2.mjs +39 -0
  54. package/dist/retry2.mjs.map +1 -0
  55. package/dist/search/reRankSearchResults.cjs +2 -21
  56. package/dist/search/reRankSearchResults.d.cts +2 -11
  57. package/dist/search/reRankSearchResults.d.mts +2 -0
  58. package/dist/search/reRankSearchResults.mjs +3 -0
  59. package/dist/search/sublimeSearch.cjs +3 -197
  60. package/dist/search/sublimeSearch.d.cts +2 -13
  61. package/dist/search/sublimeSearch.d.mts +2 -0
  62. package/dist/search/sublimeSearch.mjs +3 -0
  63. package/dist/smartDecimal.cjs +16 -0
  64. package/dist/smartDecimal.cjs.map +1 -0
  65. package/dist/smartDecimal.d.cts +5 -0
  66. package/dist/smartDecimal.d.mts +5 -0
  67. package/dist/smartDecimal.mjs +10 -0
  68. package/dist/smartDecimal.mjs.map +1 -0
  69. package/dist/sort/sortByProperty.cjs +2 -11
  70. package/dist/sort/sortByProperty.d.cts +2 -3
  71. package/dist/sort/sortByProperty.d.mts +2 -0
  72. package/dist/sort/sortByProperty.mjs +3 -0
  73. package/dist/sortByProperty.cjs +18 -0
  74. package/dist/sortByProperty.cjs.map +1 -0
  75. package/dist/sortByProperty.d.cts +5 -0
  76. package/dist/sortByProperty.d.mts +5 -0
  77. package/dist/sortByProperty.mjs +12 -0
  78. package/dist/sortByProperty.mjs.map +1 -0
  79. package/dist/string/truncate.cjs +3 -30
  80. package/dist/string/truncate.d.cts +2 -4
  81. package/dist/string/truncate.d.mts +2 -0
  82. package/dist/string/truncate.mjs +3 -0
  83. package/dist/sublimeSearch.cjs +183 -0
  84. package/dist/sublimeSearch.cjs.map +1 -0
  85. package/dist/sublimeSearch.d.cts +15 -0
  86. package/dist/sublimeSearch.d.mts +15 -0
  87. package/dist/sublimeSearch.mjs +171 -0
  88. package/dist/sublimeSearch.mjs.map +1 -0
  89. package/dist/truncate.cjs +41 -0
  90. package/dist/truncate.cjs.map +1 -0
  91. package/dist/{string/truncate.d.ts → truncate.d.cts} +4 -2
  92. package/dist/truncate.d.mts +6 -0
  93. package/dist/truncate.mjs +29 -0
  94. package/dist/truncate.mjs.map +1 -0
  95. package/package.json +20 -12
  96. package/dist/assert.cjs.map +0 -1
  97. package/dist/assert.d.ts +0 -3
  98. package/dist/assert.js +0 -10
  99. package/dist/assert.js.map +0 -1
  100. package/dist/event-bus.cjs.map +0 -1
  101. package/dist/event-bus.d.ts +0 -14
  102. package/dist/event-bus.js +0 -40
  103. package/dist/event-bus.js.map +0 -1
  104. package/dist/event-queue.cjs.map +0 -1
  105. package/dist/event-queue.d.ts +0 -5
  106. package/dist/event-queue.js +0 -30
  107. package/dist/event-queue.js.map +0 -1
  108. package/dist/number/smartDecimal.cjs.map +0 -1
  109. package/dist/number/smartDecimal.d.ts +0 -3
  110. package/dist/number/smartDecimal.js +0 -14
  111. package/dist/number/smartDecimal.js.map +0 -1
  112. package/dist/retry.cjs.map +0 -1
  113. package/dist/retry.js +0 -31
  114. package/dist/retry.js.map +0 -1
  115. package/dist/search/reRankSearchResults.cjs.map +0 -1
  116. package/dist/search/reRankSearchResults.d.ts +0 -11
  117. package/dist/search/reRankSearchResults.js +0 -22
  118. package/dist/search/reRankSearchResults.js.map +0 -1
  119. package/dist/search/sublimeSearch.cjs.map +0 -1
  120. package/dist/search/sublimeSearch.d.ts +0 -13
  121. package/dist/search/sublimeSearch.js +0 -198
  122. package/dist/search/sublimeSearch.js.map +0 -1
  123. package/dist/sort/sortByProperty.cjs.map +0 -1
  124. package/dist/sort/sortByProperty.d.ts +0 -3
  125. package/dist/sort/sortByProperty.js +0 -12
  126. package/dist/sort/sortByProperty.js.map +0 -1
  127. package/dist/string/truncate.cjs.map +0 -1
  128. package/dist/string/truncate.js +0 -31
  129. package/dist/string/truncate.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reRankSearchResults.mjs","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"}
package/dist/retry.cjs CHANGED
@@ -1,31 +1,3 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/retry.ts
2
- async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
3
- let attempt = 0;
4
- while (attempt < maxRetries) {
5
- attempt++;
6
- try {
7
- const result = await fn();
8
- if (result) {
9
- return true;
10
- }
11
- } catch (error) {
12
- console.error("Error during retry:", error);
13
- throw error;
14
- }
15
- if (attempt < maxRetries) {
16
- let computedInterval = interval;
17
- if (backoff === "linear") {
18
- computedInterval = interval * attempt;
19
- } else if (backoff === "exponential") {
20
- computedInterval = Math.pow(2, attempt - 1) * interval;
21
- computedInterval = Math.min(computedInterval, 3e4);
22
- }
23
- await new Promise((resolve) => setTimeout(resolve, computedInterval));
24
- }
25
- }
26
- return false;
27
- }
1
+ const require_retry = require('./retry2.cjs');
28
2
 
29
-
30
- exports.retry = retry;
31
- //# sourceMappingURL=retry.cjs.map
3
+ exports.retry = require_retry.retry;
package/dist/retry.d.cts CHANGED
@@ -1,4 +1,2 @@
1
- type RetryFn = () => boolean | Promise<boolean>;
2
- declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
3
-
4
- export { retry };
1
+ import { t as retry } from "./retry2.cjs";
2
+ export { retry };
@@ -0,0 +1,2 @@
1
+ import { t as retry } from "./retry2.mjs";
2
+ export { retry };
package/dist/retry.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as retry } from "./retry2.mjs";
2
+
3
+ export { retry };
@@ -0,0 +1,45 @@
1
+
2
+ //#region src/retry.ts
3
+ /**
4
+ * A utility that retries a function every `interval` milliseconds
5
+ * until the function returns true or the maximum number of retries is reached.
6
+ *
7
+ * @param fn - A function that returns a boolean or a Promise resolving to a boolean.
8
+ * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
9
+ * @param maxRetries - The maximum number of retry attempts. Defaults to 3.
10
+ * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
11
+ * @returns {Promise<boolean>} - A promise that resolves to:
12
+ * - true: If the function returns true before reaching maxRetries.
13
+ * - false: If the function never returns true or if an error occurs.
14
+ */
15
+ async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
16
+ let attempt = 0;
17
+ while (attempt < maxRetries) {
18
+ attempt++;
19
+ try {
20
+ if (await fn()) return true;
21
+ } catch (error) {
22
+ console.error("Error during retry:", error);
23
+ throw error;
24
+ }
25
+ if (attempt < maxRetries) {
26
+ let computedInterval = interval;
27
+ if (backoff === "linear") computedInterval = interval * attempt;
28
+ else if (backoff === "exponential") {
29
+ computedInterval = Math.pow(2, attempt - 1) * interval;
30
+ computedInterval = Math.min(computedInterval, 3e4);
31
+ }
32
+ await new Promise((resolve) => setTimeout(resolve, computedInterval));
33
+ }
34
+ }
35
+ return false;
36
+ }
37
+
38
+ //#endregion
39
+ Object.defineProperty(exports, 'retry', {
40
+ enumerable: true,
41
+ get: function () {
42
+ return retry;
43
+ }
44
+ });
45
+ //# sourceMappingURL=retry2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry2.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"}
@@ -1,4 +1,6 @@
1
+ //#region src/retry.d.ts
1
2
  type RetryFn = () => boolean | Promise<boolean>;
2
3
  declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
3
-
4
- export { retry };
4
+ //#endregion
5
+ export { retry as t };
6
+ //# sourceMappingURL=retry2.d.cts.map
@@ -0,0 +1,6 @@
1
+ //#region src/retry.d.ts
2
+ type RetryFn = () => boolean | Promise<boolean>;
3
+ declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
4
+ //#endregion
5
+ export { retry as t };
6
+ //# sourceMappingURL=retry2.d.mts.map
@@ -0,0 +1,39 @@
1
+ //#region src/retry.ts
2
+ /**
3
+ * A utility that retries a function every `interval` milliseconds
4
+ * until the function returns true or the maximum number of retries is reached.
5
+ *
6
+ * @param fn - A function that returns a boolean or a Promise resolving to a boolean.
7
+ * @param interval - The time interval (in milliseconds) between each retry. Defaults to 1000.
8
+ * @param maxRetries - The maximum number of retry attempts. Defaults to 3.
9
+ * @param backoff - The backoff strategy to use: 'linear', 'exponential', or null.
10
+ * @returns {Promise<boolean>} - A promise that resolves to:
11
+ * - true: If the function returns true before reaching maxRetries.
12
+ * - false: If the function never returns true or if an error occurs.
13
+ */
14
+ async function retry(fn, interval = 1e3, maxRetries = 3, backoff = "linear") {
15
+ let attempt = 0;
16
+ while (attempt < maxRetries) {
17
+ attempt++;
18
+ try {
19
+ if (await fn()) return true;
20
+ } catch (error) {
21
+ console.error("Error during retry:", error);
22
+ throw error;
23
+ }
24
+ if (attempt < maxRetries) {
25
+ let computedInterval = interval;
26
+ if (backoff === "linear") computedInterval = interval * attempt;
27
+ else if (backoff === "exponential") {
28
+ computedInterval = Math.pow(2, attempt - 1) * interval;
29
+ computedInterval = Math.min(computedInterval, 3e4);
30
+ }
31
+ await new Promise((resolve) => setTimeout(resolve, computedInterval));
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+
37
+ //#endregion
38
+ export { retry as t };
39
+ //# sourceMappingURL=retry2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry2.mjs","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,22 +1,3 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/search/reRankSearchResults.ts
2
- function reRankSearchResults(searchResults, additionalFactors) {
3
- return searchResults.map(({ score, item }) => {
4
- const additionalScore = Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
5
- const factorScore = factorScores[item.key];
6
- if (factorScore) {
7
- return acc + factorScore;
8
- }
9
- return acc;
10
- }, 0);
11
- return {
12
- score: score + additionalScore,
13
- item
14
- };
15
- }).sort((a, b) => {
16
- return b.score - a.score;
17
- });
18
- }
1
+ const require_reRankSearchResults = require('../reRankSearchResults.cjs');
19
2
 
20
-
21
- exports.reRankSearchResults = reRankSearchResults;
22
- //# sourceMappingURL=reRankSearchResults.cjs.map
3
+ exports.reRankSearchResults = require_reRankSearchResults.reRankSearchResults;
@@ -1,11 +1,2 @@
1
- declare function reRankSearchResults<T extends {
2
- key: string;
3
- }>(searchResults: Array<{
4
- score: number;
5
- item: T;
6
- }>, additionalFactors: Record<string, Record<string, number>>): Array<{
7
- score: number;
8
- item: T;
9
- }>;
10
-
11
- export { reRankSearchResults };
1
+ import { t as reRankSearchResults } from "../reRankSearchResults.cjs";
2
+ export { reRankSearchResults };
@@ -0,0 +1,2 @@
1
+ import { t as reRankSearchResults } from "../reRankSearchResults.mjs";
2
+ export { reRankSearchResults };
@@ -0,0 +1,3 @@
1
+ import { t as reRankSearchResults } from "../reRankSearchResults.mjs";
2
+
3
+ export { reRankSearchResults };
@@ -1,198 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/search/sublimeSearch.ts
2
- var SEQUENTIAL_BONUS = 60;
3
- var SEPARATOR_BONUS = 38;
4
- var CAMEL_BONUS = 30;
5
- var FIRST_LETTER_BONUS = 15;
6
- var LEADING_LETTER_PENALTY = -20;
7
- var MAX_LEADING_LETTER_PENALTY = -200;
8
- var UNMATCHED_LETTER_PENALTY = -5;
9
- var DEFAULT_KEYS = [
10
- { key: "properties.displayName", weight: 1.3 },
11
- { key: "properties.codex.alias", weight: 1 }
12
- ];
13
- function fuzzyMatchSimple(pattern, target) {
14
- let patternIdx = 0;
15
- let strIdx = 0;
16
- while (patternIdx < pattern.length && strIdx < target.length) {
17
- const patternChar = pattern.charAt(patternIdx).toLowerCase();
18
- const targetChar = target.charAt(strIdx).toLowerCase();
19
- if (patternChar === targetChar) {
20
- patternIdx++;
21
- }
22
- ++strIdx;
23
- }
24
- return pattern.length !== 0 && target.length !== 0 && patternIdx === pattern.length;
25
- }
26
- function fuzzyMatchRecursive(pattern, target, patternCurIndex, targetCurrIndex, targetMatches, matches, maxMatches, nextMatch, recursionCount, recursionLimit) {
27
- let outScore = 0;
28
- if (++recursionCount >= recursionLimit) {
29
- return { matched: false, outScore };
30
- }
31
- if (patternCurIndex === pattern.length || targetCurrIndex === target.length) {
32
- return { matched: false, outScore };
33
- }
34
- let recursiveMatch = false;
35
- let bestRecursiveMatches = [];
36
- let bestRecursiveScore = 0;
37
- let firstMatch = true;
38
- while (patternCurIndex < pattern.length && targetCurrIndex < target.length) {
39
- if (pattern[patternCurIndex].toLowerCase() === target[targetCurrIndex].toLowerCase()) {
40
- if (nextMatch >= maxMatches) {
41
- return { matched: false, outScore };
42
- }
43
- if (firstMatch && targetMatches) {
44
- matches = [...targetMatches];
45
- firstMatch = false;
46
- }
47
- const recursiveMatches = [];
48
- const recursiveResult = fuzzyMatchRecursive(
49
- pattern,
50
- target,
51
- patternCurIndex,
52
- targetCurrIndex + 1,
53
- matches,
54
- recursiveMatches,
55
- maxMatches,
56
- nextMatch,
57
- recursionCount,
58
- recursionLimit
59
- );
60
- const recursiveScore = recursiveResult.outScore;
61
- if (recursiveResult.matched) {
62
- if (!recursiveMatch || recursiveScore > bestRecursiveScore) {
63
- bestRecursiveMatches = [...recursiveMatches];
64
- bestRecursiveScore = recursiveScore;
65
- }
66
- recursiveMatch = true;
67
- }
68
- matches[nextMatch++] = targetCurrIndex;
69
- ++patternCurIndex;
70
- }
71
- ++targetCurrIndex;
72
- }
73
- const matched = patternCurIndex === pattern.length;
74
- if (matched) {
75
- outScore = 100;
76
- if (!target.toLowerCase().startsWith("n8n")) {
77
- let penalty = LEADING_LETTER_PENALTY * matches[0];
78
- penalty = penalty < MAX_LEADING_LETTER_PENALTY ? MAX_LEADING_LETTER_PENALTY : penalty;
79
- outScore += penalty;
80
- }
81
- const unmatched = target.length - nextMatch;
82
- outScore += UNMATCHED_LETTER_PENALTY * unmatched;
83
- for (let i = 0; i < nextMatch; i++) {
84
- const currIdx = matches[i];
85
- if (i > 0) {
86
- const prevIdx = matches[i - 1];
87
- if (currIdx === prevIdx + 1) {
88
- outScore += SEQUENTIAL_BONUS;
89
- }
90
- }
91
- if (currIdx > 0) {
92
- const neighbor = target[currIdx - 1];
93
- const curr = target[currIdx];
94
- if (neighbor !== neighbor.toUpperCase() && curr !== curr.toLowerCase()) {
95
- outScore += CAMEL_BONUS;
96
- }
97
- const isNeighbourSeparator = neighbor === "_" || neighbor === " ";
98
- if (isNeighbourSeparator) {
99
- outScore += SEPARATOR_BONUS;
100
- }
101
- } else {
102
- outScore += FIRST_LETTER_BONUS;
103
- }
104
- }
105
- if (recursiveMatch && (!matched || bestRecursiveScore > outScore)) {
106
- matches = [...bestRecursiveMatches];
107
- outScore = bestRecursiveScore;
108
- return { matched: true, outScore };
109
- } else if (matched) {
110
- return { matched: true, outScore };
111
- } else {
112
- return { matched: false, outScore };
113
- }
114
- }
115
- return { matched: false, outScore };
116
- }
117
- function fuzzyMatch(pattern, target) {
118
- const recursionCount = 0;
119
- const recursionLimit = 5;
120
- const matches = [];
121
- const maxMatches = 256;
122
- return fuzzyMatchRecursive(
123
- pattern,
124
- target,
125
- 0,
126
- 0,
127
- null,
128
- matches,
129
- maxMatches,
130
- 0,
131
- recursionCount,
132
- recursionLimit
133
- );
134
- }
135
- function getValue(obj, prop) {
136
- if (obj.hasOwnProperty(prop)) {
137
- return obj[prop];
138
- }
139
- const segments = prop.split(".");
140
- let result = obj;
141
- let i = 0;
142
- while (result && i < segments.length) {
143
- const key = segments[i];
144
- result = result[key];
145
- i++;
146
- }
147
- return result;
148
- }
149
- function sublimeSearch(filter, data, keys = DEFAULT_KEYS) {
150
- const results = data.reduce((accu, item) => {
151
- let values = [];
152
- keys.forEach(({ key, weight }) => {
153
- const value = getValue(item, key);
154
- if (Array.isArray(value)) {
155
- values = values.concat(value.map((v) => ({ value: v, weight })));
156
- } else if (typeof value === "string") {
157
- values.push({
158
- value,
159
- weight
160
- });
161
- }
162
- });
163
- const itemMatch = values.reduce(
164
- (result, { value, weight }) => {
165
- if (!fuzzyMatchSimple(filter, value)) {
166
- return result;
167
- }
168
- const match = fuzzyMatch(filter, value);
169
- match.outScore *= weight;
170
- const { matched, outScore } = match;
171
- if (!result && matched) {
172
- return match;
173
- }
174
- if (matched && result && outScore > result.outScore) {
175
- return match;
176
- }
177
- return result;
178
- },
179
- null
180
- );
181
- if (itemMatch) {
182
- accu.push({
183
- score: itemMatch.outScore,
184
- item
185
- });
186
- }
187
- return accu;
188
- }, []);
189
- results.sort((a, b) => {
190
- return b.score - a.score;
191
- });
192
- return results;
193
- }
1
+ const require_sublimeSearch = require('../sublimeSearch.cjs');
194
2
 
195
-
196
-
197
- exports.DEFAULT_KEYS = DEFAULT_KEYS; exports.sublimeSearch = sublimeSearch;
198
- //# sourceMappingURL=sublimeSearch.cjs.map
3
+ exports.DEFAULT_KEYS = require_sublimeSearch.DEFAULT_KEYS;
4
+ exports.sublimeSearch = require_sublimeSearch.sublimeSearch;
@@ -1,13 +1,2 @@
1
- declare const DEFAULT_KEYS: {
2
- key: string;
3
- weight: number;
4
- }[];
5
- declare function sublimeSearch<T extends object>(filter: string, data: readonly T[], keys?: Array<{
6
- key: string;
7
- weight: number;
8
- }>): Array<{
9
- score: number;
10
- item: T;
11
- }>;
12
-
13
- export { DEFAULT_KEYS, sublimeSearch };
1
+ import { n as sublimeSearch, t as DEFAULT_KEYS } from "../sublimeSearch.cjs";
2
+ export { DEFAULT_KEYS, sublimeSearch };
@@ -0,0 +1,2 @@
1
+ import { n as sublimeSearch, t as DEFAULT_KEYS } from "../sublimeSearch.mjs";
2
+ export { DEFAULT_KEYS, sublimeSearch };
@@ -0,0 +1,3 @@
1
+ import { n as sublimeSearch, t as DEFAULT_KEYS } from "../sublimeSearch.mjs";
2
+
3
+ export { DEFAULT_KEYS, sublimeSearch };
@@ -0,0 +1,16 @@
1
+
2
+ //#region src/number/smartDecimal.ts
3
+ const smartDecimal = (value, decimals = 2) => {
4
+ if (Number.isInteger(value)) return value;
5
+ if (value.toString().split(".")[1].length <= decimals) return value;
6
+ return Number(value.toFixed(decimals));
7
+ };
8
+
9
+ //#endregion
10
+ Object.defineProperty(exports, 'smartDecimal', {
11
+ enumerable: true,
12
+ get: function () {
13
+ return smartDecimal;
14
+ }
15
+ });
16
+ //# sourceMappingURL=smartDecimal.cjs.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,5 @@
1
+ //#region src/number/smartDecimal.d.ts
2
+ declare const smartDecimal: (value: number, decimals?: number) => number;
3
+ //#endregion
4
+ export { smartDecimal as t };
5
+ //# sourceMappingURL=smartDecimal.d.cts.map
@@ -0,0 +1,5 @@
1
+ //#region src/number/smartDecimal.d.ts
2
+ declare const smartDecimal: (value: number, decimals?: number) => number;
3
+ //#endregion
4
+ export { smartDecimal as t };
5
+ //# sourceMappingURL=smartDecimal.d.mts.map
@@ -0,0 +1,10 @@
1
+ //#region src/number/smartDecimal.ts
2
+ const smartDecimal = (value, decimals = 2) => {
3
+ if (Number.isInteger(value)) return value;
4
+ if (value.toString().split(".")[1].length <= decimals) return value;
5
+ return Number(value.toFixed(decimals));
6
+ };
7
+
8
+ //#endregion
9
+ export { smartDecimal as t };
10
+ //# sourceMappingURL=smartDecimal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smartDecimal.mjs","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,12 +1,3 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/sort/sortByProperty.ts
2
- var sortByProperty = (property, arr, order = "asc") => arr.sort((a, b) => {
3
- const result = String(a[property]).localeCompare(String(b[property]), void 0, {
4
- numeric: true,
5
- sensitivity: "base"
6
- });
7
- return order === "asc" ? result : -result;
8
- });
1
+ const require_sortByProperty = require('../sortByProperty.cjs');
9
2
 
10
-
11
- exports.sortByProperty = sortByProperty;
12
- //# sourceMappingURL=sortByProperty.cjs.map
3
+ exports.sortByProperty = require_sortByProperty.sortByProperty;
@@ -1,3 +1,2 @@
1
- declare const sortByProperty: <T>(property: keyof T, arr: T[], order?: "asc" | "desc") => T[];
2
-
3
- export { sortByProperty };
1
+ import { t as sortByProperty } from "../sortByProperty.cjs";
2
+ export { sortByProperty };
@@ -0,0 +1,2 @@
1
+ import { t as sortByProperty } from "../sortByProperty.mjs";
2
+ export { sortByProperty };
@@ -0,0 +1,3 @@
1
+ import { t as sortByProperty } from "../sortByProperty.mjs";
2
+
3
+ export { sortByProperty };
@@ -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"}
@@ -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.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
@@ -0,0 +1,12 @@
1
+ //#region src/sort/sortByProperty.ts
2
+ const sortByProperty = (property, arr, order = "asc") => arr.sort((a, b) => {
3
+ const result = String(a[property]).localeCompare(String(b[property]), void 0, {
4
+ numeric: true,
5
+ sensitivity: "base"
6
+ });
7
+ return order === "asc" ? result : -result;
8
+ });
9
+
10
+ //#endregion
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
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/string/truncate.ts
2
- var truncate = (text, length = 30) => text.length > length ? text.slice(0, length) + "..." : text;
3
- function truncateBeforeLast(text, maxLength) {
4
- const chars = [];
5
- const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
6
- for (const { segment } of segmenter.segment(text)) {
7
- chars.push(segment);
8
- }
9
- if (chars.length <= maxLength) {
10
- return text;
11
- }
12
- const lastWhitespaceIndex = chars.findLastIndex((ch) => ch.match(/^\s+$/));
13
- const lastWordIndex = lastWhitespaceIndex + 1;
14
- const lastWord = chars.slice(lastWordIndex);
15
- const ellipsis = "\u2026";
16
- const ellipsisLength = ellipsis.length;
17
- if (lastWord.length < 15) {
18
- const charsToRemove = chars.length - maxLength + ellipsisLength;
19
- const indexBeforeLastWord = lastWordIndex;
20
- const keepLength = indexBeforeLastWord - charsToRemove;
21
- if (keepLength > 0) {
22
- return chars.slice(0, keepLength).join("") + ellipsis + chars.slice(indexBeforeLastWord).join("");
23
- }
24
- }
25
- return chars.slice(0, maxLength - 5 - ellipsisLength).join("") + ellipsis + chars.slice(-5).join("");
26
- }
1
+ const require_truncate = require('../truncate.cjs');
27
2
 
28
-
29
-
30
- exports.truncate = truncate; exports.truncateBeforeLast = truncateBeforeLast;
31
- //# sourceMappingURL=truncate.cjs.map
3
+ exports.truncate = require_truncate.truncate;
4
+ exports.truncateBeforeLast = require_truncate.truncateBeforeLast;
@@ -1,4 +1,2 @@
1
- declare const truncate: (text: string, length?: number) => string;
2
- declare function truncateBeforeLast(text: string, maxLength: number): string;
3
-
4
- export { truncate, truncateBeforeLast };
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 };