@ztimson/utils 0.27.20 → 0.28.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.mjs CHANGED
@@ -2291,6 +2291,31 @@ function logicTest(target, condition) {
2291
2291
  }
2292
2292
  class TemplateError extends BadRequestError {
2293
2293
  }
2294
+ function findTemplateVars(html) {
2295
+ const variables = /* @__PURE__ */ new Set();
2296
+ const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
2297
+ let match;
2298
+ 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]);
2302
+ }
2303
+ const result = {};
2304
+ for (const path of variables) {
2305
+ const parts = path.split(".");
2306
+ let current = result;
2307
+ for (let i = 0; i < parts.length; i++) {
2308
+ const part = parts[i];
2309
+ if (i === parts.length - 1) {
2310
+ current[part] = "";
2311
+ } else {
2312
+ current[part] = current[part] || {};
2313
+ current = current[part];
2314
+ }
2315
+ }
2316
+ }
2317
+ return result;
2318
+ }
2294
2319
  async function renderTemplate(template, data, fetch2) {
2295
2320
  let content = template, found;
2296
2321
  const now = /* @__PURE__ */ new Date(), d = {
@@ -2617,6 +2642,7 @@ export {
2617
2642
  fileBrowser,
2618
2643
  fileText,
2619
2644
  findByProp,
2645
+ findTemplateVars,
2620
2646
  flattenArr,
2621
2647
  flattenObj,
2622
2648
  fn,