@kosatyi/ejs 0.0.55 → 0.0.57

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
@@ -132,6 +132,14 @@ var getPath = function getPath(context, name) {
132
132
  });
133
133
  return [data, prop];
134
134
  };
135
+ var bindContext = function bindContext(object, context) {
136
+ var methods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
137
+ methods.forEach(function (name) {
138
+ if (name in object) {
139
+ object[name] = object[name].bind(context);
140
+ }
141
+ });
142
+ };
135
143
  var ext = function ext(path, defaults) {
136
144
  var ext = path.split('.').pop();
137
145
  if (ext !== defaults) {
@@ -756,18 +764,18 @@ var EJS = /*#__PURE__*/function () {
756
764
  function EJS() {
757
765
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
758
766
  _classCallCheck(this, EJS);
767
+ _defineProperty(this, "export", ['cache', 'render', 'require', 'helpers', 'configure', 'preload', 'compile', 'create', '__express']);
759
768
  this.config = {};
760
769
  this.scope = {};
761
770
  configSchema(this.config, options);
771
+ bindContext(this, this, this["export"]);
762
772
  this.context = new Context(this.config);
763
773
  this.compiler = new Compiler(this.config);
764
774
  this.cache = new Cache(this.config);
765
775
  this.template = new Template(this.config, this.cache, this.compiler);
766
- var render = this.render.bind(this);
767
- var require = this.require.bind(this);
768
776
  this.helpers({
769
- require: require,
770
- render: render
777
+ require: this.require,
778
+ render: this.render
771
779
  });
772
780
  }
773
781
  _createClass(EJS, [{
package/dist/esm/index.js CHANGED
@@ -72,6 +72,14 @@ const getPath = (context, name) => {
72
72
  return [data, prop]
73
73
  };
74
74
 
75
+ const bindContext = (object, context, methods = []) => {
76
+ methods.forEach((name) => {
77
+ if (name in object) {
78
+ object[name] = object[name].bind(context);
79
+ }
80
+ });
81
+ };
82
+
75
83
  const ext = (path, defaults) => {
76
84
  const ext = path.split('.').pop();
77
85
  if (ext !== defaults) {
@@ -89,8 +97,7 @@ const extend = (...args) => {
89
97
  }, target)
90
98
  };
91
99
 
92
- const noop = () => {
93
- };
100
+ const noop = () => {};
94
101
 
95
102
  const each = (object, callback) => {
96
103
  let prop;
@@ -786,17 +793,27 @@ class Context {
786
793
  }
787
794
 
788
795
  class EJS {
796
+ export = [
797
+ 'cache',
798
+ 'render',
799
+ 'require',
800
+ 'helpers',
801
+ 'configure',
802
+ 'preload',
803
+ 'compile',
804
+ 'create',
805
+ '__express',
806
+ ]
789
807
  constructor(options = {}) {
790
808
  this.config = {};
791
809
  this.scope = {};
792
810
  configSchema(this.config, options);
811
+ bindContext(this, this, this.export);
793
812
  this.context = new Context(this.config);
794
813
  this.compiler = new Compiler(this.config);
795
814
  this.cache = new Cache(this.config);
796
815
  this.template = new Template(this.config, this.cache, this.compiler);
797
- const render = this.render.bind(this);
798
- const require = this.require.bind(this);
799
- this.helpers({ require, render });
816
+ this.helpers({ require: this.require, render: this.render });
800
817
  }
801
818
  configure(options = {}) {
802
819
  configSchema(this.config, options);
package/dist/umd/index.js CHANGED
@@ -133,6 +133,14 @@
133
133
  });
134
134
  return [data, prop];
135
135
  };
136
+ var bindContext = function bindContext(object, context) {
137
+ var methods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
138
+ methods.forEach(function (name) {
139
+ if (name in object) {
140
+ object[name] = object[name].bind(context);
141
+ }
142
+ });
143
+ };
136
144
  var ext = function ext(path, defaults) {
137
145
  var ext = path.split('.').pop();
138
146
  if (ext !== defaults) {
@@ -759,18 +767,18 @@
759
767
  function EJS() {
760
768
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
761
769
  _classCallCheck(this, EJS);
770
+ _defineProperty(this, "export", ['cache', 'render', 'require', 'helpers', 'configure', 'preload', 'compile', 'create', '__express']);
762
771
  this.config = {};
763
772
  this.scope = {};
764
773
  configSchema(this.config, options);
774
+ bindContext(this, this, this["export"]);
765
775
  this.context = new Context(this.config);
766
776
  this.compiler = new Compiler(this.config);
767
777
  this.cache = new Cache(this.config);
768
778
  this.template = new Template(this.config, this.cache, this.compiler);
769
- var render = this.render.bind(this);
770
- var require = this.require.bind(this);
771
779
  this.helpers({
772
- require: require,
773
- render: render
780
+ require: this.require,
781
+ render: this.render
774
782
  });
775
783
  }
776
784
  _createClass(EJS, [{
@@ -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,o(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){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 c=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},u=function(t){return"function"==typeof t},s=function(t){return"string"==typeof t},h=function(t){return"boolean"==typeof t},a=function(t){return"object"===e(t)},f=function(t){return void 0===t},l="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),p=function(){return l},v={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},d={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},m=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},g=m(d),y=m(v),b=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(g,(function(t){return d[t]}))},k=function(t,e,n){return null==(n=t)?"":e?b(n):n},w=function(t,e){var n=t,i=e.split("."),r=i.pop();return i.forEach((function(t){n=n[t]=n[t]||{}})),[n,r]},x=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},j=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)},E=function(){},O=function(t,e){var n;for(n in t)B(t,n)&&e(t[n],n,t)},F=function(t,e){return function(t,e,n){var i=t instanceof Array,r=i?[]:{};return O(t,(function(t,n,o){var c=e(t,n,o);!1===f(c)&&(i?r.push(c):r[n]=c)})),r}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},S=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},B=function(t,e){return t&&t.hasOwnProperty(e)},P={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]+?)"}},R=function(t,e){j(t,{path:c(s,P.path,t.path,e.path),export:c(s,P.export,t.export,e.export),resolver:c(u,P.resolver,t.resolver,e.resolver),extension:c(s,P.extension,t.extension,e.extension),withObject:c(h,P.withObject,t.withObject,e.withObject),rmWhitespace:c(h,P.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:c(h,P.watch,t.watch,e.watch),chokidar:c(a,P.export,t.export,e.export),token:j({},P.token,t.token,e.token),vars:j({},P.vars,t.vars,e.vars)})},$={},T=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},C=function(t,e){return fetch(T(t,e)).then((function(t){return t.text()}))},M=function(t,e){return new Promise((function(n,i){$.readFile(T(t,e),(function(t,e){t?i(t):n(e.toString())}))}))},U=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=u(t.resolver)?t.resolver:p()?M:C,t.watch&&p()&&(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 u(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}(),A=[{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]},A.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(y,(function(t){return"\\"+v[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){var i,r,c;n(this,t),i=this,c={},(r=o(r="list"))in i?Object.defineProperty(i,r,{value:c,enumerable:!0,configurable:!0,writable:!0}):i[r]=c,this.configure(e),!1===p()&&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 j(this.list,t),this}},{key:"exist",value:function(t){return B(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}(),_=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],q=" ",D='"',K="/",X="<",Y=">",J=function(t,e,n){var i=[],r=-1===_.indexOf(t),o=function(t,e,n){var i=[];return O(t,(function(t,n,r){var o=e(t,n,r);!1===f(o)&&i.push(o)})),i}(e,(function(t,e){if(null!=t)return[b(e),[D,b(t),D].join("")].join("=")})).join(q);return i.push([X,t,q,o,Y].join("")),n&&i.push(n instanceof Array?n.join(""):n),r&&i.push([X,K,t,Y].join("")),i.join("")},V=function(t){return Promise.all(t).then((function(t){return t.join("")}))},z=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,h=n.MACRO,a=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),j(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){j(f.prototype,t)},f.prototype=j({},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(),V(n)},n.error=function(t){throw t},n.end=function(){return V(e)},n}()),f.define(o,{},!0),f.define(h,{},!0),f.define(r,!1,!0),f.define(i,!1,!0),f.method("initBlocks",(function(){this[o]={}})),f.method("initMacro",(function(){this[h]={}})),f.method("getMacro",(function(){return this[h]})),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),F(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(),u(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=w(this,t),i=n.shift(),r=n.pop();return B(i,r)?i[r]:e})),f.method("set",(function(t,e){var n=w(this,t),i=n.shift(),r=n.pop();return this.getExtend()&&B(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(u(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()))}:E}()))}})),f.method("include",(function(t,e,n){var i=!1===n?{}:this.clone(!0),r=j(i,e||{}),o=this.render(t,r);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(S(n,(function(t){var n=this.getMacro();O(t,(function(t,i){n[[e,i].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(S(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return J(t,e,n)})),f.method("el",(function(t,e,n){u(n)&&(n=this.fn(n)()),this.echo(S(n,(function(n){return J(t,e,n)}),this))})),f.method("each",(function(t,e){s(t)&&(t=this.get(t,[])),O(t,e)}))}}]),t}(),G=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n(this,t),this.config={},this.scope={},R(this.config,e),this.context=new z(this.config),this.compiler=new L(this.config),this.cache=new W(this.config),this.template=new U(this.config,this.cache,this.compiler);var i=this.render.bind(this),r=this.require.bind(this);this.helpers({require:r,render:i})}return r(t,[{key:"configure",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return R(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=x(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=x(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(j(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){u(e)&&(n=e,e={});var i=j({},(e=e||{}).settings),r=c(s,P.path,i.views),o=c(h,P.cache,i["view cache"]),a=j({},i["view options"]),f=$.relative(r,t);return a.path=r,a.cache=o,this.configure(a),this.render(f,e).then((function(t){n(null,t)})).catch((function(t){n(t)}))}}]),t}(),H=new G({}),I=H.__express,Q=H.render,Z=H.context,tt=H.compile,et=H.helpers,nt=H.preload,it=H.configure,rt=H.create;t.EJS=G,t.__express=I,t.compile=tt,t.configure=it,t.context=Z,t.create=rt,t.element=J,t.helpers=et,t.preload=nt,t.render=Q,t.safeValue=k}));
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}));
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.55",
6
+ "version": "0.0.57",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "browser": "dist/umd/index.js",