@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.cjs
CHANGED
|
@@ -428,6 +428,8 @@ ${opts.message || this.desc}`;
|
|
|
428
428
|
return function(a, b) {
|
|
429
429
|
const aVal = dotNotation(a, prop);
|
|
430
430
|
const bVal = dotNotation(b, prop);
|
|
431
|
+
if (aVal === void 0) return 1;
|
|
432
|
+
if (bVal === void 0) return -1;
|
|
431
433
|
if (typeof aVal == "number" && typeof bVal == "number")
|
|
432
434
|
return (reverse ? -1 : 1) * (aVal - bVal);
|
|
433
435
|
if (aVal > bVal) return reverse ? -1 : 1;
|
|
@@ -2297,41 +2299,40 @@ ${opts.message || this.desc}`;
|
|
|
2297
2299
|
}
|
|
2298
2300
|
function findTemplateVars(html) {
|
|
2299
2301
|
const variables = /* @__PURE__ */ new Set();
|
|
2302
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
2300
2303
|
const excluded = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]);
|
|
2301
2304
|
for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) {
|
|
2302
2305
|
const [element, index = "index"] = loop[1].replaceAll(/[()\s]/g, "").split(",");
|
|
2303
2306
|
excluded.add(element);
|
|
2304
2307
|
excluded.add(index);
|
|
2305
|
-
const
|
|
2306
|
-
const
|
|
2307
|
-
if (
|
|
2308
|
+
const arrayVar = loop[2].trim();
|
|
2309
|
+
const root = arrayVar.split(".")[0];
|
|
2310
|
+
if (!excluded.has(root)) {
|
|
2311
|
+
variables.add(arrayVar);
|
|
2312
|
+
arrays.add(arrayVar);
|
|
2313
|
+
}
|
|
2308
2314
|
}
|
|
2309
2315
|
for (const ifStmt of matchAll(html, /\{\{\s*?[!]?\?\s*?([^}]+?)\s*?}}/g)) {
|
|
2310
2316
|
const code = ifStmt[1].replace(/["'`][^"'`]*["'`]/g, "");
|
|
2311
|
-
const
|
|
2317
|
+
const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
|
|
2318
|
+
const parts = v.split(".");
|
|
2319
|
+
return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
|
|
2320
|
+
});
|
|
2321
|
+
const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2312
2322
|
for (const v of vars) {
|
|
2313
2323
|
const root = v.split(".")[0];
|
|
2314
|
-
if (!excluded.has(root)) variables.add(
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
for (const ifBlock of matchAll(html, /\{\{\s*?\?\s*?.+?\s*?}}([\s\S]*?)\{\{\s*?\/\?\s*?}}/g)) {
|
|
2318
|
-
const content = ifBlock[1];
|
|
2319
|
-
const regex2 = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
|
|
2320
|
-
let match2;
|
|
2321
|
-
while ((match2 = regex2.exec(content)) !== null) {
|
|
2322
|
-
const code = match2[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
|
|
2323
|
-
const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2324
|
-
for (const v of vars) {
|
|
2325
|
-
const root = v.split(".")[0];
|
|
2326
|
-
if (!excluded.has(root)) variables.add(v);
|
|
2327
|
-
}
|
|
2324
|
+
if (!excluded.has(root)) variables.add(v);
|
|
2328
2325
|
}
|
|
2329
2326
|
}
|
|
2330
2327
|
const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
|
|
2331
2328
|
let match;
|
|
2332
2329
|
while ((match = regex.exec(html)) !== null) {
|
|
2333
2330
|
const code = match[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
|
|
2334
|
-
const
|
|
2331
|
+
const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
|
|
2332
|
+
const parts = v.split(".");
|
|
2333
|
+
return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
|
|
2334
|
+
});
|
|
2335
|
+
const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
|
|
2335
2336
|
for (const v of vars) {
|
|
2336
2337
|
const root = v.split(".")[0];
|
|
2337
2338
|
if (!excluded.has(root)) variables.add(v);
|
|
@@ -2344,7 +2345,8 @@ ${opts.message || this.desc}`;
|
|
|
2344
2345
|
for (let i = 0; i < parts.length; i++) {
|
|
2345
2346
|
const part = parts[i];
|
|
2346
2347
|
if (i === parts.length - 1) {
|
|
2347
|
-
|
|
2348
|
+
const fullPath = parts.slice(0, i + 1).join(".");
|
|
2349
|
+
current[part] = arrays.has(fullPath) ? [] : "";
|
|
2348
2350
|
} else {
|
|
2349
2351
|
current[part] = current[part] || {};
|
|
2350
2352
|
current = current[part];
|