@n8n/utils 1.20.0 → 1.21.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/truncate.cjs +3 -2
- package/dist/truncate.cjs.map +1 -1
- package/dist/truncate.d.cts +1 -1
- package/dist/truncate.d.mts +1 -1
- package/dist/truncate.mjs +3 -2
- package/dist/truncate.mjs.map +1 -1
- package/package.json +2 -2
package/dist/truncate.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const truncate = (text, length = 30) => text.length > length ? text.slice(0, len
|
|
|
7
7
|
* - Remove chars just before the last word, as long as the last word is under 15 chars
|
|
8
8
|
* - Otherwise preserve the last 5 chars of the name and remove chars before that
|
|
9
9
|
*/
|
|
10
|
-
function truncateBeforeLast(text, maxLength) {
|
|
10
|
+
function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
11
11
|
const chars = [];
|
|
12
12
|
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
13
13
|
for (const { segment } of segmenter.segment(text)) chars.push(segment);
|
|
@@ -22,7 +22,8 @@ function truncateBeforeLast(text, maxLength) {
|
|
|
22
22
|
const keepLength = indexBeforeLastWord - charsToRemove;
|
|
23
23
|
if (keepLength > 0) return chars.slice(0, keepLength).join("") + ellipsis + chars.slice(indexBeforeLastWord).join("");
|
|
24
24
|
}
|
|
25
|
-
return chars.slice(0, maxLength
|
|
25
|
+
if (lastCharsLength < 1) return chars.slice(0, maxLength).join("") + ellipsis;
|
|
26
|
+
return chars.slice(0, maxLength - lastCharsLength - ellipsisLength).join("") + ellipsis + chars.slice(-lastCharsLength).join("");
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
//#endregion
|
package/dist/truncate.cjs.map
CHANGED
|
@@ -1 +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(
|
|
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(\n\ttext: string,\n\tmaxLength: number,\n\tlastCharsLength: number = 5,\n): 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\tif (lastCharsLength < 1) {\n\t\treturn chars.slice(0, maxLength).join('') + ellipsis;\n\t}\n\n\treturn (\n\t\tchars.slice(0, maxLength - lastCharsLength - ellipsisLength).join('') +\n\t\tellipsis +\n\t\tchars.slice(-lastCharsLength).join('')\n\t);\n}\n"],"mappings":";;AAAA,MAAa,YAAY,MAAc,SAAS,OAC/C,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ;;;;;;;AAQxD,SAAgB,mBACf,MACA,WACA,kBAA0B,GACjB;CACT,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,KAAI,kBAAkB,EACrB,QAAO,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,GAAG,GAAG;AAG7C,QACC,MAAM,MAAM,GAAG,YAAY,kBAAkB,eAAe,CAAC,KAAK,GAAG,GACrE,WACA,MAAM,MAAM,CAAC,gBAAgB,CAAC,KAAK,GAAG"}
|
package/dist/truncate.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/string/truncate.d.ts
|
|
2
2
|
declare const truncate: (text: string, length?: number) => string;
|
|
3
|
-
declare function truncateBeforeLast(text: string, maxLength: number): string;
|
|
3
|
+
declare function truncateBeforeLast(text: string, maxLength: number, lastCharsLength?: number): string;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { truncateBeforeLast as n, truncate as t };
|
|
6
6
|
//# sourceMappingURL=truncate.d.cts.map
|
package/dist/truncate.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/string/truncate.d.ts
|
|
2
2
|
declare const truncate: (text: string, length?: number) => string;
|
|
3
|
-
declare function truncateBeforeLast(text: string, maxLength: number): string;
|
|
3
|
+
declare function truncateBeforeLast(text: string, maxLength: number, lastCharsLength?: number): string;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { truncateBeforeLast as n, truncate as t };
|
|
6
6
|
//# sourceMappingURL=truncate.d.mts.map
|
package/dist/truncate.mjs
CHANGED
|
@@ -6,7 +6,7 @@ const truncate = (text, length = 30) => text.length > length ? text.slice(0, len
|
|
|
6
6
|
* - Remove chars just before the last word, as long as the last word is under 15 chars
|
|
7
7
|
* - Otherwise preserve the last 5 chars of the name and remove chars before that
|
|
8
8
|
*/
|
|
9
|
-
function truncateBeforeLast(text, maxLength) {
|
|
9
|
+
function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
10
10
|
const chars = [];
|
|
11
11
|
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
12
12
|
for (const { segment } of segmenter.segment(text)) chars.push(segment);
|
|
@@ -21,7 +21,8 @@ function truncateBeforeLast(text, maxLength) {
|
|
|
21
21
|
const keepLength = indexBeforeLastWord - charsToRemove;
|
|
22
22
|
if (keepLength > 0) return chars.slice(0, keepLength).join("") + ellipsis + chars.slice(indexBeforeLastWord).join("");
|
|
23
23
|
}
|
|
24
|
-
return chars.slice(0, maxLength
|
|
24
|
+
if (lastCharsLength < 1) return chars.slice(0, maxLength).join("") + ellipsis;
|
|
25
|
+
return chars.slice(0, maxLength - lastCharsLength - ellipsisLength).join("") + ellipsis + chars.slice(-lastCharsLength).join("");
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
//#endregion
|
package/dist/truncate.mjs.map
CHANGED
|
@@ -1 +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(
|
|
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(\n\ttext: string,\n\tmaxLength: number,\n\tlastCharsLength: number = 5,\n): 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\tif (lastCharsLength < 1) {\n\t\treturn chars.slice(0, maxLength).join('') + ellipsis;\n\t}\n\n\treturn (\n\t\tchars.slice(0, maxLength - lastCharsLength - ellipsisLength).join('') +\n\t\tellipsis +\n\t\tchars.slice(-lastCharsLength).join('')\n\t);\n}\n"],"mappings":";AAAA,MAAa,YAAY,MAAc,SAAS,OAC/C,KAAK,SAAS,SAAS,KAAK,MAAM,GAAG,OAAO,GAAG,QAAQ;;;;;;;AAQxD,SAAgB,mBACf,MACA,WACA,kBAA0B,GACjB;CACT,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,KAAI,kBAAkB,EACrB,QAAO,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,GAAG,GAAG;AAG7C,QACC,MAAM,MAAM,GAAG,YAAY,kBAAkB,eAAe,CAAC,KAAK,GAAG,GACrE,WACA,MAAM,MAAM,CAAC,gBAAgB,CAAC,KAAK,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.21.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"LICENSE.md",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"typescript": "5.9.2",
|
|
35
35
|
"vite": "npm:rolldown-vite@latest",
|
|
36
36
|
"vitest": "^3.1.3",
|
|
37
|
-
"@n8n/typescript-config": "1.3.0",
|
|
38
37
|
"@n8n/eslint-config": "0.0.1",
|
|
38
|
+
"@n8n/typescript-config": "1.3.0",
|
|
39
39
|
"@n8n/vitest-config": "1.5.0"
|
|
40
40
|
},
|
|
41
41
|
"license": "SEE LICENSE IN LICENSE.md",
|