@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.cjs +26 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -1
- package/dist/template.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2295,6 +2295,31 @@ ${opts.message || this.desc}`;
|
|
|
2295
2295
|
}
|
|
2296
2296
|
class TemplateError extends BadRequestError {
|
|
2297
2297
|
}
|
|
2298
|
+
function findTemplateVars(html) {
|
|
2299
|
+
const variables = /* @__PURE__ */ new Set();
|
|
2300
|
+
const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
|
|
2301
|
+
let match;
|
|
2302
|
+
while ((match = regex.exec(html)) !== null) {
|
|
2303
|
+
const code = match[1].trim();
|
|
2304
|
+
const varMatch = code.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)/);
|
|
2305
|
+
if (varMatch) variables.add(varMatch[1]);
|
|
2306
|
+
}
|
|
2307
|
+
const result = {};
|
|
2308
|
+
for (const path of variables) {
|
|
2309
|
+
const parts = path.split(".");
|
|
2310
|
+
let current = result;
|
|
2311
|
+
for (let i = 0; i < parts.length; i++) {
|
|
2312
|
+
const part = parts[i];
|
|
2313
|
+
if (i === parts.length - 1) {
|
|
2314
|
+
current[part] = "";
|
|
2315
|
+
} else {
|
|
2316
|
+
current[part] = current[part] || {};
|
|
2317
|
+
current = current[part];
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
return result;
|
|
2322
|
+
}
|
|
2298
2323
|
async function renderTemplate(template, data, fetch2) {
|
|
2299
2324
|
let content = template, found;
|
|
2300
2325
|
const now = /* @__PURE__ */ new Date(), d = {
|
|
@@ -2620,6 +2645,7 @@ ${opts.message || this.desc}`;
|
|
|
2620
2645
|
exports2.fileBrowser = fileBrowser;
|
|
2621
2646
|
exports2.fileText = fileText;
|
|
2622
2647
|
exports2.findByProp = findByProp;
|
|
2648
|
+
exports2.findTemplateVars = findTemplateVars;
|
|
2623
2649
|
exports2.flattenArr = flattenArr;
|
|
2624
2650
|
exports2.flattenObj = flattenObj;
|
|
2625
2651
|
exports2.fn = fn;
|