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