@kosatyi/ejs 0.0.108 → 0.0.110

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/umd/index.js CHANGED
@@ -96,7 +96,7 @@
96
96
  const symbols = string => {
97
97
  return ('' + string).replace(symbolEntitiesMatch, match => '\\' + symbolEntities[match]);
98
98
  };
99
- const safeValue = (value, escape) => {
99
+ const escapeValue = (value, escape) => {
100
100
  const check = value;
101
101
  return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
102
102
  };
@@ -155,12 +155,26 @@
155
155
  }
156
156
  };
157
157
 
158
- class Template {
158
+ class EjsError extends Error {
159
+ constructor(code, content) {
160
+ super(content);
161
+ this.code = code;
162
+ if (content instanceof Error) {
163
+ this.stack = content.stack;
164
+ this.message = content.message;
165
+ }
166
+ }
167
+ }
168
+ const error = (code, content) => {
169
+ throw new EjsError(code, content);
170
+ };
171
+
172
+ class EjsTemplate {
159
173
  #path;
160
174
  #resolver;
161
175
  #cache;
162
176
  #compiler;
163
- static exports = ['configure', 'get', 'compile'];
177
+ static exports = ['configure', 'get'];
164
178
  constructor(options, cache, compiler) {
165
179
  bindContext(this, this.constructor.exports);
166
180
  this.#cache = cache;
@@ -176,11 +190,11 @@
176
190
  #resolve(template) {
177
191
  const cached = this.#cache.get(template);
178
192
  if (cached instanceof Promise) return cached;
179
- const result = Promise.resolve(this.#resolver(this.#path, template));
193
+ const result = Promise.resolve(this.#resolver(this.#path, template, error));
180
194
  this.#cache.set(template, result);
181
195
  return result;
182
196
  }
183
- compile(content, template) {
197
+ #compile(content, template) {
184
198
  const cached = this.#cache.get(template);
185
199
  if (typeof cached === 'function') return cached;
186
200
  if (typeof content === 'string') {
@@ -192,7 +206,9 @@
192
206
  }
193
207
  }
194
208
  get(template) {
195
- return this.#resolve(template).then(content => this.compile(content, template));
209
+ return this.#resolve(template).then(content => {
210
+ return this.#compile(content, template);
211
+ });
196
212
  }
197
213
  }
198
214
 
@@ -208,9 +224,9 @@
208
224
  return match;
209
225
  });
210
226
  };
211
- class Compiler {
227
+ class EjsCompiler {
212
228
  #config = {};
213
- static exports = ['compile'];
229
+ static exports = ['configure', 'compile'];
214
230
  constructor(options) {
215
231
  bindContext(this, this.constructor.exports);
216
232
  this.configure(options);
@@ -267,7 +283,7 @@
267
283
  });
268
284
  });
269
285
  OUTPUT += `');`;
270
- OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e,'${path}')}`;
286
+ OUTPUT = `try{${OUTPUT}}catch(e){return ${BUFFER}.error(e)}`;
271
287
  if (this.#config.strict === false) {
272
288
  OUTPUT = `with(${SCOPE}){${OUTPUT}}`;
273
289
  }
@@ -289,7 +305,7 @@
289
305
  }
290
306
  }
291
307
 
292
- class Cache {
308
+ class EjsCache {
293
309
  static exports = ['load', 'set', 'get', 'exist', 'clear', 'remove', 'resolve'];
294
310
  #cache = true;
295
311
  #precompiled;
@@ -363,31 +379,13 @@
363
379
  return result.join('');
364
380
  };
365
381
 
366
- class TemplateError extends Error {
367
- name = 'TemplateError';
368
- constructor(error) {
369
- super(error);
370
- if (error instanceof Error) {
371
- this.stack = error.stack;
372
- this.filename = error.filename;
373
- this.lineno = error.lineno;
374
- }
375
- }
376
- }
377
- class TemplateNotFound extends TemplateError {
378
- name = 'TemplateNotFound';
379
- code = 404;
380
- }
381
- class TemplateSyntaxError extends TemplateError {
382
- name = 'TemplateSyntaxError';
383
- code = 500;
384
- }
385
-
386
382
  const resolve = list => {
387
- return Promise.all(list || []).then(list => list.join('')).catch(e => e);
383
+ return Promise.all(list || []).then(list => list.join('')).catch(e => {
384
+ return error(500, e);
385
+ });
388
386
  };
389
- const reject = error => {
390
- return Promise.reject(new TemplateSyntaxError(error));
387
+ const reject = e => {
388
+ return Promise.reject(error(500, e));
391
389
  };
392
390
  const EjsBuffer = () => {
393
391
  let store = [];
@@ -412,7 +410,7 @@
412
410
  array = store.pop();
413
411
  return resolve(result);
414
412
  };
415
- EjsBuffer.error = (e, filename) => {
413
+ EjsBuffer.error = e => {
416
414
  return reject(e);
417
415
  };
418
416
  EjsBuffer.end = () => {
@@ -441,13 +439,6 @@
441
439
  this[MACRO] = {};
442
440
  Object.assign(this, omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]));
443
441
  }
444
- Object.entries(methods).forEach(_ref => {
445
- let [name, value] = _ref;
446
- if (isFunction(value) && globals.includes(name)) {
447
- value = value.bind(EjsContext.prototype);
448
- }
449
- EjsContext.prototype[name] = value;
450
- });
451
442
  Object.defineProperty(EjsContext.prototype, BUFFER, {
452
443
  value: EjsBuffer()
453
444
  });
@@ -472,36 +463,31 @@
472
463
  writable: true
473
464
  });
474
465
  Object.defineProperties(EjsContext.prototype, {
475
- /** @type {function} */
476
466
  setParentTemplate: {
477
467
  value(value) {
478
468
  this[PARENT] = value;
479
469
  return this;
480
470
  }
481
471
  },
482
- /** @type {function} */
483
472
  getParentTemplate: {
484
473
  value() {
485
474
  return this[PARENT];
486
475
  }
487
476
  },
488
- /** @type {function} */
489
- useSafeValue: {
490
- get: () => safeValue
477
+ useEscapeValue: {
478
+ get: () => escapeValue
491
479
  },
492
- /** @type {function} */
493
480
  useComponent: {
494
481
  get() {
495
482
  if (isFunction(this[COMPONENT])) {
496
483
  return this[COMPONENT].bind(this);
497
484
  } else {
498
- return () => {
485
+ return function () {
499
486
  throw new Error(`${COMPONENT} must be a function`);
500
487
  };
501
488
  }
502
489
  }
503
490
  },
504
- /** @type {function} */
505
491
  useElement: {
506
492
  get() {
507
493
  if (isFunction(this[ELEMENT])) {
@@ -513,51 +499,43 @@
513
499
  }
514
500
  }
515
501
  },
516
- /** @type {function} */
517
502
  useBuffer: {
518
503
  get() {
519
504
  return this[BUFFER];
520
505
  }
521
506
  },
522
- /** @type {function} */
523
507
  getMacro: {
524
508
  value() {
525
509
  return this[MACRO];
526
510
  }
527
511
  },
528
- /** @type {function} */
529
512
  getBlocks: {
530
513
  value() {
531
514
  return this[BLOCKS];
532
515
  }
533
516
  },
534
- /** @type {function} */
535
517
  setExtend: {
536
518
  value(value) {
537
519
  this[EXTEND] = value;
538
520
  return this;
539
521
  }
540
522
  },
541
- /** @type {function} */
542
523
  getExtend: {
543
524
  value() {
544
525
  return this[EXTEND];
545
526
  }
546
527
  },
547
- /** @type {function} */
548
528
  setLayout: {
549
529
  value(layout) {
550
530
  this[LAYOUT] = layout;
551
531
  return this;
552
532
  }
553
533
  },
554
- /** @type {function} */
555
534
  getLayout: {
556
535
  value() {
557
536
  return this[LAYOUT];
558
537
  }
559
538
  },
560
- /** @type {function} */
561
539
  clone: {
562
540
  value(exclude_blocks) {
563
541
  const filter = [LAYOUT, EXTEND, BUFFER];
@@ -567,32 +545,29 @@
567
545
  return omit(this, filter);
568
546
  }
569
547
  },
570
- /** @type {function} */
571
548
  extend: {
572
549
  value(layout) {
573
550
  this.setExtend(true);
574
551
  this.setLayout(layout);
575
552
  }
576
553
  },
577
- /** @type {function} */
578
554
  echo: {
579
555
  value() {
580
556
  return [].slice.call(arguments).forEach(this.useBuffer);
581
557
  }
582
558
  },
583
- /** @type {function} */
584
559
  fn: {
585
560
  value(callback) {
586
- return () => {
561
+ const context = this;
562
+ return function () {
587
563
  if (isFunction(callback)) {
588
- this.useBuffer.backup();
589
- this.useBuffer(callback.apply(this, arguments));
590
- return this.useBuffer.restore();
564
+ context.useBuffer.backup();
565
+ context.useBuffer(callback.apply(context, arguments));
566
+ return context.useBuffer.restore();
591
567
  }
592
568
  };
593
569
  }
594
570
  },
595
- /** @type {function} */
596
571
  macro: {
597
572
  value(name, callback) {
598
573
  const list = this.getMacro();
@@ -603,7 +578,6 @@
603
578
  };
604
579
  }
605
580
  },
606
- /** @type {function} */
607
581
  call: {
608
582
  value(name) {
609
583
  const list = this.getMacro();
@@ -614,35 +588,35 @@
614
588
  }
615
589
  }
616
590
  },
617
- /** @type {function} */
618
591
  block: {
619
592
  value(name, callback) {
620
593
  const blocks = this.getBlocks();
621
594
  blocks[name] = blocks[name] || [];
622
595
  blocks[name].push(this.fn(callback));
623
596
  if (this.getExtend()) return;
597
+ const context = this;
624
598
  const list = Object.assign([], blocks[name]);
625
- const shift = () => list.shift();
626
- const next = () => {
599
+ const shift = function () {
600
+ return list.shift();
601
+ };
602
+ const next = function () {
627
603
  const parent = shift();
628
604
  if (parent) {
629
- return () => {
630
- this.echo(parent(next()));
605
+ return function () {
606
+ context.echo(parent(next()));
631
607
  };
632
608
  } else {
633
- return () => {};
609
+ return function () {};
634
610
  }
635
611
  };
636
612
  this.echo(shift()(next()));
637
613
  }
638
614
  },
639
- /** @type {function} */
640
615
  hasBlock: {
641
616
  value(name) {
642
617
  return this.getBlocks().hasOwnProperty(name);
643
618
  }
644
619
  },
645
- /** @type {function} */
646
620
  include: {
647
621
  value(path, data, cx) {
648
622
  const context = cx === false ? {} : this.clone(true);
@@ -651,7 +625,6 @@
651
625
  this.echo(promise);
652
626
  }
653
627
  },
654
- /** @type {function} */
655
628
  use: {
656
629
  value(path, namespace) {
657
630
  this.echo(Promise.resolve(this.require(path)).then(exports$1 => {
@@ -662,13 +635,6 @@
662
635
  }));
663
636
  }
664
637
  },
665
- /** @type {function} */
666
- async: {
667
- value(promise, callback) {
668
- this.echo(Promise.resolve(promise).then(callback));
669
- }
670
- },
671
- /** @type {function} */
672
638
  get: {
673
639
  value(name, defaults) {
674
640
  const path = getPath(this, name, true);
@@ -677,7 +643,6 @@
677
643
  return hasProp(result, prop) ? result[prop] : defaults;
678
644
  }
679
645
  },
680
- /** @type {function} */
681
646
  set: {
682
647
  value(name, value) {
683
648
  const path = getPath(this, name, false);
@@ -689,7 +654,6 @@
689
654
  return result[prop] = value;
690
655
  }
691
656
  },
692
- /** @type {function} */
693
657
  each: {
694
658
  value(object, callback) {
695
659
  if (isString(object)) {
@@ -699,7 +663,6 @@
699
663
  },
700
664
  writable: true
701
665
  },
702
- /** @type {function} */
703
666
  el: {
704
667
  value(tag, attr, content) {
705
668
  content = isFunction(content) ? this.fn(content)() : content;
@@ -707,15 +670,21 @@
707
670
  },
708
671
  writable: true
709
672
  },
710
- /** @type {function} */
711
673
  ui: {
712
- value(layout) {},
674
+ value() {},
713
675
  writable: true
714
676
  }
715
677
  });
678
+ Object.entries(methods).forEach(_ref => {
679
+ let [name, value] = _ref;
680
+ if (isFunction(value) && globals.includes(name)) {
681
+ value = value.bind(EjsContext.prototype);
682
+ }
683
+ EjsContext.prototype[name] = value;
684
+ });
716
685
  return EjsContext;
717
686
  };
718
- class Context {
687
+ class EjsContext {
719
688
  #context;
720
689
  static exports = ['create', 'globals', 'helpers'];
721
690
  constructor(options, methods) {
@@ -746,10 +715,10 @@
746
715
  bindContext(this, this.constructor.exports);
747
716
  this.#methods = {};
748
717
  this.#config = configSchema({}, options);
749
- this.#context = new Context(this.#config, this.#methods);
750
- this.#compiler = new Compiler(this.#config);
751
- this.#cache = new Cache(this.#config);
752
- this.#template = new Template(this.#config, this.#cache, this.#compiler);
718
+ this.#context = new EjsContext(this.#config, this.#methods);
719
+ this.#compiler = new EjsCompiler(this.#config);
720
+ this.#cache = new EjsCache(this.#config);
721
+ this.#template = new EjsTemplate(this.#config, this.#cache, this.#compiler);
753
722
  this.helpers({
754
723
  render: this.render,
755
724
  require: this.require
@@ -796,7 +765,7 @@
796
765
  return name;
797
766
  }
798
767
  #output(path, data) {
799
- return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useSafeValue]));
768
+ return this.#template.get(path).then(callback => callback.apply(data, [data, data.useComponent, data.useElement, data.useBuffer, data.useEscapeValue]));
800
769
  }
801
770
  #renderLayout(name, params, parentTemplate) {
802
771
  const data = this.createContext(params);
@@ -845,26 +814,29 @@
845
814
  };
846
815
  };
847
816
 
848
- const readFile = (path, template) => {
849
- return fs.readFile(joinPath(path, template)).then(contents => contents.toString()).then(text => String(text));
817
+ const readFile = (path, template, error) => {
818
+ return fs.readFile(joinPath(path, template)).then(contents => contents.toString()).catch(reason => {
819
+ if (reason.code === 'ENOENT') {
820
+ error(404, `template ${template} not found`);
821
+ } else {
822
+ error(500, reason);
823
+ }
824
+ });
850
825
  };
851
826
 
852
827
  const {
853
828
  render,
854
- createContext,
855
- compile,
856
829
  helpers,
857
- preload,
858
830
  configure,
859
- create
831
+ create,
832
+ createContext,
833
+ compile,
834
+ preload
860
835
  } = new EjsInstance({
861
836
  resolver: readFile
862
837
  });
863
838
  const __express = expressRenderer(configure, render);
864
839
 
865
- exports.TemplateError = TemplateError;
866
- exports.TemplateNotFound = TemplateNotFound;
867
- exports.TemplateSyntaxError = TemplateSyntaxError;
868
840
  exports.__express = __express;
869
841
  exports.compile = compile;
870
842
  exports.configure = configure;
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejsInstance={})}(this,(function(t){"use strict";const e="ejsPrecompiled",s=!0,i="views",r="ejs",o=!0,n=!0,c=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),h=[],a={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},l={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},u=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,p=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},f=t=>Array.isArray(t),g=t=>"function"==typeof t,m=t=>"string"==typeof t,d=t=>"boolean"==typeof t,v=(t,v)=>{return Object.assign(t,{path:p(m,i,t.path,v.path),precompiled:p(m,e,t.export,v.export),resolver:p(g,c,t.resolver,v.resolver),extension:p(m,r,t.extension,v.extension),strict:p(d,n,t.strict,v.strict),rmWhitespace:p(d,o,t.rmWhitespace,v.rmWhitespace),cache:p(d,s,t.cache,v.cache),globals:p(f,h,t.globals,(b=v.globals,!!f(b)&&b.filter((t=>{const e=u.test(t);return!1===e&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),e})))),token:Object.assign({},l,t.token,v.token),vars:Object.assign({},a,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},x={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},y=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=y(x),E=y(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>x[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let i=t,r=String(e).split("."),o=r.pop();for(let t=0;t<r.length;t++){const e=r[t];if(g(i.toJSON)&&(i=i.toJSON()),s&&!1===i.hasOwnProperty(e)){i={};break}i=i[e]=i[e]||{}}return g(i.toJSON)&&(i=i.toJSON()),[i,o]},P=(t,e)=>{let s;for(s in t)S(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},S=(t,e)=>t&&Object.hasOwn(t,e),C=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,i=e.length;s<i;s++){const i=e[s];i in t&&(t[i]=t[i].bind(t))}};class T{#t;#e;#s;#i;static exports=["configure","get","compile"];constructor(t,e,s){C(this,this.constructor.exports),this.#s=e,this.#i=s,this.configure(t??{})}configure(t){this.#t=t.path,g(t.resolver)&&(this.#e=t.resolver)}#r(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t));return this.#s.set(t,s),s}compile(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#i.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#r(t).then((e=>this.compile(e,t)))}}const N=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class B{#o={};static exports=["compile"];constructor(t){C(this,this.constructor.exports),this.configure(t)}configure(t){this.#o.strict=t.strict,this.#o.rmWhitespace=t.rmWhitespace,this.#o.token=t.token,this.#o.vars=t.vars,this.#o.globals=t.globals,this.#o.legacy=t.legacy??!0,this.#o.slurp={match:"[s\t\n]*",start:[this.#o.token.start,"_"],end:["_",this.#o.token.end]},this.#o.matches=[],this.#o.formats=[];for(const[t,e]of N)this.#o.matches.push(this.#o.token.start.concat(t).concat(this.#o.token.regex).concat(this.#o.token.end)),this.#o.formats.push(e);this.#o.regex=new RegExp(this.#o.matches.join("|").concat("|$"),"g"),this.#o.slurpStart=new RegExp([this.#o.slurp.match,this.#o.slurp.start.join("")].join(""),"gm"),this.#o.slurpEnd=new RegExp([this.#o.slurp.end.join(""),this.#o.slurp.match].join(""),"gm"),this.#o.globals.length&&(this.#o.legacy?this.#o.globalVariables=`const ${this.#o.globals.map((t=>`${t}=${this.#o.vars.SCOPE}.${t}`)).join(",")};`:this.#o.globalVariables=`const {${this.#o.globals.join(",")}} = ${this.#o.vars.SCOPE};`)}compile(t,e){const s=this.#o.globalVariables,{SCOPE:i,SAFE:r,BUFFER:o,COMPONENT:n,ELEMENT:c}=this.#o.vars;this.#o.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#o.slurpStart,this.#o.token.start).replace(this.#o.slurpEnd,this.#o.token.end);let h=`${o}('`;((t,e,s)=>{let i=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),r=t.shift();return s(t,i,e),i=e+r.length,r}))})(this.#o.regex,t,((e,s,i)=>{h+=(""+t.slice(s,i)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#o.formats[e](t.trim(),o,r))}))})),h+="');",h=`try{${h}}catch(e){return ${o}.error(e,'${e}')}`,!1===this.#o.strict&&(h=`with(${i}){${h}}`),h=`${o}.start();${h}return ${o}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[i,n,c,o,r],e=Function.apply(null,t.concat(h));return e.source=`(function(${t.join(",")}){\n${h}\n});`,e}catch(t){throw t.filename=e,t.source=h,t}}}class L{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#n;#c={};constructor(t){C(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#c[t]}set(t,e){this.#s&&(this.#c[t]=e)}exist(t){if(this.#s)return this.#c.hasOwnProperty(t)}clear(){Object.keys(this.#c).forEach(this.remove)}remove(t){delete this.#c[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#c,t||{})}configure(t){this.#s=t.cache,this.#n=t.precompiled,"object"==typeof window&&this.load(window[this.#n])}}const A=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",M='"',R="/",q="<",U=">",W=t=>{let[e,s]=t;if(null!=s)return[$(e),[M,$(s),M].join("")].join("=")};class _ extends Error{name="TemplateError";constructor(t){super(t),t instanceof Error&&(this.stack=t.stack,this.filename=t.filename,this.lineno=t.lineno)}}class V extends _{name="TemplateSyntaxError";code=500}const J=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>t)),z=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),J(s)},s.error=(t,e)=>{return s=t,Promise.reject(new V(s));var s},s.end=()=>J(e),s},D=Symbol("EjsContext.parentTemplate"),K=(t,e)=>{const{BLOCKS:s,MACRO:i,EXTEND:r,LAYOUT:o,BUFFER:n,SAFE:c,SCOPE:h,COMPONENT:a,ELEMENT:l}=t.vars,u=t.globals||[];function p(t){this[D]=null,this[s]={},this[i]={},Object.assign(this,k(t,[h,n,c,a,l]))}return Object.entries(e).forEach((t=>{let[e,s]=t;g(s)&&u.includes(e)&&(s=s.bind(p.prototype)),p.prototype[e]=s})),Object.defineProperty(p.prototype,n,{value:z()}),Object.defineProperty(p.prototype,s,{value:{},writable:!0}),Object.defineProperty(p.prototype,i,{value:{},writable:!0}),Object.defineProperty(p.prototype,o,{value:!1,writable:!0}),Object.defineProperty(p.prototype,r,{value:!1,writable:!0}),Object.defineProperty(p.prototype,D,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value(t){return this[D]=t,this}},getParentTemplate:{value(){return this[D]}},useSafeValue:{get:()=>O},useComponent:{get(){return g(this[a])?this[a].bind(this):()=>{throw new Error(`${a} must be a function`)}}},useElement:{get(){return g(this[l])?this[l].bind(this):()=>{throw new Error(`${l} must be a function`)}}},useBuffer:{get(){return this[n]}},getMacro:{value(){return this[i]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[r]=t,this}},getExtend:{value(){return this[r]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,r,n];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){return()=>{if(g(t))return this.useBuffer.backup(),this.useBuffer(t.apply(this,arguments)),this.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),i=this.fn(e),r=this;s[t]=function(){return r.echo(i.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(g(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const i=Object.assign([],s[t]),r=()=>i.shift(),o=()=>{const t=r();return t?()=>{this.echo(t(o()))}:()=>{}};this.echo(r()(o()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const i=!1===s?{}:this.clone(!0),r=Object.assign(i,e||{}),o=this.render(t,r);this.echo(o)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,i)=>{s[[e,i].join(".")]=t}))})))}},async:{value(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value(t,e){const s=w(this,t,!0),i=s.shift(),r=s.pop();return S(i,r)?i[r]:e}},set:{value(t,e){const s=w(this,t,!1),i=s.shift(),r=s.pop();return this.getParentTemplate()&&S(i,r)?i[r]:i[r]=e}},each:{value(t,e){m(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=g(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const i=[],r=-1===A.indexOf(t),o=Object.entries(e??{}).map(W).filter((t=>t)).join(F);return i.push([q,t,F,o,U].join("")),s&&r&&i.push(Array.isArray(s)?s.join(""):s),r&&i.push([q,R,t,U].join("")),i.join("")})(t,e,s))))},writable:!0},ui:{value(t){},writable:!0}}),p};class X{#h;static exports=["create","globals","helpers"];constructor(t,e){C(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#h(t)}helpers(t){Object.assign(this.#h.prototype,t)}configure(t,e){this.#h=K(t,e)}}var Y={};const{render:Z,createContext:I,compile:G,helpers:H,preload:Q,configure:tt,create:et}=new class{#s;#h;#i;#a;#o={};#l={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};C(this,this.constructor.exports),this.#l={},this.#o=v({},t),this.#h=new X(this.#o,this.#l),this.#i=new B(this.#o),this.#s=new L(this.#o),this.#a=new T(this.#o,this.#s,this.#i),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#o,t),this.#h.configure(this.#o,this.#l),this.#i.configure(this.#o),this.#s.configure(this.#o),this.#a.configure(this.#o)),this.#o}createContext(t){return this.#h.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#i.compile(t,e)}helpers(t){this.#h.helpers(Object.assign(this.#l,t))}async render(t,e){const s=this.createContext(e);return this.#u(this.#t(t),s).then(this.#p(t,s))}async require(t){const e=this.createContext({});return this.#u(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#o.extension&&(t=[t,this.#o.extension].join(".")),t}#u(t,e){return this.#a.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useSafeValue])))}#f(t,e,s){const i=this.createContext(e);return s&&i.setParentTemplate(s),this.#u(this.#t(t),i).then(this.#p(t,i))}#p(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#f(e.getLayout(),e,t)):s}}({resolver:(t,e)=>Y.readFile(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((t=>t.toString())).then((t=>String(t)))}),st=((t,e)=>function(r,o,n){g(o)&&(n=o,o={}),o=o||{};const c=Object.assign({},o.settings),h=p(m,i,c.views),a=p(d,s,c["view cache"]),l=Object.assign({},c["view options"]),u=Y.relative(h,r);return l.path=h,l.cache=a,t(l),e(u,o).then((t=>{n(null,t)})).catch((t=>{n(t)}))})(tt,Z);t.TemplateError=_,t.TemplateNotFound=class extends _{name="TemplateNotFound";code=404},t.TemplateSyntaxError=V,t.__express=st,t.compile=G,t.configure=tt,t.create=et,t.createContext=I,t.helpers=H,t.preload=Q,t.render=Z}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ejsInstance={})}(this,(function(t){"use strict";const e="ejsPrecompiled",s=!0,i="views",r="ejs",o=!0,n=!0,c=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),h=[],a={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},l={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},u=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,p=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},f=t=>Array.isArray(t),g=t=>"function"==typeof t,m=t=>"string"==typeof t,d=t=>"boolean"==typeof t,v=(t,v)=>{return Object.assign(t,{path:p(m,i,t.path,v.path),precompiled:p(m,e,t.export,v.export),resolver:p(g,c,t.resolver,v.resolver),extension:p(m,r,t.extension,v.extension),strict:p(d,n,t.strict,v.strict),rmWhitespace:p(d,o,t.rmWhitespace,v.rmWhitespace),cache:p(d,s,t.cache,v.cache),globals:p(f,h,t.globals,(b=v.globals,!!f(b)&&b.filter((t=>{const e=u.test(t);return!1===e&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),e})))),token:Object.assign({},l,t.token,v.token),vars:Object.assign({},a,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},x={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},y=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=y(x),E=y(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>x[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let i=t,r=String(e).split("."),o=r.pop();for(let t=0;t<r.length;t++){const e=r[t];if(g(i.toJSON)&&(i=i.toJSON()),s&&!1===i.hasOwnProperty(e)){i={};break}i=i[e]=i[e]||{}}return g(i.toJSON)&&(i=i.toJSON()),[i,o]},P=(t,e)=>{let s;for(s in t)C(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},C=(t,e)=>t&&Object.hasOwn(t,e),S=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,i=e.length;s<i;s++){const i=e[s];i in t&&(t[i]=t[i].bind(t))}};class T extends Error{constructor(t,e){super(e),this.code=t,e instanceof Error&&(this.stack=e.stack,this.message=e.message)}}const N=(t,e)=>{throw new T(t,e)};class B{#t;#e;#s;#i;static exports=["configure","get"];constructor(t,e,s){S(this,this.constructor.exports),this.#s=e,this.#i=s,this.configure(t??{})}configure(t){this.#t=t.path,g(t.resolver)&&(this.#e=t.resolver)}#r(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t,N));return this.#s.set(t,s),s}#o(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#i.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#r(t).then((e=>this.#o(e,t)))}}const L=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class A{#n={};static exports=["configure","compile"];constructor(t){S(this,this.constructor.exports),this.configure(t)}configure(t){this.#n.strict=t.strict,this.#n.rmWhitespace=t.rmWhitespace,this.#n.token=t.token,this.#n.vars=t.vars,this.#n.globals=t.globals,this.#n.legacy=t.legacy??!0,this.#n.slurp={match:"[s\t\n]*",start:[this.#n.token.start,"_"],end:["_",this.#n.token.end]},this.#n.matches=[],this.#n.formats=[];for(const[t,e]of L)this.#n.matches.push(this.#n.token.start.concat(t).concat(this.#n.token.regex).concat(this.#n.token.end)),this.#n.formats.push(e);this.#n.regex=new RegExp(this.#n.matches.join("|").concat("|$"),"g"),this.#n.slurpStart=new RegExp([this.#n.slurp.match,this.#n.slurp.start.join("")].join(""),"gm"),this.#n.slurpEnd=new RegExp([this.#n.slurp.end.join(""),this.#n.slurp.match].join(""),"gm"),this.#n.globals.length&&(this.#n.legacy?this.#n.globalVariables=`const ${this.#n.globals.map((t=>`${t}=${this.#n.vars.SCOPE}.${t}`)).join(",")};`:this.#n.globalVariables=`const {${this.#n.globals.join(",")}} = ${this.#n.vars.SCOPE};`)}compile(t,e){const s=this.#n.globalVariables,{SCOPE:i,SAFE:r,BUFFER:o,COMPONENT:n,ELEMENT:c}=this.#n.vars;this.#n.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#n.slurpStart,this.#n.token.start).replace(this.#n.slurpEnd,this.#n.token.end);let h=`${o}('`;((t,e,s)=>{let i=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),r=t.shift();return s(t,i,e),i=e+r.length,r}))})(this.#n.regex,t,((e,s,i)=>{h+=(""+t.slice(s,i)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#n.formats[e](t.trim(),o,r))}))})),h+="');",h=`try{${h}}catch(e){return ${o}.error(e)}`,!1===this.#n.strict&&(h=`with(${i}){${h}}`),h=`${o}.start();${h}return ${o}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[i,n,c,o,r],e=Function.apply(null,t.concat(h));return e.source=`(function(${t.join(",")}){\n${h}\n});`,e}catch(t){throw t.filename=e,t.source=h,t}}}class M{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#c;#h={};constructor(t){S(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#h[t]}set(t,e){this.#s&&(this.#h[t]=e)}exist(t){if(this.#s)return this.#h.hasOwnProperty(t)}clear(){Object.keys(this.#h).forEach(this.remove)}remove(t){delete this.#h[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#h,t||{})}configure(t){this.#s=t.cache,this.#c=t.precompiled,"object"==typeof window&&this.load(window[this.#c])}}const F=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],R=" ",q='"',U="/",W="<",_=">",V=t=>{let[e,s]=t;if(null!=s)return[$(e),[q,$(s),q].join("")].join("=")},J=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>N(500,t))),z=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),J(s)},s.error=t=>(t=>Promise.reject(N(500,t)))(t),s.end=()=>J(e),s},D=Symbol("EjsContext.parentTemplate"),K=(t,e)=>{const{BLOCKS:s,MACRO:i,EXTEND:r,LAYOUT:o,BUFFER:n,SAFE:c,SCOPE:h,COMPONENT:a,ELEMENT:l}=t.vars,u=t.globals||[];function p(t){this[D]=null,this[s]={},this[i]={},Object.assign(this,k(t,[h,n,c,a,l]))}return Object.defineProperty(p.prototype,n,{value:z()}),Object.defineProperty(p.prototype,s,{value:{},writable:!0}),Object.defineProperty(p.prototype,i,{value:{},writable:!0}),Object.defineProperty(p.prototype,o,{value:!1,writable:!0}),Object.defineProperty(p.prototype,r,{value:!1,writable:!0}),Object.defineProperty(p.prototype,D,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value(t){return this[D]=t,this}},getParentTemplate:{value(){return this[D]}},useEscapeValue:{get:()=>O},useComponent:{get(){return g(this[a])?this[a].bind(this):function(){throw new Error(`${a} must be a function`)}}},useElement:{get(){return g(this[l])?this[l].bind(this):()=>{throw new Error(`${l} must be a function`)}}},useBuffer:{get(){return this[n]}},getMacro:{value(){return this[i]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[r]=t,this}},getExtend:{value(){return this[r]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,r,n];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){const e=this;return function(){if(g(t))return e.useBuffer.backup(),e.useBuffer(t.apply(e,arguments)),e.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),i=this.fn(e),r=this;s[t]=function(){return r.echo(i.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(g(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const i=this,r=Object.assign([],s[t]),o=function(){return r.shift()},n=function(){const t=o();return t?function(){i.echo(t(n()))}:function(){}};this.echo(o()(n()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const i=!1===s?{}:this.clone(!0),r=Object.assign(i,e||{}),o=this.render(t,r);this.echo(o)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,i)=>{s[[e,i].join(".")]=t}))})))}},get:{value(t,e){const s=w(this,t,!0),i=s.shift(),r=s.pop();return C(i,r)?i[r]:e}},set:{value(t,e){const s=w(this,t,!1),i=s.shift(),r=s.pop();return this.getParentTemplate()&&C(i,r)?i[r]:i[r]=e}},each:{value(t,e){m(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=g(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const i=[],r=-1===F.indexOf(t),o=Object.entries(e??{}).map(V).filter((t=>t)).join(R);return i.push([W,t,R,o,_].join("")),s&&r&&i.push(Array.isArray(s)?s.join(""):s),r&&i.push([W,U,t,_].join("")),i.join("")})(t,e,s))))},writable:!0},ui:{value(){},writable:!0}}),Object.entries(e).forEach((t=>{let[e,s]=t;g(s)&&u.includes(e)&&(s=s.bind(p.prototype)),p.prototype[e]=s})),p};class X{#a;static exports=["create","globals","helpers"];constructor(t,e){S(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#a(t)}helpers(t){Object.assign(this.#a.prototype,t)}configure(t,e){this.#a=K(t,e)}}var Y={};const{render:Z,helpers:I,configure:G,create:H,createContext:Q,compile:tt,preload:et}=new class{#s;#a;#i;#l;#n={};#u={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};S(this,this.constructor.exports),this.#u={},this.#n=v({},t),this.#a=new X(this.#n,this.#u),this.#i=new A(this.#n),this.#s=new M(this.#n),this.#l=new B(this.#n,this.#s,this.#i),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#n,t),this.#a.configure(this.#n,this.#u),this.#i.configure(this.#n),this.#s.configure(this.#n),this.#l.configure(this.#n)),this.#n}createContext(t){return this.#a.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#i.compile(t,e)}helpers(t){this.#a.helpers(Object.assign(this.#u,t))}async render(t,e){const s=this.createContext(e);return this.#p(this.#t(t),s).then(this.#f(t,s))}async require(t){const e=this.createContext({});return this.#p(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#n.extension&&(t=[t,this.#n.extension].join(".")),t}#p(t,e){return this.#l.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useEscapeValue])))}#g(t,e,s){const i=this.createContext(e);return s&&i.setParentTemplate(s),this.#p(this.#t(t),i).then(this.#f(t,i))}#f(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#g(e.getLayout(),e,t)):s}}({resolver:(t,e,s)=>Y.readFile(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((t=>t.toString())).catch((t=>{"ENOENT"===t.code?s(404,`template ${e} not found`):s(500,t)}))}),st=((t,e)=>function(r,o,n){g(o)&&(n=o,o={}),o=o||{};const c=Object.assign({},o.settings),h=p(m,i,c.views),a=p(d,s,c["view cache"]),l=Object.assign({},c["view options"]),u=Y.relative(h,r);return l.path=h,l.cache=a,t(l),e(u,o).then((t=>{n(null,t)})).catch((t=>{n(t)}))})(G,Z);t.__express=st,t.compile=tt,t.configure=G,t.create=H,t.createContext=Q,t.helpers=I,t.preload=et,t.render=Z}));