@kosatyi/ejs 0.0.58 → 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,23 +187,25 @@ 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 BreakException = {};
127
- var getPath = function getPath(context, name, create) {
190
+ var getPath = function getPath(context, name, strict) {
128
191
  var data = context;
129
- var chunk = name.split('.');
130
- var prop = chunk.pop();
192
+ var chunks = name.split('.');
193
+ var prop = chunks.pop();
194
+ var _iterator = _createForOfIteratorHelper(chunks),
195
+ _step;
131
196
  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;
197
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
198
+ var part = _step.value;
199
+ if (strict && data.hasOwnProperty(part) === false) {
200
+ data = {};
201
+ break;
139
202
  }
140
- });
141
- } catch (e) {
142
- if (e !== BreakException) throw e;
203
+ data = data[part] = data[part] || {};
204
+ }
205
+ } catch (err) {
206
+ _iterator.e(err);
207
+ } finally {
208
+ _iterator.f();
143
209
  }
144
210
  return [data, prop];
145
211
  };
@@ -677,13 +743,13 @@ var Context = /*#__PURE__*/function () {
677
743
  };
678
744
  });
679
745
  Scope.method('get', function (name, defaults) {
680
- var path = getPath(this, name, false);
746
+ var path = getPath(this, name, true);
681
747
  var result = path.shift();
682
748
  var prop = path.pop();
683
749
  return hasProp(result, prop) ? result[prop] : defaults;
684
750
  });
685
751
  Scope.method('set', function (name, value) {
686
- var path = getPath(this, name, true);
752
+ var path = getPath(this, name, false);
687
753
  var result = path.shift();
688
754
  var prop = path.pop();
689
755
  if (this.getExtend() && hasProp(result, prop)) {
package/dist/esm/index.js CHANGED
@@ -62,24 +62,16 @@ const safeValue = (value, escape, check) => {
62
62
  return (check = value) == null ? '' : escape ? entities(check) : check
63
63
  };
64
64
 
65
- const BreakException = {};
66
-
67
- const getPath = (context, name, create) => {
65
+ const getPath = (context, name, strict) => {
68
66
  let data = context;
69
- let chunk = name.split('.');
70
- let prop = chunk.pop();
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
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
+ }
74
+ data = data[part] = data[part] || {};
83
75
  }
84
76
  return [data, prop]
85
77
  };
@@ -685,14 +677,14 @@ class Context {
685
677
  });
686
678
 
687
679
  Scope.method('get', function (name, defaults) {
688
- const path = getPath(this, name, false);
680
+ const path = getPath(this, name, true);
689
681
  const result = path.shift();
690
682
  const prop = path.pop();
691
683
  return hasProp(result, prop) ? result[prop] : defaults
692
684
  });
693
685
 
694
686
  Scope.method('set', function (name, value) {
695
- const path = getPath(this, name, true);
687
+ const path = getPath(this, name, false);
696
688
  const result = path.shift();
697
689
  const prop = path.pop();
698
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,23 +188,25 @@
124
188
  var safeValue = function safeValue(value, escape, check) {
125
189
  return (check = value) == null ? '' : escape ? entities(check) : check;
126
190
  };
127
- var BreakException = {};
128
- var getPath = function getPath(context, name, create) {
191
+ var getPath = function getPath(context, name, strict) {
129
192
  var data = context;
130
- var chunk = name.split('.');
131
- var prop = chunk.pop();
193
+ var chunks = name.split('.');
194
+ var prop = chunks.pop();
195
+ var _iterator = _createForOfIteratorHelper(chunks),
196
+ _step;
132
197
  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;
198
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
199
+ var part = _step.value;
200
+ if (strict && data.hasOwnProperty(part) === false) {
201
+ data = {};
202
+ break;
140
203
  }
141
- });
142
- } catch (e) {
143
- if (e !== BreakException) throw e;
204
+ data = data[part] = data[part] || {};
205
+ }
206
+ } catch (err) {
207
+ _iterator.e(err);
208
+ } finally {
209
+ _iterator.f();
144
210
  }
145
211
  return [data, prop];
146
212
  };
@@ -680,13 +746,13 @@
680
746
  };
681
747
  });
682
748
  Scope.method('get', function (name, defaults) {
683
- var path = getPath(this, name, false);
749
+ var path = getPath(this, name, true);
684
750
  var result = path.shift();
685
751
  var prop = path.pop();
686
752
  return hasProp(result, prop) ? result[prop] : defaults;
687
753
  });
688
754
  Scope.method('set', function (name, value) {
689
- var path = getPath(this, name, true);
755
+ var path = getPath(this, name, false);
690
756
  var result = path.shift();
691
757
  var prop = path.pop();
692
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),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}));
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.58",
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",