@kosatyi/ejs 0.0.59 → 0.0.60

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
@@ -48,6 +48,70 @@ function _defineProperty(obj, key, value) {
48
48
  }
49
49
  return obj;
50
50
  }
51
+ function _unsupportedIterableToArray(o, minLen) {
52
+ if (!o) return;
53
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
54
+ var n = Object.prototype.toString.call(o).slice(8, -1);
55
+ if (n === "Object" && o.constructor) n = o.constructor.name;
56
+ if (n === "Map" || n === "Set") return Array.from(o);
57
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
58
+ }
59
+ function _arrayLikeToArray(arr, len) {
60
+ if (len == null || len > arr.length) len = arr.length;
61
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
62
+ return arr2;
63
+ }
64
+ function _createForOfIteratorHelper(o, allowArrayLike) {
65
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
66
+ if (!it) {
67
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
68
+ if (it) o = it;
69
+ var i = 0;
70
+ var F = function () {};
71
+ return {
72
+ s: F,
73
+ n: function () {
74
+ if (i >= o.length) return {
75
+ done: true
76
+ };
77
+ return {
78
+ done: false,
79
+ value: o[i++]
80
+ };
81
+ },
82
+ e: function (e) {
83
+ throw e;
84
+ },
85
+ f: F
86
+ };
87
+ }
88
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89
+ }
90
+ var normalCompletion = true,
91
+ didErr = false,
92
+ err;
93
+ return {
94
+ s: function () {
95
+ it = it.call(o);
96
+ },
97
+ n: function () {
98
+ var step = it.next();
99
+ normalCompletion = step.done;
100
+ return step;
101
+ },
102
+ e: function (e) {
103
+ didErr = true;
104
+ err = e;
105
+ },
106
+ f: function () {
107
+ try {
108
+ if (!normalCompletion && it.return != null) it.return();
109
+ } finally {
110
+ if (didErr) throw err;
111
+ }
112
+ }
113
+ };
114
+ }
51
115
  function _toPrimitive(input, hint) {
52
116
  if (typeof input !== "object" || input === null) return input;
53
117
  var prim = input[Symbol.toPrimitive];
@@ -123,13 +187,26 @@ var symbols = function symbols(string) {
123
187
  var safeValue = function safeValue(value, escape, check) {
124
188
  return (check = value) == null ? '' : escape ? entities(check) : check;
125
189
  };
126
- var getPath = function getPath(context, name, create) {
127
- var data = create ? context : Object.assign({}, context);
128
- var chunk = name.split('.');
129
- var prop = chunk.pop();
130
- chunk.forEach(function (part) {
131
- data = data[part] = data[part] || {};
132
- });
190
+ var getPath = function getPath(context, name, strict) {
191
+ var data = context;
192
+ var chunks = name.split('.');
193
+ var prop = chunks.pop();
194
+ var _iterator = _createForOfIteratorHelper(chunks),
195
+ _step;
196
+ try {
197
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
198
+ var part = _step.value;
199
+ if (strict && data.hasOwnProperty(part) === false) {
200
+ data = {};
201
+ break;
202
+ }
203
+ data = data[part] = data[part] || {};
204
+ }
205
+ } catch (err) {
206
+ _iterator.e(err);
207
+ } finally {
208
+ _iterator.f();
209
+ }
133
210
  return [data, prop];
134
211
  };
135
212
  var bindContext = function bindContext(object, context) {
@@ -666,13 +743,13 @@ var Context = /*#__PURE__*/function () {
666
743
  };
667
744
  });
668
745
  Scope.method('get', function (name, defaults) {
669
- var path = getPath(this, name, false);
746
+ var path = getPath(this, name, true);
670
747
  var result = path.shift();
671
748
  var prop = path.pop();
672
749
  return hasProp(result, prop) ? result[prop] : defaults;
673
750
  });
674
751
  Scope.method('set', function (name, value) {
675
- var path = getPath(this, name, true);
752
+ var path = getPath(this, name, false);
676
753
  var result = path.shift();
677
754
  var prop = path.pop();
678
755
  if (this.getExtend() && hasProp(result, prop)) {
package/dist/esm/index.js CHANGED
@@ -62,13 +62,17 @@ const safeValue = (value, escape, check) => {
62
62
  return (check = value) == null ? '' : escape ? entities(check) : check
63
63
  };
64
64
 
65
- const getPath = (context, name, create) => {
66
- let data = create ? context : Object.assign({}, context);
67
- let chunk = name.split('.');
68
- let prop = chunk.pop();
69
- chunk.forEach((part) => {
65
+ const getPath = (context, name, strict) => {
66
+ let data = context;
67
+ let chunks = name.split('.');
68
+ let prop = chunks.pop();
69
+ for (const part of chunks) {
70
+ if (strict && data.hasOwnProperty(part) === false) {
71
+ data = {};
72
+ break
73
+ }
70
74
  data = data[part] = data[part] || {};
71
- });
75
+ }
72
76
  return [data, prop]
73
77
  };
74
78
 
@@ -673,14 +677,14 @@ class Context {
673
677
  });
674
678
 
675
679
  Scope.method('get', function (name, defaults) {
676
- const path = getPath(this, name, false);
680
+ const path = getPath(this, name, true);
677
681
  const result = path.shift();
678
682
  const prop = path.pop();
679
683
  return hasProp(result, prop) ? result[prop] : defaults
680
684
  });
681
685
 
682
686
  Scope.method('set', function (name, value) {
683
- const path = getPath(this, name, true);
687
+ const path = getPath(this, name, false);
684
688
  const result = path.shift();
685
689
  const prop = path.pop();
686
690
  if (this.getExtend() && hasProp(result, prop)) {
package/dist/umd/index.js CHANGED
@@ -49,6 +49,70 @@
49
49
  }
50
50
  return obj;
51
51
  }
52
+ function _unsupportedIterableToArray(o, minLen) {
53
+ if (!o) return;
54
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
55
+ var n = Object.prototype.toString.call(o).slice(8, -1);
56
+ if (n === "Object" && o.constructor) n = o.constructor.name;
57
+ if (n === "Map" || n === "Set") return Array.from(o);
58
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
59
+ }
60
+ function _arrayLikeToArray(arr, len) {
61
+ if (len == null || len > arr.length) len = arr.length;
62
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
63
+ return arr2;
64
+ }
65
+ function _createForOfIteratorHelper(o, allowArrayLike) {
66
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
67
+ if (!it) {
68
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
69
+ if (it) o = it;
70
+ var i = 0;
71
+ var F = function () {};
72
+ return {
73
+ s: F,
74
+ n: function () {
75
+ if (i >= o.length) return {
76
+ done: true
77
+ };
78
+ return {
79
+ done: false,
80
+ value: o[i++]
81
+ };
82
+ },
83
+ e: function (e) {
84
+ throw e;
85
+ },
86
+ f: F
87
+ };
88
+ }
89
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
90
+ }
91
+ var normalCompletion = true,
92
+ didErr = false,
93
+ err;
94
+ return {
95
+ s: function () {
96
+ it = it.call(o);
97
+ },
98
+ n: function () {
99
+ var step = it.next();
100
+ normalCompletion = step.done;
101
+ return step;
102
+ },
103
+ e: function (e) {
104
+ didErr = true;
105
+ err = e;
106
+ },
107
+ f: function () {
108
+ try {
109
+ if (!normalCompletion && it.return != null) it.return();
110
+ } finally {
111
+ if (didErr) throw err;
112
+ }
113
+ }
114
+ };
115
+ }
52
116
  function _toPrimitive(input, hint) {
53
117
  if (typeof input !== "object" || input === null) return input;
54
118
  var prim = input[Symbol.toPrimitive];
@@ -124,13 +188,26 @@
124
188
  var safeValue = function safeValue(value, escape, check) {
125
189
  return (check = value) == null ? '' : escape ? entities(check) : check;
126
190
  };
127
- var getPath = function getPath(context, name, create) {
128
- var data = create ? context : Object.assign({}, context);
129
- var chunk = name.split('.');
130
- var prop = chunk.pop();
131
- chunk.forEach(function (part) {
132
- data = data[part] = data[part] || {};
133
- });
191
+ var getPath = function getPath(context, name, strict) {
192
+ var data = context;
193
+ var chunks = name.split('.');
194
+ var prop = chunks.pop();
195
+ var _iterator = _createForOfIteratorHelper(chunks),
196
+ _step;
197
+ try {
198
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
199
+ var part = _step.value;
200
+ if (strict && data.hasOwnProperty(part) === false) {
201
+ data = {};
202
+ break;
203
+ }
204
+ data = data[part] = data[part] || {};
205
+ }
206
+ } catch (err) {
207
+ _iterator.e(err);
208
+ } finally {
209
+ _iterator.f();
210
+ }
134
211
  return [data, prop];
135
212
  };
136
213
  var bindContext = function bindContext(object, context) {
@@ -669,13 +746,13 @@
669
746
  };
670
747
  });
671
748
  Scope.method('get', function (name, defaults) {
672
- var path = getPath(this, name, false);
749
+ var path = getPath(this, name, true);
673
750
  var result = path.shift();
674
751
  var prop = path.pop();
675
752
  return hasProp(result, prop) ? result[prop] : defaults;
676
753
  });
677
754
  Scope.method('set', function (name, value) {
678
- var path = getPath(this, name, true);
755
+ var path = getPath(this, name, false);
679
756
  var result = path.shift();
680
757
  var prop = path.pop();
681
758
  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,n){var i=n?t:Object.assign({},t),r=e.split("."),o=r.pop();return r.forEach((function(t){i=i[t]=i[t]||{}})),[i,o]},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,!1),i=n.shift(),r=n.pop();return P(i,r)?i[r]:e})),f.method("set",(function(t,e){var n=x(this,t,!0),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 r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,s(r.key),r)}}function i(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e,n){return(e=s(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function u(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){s=!0,o=t},f:function(){try{u||null==n.return||n.return()}finally{if(s)throw o}}}}function s(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;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 a=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},h=function(t){return"function"==typeof t},f=function(t){return"string"==typeof t},l=function(t){return"boolean"==typeof t},p=function(t){return"object"===e(t)},v=function(t){return void 0===t},d="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),m=function(){return d},g={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},y={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},b=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},w=b(y),k=b(g),x=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(w,(function(t){return y[t]}))},j=function(t,e,n){return null==(n=t)?"":e?x(n):n},E=function(t,e,n){var r,i=t,o=e.split("."),c=o.pop(),s=u(o);try{for(s.s();!(r=s.n()).done;){var a=r.value;if(n&&!1===i.hasOwnProperty(a)){i={};break}i=i[a]=i[a]||{}}}catch(t){s.e(t)}finally{s.f()}return[i,c]},O=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},S=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},F=function(){},B=function(t,e){var n;for(n in t)R(t,n)&&e(t[n],n,t)},P=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return B(t,(function(t,n,o){var c=e(t,n,o);!1===v(c)&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},A=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){S(t,{path:a(f,$.path,t.path,e.path),export:a(f,$.export,t.export,e.export),resolver:a(h,$.resolver,t.resolver,e.resolver),extension:a(f,$.extension,t.extension,e.extension),withObject:a(l,$.withObject,t.withObject,e.withObject),rmWhitespace:a(l,$.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:a(l,$.watch,t.watch,e.watch),chokidar:a(p,$.export,t.export,e.export),token:S({},$.token,t.token,e.token),vars:S({},$.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()}))},_=function(t,e){return new Promise((function(n,r){C.readFile(M(t,e),(function(t,e){t?r(t):n(e.toString())}))}))},L=function(){function t(e,r,i){n(this,t),this.cache=r,this.watcher={unwatch:function(){},on:function(){}},this.compiler=i,this.configure(e)}return i(t,[{key:"configure",value:function(t){var e=this;this.path=t.path,this.chokidar=t.chokidar,this.resolver=h(t.resolver)?t.resolver:m()?_:U,t.watch&&m()&&(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 h(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}(),N=[{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,"('")}}],W=function(){function t(e){n(this,t),this.configure(e)}return i(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]},N.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,r=this.vars,i=r.SCOPE,o=r.SAFE,c=r.BUFFER,u=r.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,a,h,f="".concat(c,"('");s=this.regex,a=function(e,r,i){f+=(""+t.slice(r,i)).replace(k,(function(t){return"\\"+g[t]})),e.forEach((function(t,e){t&&(f+=n.formats[e](t))}))},h=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return a(t,h,e),h=e+n.length,n})),f="try{".concat(f+="');","}catch(e){console.info(e)}"),this.withObject&&(f="with(".concat(i,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(i,u,c,o,f)).source="(function(".concat(i,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),q="undefined"!=typeof globalThis?globalThis:window||self,I=function(){function t(e){n(this,t),o(this,"list",{}),this.configure(e),!1===m()&&this.load(q[this.namespace])}return i(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return S(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 r=[],i=-1===D.indexOf(t),o=function(t,e,n){var r=[];return B(t,(function(t,n,i){var o=e(t,n,i);!1===v(o)&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[x(e),[X,x(t),X].join("")].join("=")})).join(K);return r.push([J,t,K,o,V].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([J,Y,t,V].join("")),r.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 i(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,i=n.LAYOUT,o=n.BLOCKS,c=n.BUFFER,u=n.MACRO,s=n.COMPONENT;function a(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),S(this,t)}this.create=function(t){return new a(t)},this.helpers=function(t){S(a.prototype,t)},a.prototype=S({},e||{}),a.define=a.method=function(t,e,n,r,i){return Object.defineProperty(a.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:i||!1})},a.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}()),a.define(o,{},!0),a.define(u,{},!0),a.define(i,!1,!0),a.define(r,!1,!0),a.method("initBlocks",(function(){this[o]={}})),a.method("initMacro",(function(){this[u]={}})),a.method("getMacro",(function(){return this[u]})),a.method("getBuffer",(function(){return this[c]})),a.method("getComponent",(function(){var t=this;return s in t?function(){return t[s].apply(t,arguments)}:function(){console.log("%s function not defined",s)}})),a.method("getBlocks",(function(){return this[o]})),a.method("setExtend",(function(t){this[r]=t})),a.method("getExtend",(function(){return this[r]})),a.method("setLayout",(function(t){this[i]=t})),a.method("getLayout",(function(){return this[i]})),a.method("clone",(function(t){var e=[i,r,c];return!0===t&&e.push(o),P(this,e)})),a.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),a.method("echo",(function(){var t=this.getBuffer();[].slice.call(arguments).forEach(t)})),a.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),h(t)&&t.apply(n,arguments),e.restore()}})),a.method("get",(function(t,e){var n=E(this,t,!0),r=n.shift(),i=n.pop();return R(r,i)?r[i]:e})),a.method("set",(function(t,e){var n=E(this,t,!1),r=n.shift(),i=n.pop();return this.getExtend()&&R(r,i)?r[i]:r[i]=e})),a.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),i=this;n[t]=function(){return i.echo(r.apply(void 0,arguments))}})),a.method("call",(function(t){var e=this.getMacro()[t],n=[].slice.call(arguments,1);if(h(e))return e.apply(e,n)})),a.method("block",(function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var i=Object.assign([],r[t]),o=function(){return i.shift()};this.echo(o()(function t(){var e=o();return e?function(){n.echo(e(t()))}:F}()))}})),a.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=S(r,e||{}),o=this.render(t,i);this.echo(o)})),a.method("use",(function(t,e){var n=this.require(t);this.echo(A(n,(function(t){var n=this.getMacro();B(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),a.method("async",(function(t,e){this.echo(A(t,(function(t){return this.fn(e)(t)}),this))})),a.method("node",(function(t,e,n){return z(t,e,n)})),a.method("el",(function(t,e,n){h(n)&&(n=this.fn(n)()),this.echo(A(n,(function(n){return z(t,e,n)}),this))})),a.method("each",(function(t,e){f(t)&&(t=this.get(t,[])),B(t,e)}))}}]),t}(),Q=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 W(this.config),this.cache=new I(this.config),this.template=new L(this.config,this.cache,this.compiler),this.helpers({require:this.require,render:this.render})}return i(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(),j)}))}},{key:"render",value:function(t,e){var n=this,r=O(t,this.config.extension),i=this.context.create(e);return this.output(r,i).then((function(t){if(i.getExtend()){i.setExtend(!1);var e=i.getLayout(),r=i.clone();return n.render(e,r)}return t}))}},{key:"require",value:function(t){var e=O(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(S(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){h(e)&&(n=e,e={});var r=S({},(e=e||{}).settings),i=a(f,$.path,r.views),o=a(l,$.cache,r["view cache"]),c=S({},r["view options"]),u=C.relative(i,t);return c.path=i,c.cache=o,this.configure(c),this.render(u,e).then((function(t){n(null,t)})).catch((function(t){n(t)}))}}]),t}(),Z=new Q({}),tt=Z.__express,et=Z.render,nt=Z.context,rt=Z.compile,it=Z.helpers,ot=Z.preload,ct=Z.configure,ut=Z.create;t.EJS=Q,t.__express=tt,t.compile=rt,t.configure=ct,t.context=nt,t.create=ut,t.element=z,t.helpers=it,t.preload=ot,t.render=et,t.safeValue=j}));
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.59",
6
+ "version": "0.0.60",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "browser": "dist/umd/index.js",