@ztimson/utils 0.28.1 → 0.28.2
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 +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +20 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2293,41 +2293,40 @@ class TemplateError extends BadRequestError {
|
|
|
2293
2293
|
}
|
|
2294
2294
|
function findTemplateVars(html) {
|
|
2295
2295
|
const variables = /* @__PURE__ */ new Set();
|
|
2296
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
2296
2297
|
const excluded = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]);
|
|
2297
2298
|
for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) {
|
|
2298
2299
|
const [element, index = "index"] = loop[1].replaceAll(/[()\s]/g, "").split(",");
|
|
2299
2300
|
excluded.add(element);
|
|
2300
2301
|
excluded.add(index);
|
|
2301
|
-
const
|
|
2302
|
-
const
|
|
2303
|
-
if (
|
|
2302
|
+
const arrayVar = loop[2].trim();
|
|
2303
|
+
const root = arrayVar.split(".")[0];
|
|
2304
|
+
if (!excluded.has(root)) {
|
|
2305
|
+
variables.add(arrayVar);
|
|
2306
|
+
arrays.add(arrayVar);
|
|
2307
|
+
}
|
|
2304
2308
|
}
|
|
2305
2309
|
for (const ifStmt of matchAll(html, /\{\{\s*?[!]?\?\s*?([^}]+?)\s*?}}/g)) {
|
|
2306
2310
|
const code = ifStmt[1].replace(/["'`][^"'`]*["'`]/g, "");
|
|
2307
|
-
const
|
|
2311
|
+
const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
|
|
2312
|
+
const parts = v.split(".");
|
|
2313
|
+
return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
|
|
2314
|
+
});
|
|
2315
|
+
const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2308
2316
|
for (const v of vars) {
|
|
2309
2317
|
const root = v.split(".")[0];
|
|
2310
|
-
if (!excluded.has(root)) variables.add(
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
for (const ifBlock of matchAll(html, /\{\{\s*?\?\s*?.+?\s*?}}([\s\S]*?)\{\{\s*?\/\?\s*?}}/g)) {
|
|
2314
|
-
const content = ifBlock[1];
|
|
2315
|
-
const regex2 = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
|
|
2316
|
-
let match2;
|
|
2317
|
-
while ((match2 = regex2.exec(content)) !== null) {
|
|
2318
|
-
const code = match2[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
|
|
2319
|
-
const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2320
|
-
for (const v of vars) {
|
|
2321
|
-
const root = v.split(".")[0];
|
|
2322
|
-
if (!excluded.has(root)) variables.add(v);
|
|
2323
|
-
}
|
|
2318
|
+
if (!excluded.has(root)) variables.add(v);
|
|
2324
2319
|
}
|
|
2325
2320
|
}
|
|
2326
2321
|
const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
|
|
2327
2322
|
let match;
|
|
2328
2323
|
while ((match = regex.exec(html)) !== null) {
|
|
2329
2324
|
const code = match[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
|
|
2330
|
-
const
|
|
2325
|
+
const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
|
|
2326
|
+
const parts = v.split(".");
|
|
2327
|
+
return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
|
|
2328
|
+
});
|
|
2329
|
+
const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2331
2330
|
for (const v of vars) {
|
|
2332
2331
|
const root = v.split(".")[0];
|
|
2333
2332
|
if (!excluded.has(root)) variables.add(v);
|
|
@@ -2340,7 +2339,8 @@ function findTemplateVars(html) {
|
|
|
2340
2339
|
for (let i = 0; i < parts.length; i++) {
|
|
2341
2340
|
const part = parts[i];
|
|
2342
2341
|
if (i === parts.length - 1) {
|
|
2343
|
-
|
|
2342
|
+
const fullPath = parts.slice(0, i + 1).join(".");
|
|
2343
|
+
current[part] = arrays.has(fullPath) ? [] : "";
|
|
2344
2344
|
} else {
|
|
2345
2345
|
current[part] = current[part] || {};
|
|
2346
2346
|
current = current[part];
|