@ztimson/utils 0.28.0 → 0.28.1

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.mjs CHANGED
@@ -2293,12 +2293,45 @@ class TemplateError extends BadRequestError {
2293
2293
  }
2294
2294
  function findTemplateVars(html) {
2295
2295
  const variables = /* @__PURE__ */ new Set();
2296
+ const excluded = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]);
2297
+ for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) {
2298
+ const [element, index = "index"] = loop[1].replaceAll(/[()\s]/g, "").split(",");
2299
+ excluded.add(element);
2300
+ excluded.add(index);
2301
+ const arrayRef = loop[2].trim();
2302
+ const arrayVar = arrayRef.split(".")[0].match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/)?.[0];
2303
+ if (arrayVar && !excluded.has(arrayVar)) variables.add(arrayVar);
2304
+ }
2305
+ for (const ifStmt of matchAll(html, /\{\{\s*?[!]?\?\s*?([^}]+?)\s*?}}/g)) {
2306
+ const code = ifStmt[1].replace(/["'`][^"'`]*["'`]/g, "");
2307
+ const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2308
+ for (const v of vars) {
2309
+ const root = v.split(".")[0];
2310
+ if (!excluded.has(root)) variables.add(root);
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
+ }
2324
+ }
2325
+ }
2296
2326
  const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
2297
2327
  let match;
2298
2328
  while ((match = regex.exec(html)) !== null) {
2299
- const code = match[1].trim();
2300
- const varMatch = code.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)/);
2301
- if (varMatch) variables.add(varMatch[1]);
2329
+ const code = match[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
2330
+ const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2331
+ for (const v of vars) {
2332
+ const root = v.split(".")[0];
2333
+ if (!excluded.has(root)) variables.add(v);
2334
+ }
2302
2335
  }
2303
2336
  const result = {};
2304
2337
  for (const path of variables) {