diff --git a/package.json b/package.json index 55566a5..381017b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.28.12", + "version": "0.28.13", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/template.ts b/src/template.ts index 6bd3dd5..26bf810 100644 --- a/src/template.ts +++ b/src/template.ts @@ -8,7 +8,16 @@ export class TemplateError extends BadRequestError { } export function findTemplateVars(html: string): Record { const variables = new Set(); const arrays = new Set(); - const excluded = new Set(['true', 'false', 'null', 'undefined']); + const excluded = new Set([ + 'let', 'const', 'var', 'function', 'if', 'while', 'do', 'this', 'typeof', + 'new', 'instanceof', 'in', 'for', 'else', 'case', 'break', 'continue', + 'switch', 'default', 'with', 'eval', 'arguments', 'void', 'delete', 'null', + 'undefined', 'true', 'false', 'async', 'await', 'try', 'catch', 'finally', + 'throw', 'return', 'yield', 'debugger', 'extends', 'import', 'export', + 'class', 'super', 'static', 'get', 'set', 'constructor', 'enum', 'implements', + 'interface', 'package', 'private', 'protected', 'public', 'abstract', 'final', + 'native', 'synchronized', 'throws', 'transient', 'volatile' + ]); // Extract & exclude loop variables, mark arrays for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) { @@ -70,6 +79,7 @@ export function findTemplateVars(html: string): Record { } return result; } + export async function renderTemplate(template: string, data: any, fetch?: (file: string) => Promise) { if(!fetch) fetch = (file) => { throw new TemplateError(`Unable to fetch template: ${file}`); }