@n8n/utils 1.28.1 → 1.30.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/index.cjs +7 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/placeholder.cjs +8 -0
- package/dist/placeholder.d.cts +2 -0
- package/dist/placeholder.d.mts +2 -0
- package/dist/placeholder.mjs +3 -0
- package/dist/placeholder2.cjs +111 -0
- package/dist/placeholder2.cjs.map +1 -0
- package/dist/placeholder2.d.cts +14 -0
- package/dist/placeholder2.d.mts +14 -0
- package/dist/placeholder2.mjs +75 -0
- package/dist/placeholder2.mjs.map +1 -0
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -10,12 +10,19 @@ const require_sortByProperty = require('./sortByProperty.cjs');
|
|
|
10
10
|
const require_truncate = require('./truncate.cjs');
|
|
11
11
|
const require_sanitize = require('./sanitize.cjs');
|
|
12
12
|
const require_path = require('./path.cjs');
|
|
13
|
+
const require_placeholder = require('./placeholder2.cjs');
|
|
13
14
|
|
|
14
15
|
exports.DEFAULT_KEYS = require_sublimeSearch.DEFAULT_KEYS;
|
|
15
16
|
exports.assert = require_assert.assert;
|
|
16
17
|
exports.createEventBus = require_event_bus.createEventBus;
|
|
17
18
|
exports.createEventQueue = require_event_queue.createEventQueue;
|
|
19
|
+
exports.extractPlaceholderLabels = require_placeholder.extractPlaceholderLabels;
|
|
20
|
+
exports.findPlaceholderDetails = require_placeholder.findPlaceholderDetails;
|
|
21
|
+
exports.formatPlaceholderPath = require_placeholder.formatPlaceholderPath;
|
|
18
22
|
exports.generateNanoId = require_workflowId.generateNanoId;
|
|
23
|
+
exports.hasPlaceholderDeep = require_placeholder.hasPlaceholderDeep;
|
|
24
|
+
exports.isPlaceholderString = require_placeholder.isPlaceholderString;
|
|
25
|
+
exports.isPlaceholderValue = require_placeholder.isPlaceholderValue;
|
|
19
26
|
exports.isWindowsFilePath = require_path.isWindowsFilePath;
|
|
20
27
|
exports.reRankSearchResults = require_reRankSearchResults.reRankSearchResults;
|
|
21
28
|
exports.retry = require_retry.retry;
|
package/dist/index.d.cts
CHANGED
|
@@ -10,4 +10,5 @@ import { t as reRankSearchResults } from "./reRankSearchResults.cjs";
|
|
|
10
10
|
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.cjs";
|
|
11
11
|
import { t as sortByProperty } from "./sortByProperty.cjs";
|
|
12
12
|
import { n as truncateBeforeLast, t as truncate } from "./truncate.cjs";
|
|
13
|
-
|
|
13
|
+
import { a as hasPlaceholderDeep, i as formatPlaceholderPath, n as extractPlaceholderLabels, o as isPlaceholderString, r as findPlaceholderDetails, s as isPlaceholderValue, t as PlaceholderDetail } from "./placeholder2.cjs";
|
|
14
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, PlaceholderDetail, assert, createEventBus, createEventQueue, extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, generateNanoId, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue, isWindowsFilePath, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.d.mts
CHANGED
|
@@ -10,4 +10,5 @@ import { t as reRankSearchResults } from "./reRankSearchResults.mjs";
|
|
|
10
10
|
import { n as sublimeSearch, t as DEFAULT_KEYS } from "./sublimeSearch.mjs";
|
|
11
11
|
import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
12
12
|
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
13
|
-
|
|
13
|
+
import { a as hasPlaceholderDeep, i as formatPlaceholderPath, n as extractPlaceholderLabels, o as isPlaceholderString, r as findPlaceholderDetails, s as isPlaceholderValue, t as PlaceholderDetail } from "./placeholder2.mjs";
|
|
14
|
+
export { CallbackFn, DEFAULT_KEYS, EventBus, PlaceholderDetail, assert, createEventBus, createEventQueue, extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, generateNanoId, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue, isWindowsFilePath, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
package/dist/index.mjs
CHANGED
|
@@ -10,5 +10,6 @@ import { t as sortByProperty } from "./sortByProperty.mjs";
|
|
|
10
10
|
import { n as truncateBeforeLast, t as truncate } from "./truncate.mjs";
|
|
11
11
|
import { t as sanitizeFilename } from "./sanitize.mjs";
|
|
12
12
|
import { t as isWindowsFilePath } from "./path.mjs";
|
|
13
|
+
import { a as isPlaceholderString, i as hasPlaceholderDeep, n as findPlaceholderDetails, o as isPlaceholderValue, r as formatPlaceholderPath, t as extractPlaceholderLabels } from "./placeholder2.mjs";
|
|
13
14
|
|
|
14
|
-
export { DEFAULT_KEYS, assert, createEventBus, createEventQueue, generateNanoId, isWindowsFilePath, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
|
15
|
+
export { DEFAULT_KEYS, assert, createEventBus, createEventQueue, extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, generateNanoId, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue, isWindowsFilePath, reRankSearchResults, retry, sanitizeFilename, smartDecimal, sortByProperty, sublimeSearch, truncate, truncateBeforeLast };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const require_placeholder = require('./placeholder2.cjs');
|
|
2
|
+
|
|
3
|
+
exports.extractPlaceholderLabels = require_placeholder.extractPlaceholderLabels;
|
|
4
|
+
exports.findPlaceholderDetails = require_placeholder.findPlaceholderDetails;
|
|
5
|
+
exports.formatPlaceholderPath = require_placeholder.formatPlaceholderPath;
|
|
6
|
+
exports.hasPlaceholderDeep = require_placeholder.hasPlaceholderDeep;
|
|
7
|
+
exports.isPlaceholderString = require_placeholder.isPlaceholderString;
|
|
8
|
+
exports.isPlaceholderValue = require_placeholder.isPlaceholderValue;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as hasPlaceholderDeep, i as formatPlaceholderPath, n as extractPlaceholderLabels, o as isPlaceholderString, r as findPlaceholderDetails, s as isPlaceholderValue, t as PlaceholderDetail } from "./placeholder2.cjs";
|
|
2
|
+
export { PlaceholderDetail, extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as hasPlaceholderDeep, i as formatPlaceholderPath, n as extractPlaceholderLabels, o as isPlaceholderString, r as findPlaceholderDetails, s as isPlaceholderValue, t as PlaceholderDetail } from "./placeholder2.mjs";
|
|
2
|
+
export { PlaceholderDetail, extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as isPlaceholderString, i as hasPlaceholderDeep, n as findPlaceholderDetails, o as isPlaceholderValue, r as formatPlaceholderPath, t as extractPlaceholderLabels } from "./placeholder2.mjs";
|
|
2
|
+
|
|
3
|
+
export { extractPlaceholderLabels, findPlaceholderDetails, formatPlaceholderPath, hasPlaceholderDeep, isPlaceholderString, isPlaceholderValue };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/placeholder.ts
|
|
3
|
+
const PLACEHOLDER_SUFFIX = "__>";
|
|
4
|
+
const PLACEHOLDER_VALUE_PREFIX = "<__PLACEHOLDER_VALUE__";
|
|
5
|
+
const PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;
|
|
6
|
+
/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */
|
|
7
|
+
function isPlaceholderString(value) {
|
|
8
|
+
return typeof value === "string" && value.startsWith(PLACEHOLDER_VALUE_PREFIX) && value.endsWith(PLACEHOLDER_SUFFIX);
|
|
9
|
+
}
|
|
10
|
+
/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */
|
|
11
|
+
function hasPlaceholderDeep(value) {
|
|
12
|
+
if (typeof value === "string") return isPlaceholderString(value);
|
|
13
|
+
if (Array.isArray(value)) return value.some(hasPlaceholderDeep);
|
|
14
|
+
if (value !== null && typeof value === "object") return Object.values(value).some(hasPlaceholderDeep);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */
|
|
18
|
+
function isPlaceholderValue(value) {
|
|
19
|
+
if (typeof value !== "string") return false;
|
|
20
|
+
return !!value.match(PLACEHOLDER_REGEX);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extracts the label from a single placeholder string.
|
|
24
|
+
* Handles formats like:
|
|
25
|
+
* - <__PLACEHOLDER_VALUE__label__>
|
|
26
|
+
* - <__PLACEHOLDER__: label__>
|
|
27
|
+
*/
|
|
28
|
+
function extractLabelFromPlaceholder(placeholder) {
|
|
29
|
+
let label = placeholder.slice(14, -3);
|
|
30
|
+
if (label.startsWith("_VALUE__")) label = label.slice(8);
|
|
31
|
+
else if (label.startsWith("__:")) label = label.slice(3);
|
|
32
|
+
else if (label.startsWith("__")) label = label.slice(2);
|
|
33
|
+
return label.trim();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extracts all placeholder labels from a string value.
|
|
37
|
+
* Handles both cases where the entire value is a placeholder and where
|
|
38
|
+
* placeholders are embedded within code (e.g., Code node).
|
|
39
|
+
* Returns an array of labels found.
|
|
40
|
+
*/
|
|
41
|
+
function extractPlaceholderLabels(value) {
|
|
42
|
+
if (typeof value !== "string") return [];
|
|
43
|
+
const labels = [];
|
|
44
|
+
const regex = new RegExp(PLACEHOLDER_REGEX.source, "g");
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = regex.exec(value)) !== null) {
|
|
47
|
+
const label = extractLabelFromPlaceholder(match[0]);
|
|
48
|
+
if (label.length > 0) labels.push(label);
|
|
49
|
+
}
|
|
50
|
+
return labels;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Recursively searches through a value (object, array, or primitive) to find
|
|
54
|
+
* all placeholder values and their paths.
|
|
55
|
+
*/
|
|
56
|
+
function findPlaceholderDetails(value, path = []) {
|
|
57
|
+
if (typeof value === "string") return extractPlaceholderLabels(value).map((label) => ({
|
|
58
|
+
path,
|
|
59
|
+
label
|
|
60
|
+
}));
|
|
61
|
+
if (Array.isArray(value)) return value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));
|
|
62
|
+
if (value !== null && typeof value === "object") return Object.entries(value).flatMap(([key, nested]) => findPlaceholderDetails(nested, [...path, key]));
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Formats a path array into a dot-notation string for display.
|
|
67
|
+
* Array indices are preserved as [N] without leading dots.
|
|
68
|
+
*/
|
|
69
|
+
function formatPlaceholderPath(path) {
|
|
70
|
+
if (path.length === 0) return "parameters";
|
|
71
|
+
return path.map((segment, index) => segment.startsWith("[") || index === 0 ? segment : `.${segment}`).join("");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
Object.defineProperty(exports, 'extractPlaceholderLabels', {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return extractPlaceholderLabels;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, 'findPlaceholderDetails', {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () {
|
|
84
|
+
return findPlaceholderDetails;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, 'formatPlaceholderPath', {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return formatPlaceholderPath;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, 'hasPlaceholderDeep', {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () {
|
|
96
|
+
return hasPlaceholderDeep;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, 'isPlaceholderString', {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () {
|
|
102
|
+
return isPlaceholderString;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, 'isPlaceholderValue', {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () {
|
|
108
|
+
return isPlaceholderValue;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=placeholder2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder2.cjs","names":["labels: string[]"],"sources":["../src/placeholder.ts"],"sourcesContent":["const PLACEHOLDER_PREFIX = '<__PLACEHOLDER';\nconst PLACEHOLDER_SUFFIX = '__>';\nconst PLACEHOLDER_VALUE_PREFIX = '<__PLACEHOLDER_VALUE__';\n\nconst PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;\n\nexport interface PlaceholderDetail {\n\tpath: string[];\n\tlabel: string;\n}\n\n/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */\nexport function isPlaceholderString(value: unknown): boolean {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.startsWith(PLACEHOLDER_VALUE_PREFIX) &&\n\t\tvalue.endsWith(PLACEHOLDER_SUFFIX)\n\t);\n}\n\n/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */\nexport function hasPlaceholderDeep(value: unknown): boolean {\n\tif (typeof value === 'string') return isPlaceholderString(value);\n\tif (Array.isArray(value)) return value.some(hasPlaceholderDeep);\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.values(value as Record<string, unknown>).some(hasPlaceholderDeep);\n\t}\n\treturn false;\n}\n\n/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */\nexport function isPlaceholderValue(value: unknown): boolean {\n\tif (typeof value !== 'string') return false;\n\treturn !!value.match(PLACEHOLDER_REGEX);\n}\n\n/**\n * Extracts the label from a single placeholder string.\n * Handles formats like:\n * - <__PLACEHOLDER_VALUE__label__>\n * - <__PLACEHOLDER__: label__>\n */\nfunction extractLabelFromPlaceholder(placeholder: string): string {\n\tlet label = placeholder.slice(PLACEHOLDER_PREFIX.length, -PLACEHOLDER_SUFFIX.length);\n\n\tif (label.startsWith('_VALUE__')) {\n\t\tlabel = label.slice('_VALUE__'.length);\n\t} else if (label.startsWith('__:')) {\n\t\tlabel = label.slice('__:'.length);\n\t} else if (label.startsWith('__')) {\n\t\tlabel = label.slice('__'.length);\n\t}\n\n\treturn label.trim();\n}\n\n/**\n * Extracts all placeholder labels from a string value.\n * Handles both cases where the entire value is a placeholder and where\n * placeholders are embedded within code (e.g., Code node).\n * Returns an array of labels found.\n */\nexport function extractPlaceholderLabels(value: unknown): string[] {\n\tif (typeof value !== 'string') return [];\n\n\tconst labels: string[] = [];\n\tconst regex = new RegExp(PLACEHOLDER_REGEX.source, 'g');\n\tlet match;\n\n\twhile ((match = regex.exec(value)) !== null) {\n\t\tconst label = extractLabelFromPlaceholder(match[0]);\n\t\tif (label.length > 0) {\n\t\t\tlabels.push(label);\n\t\t}\n\t}\n\n\treturn labels;\n}\n\n/**\n * Recursively searches through a value (object, array, or primitive) to find\n * all placeholder values and their paths.\n */\nexport function findPlaceholderDetails(value: unknown, path: string[] = []): PlaceholderDetail[] {\n\tif (typeof value === 'string') {\n\t\tconst labels = extractPlaceholderLabels(value);\n\t\treturn labels.map((label) => ({ path, label }));\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));\n\t}\n\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.entries(value).flatMap(([key, nested]) =>\n\t\t\tfindPlaceholderDetails(nested, [...path, key]),\n\t\t);\n\t}\n\n\treturn [];\n}\n\n/**\n * Formats a path array into a dot-notation string for display.\n * Array indices are preserved as [N] without leading dots.\n */\nexport function formatPlaceholderPath(path: string[]): string {\n\tif (path.length === 0) return 'parameters';\n\n\treturn path\n\t\t.map((segment, index) => (segment.startsWith('[') || index === 0 ? segment : `.${segment}`))\n\t\t.join('');\n}\n"],"mappings":";;AACA,MAAM,qBAAqB;AAC3B,MAAM,2BAA2B;AAEjC,MAAM,oBAAoB;;AAQ1B,SAAgB,oBAAoB,OAAyB;AAC5D,QACC,OAAO,UAAU,YACjB,MAAM,WAAW,yBAAyB,IAC1C,MAAM,SAAS,mBAAmB;;;AAKpC,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO,oBAAoB,MAAM;AAChE,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,mBAAmB;AAC/D,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,OAAO,MAAiC,CAAC,KAAK,mBAAmB;AAEhF,QAAO;;;AAIR,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAO,CAAC,CAAC,MAAM,MAAM,kBAAkB;;;;;;;;AASxC,SAAS,4BAA4B,aAA6B;CACjE,IAAI,QAAQ,YAAY,MAAM,IAA2B,GAA2B;AAEpF,KAAI,MAAM,WAAW,WAAW,CAC/B,SAAQ,MAAM,MAAM,EAAkB;UAC5B,MAAM,WAAW,MAAM,CACjC,SAAQ,MAAM,MAAM,EAAa;UACvB,MAAM,WAAW,KAAK,CAChC,SAAQ,MAAM,MAAM,EAAY;AAGjC,QAAO,MAAM,MAAM;;;;;;;;AASpB,SAAgB,yBAAyB,OAA0B;AAClE,KAAI,OAAO,UAAU,SAAU,QAAO,EAAE;CAExC,MAAMA,SAAmB,EAAE;CAC3B,MAAM,QAAQ,IAAI,OAAO,kBAAkB,QAAQ,IAAI;CACvD,IAAI;AAEJ,SAAQ,QAAQ,MAAM,KAAK,MAAM,MAAM,MAAM;EAC5C,MAAM,QAAQ,4BAA4B,MAAM,GAAG;AACnD,MAAI,MAAM,SAAS,EAClB,QAAO,KAAK,MAAM;;AAIpB,QAAO;;;;;;AAOR,SAAgB,uBAAuB,OAAgB,OAAiB,EAAE,EAAuB;AAChG,KAAI,OAAO,UAAU,SAEpB,QADe,yBAAyB,MAAM,CAChC,KAAK,WAAW;EAAE;EAAM;EAAO,EAAE;AAGhD,KAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,MAAM,SAAS,MAAM,UAAU,uBAAuB,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC;AAG7F,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,YAC3C,uBAAuB,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,CAC9C;AAGF,QAAO,EAAE;;;;;;AAOV,SAAgB,sBAAsB,MAAwB;AAC7D,KAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAO,KACL,KAAK,SAAS,UAAW,QAAQ,WAAW,IAAI,IAAI,UAAU,IAAI,UAAU,IAAI,UAAW,CAC3F,KAAK,GAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/placeholder.d.ts
|
|
2
|
+
interface PlaceholderDetail {
|
|
3
|
+
path: string[];
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
declare function isPlaceholderString(value: unknown): boolean;
|
|
7
|
+
declare function hasPlaceholderDeep(value: unknown): boolean;
|
|
8
|
+
declare function isPlaceholderValue(value: unknown): boolean;
|
|
9
|
+
declare function extractPlaceholderLabels(value: unknown): string[];
|
|
10
|
+
declare function findPlaceholderDetails(value: unknown, path?: string[]): PlaceholderDetail[];
|
|
11
|
+
declare function formatPlaceholderPath(path: string[]): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { hasPlaceholderDeep as a, formatPlaceholderPath as i, extractPlaceholderLabels as n, isPlaceholderString as o, findPlaceholderDetails as r, isPlaceholderValue as s, PlaceholderDetail as t };
|
|
14
|
+
//# sourceMappingURL=placeholder2.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/placeholder.d.ts
|
|
2
|
+
interface PlaceholderDetail {
|
|
3
|
+
path: string[];
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
declare function isPlaceholderString(value: unknown): boolean;
|
|
7
|
+
declare function hasPlaceholderDeep(value: unknown): boolean;
|
|
8
|
+
declare function isPlaceholderValue(value: unknown): boolean;
|
|
9
|
+
declare function extractPlaceholderLabels(value: unknown): string[];
|
|
10
|
+
declare function findPlaceholderDetails(value: unknown, path?: string[]): PlaceholderDetail[];
|
|
11
|
+
declare function formatPlaceholderPath(path: string[]): string;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { hasPlaceholderDeep as a, formatPlaceholderPath as i, extractPlaceholderLabels as n, isPlaceholderString as o, findPlaceholderDetails as r, isPlaceholderValue as s, PlaceholderDetail as t };
|
|
14
|
+
//# sourceMappingURL=placeholder2.d.mts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/placeholder.ts
|
|
2
|
+
const PLACEHOLDER_SUFFIX = "__>";
|
|
3
|
+
const PLACEHOLDER_VALUE_PREFIX = "<__PLACEHOLDER_VALUE__";
|
|
4
|
+
const PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;
|
|
5
|
+
/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */
|
|
6
|
+
function isPlaceholderString(value) {
|
|
7
|
+
return typeof value === "string" && value.startsWith(PLACEHOLDER_VALUE_PREFIX) && value.endsWith(PLACEHOLDER_SUFFIX);
|
|
8
|
+
}
|
|
9
|
+
/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */
|
|
10
|
+
function hasPlaceholderDeep(value) {
|
|
11
|
+
if (typeof value === "string") return isPlaceholderString(value);
|
|
12
|
+
if (Array.isArray(value)) return value.some(hasPlaceholderDeep);
|
|
13
|
+
if (value !== null && typeof value === "object") return Object.values(value).some(hasPlaceholderDeep);
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */
|
|
17
|
+
function isPlaceholderValue(value) {
|
|
18
|
+
if (typeof value !== "string") return false;
|
|
19
|
+
return !!value.match(PLACEHOLDER_REGEX);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extracts the label from a single placeholder string.
|
|
23
|
+
* Handles formats like:
|
|
24
|
+
* - <__PLACEHOLDER_VALUE__label__>
|
|
25
|
+
* - <__PLACEHOLDER__: label__>
|
|
26
|
+
*/
|
|
27
|
+
function extractLabelFromPlaceholder(placeholder) {
|
|
28
|
+
let label = placeholder.slice(14, -3);
|
|
29
|
+
if (label.startsWith("_VALUE__")) label = label.slice(8);
|
|
30
|
+
else if (label.startsWith("__:")) label = label.slice(3);
|
|
31
|
+
else if (label.startsWith("__")) label = label.slice(2);
|
|
32
|
+
return label.trim();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts all placeholder labels from a string value.
|
|
36
|
+
* Handles both cases where the entire value is a placeholder and where
|
|
37
|
+
* placeholders are embedded within code (e.g., Code node).
|
|
38
|
+
* Returns an array of labels found.
|
|
39
|
+
*/
|
|
40
|
+
function extractPlaceholderLabels(value) {
|
|
41
|
+
if (typeof value !== "string") return [];
|
|
42
|
+
const labels = [];
|
|
43
|
+
const regex = new RegExp(PLACEHOLDER_REGEX.source, "g");
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = regex.exec(value)) !== null) {
|
|
46
|
+
const label = extractLabelFromPlaceholder(match[0]);
|
|
47
|
+
if (label.length > 0) labels.push(label);
|
|
48
|
+
}
|
|
49
|
+
return labels;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Recursively searches through a value (object, array, or primitive) to find
|
|
53
|
+
* all placeholder values and their paths.
|
|
54
|
+
*/
|
|
55
|
+
function findPlaceholderDetails(value, path = []) {
|
|
56
|
+
if (typeof value === "string") return extractPlaceholderLabels(value).map((label) => ({
|
|
57
|
+
path,
|
|
58
|
+
label
|
|
59
|
+
}));
|
|
60
|
+
if (Array.isArray(value)) return value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));
|
|
61
|
+
if (value !== null && typeof value === "object") return Object.entries(value).flatMap(([key, nested]) => findPlaceholderDetails(nested, [...path, key]));
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Formats a path array into a dot-notation string for display.
|
|
66
|
+
* Array indices are preserved as [N] without leading dots.
|
|
67
|
+
*/
|
|
68
|
+
function formatPlaceholderPath(path) {
|
|
69
|
+
if (path.length === 0) return "parameters";
|
|
70
|
+
return path.map((segment, index) => segment.startsWith("[") || index === 0 ? segment : `.${segment}`).join("");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { isPlaceholderString as a, hasPlaceholderDeep as i, findPlaceholderDetails as n, isPlaceholderValue as o, formatPlaceholderPath as r, extractPlaceholderLabels as t };
|
|
75
|
+
//# sourceMappingURL=placeholder2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder2.mjs","names":["labels: string[]"],"sources":["../src/placeholder.ts"],"sourcesContent":["const PLACEHOLDER_PREFIX = '<__PLACEHOLDER';\nconst PLACEHOLDER_SUFFIX = '__>';\nconst PLACEHOLDER_VALUE_PREFIX = '<__PLACEHOLDER_VALUE__';\n\nconst PLACEHOLDER_REGEX = /<__PLACEHOLDER.*?__>/;\n\nexport interface PlaceholderDetail {\n\tpath: string[];\n\tlabel: string;\n}\n\n/** Check if a value is a placeholder sentinel string (format: `<__PLACEHOLDER_VALUE__hint__>`). */\nexport function isPlaceholderString(value: unknown): boolean {\n\treturn (\n\t\ttypeof value === 'string' &&\n\t\tvalue.startsWith(PLACEHOLDER_VALUE_PREFIX) &&\n\t\tvalue.endsWith(PLACEHOLDER_SUFFIX)\n\t);\n}\n\n/** Recursively check if a value (string, array, or object) contains any placeholder sentinel strings. */\nexport function hasPlaceholderDeep(value: unknown): boolean {\n\tif (typeof value === 'string') return isPlaceholderString(value);\n\tif (Array.isArray(value)) return value.some(hasPlaceholderDeep);\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.values(value as Record<string, unknown>).some(hasPlaceholderDeep);\n\t}\n\treturn false;\n}\n\n/** Checks if a value is a placeholder value (matches the placeholder regex pattern). */\nexport function isPlaceholderValue(value: unknown): boolean {\n\tif (typeof value !== 'string') return false;\n\treturn !!value.match(PLACEHOLDER_REGEX);\n}\n\n/**\n * Extracts the label from a single placeholder string.\n * Handles formats like:\n * - <__PLACEHOLDER_VALUE__label__>\n * - <__PLACEHOLDER__: label__>\n */\nfunction extractLabelFromPlaceholder(placeholder: string): string {\n\tlet label = placeholder.slice(PLACEHOLDER_PREFIX.length, -PLACEHOLDER_SUFFIX.length);\n\n\tif (label.startsWith('_VALUE__')) {\n\t\tlabel = label.slice('_VALUE__'.length);\n\t} else if (label.startsWith('__:')) {\n\t\tlabel = label.slice('__:'.length);\n\t} else if (label.startsWith('__')) {\n\t\tlabel = label.slice('__'.length);\n\t}\n\n\treturn label.trim();\n}\n\n/**\n * Extracts all placeholder labels from a string value.\n * Handles both cases where the entire value is a placeholder and where\n * placeholders are embedded within code (e.g., Code node).\n * Returns an array of labels found.\n */\nexport function extractPlaceholderLabels(value: unknown): string[] {\n\tif (typeof value !== 'string') return [];\n\n\tconst labels: string[] = [];\n\tconst regex = new RegExp(PLACEHOLDER_REGEX.source, 'g');\n\tlet match;\n\n\twhile ((match = regex.exec(value)) !== null) {\n\t\tconst label = extractLabelFromPlaceholder(match[0]);\n\t\tif (label.length > 0) {\n\t\t\tlabels.push(label);\n\t\t}\n\t}\n\n\treturn labels;\n}\n\n/**\n * Recursively searches through a value (object, array, or primitive) to find\n * all placeholder values and their paths.\n */\nexport function findPlaceholderDetails(value: unknown, path: string[] = []): PlaceholderDetail[] {\n\tif (typeof value === 'string') {\n\t\tconst labels = extractPlaceholderLabels(value);\n\t\treturn labels.map((label) => ({ path, label }));\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.flatMap((item, index) => findPlaceholderDetails(item, [...path, `[${index}]`]));\n\t}\n\n\tif (value !== null && typeof value === 'object') {\n\t\treturn Object.entries(value).flatMap(([key, nested]) =>\n\t\t\tfindPlaceholderDetails(nested, [...path, key]),\n\t\t);\n\t}\n\n\treturn [];\n}\n\n/**\n * Formats a path array into a dot-notation string for display.\n * Array indices are preserved as [N] without leading dots.\n */\nexport function formatPlaceholderPath(path: string[]): string {\n\tif (path.length === 0) return 'parameters';\n\n\treturn path\n\t\t.map((segment, index) => (segment.startsWith('[') || index === 0 ? segment : `.${segment}`))\n\t\t.join('');\n}\n"],"mappings":";AACA,MAAM,qBAAqB;AAC3B,MAAM,2BAA2B;AAEjC,MAAM,oBAAoB;;AAQ1B,SAAgB,oBAAoB,OAAyB;AAC5D,QACC,OAAO,UAAU,YACjB,MAAM,WAAW,yBAAyB,IAC1C,MAAM,SAAS,mBAAmB;;;AAKpC,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO,oBAAoB,MAAM;AAChE,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,mBAAmB;AAC/D,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,OAAO,MAAiC,CAAC,KAAK,mBAAmB;AAEhF,QAAO;;;AAIR,SAAgB,mBAAmB,OAAyB;AAC3D,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAO,CAAC,CAAC,MAAM,MAAM,kBAAkB;;;;;;;;AASxC,SAAS,4BAA4B,aAA6B;CACjE,IAAI,QAAQ,YAAY,MAAM,IAA2B,GAA2B;AAEpF,KAAI,MAAM,WAAW,WAAW,CAC/B,SAAQ,MAAM,MAAM,EAAkB;UAC5B,MAAM,WAAW,MAAM,CACjC,SAAQ,MAAM,MAAM,EAAa;UACvB,MAAM,WAAW,KAAK,CAChC,SAAQ,MAAM,MAAM,EAAY;AAGjC,QAAO,MAAM,MAAM;;;;;;;;AASpB,SAAgB,yBAAyB,OAA0B;AAClE,KAAI,OAAO,UAAU,SAAU,QAAO,EAAE;CAExC,MAAMA,SAAmB,EAAE;CAC3B,MAAM,QAAQ,IAAI,OAAO,kBAAkB,QAAQ,IAAI;CACvD,IAAI;AAEJ,SAAQ,QAAQ,MAAM,KAAK,MAAM,MAAM,MAAM;EAC5C,MAAM,QAAQ,4BAA4B,MAAM,GAAG;AACnD,MAAI,MAAM,SAAS,EAClB,QAAO,KAAK,MAAM;;AAIpB,QAAO;;;;;;AAOR,SAAgB,uBAAuB,OAAgB,OAAiB,EAAE,EAAuB;AAChG,KAAI,OAAO,UAAU,SAEpB,QADe,yBAAyB,MAAM,CAChC,KAAK,WAAW;EAAE;EAAM;EAAO,EAAE;AAGhD,KAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,MAAM,SAAS,MAAM,UAAU,uBAAuB,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC;AAG7F,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,KAAK,YAC3C,uBAAuB,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC,CAC9C;AAGF,QAAO,EAAE;;;;;;AAOV,SAAgB,sBAAsB,MAAwB;AAC7D,KAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAO,KACL,KAAK,SAAS,UAAW,QAAQ,WAAW,IAAI,IAAI,UAAU,IAAI,UAAU,IAAI,UAAW,CAC3F,KAAK,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.30.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"LICENSE.md",
|
|
8
|
+
"LICENSE_EE.md"
|
|
9
9
|
],
|
|
10
10
|
"main": "./dist/index.cjs",
|
|
11
11
|
"module": "./dist/index.mjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"nanoid": "3.3.8",
|
|
32
|
-
"@n8n/constants": "0.
|
|
32
|
+
"@n8n/constants": "0.23.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"typescript": "6.0.2",
|
|
39
39
|
"vite": "^8.0.2",
|
|
40
40
|
"vitest": "^4.1.1",
|
|
41
|
-
"@n8n/eslint-config": "0.0.1",
|
|
42
41
|
"@n8n/typescript-config": "1.4.0",
|
|
43
|
-
"@n8n/
|
|
42
|
+
"@n8n/eslint-config": "0.0.1",
|
|
43
|
+
"@n8n/vitest-config": "1.10.0"
|
|
44
44
|
},
|
|
45
45
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
46
46
|
"homepage": "https://n8n.io",
|