@kosatyi/ejs 0.0.57 → 0.0.58

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/cjs/index.js CHANGED
@@ -123,13 +123,24 @@ var symbols = function symbols(string) {
123
123
  var safeValue = function safeValue(value, escape, check) {
124
124
  return (check = value) == null ? '' : escape ? entities(check) : check;
125
125
  };
126
- var getPath = function getPath(context, name) {
126
+ var BreakException = {};
127
+ var getPath = function getPath(context, name, create) {
127
128
  var data = context;
128
129
  var chunk = name.split('.');
129
130
  var prop = chunk.pop();
130
- chunk.forEach(function (part) {
131
- data = data[part] = data[part] || {};
132
- });
131
+ try {
132
+ chunk.forEach(function (part) {
133
+ if (isObject(data[part])) {
134
+ data = data[part];
135
+ } else if (create === true) {
136
+ data = data[part] = {};
137
+ } else {
138
+ throw BreakException;
139
+ }
140
+ });
141
+ } catch (e) {
142
+ if (e !== BreakException) throw e;
143
+ }
133
144
  return [data, prop];
134
145
  };
135
146
  var bindContext = function bindContext(object, context) {
@@ -666,13 +677,13 @@ var Context = /*#__PURE__*/function () {
666
677
  };
667
678
  });
668
679
  Scope.method('get', function (name, defaults) {
669
- var path = getPath(this, name);
680
+ var path = getPath(this, name, false);
670
681
  var result = path.shift();
671
682
  var prop = path.pop();
672
683
  return hasProp(result, prop) ? result[prop] : defaults;
673
684
  });
674
685
  Scope.method('set', function (name, value) {
675
- var path = getPath(this, name);
686
+ var path = getPath(this, name, true);
676
687
  var result = path.shift();
677
688
  var prop = path.pop();
678
689
  if (this.getExtend() && hasProp(result, prop)) {
package/dist/esm/index.js CHANGED
@@ -62,13 +62,25 @@ const safeValue = (value, escape, check) => {
62
62
  return (check = value) == null ? '' : escape ? entities(check) : check
63
63
  };
64
64
 
65
- const getPath = (context, name) => {
65
+ const BreakException = {};
66
+
67
+ const getPath = (context, name, create) => {
66
68
  let data = context;
67
69
  let chunk = name.split('.');
68
70
  let prop = chunk.pop();
69
- chunk.forEach((part) => {
70
- data = data[part] = data[part] || {};
71
- });
71
+ try {
72
+ chunk.forEach((part) => {
73
+ if (isObject(data[part])) {
74
+ data = data[part];
75
+ } else if (create === true) {
76
+ data = data[part] = {};
77
+ } else {
78
+ throw BreakException
79
+ }
80
+ });
81
+ } catch (e) {
82
+ if (e !== BreakException) throw e
83
+ }
72
84
  return [data, prop]
73
85
  };
74
86
 
@@ -673,14 +685,14 @@ class Context {
673
685
  });
674
686
 
675
687
  Scope.method('get', function (name, defaults) {
676
- const path = getPath(this, name);
688
+ const path = getPath(this, name, false);
677
689
  const result = path.shift();
678
690
  const prop = path.pop();
679
691
  return hasProp(result, prop) ? result[prop] : defaults
680
692
  });
681
693
 
682
694
  Scope.method('set', function (name, value) {
683
- const path = getPath(this, name);
695
+ const path = getPath(this, name, true);
684
696
  const result = path.shift();
685
697
  const prop = path.pop();
686
698
  if (this.getExtend() && hasProp(result, prop)) {
package/dist/umd/index.js CHANGED
@@ -124,13 +124,24 @@
124
124
  var safeValue = function safeValue(value, escape, check) {
125
125
  return (check = value) == null ? '' : escape ? entities(check) : check;
126
126
  };
127
- var getPath = function getPath(context, name) {
127
+ var BreakException = {};
128
+ var getPath = function getPath(context, name, create) {
128
129
  var data = context;
129
130
  var chunk = name.split('.');
130
131
  var prop = chunk.pop();
131
- chunk.forEach(function (part) {
132
- data = data[part] = data[part] || {};
133
- });
132
+ try {
133
+ chunk.forEach(function (part) {
134
+ if (isObject(data[part])) {
135
+ data = data[part];
136
+ } else if (create === true) {
137
+ data = data[part] = {};
138
+ } else {
139
+ throw BreakException;
140
+ }
141
+ });
142
+ } catch (e) {
143
+ if (e !== BreakException) throw e;
144
+ }
134
145
  return [data, prop];
135
146
  };
136
147
  var bindContext = function bindContext(object, context) {
@@ -669,13 +680,13 @@
669
680
  };
670
681
  });
671
682
  Scope.method('get', function (name, defaults) {
672
- var path = getPath(this, name);
683
+ var path = getPath(this, name, false);
673
684
  var result = path.shift();
674
685
  var prop = path.pop();
675
686
  return hasProp(result, prop) ? result[prop] : defaults;
676
687
  });
677
688
  Scope.method('set', function (name, value) {
678
- var path = getPath(this, name);
689
+ var path = getPath(this, name, true);
679
690
  var result = path.shift();
680
691
  var prop = path.pop();
681
692
  if (this.getExtend() && hasProp(result, prop)) {
@@ -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).ejs={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,c(i.key),i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e,n){return(e=c(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var u=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},s=function(t){return"function"==typeof t},h=function(t){return"string"==typeof t},a=function(t){return"boolean"==typeof t},f=function(t){return"object"===e(t)},l=function(t){return void 0===t},p="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),v=function(){return p},d={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},m={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},g=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},y=g(m),b=g(d),k=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(y,(function(t){return m[t]}))},w=function(t,e,n){return null==(n=t)?"":e?k(n):n},x=function(t,e){var n=t,i=e.split("."),r=i.pop();return i.forEach((function(t){n=n[t]=n[t]||{}})),[n,r]},j=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},E=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),i)},O=function(){},F=function(t,e){var n;for(n in t)P(t,n)&&e(t[n],n,t)},S=function(t,e){return function(t,e,n){var i=t instanceof Array,r=i?[]:{};return F(t,(function(t,n,o){var c=e(t,n,o);!1===l(c)&&(i?r.push(c):r[n]=c)})),r}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},B=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},P=function(t,e){return t&&t.hasOwnProperty(e)},R={export:"ejsPrecompiled",watch:!1,chokidar:null,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!0,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},$=function(t,e){E(t,{path:u(h,R.path,t.path,e.path),export:u(h,R.export,t.export,e.export),resolver:u(s,R.resolver,t.resolver,e.resolver),extension:u(h,R.extension,t.extension,e.extension),withObject:u(a,R.withObject,t.withObject,e.withObject),rmWhitespace:u(a,R.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:u(a,R.watch,t.watch,e.watch),chokidar:u(f,R.export,t.export,e.export),token:E({},R.token,t.token,e.token),vars:E({},R.vars,t.vars,e.vars)})},T={},C=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},M=function(t,e){return fetch(C(t,e)).then((function(t){return t.text()}))},U=function(t,e){return new Promise((function(n,i){T.readFile(C(t,e),(function(t,e){t?i(t):n(e.toString())}))}))},A=function(){function t(e,i,r){n(this,t),this.cache=i,this.watcher={unwatch:function(){},on:function(){}},this.compiler=r,this.configure(e)}return r(t,[{key:"configure",value:function(t){var e=this;this.path=t.path,this.chokidar=t.chokidar,this.resolver=s(t.resolver)?t.resolver:v()?U:M,t.watch&&v()&&(this.watcher&&this.watcher.unwatch("."),this.chokidar&&(this.watcher=this.chokidar.watch(".",{cwd:this.path}).on("change",(function(t){e.cache.remove(t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return s(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),_=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],L=function(){function t(e){n(this,t),this.configure(e)}return r(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},_.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,i=this.vars,r=i.SCOPE,o=i.SAFE,c=i.BUFFER,u=i.COMPONENT;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var s,h,a,f="".concat(c,"('");s=this.regex,h=function(e,i,r){f+=(""+t.slice(i,r)).replace(b,(function(t){return"\\"+d[t]})),e.forEach((function(t,e){t&&(f+=n.formats[e](t))}))},a=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return h(t,a,e),a=e+n.length,n})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),this.withObject&&(f="with(".concat(r,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(r,u,c,o,f)).source="(function(".concat(r,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),N="undefined"!=typeof globalThis?globalThis:window||self,W=function(){function t(e){n(this,t),o(this,"list",{}),this.configure(e),!1===v()&&this.load(N[this.namespace])}return r(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return E(this.list,t),this}},{key:"exist",value:function(t){return P(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],D=" ",K='"',X="/",Y="<",J=">",V=function(t,e,n){var i=[],r=-1===q.indexOf(t),o=function(t,e,n){var i=[];return F(t,(function(t,n,r){var o=e(t,n,r);!1===l(o)&&i.push(o)})),i}(e,(function(t,e){if(null!=t)return[k(e),[K,k(t),K].join("")].join("=")})).join(D);return i.push([Y,t,D,o,J].join("")),n&&i.push(n instanceof Array?n.join(""):n),r&&i.push([Y,X,t,J].join("")),i.join("")},z=function(t){return Promise.all(t).then((function(t){return t.join("")}))},G=function(){function t(e){n(this,t),this.configure(e)}return r(t,[{key:"configure",value:function(t,e){var n=t.vars,i=n.EXTEND,r=n.LAYOUT,o=n.BLOCKS,c=n.BUFFER,u=n.MACRO,a=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),E(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){E(f.prototype,t)},f.prototype=E({},e||{}),f.define=f.method=function(t,e,n,i,r){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:i||!1,enumerable:r||!1})},f.define(c,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),z(n)},n.error=function(t){throw t},n.end=function(){return z(e)},n}()),f.define(o,{},!0),f.define(u,{},!0),f.define(r,!1,!0),f.define(i,!1,!0),f.method("initBlocks",(function(){this[o]={}})),f.method("initMacro",(function(){this[u]={}})),f.method("getMacro",(function(){return this[u]})),f.method("getBuffer",(function(){return this[c]})),f.method("getComponent",(function(){var t=this;return a in t?function(){return t[a].apply(t,arguments)}:function(){console.log("%s function not defined",a)}})),f.method("getBlocks",(function(){return this[o]})),f.method("setExtend",(function(t){this[i]=t})),f.method("getExtend",(function(){return this[i]})),f.method("setLayout",(function(t){this[r]=t})),f.method("getLayout",(function(){return this[r]})),f.method("clone",(function(t){var e=[r,i,c];return!0===t&&e.push(o),S(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer();[].slice.call(arguments).forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),s(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=x(this,t),i=n.shift(),r=n.pop();return P(i,r)?i[r]:e})),f.method("set",(function(t,e){var n=x(this,t),i=n.shift(),r=n.pop();return this.getExtend()&&P(i,r)?i[r]:i[r]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),i=this.fn(e),r=this;n[t]=function(){return r.echo(i.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro()[t],n=[].slice.call(arguments,1);if(s(e))return e.apply(e,n)})),f.method("block",(function(t,e){var n=this,i=this.getBlocks();if(i[t]=i[t]||[],i[t].push(this.fn(e)),!this.getExtend()){var r=Object.assign([],i[t]),o=function(){return r.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:O}()))}})),f.method("include",(function(t,e,n){var i=!1===n?{}:this.clone(!0),r=E(i,e||{}),o=this.render(t,r);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(B(n,(function(t){var n=this.getMacro();F(t,(function(t,i){n[[e,i].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(B(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return V(t,e,n)})),f.method("el",(function(t,e,n){s(n)&&(n=this.fn(n)()),this.echo(B(n,(function(n){return V(t,e,n)}),this))})),f.method("each",(function(t,e){h(t)&&(t=this.get(t,[])),F(t,e)}))}}]),t}(),H=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n(this,t),o(this,"export",["cache","render","require","helpers","configure","preload","compile","create","__express"]),this.config={},this.scope={},$(this.config,e),function(t,e){(arguments.length>2&&void 0!==arguments[2]?arguments[2]:[]).forEach((function(n){n in t&&(t[n]=t[n].bind(e))}))}(this,this,this.export),this.context=new G(this.config),this.compiler=new L(this.config),this.cache=new W(this.config),this.template=new A(this.config,this.cache,this.compiler),this.helpers({require:this.require,render:this.render})}return r(t,[{key:"configure",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return $(this.config,t),this.context.configure(this.config,this.scope),this.compiler.configure(this.config),this.cache.configure(this.config),this.template.configure(this.config),this.config}},{key:"output",value:function(t,e){return this.template.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),w)}))}},{key:"render",value:function(t,e){var n=this,i=j(t,this.config.extension),r=this.context.create(e);return this.output(i,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),i=r.clone();return n.render(e,i)}return t}))}},{key:"require",value:function(t){var e=j(t,this.config.extension),n=this.context.create({});return this.output(e,n).then((function(){return n.getMacro()}))}},{key:"create",value:function(){return new t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"helpers",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.context.helpers(E(this.scope,t))}},{key:"preload",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.cache.load(t)}},{key:"compile",value:function(t,e){return this.compiler.compile(t,e)}},{key:"__express",value:function(t,e,n){s(e)&&(n=e,e={});var i=E({},(e=e||{}).settings),r=u(h,R.path,i.views),o=u(a,R.cache,i["view cache"]),c=E({},i["view options"]),f=T.relative(r,t);return c.path=r,c.cache=o,this.configure(c),this.render(f,e).then((function(t){n(null,t)})).catch((function(t){n(t)}))}}]),t}(),I=new H({}),Q=I.__express,Z=I.render,tt=I.context,et=I.compile,nt=I.helpers,it=I.preload,rt=I.configure,ot=I.create;t.EJS=H,t.__express=Q,t.compile=et,t.configure=rt,t.context=tt,t.create=ot,t.element=V,t.helpers=nt,t.preload=it,t.render=Z,t.safeValue=w}));
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).ejs={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,c(i.key),i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e,n){return(e=c(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var u=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},s=function(t){return"function"==typeof t},h=function(t){return"string"==typeof t},a=function(t){return"boolean"==typeof t},f=function(t){return"object"===e(t)},l=function(t){return void 0===t},p="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),v=function(){return p},d={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},m={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},g=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},y=g(m),b=g(d),w=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(y,(function(t){return m[t]}))},k=function(t,e,n){return null==(n=t)?"":e?w(n):n},x={},j=function(t,e,n){var i=t,r=e.split("."),o=r.pop();try{r.forEach((function(t){if(f(i[t]))i=i[t];else{if(!0!==n)throw x;i=i[t]={}}}))}catch(t){if(t!==x)throw t}return[i,o]},E=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},O=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),i)},F=function(){},S=function(t,e){var n;for(n in t)R(t,n)&&e(t[n],n,t)},B=function(t,e){return function(t,e,n){var i=t instanceof Array,r=i?[]:{};return S(t,(function(t,n,o){var c=e(t,n,o);!1===l(c)&&(i?r.push(c):r[n]=c)})),r}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},P=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},R=function(t,e){return t&&t.hasOwnProperty(e)},$={export:"ejsPrecompiled",watch:!1,chokidar:null,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!0,vars:{SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},T=function(t,e){O(t,{path:u(h,$.path,t.path,e.path),export:u(h,$.export,t.export,e.export),resolver:u(s,$.resolver,t.resolver,e.resolver),extension:u(h,$.extension,t.extension,e.extension),withObject:u(a,$.withObject,t.withObject,e.withObject),rmWhitespace:u(a,$.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:u(a,$.watch,t.watch,e.watch),chokidar:u(f,$.export,t.export,e.export),token:O({},$.token,t.token,e.token),vars:O({},$.vars,t.vars,e.vars)})},C={},M=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},U=function(t,e){return fetch(M(t,e)).then((function(t){return t.text()}))},A=function(t,e){return new Promise((function(n,i){C.readFile(M(t,e),(function(t,e){t?i(t):n(e.toString())}))}))},_=function(){function t(e,i,r){n(this,t),this.cache=i,this.watcher={unwatch:function(){},on:function(){}},this.compiler=r,this.configure(e)}return r(t,[{key:"configure",value:function(t){var e=this;this.path=t.path,this.chokidar=t.chokidar,this.resolver=s(t.resolver)?t.resolver:v()?A:U,t.watch&&v()&&(this.watcher&&this.watcher.unwatch("."),this.chokidar&&(this.watcher=this.chokidar.watch(".",{cwd:this.path}).on("change",(function(t){e.cache.remove(t)}))))}},{key:"resolve",value:function(t){return this.resolver(this.path,t)}},{key:"result",value:function(t,e){return this.cache.set(t,e),e}},{key:"compile",value:function(t,e){return s(t)?t:this.compiler.compile(t,e)}},{key:"get",value:function(t){var e=this;if(this.cache.exist(t))return this.cache.resolve(t);var n=this.resolve(t).then((function(n){return e.result(t,e.compile(n,t))}));return this.result(t,n)}}]),t}(),L=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],N=function(){function t(e){n(this,t),this.configure(e)}return r(t,[{key:"configure",value:function(t){var e=this;this.withObject=t.withObject,this.rmWhitespace=t.rmWhitespace,this.token=t.token,this.vars=t.vars,this.matches=[],this.formats=[],this.slurp={match:"[ \\t]*",start:[this.token.start,"_"],end:["_",this.token.end]},L.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),this.regex=new RegExp(this.matches.join("|").concat("|$"),"g"),this.slurpStart=new RegExp([this.slurp.match,this.slurp.start.join("")].join(""),"gm"),this.slurpEnd=new RegExp([this.slurp.end.join(""),this.slurp.match].join(""),"gm")}},{key:"truncate",value:function(t){return t&&t.replace(/^(?:\r\n|\r|\n)/,"")}},{key:"compile",value:function(t,e){var n=this,i=this.vars,r=i.SCOPE,o=i.SAFE,c=i.BUFFER,u=i.COMPONENT;this.rmWhitespace&&(t=t.replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=t.replace(this.slurpStart,this.token.start).replace(this.slurpEnd,this.token.end);var s,h,a,f="".concat(c,"('");s=this.regex,h=function(e,i,r){f+=(""+t.slice(i,r)).replace(b,(function(t){return"\\"+d[t]})),e.forEach((function(t,e){t&&(f+=n.formats[e](t))}))},a=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return h(t,a,e),a=e+n.length,n})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),this.withObject&&(f="with(".concat(r,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(r,u,c,o,f)).source="(function(".concat(r,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),W="undefined"!=typeof globalThis?globalThis:window||self,q=function(){function t(e){n(this,t),o(this,"list",{}),this.configure(e),!1===v()&&this.load(W[this.namespace])}return r(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return O(this.list,t),this}},{key:"exist",value:function(t){return R(this.list,t)}},{key:"get",value:function(t){return this.list[t]}},{key:"remove",value:function(t){delete this.list[t]}},{key:"resolve",value:function(t){return Promise.resolve(this.get(t))}},{key:"set",value:function(t,e){return this.list[t]=e,this}}]),t}(),D=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],K=" ",X='"',Y="/",J="<",V=">",z=function(t,e,n){var i=[],r=-1===D.indexOf(t),o=function(t,e,n){var i=[];return S(t,(function(t,n,r){var o=e(t,n,r);!1===l(o)&&i.push(o)})),i}(e,(function(t,e){if(null!=t)return[w(e),[X,w(t),X].join("")].join("=")})).join(K);return i.push([J,t,K,o,V].join("")),n&&i.push(n instanceof Array?n.join(""):n),r&&i.push([J,Y,t,V].join("")),i.join("")},G=function(t){return Promise.all(t).then((function(t){return t.join("")}))},H=function(){function t(e){n(this,t),this.configure(e)}return r(t,[{key:"configure",value:function(t,e){var n=t.vars,i=n.EXTEND,r=n.LAYOUT,o=n.BLOCKS,c=n.BUFFER,u=n.MACRO,a=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),O(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){O(f.prototype,t)},f.prototype=O({},e||{}),f.define=f.method=function(t,e,n,i,r){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:i||!1,enumerable:r||!1})},f.define(c,function(){var t=[],e=[];function n(t){e.push(t)}return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),G(n)},n.error=function(t){throw t},n.end=function(){return G(e)},n}()),f.define(o,{},!0),f.define(u,{},!0),f.define(r,!1,!0),f.define(i,!1,!0),f.method("initBlocks",(function(){this[o]={}})),f.method("initMacro",(function(){this[u]={}})),f.method("getMacro",(function(){return this[u]})),f.method("getBuffer",(function(){return this[c]})),f.method("getComponent",(function(){var t=this;return a in t?function(){return t[a].apply(t,arguments)}:function(){console.log("%s function not defined",a)}})),f.method("getBlocks",(function(){return this[o]})),f.method("setExtend",(function(t){this[i]=t})),f.method("getExtend",(function(){return this[i]})),f.method("setLayout",(function(t){this[r]=t})),f.method("getLayout",(function(){return this[r]})),f.method("clone",(function(t){var e=[r,i,c];return!0===t&&e.push(o),B(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer();[].slice.call(arguments).forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),s(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=j(this,t,!1),i=n.shift(),r=n.pop();return R(i,r)?i[r]:e})),f.method("set",(function(t,e){var n=j(this,t,!0),i=n.shift(),r=n.pop();return this.getExtend()&&R(i,r)?i[r]:i[r]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),i=this.fn(e),r=this;n[t]=function(){return r.echo(i.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro()[t],n=[].slice.call(arguments,1);if(s(e))return e.apply(e,n)})),f.method("block",(function(t,e){var n=this,i=this.getBlocks();if(i[t]=i[t]||[],i[t].push(this.fn(e)),!this.getExtend()){var r=Object.assign([],i[t]),o=function(){return r.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:F}()))}})),f.method("include",(function(t,e,n){var i=!1===n?{}:this.clone(!0),r=O(i,e||{}),o=this.render(t,r);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(P(n,(function(t){var n=this.getMacro();S(t,(function(t,i){n[[e,i].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(P(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return z(t,e,n)})),f.method("el",(function(t,e,n){s(n)&&(n=this.fn(n)()),this.echo(P(n,(function(n){return z(t,e,n)}),this))})),f.method("each",(function(t,e){h(t)&&(t=this.get(t,[])),S(t,e)}))}}]),t}(),I=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n(this,t),o(this,"export",["cache","render","require","helpers","configure","preload","compile","create","__express"]),this.config={},this.scope={},T(this.config,e),function(t,e){(arguments.length>2&&void 0!==arguments[2]?arguments[2]:[]).forEach((function(n){n in t&&(t[n]=t[n].bind(e))}))}(this,this,this.export),this.context=new H(this.config),this.compiler=new N(this.config),this.cache=new q(this.config),this.template=new _(this.config,this.cache,this.compiler),this.helpers({require:this.require,render:this.render})}return r(t,[{key:"configure",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return T(this.config,t),this.context.configure(this.config,this.scope),this.compiler.configure(this.config),this.cache.configure(this.config),this.template.configure(this.config),this.config}},{key:"output",value:function(t,e){return this.template.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),k)}))}},{key:"render",value:function(t,e){var n=this,i=E(t,this.config.extension),r=this.context.create(e);return this.output(i,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),i=r.clone();return n.render(e,i)}return t}))}},{key:"require",value:function(t){var e=E(t,this.config.extension),n=this.context.create({});return this.output(e,n).then((function(){return n.getMacro()}))}},{key:"create",value:function(){return new t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"helpers",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.context.helpers(O(this.scope,t))}},{key:"preload",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.cache.load(t)}},{key:"compile",value:function(t,e){return this.compiler.compile(t,e)}},{key:"__express",value:function(t,e,n){s(e)&&(n=e,e={});var i=O({},(e=e||{}).settings),r=u(h,$.path,i.views),o=u(a,$.cache,i["view cache"]),c=O({},i["view options"]),f=C.relative(r,t);return c.path=r,c.cache=o,this.configure(c),this.render(f,e).then((function(t){n(null,t)})).catch((function(t){n(t)}))}}]),t}(),Q=new I({}),Z=Q.__express,tt=Q.render,et=Q.context,nt=Q.compile,it=Q.helpers,rt=Q.preload,ot=Q.configure,ct=Q.create;t.EJS=I,t.__express=Z,t.compile=nt,t.configure=ot,t.context=et,t.create=ct,t.element=z,t.helpers=it,t.preload=rt,t.render=tt,t.safeValue=k}));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "EJS Templates",
4
4
  "homepage": "https://github.com/kosatyi/ejs",
5
5
  "type": "module",
6
- "version": "0.0.57",
6
+ "version": "0.0.58",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "browser": "dist/umd/index.js",