@n8n/utils 1.25.0 → 1.27.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 +5 -4
- 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 +5 -4
- package/dist/truncate.mjs.map +1 -1
- package/package.json +8 -8
package/dist/truncate.cjs
CHANGED
|
@@ -4,10 +4,11 @@ const truncate = (text, length = 30) => text.length > length ? text.slice(0, len
|
|
|
4
4
|
/**
|
|
5
5
|
* Replace part of given text with ellipsis following the rules below:
|
|
6
6
|
*
|
|
7
|
-
* - Remove chars just before the last word, as long as the last word is
|
|
8
|
-
*
|
|
7
|
+
* - Remove chars just before the last word, as long as the last word is between
|
|
8
|
+
* minLastWordLength and 15 chars
|
|
9
|
+
* - Otherwise preserve the last `lastCharsLength` chars and remove chars before that
|
|
9
10
|
*/
|
|
10
|
-
function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
11
|
+
function truncateBeforeLast(text, maxLength, lastCharsLength = 5, minLastWordLength = 1) {
|
|
11
12
|
const chars = [];
|
|
12
13
|
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
13
14
|
for (const { segment } of segmenter.segment(text)) chars.push(segment);
|
|
@@ -16,7 +17,7 @@ function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
|
16
17
|
const lastWord = chars.slice(lastWordIndex);
|
|
17
18
|
const ellipsis = "…";
|
|
18
19
|
const ellipsisLength = 1;
|
|
19
|
-
if (lastWord.length < 15) {
|
|
20
|
+
if (lastWord.length >= minLastWordLength && lastWord.length < 15) {
|
|
20
21
|
const charsToRemove = chars.length - maxLength + ellipsisLength;
|
|
21
22
|
const indexBeforeLastWord = lastWordIndex;
|
|
22
23
|
const keepLength = indexBeforeLastWord - charsToRemove;
|
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
|
|
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 between\n * minLastWordLength and 15 chars\n * - Otherwise preserve the last `lastCharsLength` chars and remove chars before that\n */\nexport function truncateBeforeLast(\n\ttext: string,\n\tmaxLength: number,\n\tlastCharsLength: number = 5,\n\tminLastWordLength: number = 1,\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 >= minLastWordLength && 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;;;;;;;;AASxD,SAAgB,mBACf,MACA,WACA,kBAA0B,GAC1B,oBAA4B,GACnB;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,UAAU,qBAAqB,SAAS,SAAS,IAAI;EACjE,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, lastCharsLength?: number): string;
|
|
3
|
+
declare function truncateBeforeLast(text: string, maxLength: number, lastCharsLength?: number, minLastWordLength?: 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, lastCharsLength?: number): string;
|
|
3
|
+
declare function truncateBeforeLast(text: string, maxLength: number, lastCharsLength?: number, minLastWordLength?: 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
|
@@ -3,10 +3,11 @@ const truncate = (text, length = 30) => text.length > length ? text.slice(0, len
|
|
|
3
3
|
/**
|
|
4
4
|
* Replace part of given text with ellipsis following the rules below:
|
|
5
5
|
*
|
|
6
|
-
* - Remove chars just before the last word, as long as the last word is
|
|
7
|
-
*
|
|
6
|
+
* - Remove chars just before the last word, as long as the last word is between
|
|
7
|
+
* minLastWordLength and 15 chars
|
|
8
|
+
* - Otherwise preserve the last `lastCharsLength` chars and remove chars before that
|
|
8
9
|
*/
|
|
9
|
-
function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
10
|
+
function truncateBeforeLast(text, maxLength, lastCharsLength = 5, minLastWordLength = 1) {
|
|
10
11
|
const chars = [];
|
|
11
12
|
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
12
13
|
for (const { segment } of segmenter.segment(text)) chars.push(segment);
|
|
@@ -15,7 +16,7 @@ function truncateBeforeLast(text, maxLength, lastCharsLength = 5) {
|
|
|
15
16
|
const lastWord = chars.slice(lastWordIndex);
|
|
16
17
|
const ellipsis = "…";
|
|
17
18
|
const ellipsisLength = 1;
|
|
18
|
-
if (lastWord.length < 15) {
|
|
19
|
+
if (lastWord.length >= minLastWordLength && lastWord.length < 15) {
|
|
19
20
|
const charsToRemove = chars.length - maxLength + ellipsisLength;
|
|
20
21
|
const indexBeforeLastWord = lastWordIndex;
|
|
21
22
|
const keepLength = indexBeforeLastWord - charsToRemove;
|
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
|
|
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 between\n * minLastWordLength and 15 chars\n * - Otherwise preserve the last `lastCharsLength` chars and remove chars before that\n */\nexport function truncateBeforeLast(\n\ttext: string,\n\tmaxLength: number,\n\tlastCharsLength: number = 5,\n\tminLastWordLength: number = 1,\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 >= minLastWordLength && 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;;;;;;;;AASxD,SAAgB,mBACf,MACA,WACA,kBAA0B,GAC1B,oBAA4B,GACnB;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,UAAU,qBAAqB,SAAS,SAAS,IAAI;EACjE,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.27.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"LICENSE.md",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"nanoid": "3.3.8",
|
|
32
|
-
"@n8n/constants": "0.
|
|
32
|
+
"@n8n/constants": "0.20.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@testing-library/jest-dom": "^6.6.3",
|
|
36
36
|
"@testing-library/user-event": "^14.6.1",
|
|
37
37
|
"tsdown": "^0.16.5",
|
|
38
|
-
"typescript": "
|
|
39
|
-
"vite": "
|
|
40
|
-
"vitest": "^
|
|
41
|
-
"@n8n/
|
|
42
|
-
"@n8n/
|
|
43
|
-
"@n8n/
|
|
38
|
+
"typescript": "6.0.2",
|
|
39
|
+
"vite": "^8.0.2",
|
|
40
|
+
"vitest": "^4.1.1",
|
|
41
|
+
"@n8n/eslint-config": "0.0.1",
|
|
42
|
+
"@n8n/typescript-config": "1.4.0",
|
|
43
|
+
"@n8n/vitest-config": "1.9.0"
|
|
44
44
|
},
|
|
45
45
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
46
46
|
"homepage": "https://n8n.io",
|