@n8n/utils 1.18.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.
- package/dist/assert.cjs +2 -11
- package/dist/assert.d.cts +2 -5
- package/dist/assert.d.mts +2 -0
- package/dist/assert.mjs +3 -0
- package/dist/assert2.cjs +17 -0
- package/dist/assert2.cjs.map +1 -0
- package/dist/{assert.d.ts → assert2.d.cts} +2 -2
- package/dist/assert2.d.mts +5 -0
- package/dist/{assert.js → assert2.mjs} +2 -2
- package/dist/assert2.mjs.map +1 -0
- package/dist/event-bus.cjs +2 -43
- package/dist/event-bus.d.cts +2 -14
- package/dist/event-bus.d.mts +2 -0
- package/dist/event-bus.mjs +3 -0
- package/dist/event-bus2.cjs +49 -0
- package/dist/event-bus2.cjs.map +1 -0
- package/dist/{event-bus.d.ts → event-bus2.d.cts} +2 -2
- package/dist/event-bus2.d.mts +14 -0
- package/dist/{event-bus.js → event-bus2.mjs} +2 -2
- package/dist/event-bus2.mjs.map +1 -0
- package/dist/event-queue.cjs +2 -40
- package/dist/event-queue.d.cts +2 -7
- package/dist/event-queue.d.mts +2 -0
- package/dist/event-queue.mjs +3 -0
- package/dist/event-queue2.cjs +46 -0
- package/dist/event-queue2.cjs.map +1 -0
- package/dist/{event-queue.d.ts → event-queue2.d.cts} +2 -2
- package/dist/event-queue2.d.mts +7 -0
- package/dist/{event-queue.js → event-queue2.mjs} +2 -2
- package/dist/event-queue2.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +11 -0
- package/dist/number/smartDecimal.cjs +2 -10
- package/dist/number/smartDecimal.d.cts +2 -5
- package/dist/number/smartDecimal.d.mts +2 -0
- package/dist/number/smartDecimal.mjs +3 -0
- package/dist/reRankSearchResults.cjs +25 -0
- package/dist/reRankSearchResults.cjs.map +1 -0
- package/dist/{search/reRankSearchResults.d.ts → reRankSearchResults.d.cts} +2 -2
- package/dist/reRankSearchResults.d.mts +13 -0
- package/dist/{search/reRankSearchResults.js → reRankSearchResults.mjs} +2 -2
- package/dist/reRankSearchResults.mjs.map +1 -0
- package/dist/retry.cjs +2 -39
- package/dist/retry.d.cts +2 -6
- package/dist/retry.d.mts +2 -0
- package/dist/retry.mjs +3 -0
- package/dist/retry2.cjs +45 -0
- package/dist/retry2.cjs.map +1 -0
- package/dist/{retry.d.ts → retry2.d.cts} +2 -2
- package/dist/retry2.d.mts +6 -0
- package/dist/{retry.js → retry2.mjs} +2 -2
- package/dist/retry2.mjs.map +1 -0
- package/dist/search/reRankSearchResults.cjs +2 -19
- package/dist/search/reRankSearchResults.d.cts +2 -13
- package/dist/search/reRankSearchResults.d.mts +2 -0
- package/dist/search/reRankSearchResults.mjs +3 -0
- package/dist/search/sublimeSearch.cjs +3 -172
- package/dist/search/sublimeSearch.d.cts +2 -15
- package/dist/search/sublimeSearch.d.mts +2 -0
- package/dist/search/sublimeSearch.mjs +3 -0
- package/dist/smartDecimal.cjs +16 -0
- package/dist/smartDecimal.cjs.map +1 -0
- package/dist/{number/smartDecimal.d.ts → smartDecimal.d.cts} +2 -2
- package/dist/smartDecimal.d.mts +5 -0
- package/dist/{number/smartDecimal.js → smartDecimal.mjs} +2 -2
- package/dist/smartDecimal.mjs.map +1 -0
- package/dist/sort/sortByProperty.cjs +2 -12
- package/dist/sort/sortByProperty.d.cts +2 -5
- package/dist/sort/sortByProperty.d.mts +2 -0
- package/dist/sort/sortByProperty.mjs +3 -0
- package/dist/sortByProperty.cjs +18 -0
- package/dist/sortByProperty.cjs.map +1 -0
- package/dist/{sort/sortByProperty.d.ts → sortByProperty.d.cts} +2 -2
- package/dist/sortByProperty.d.mts +5 -0
- package/dist/{sort/sortByProperty.js → sortByProperty.mjs} +2 -2
- package/dist/sortByProperty.mjs.map +1 -0
- package/dist/string/truncate.cjs +3 -30
- package/dist/string/truncate.d.cts +2 -6
- package/dist/string/truncate.d.mts +2 -0
- package/dist/string/truncate.mjs +3 -0
- package/dist/sublimeSearch.cjs +183 -0
- package/dist/sublimeSearch.cjs.map +1 -0
- package/dist/{search/sublimeSearch.d.ts → sublimeSearch.d.cts} +2 -2
- package/dist/sublimeSearch.d.mts +15 -0
- package/dist/{search/sublimeSearch.js → sublimeSearch.mjs} +2 -2
- package/dist/sublimeSearch.mjs.map +1 -0
- package/dist/truncate.cjs +41 -0
- package/dist/truncate.cjs.map +1 -0
- package/dist/{string/truncate.d.ts → truncate.d.cts} +2 -2
- package/dist/truncate.d.mts +6 -0
- package/dist/{string/truncate.js → truncate.mjs} +2 -2
- package/dist/truncate.mjs.map +1 -0
- package/package.json +14 -6
- package/dist/assert.cjs.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/event-bus.cjs.map +0 -1
- package/dist/event-bus.js.map +0 -1
- package/dist/event-queue.cjs.map +0 -1
- package/dist/event-queue.js.map +0 -1
- package/dist/number/smartDecimal.cjs.map +0 -1
- package/dist/number/smartDecimal.js.map +0 -1
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.js.map +0 -1
- package/dist/search/reRankSearchResults.cjs.map +0 -1
- package/dist/search/reRankSearchResults.js.map +0 -1
- package/dist/search/sublimeSearch.cjs.map +0 -1
- package/dist/search/sublimeSearch.js.map +0 -1
- package/dist/sort/sortByProperty.cjs.map +0 -1
- package/dist/sort/sortByProperty.js.map +0 -1
- package/dist/string/truncate.cjs.map +0 -1
- package/dist/string/truncate.js.map +0 -1
package/dist/retry.mjs
ADDED
package/dist/retry2.cjs
ADDED
|
@@ -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"}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
type RetryFn = () => boolean | Promise<boolean>;
|
|
3
3
|
declare function retry(fn: RetryFn, interval?: number, maxRetries?: number, backoff?: 'exponential' | 'linear' | null): Promise<boolean>;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { retry };
|
|
6
|
-
//# sourceMappingURL=
|
|
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 @@
|
|
|
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,20 +1,3 @@
|
|
|
1
|
+
const require_reRankSearchResults = require('../reRankSearchResults.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
function reRankSearchResults(searchResults, additionalFactors) {
|
|
4
|
-
return searchResults.map(({ score, item }) => {
|
|
5
|
-
return {
|
|
6
|
-
score: score + Object.entries(additionalFactors).reduce((acc, [_, factorScores]) => {
|
|
7
|
-
const factorScore = factorScores[item.key];
|
|
8
|
-
if (factorScore) return acc + factorScore;
|
|
9
|
-
return acc;
|
|
10
|
-
}, 0),
|
|
11
|
-
item
|
|
12
|
-
};
|
|
13
|
-
}).sort((a, b) => {
|
|
14
|
-
return b.score - a.score;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.reRankSearchResults = reRankSearchResults;
|
|
20
|
-
//# sourceMappingURL=reRankSearchResults.cjs.map
|
|
3
|
+
exports.reRankSearchResults = require_reRankSearchResults.reRankSearchResults;
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
key: string;
|
|
4
|
-
}>(searchResults: Array<{
|
|
5
|
-
score: number;
|
|
6
|
-
item: T;
|
|
7
|
-
}>, additionalFactors: Record<string, Record<string, number>>): Array<{
|
|
8
|
-
score: number;
|
|
9
|
-
item: T;
|
|
10
|
-
}>;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { reRankSearchResults };
|
|
13
|
-
//# sourceMappingURL=reRankSearchResults.d.cts.map
|
|
1
|
+
import { t as reRankSearchResults } from "../reRankSearchResults.cjs";
|
|
2
|
+
export { reRankSearchResults };
|
|
@@ -1,173 +1,4 @@
|
|
|
1
|
+
const require_sublimeSearch = require('../sublimeSearch.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
exports.DEFAULT_KEYS = DEFAULT_KEYS;
|
|
172
|
-
exports.sublimeSearch = sublimeSearch;
|
|
173
|
-
//# sourceMappingURL=sublimeSearch.cjs.map
|
|
3
|
+
exports.DEFAULT_KEYS = require_sublimeSearch.DEFAULT_KEYS;
|
|
4
|
+
exports.sublimeSearch = require_sublimeSearch.sublimeSearch;
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { DEFAULT_KEYS, sublimeSearch };
|
|
15
|
-
//# sourceMappingURL=sublimeSearch.d.cts.map
|
|
1
|
+
import { n as sublimeSearch, t as DEFAULT_KEYS } from "../sublimeSearch.cjs";
|
|
2
|
+
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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/number/smartDecimal.d.ts
|
|
2
2
|
declare const smartDecimal: (value: number, decimals?: number) => number;
|
|
3
3
|
//#endregion
|
|
4
|
-
export { smartDecimal };
|
|
5
|
-
//# sourceMappingURL=smartDecimal.d.
|
|
4
|
+
export { smartDecimal as t };
|
|
5
|
+
//# sourceMappingURL=smartDecimal.d.cts.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,13 +1,3 @@
|
|
|
1
|
+
const require_sortByProperty = require('../sortByProperty.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
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
|
-
exports.sortByProperty = sortByProperty;
|
|
13
|
-
//# sourceMappingURL=sortByProperty.cjs.map
|
|
3
|
+
exports.sortByProperty = require_sortByProperty.sortByProperty;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#endregion
|
|
4
|
-
export { sortByProperty };
|
|
5
|
-
//# sourceMappingURL=sortByProperty.d.cts.map
|
|
1
|
+
import { t as sortByProperty } from "../sortByProperty.cjs";
|
|
2
|
+
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"}
|
|
@@ -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.
|
|
4
|
+
export { sortByProperty as t };
|
|
5
|
+
//# sourceMappingURL=sortByProperty.d.cts.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"}
|
package/dist/string/truncate.cjs
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
|
+
const require_truncate = require('../truncate.cjs');
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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 };
|