@kosatyi/ejs 0.0.34 → 0.0.35

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/ejs.cjs CHANGED
@@ -22,6 +22,7 @@ defaults.rmWhitespace = true;
22
22
  defaults.withObject = false;
23
23
  defaults.vars = {
24
24
  SCOPE: 'ejs',
25
+ COMPONENT: 'ui',
25
26
  EXTEND: '$$e',
26
27
  BUFFER: '$$a',
27
28
  LAYOUT: '$$l',
@@ -49,6 +50,9 @@ var isString = function isString(v) {
49
50
  var isBoolean = function isBoolean(v) {
50
51
  return typeof v === 'boolean';
51
52
  };
53
+ var isUndefined = function isUndefined(v) {
54
+ return typeof v === 'undefined';
55
+ };
52
56
 
53
57
  var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
54
58
  var isNode = function isNode() {
@@ -129,7 +133,7 @@ var map = function map(object, callback, context) {
129
133
  var result = [];
130
134
  each(object, function (value, key, object) {
131
135
  var item = callback(value, key, object);
132
- if (item !== undefined) {
136
+ if (isUndefined(item) === false) {
133
137
  result.push(item);
134
138
  }
135
139
  });
@@ -140,7 +144,7 @@ var filter = function filter(object, callback, context) {
140
144
  var result = isArray ? [] : {};
141
145
  each(object, function (value, key, object) {
142
146
  var item = callback(value, key, object);
143
- if (item !== undefined) {
147
+ if (isUndefined(item) === false) {
144
148
  if (isArray) {
145
149
  result.push(item);
146
150
  } else {
@@ -312,7 +316,8 @@ var Compiler = /*#__PURE__*/function () {
312
316
  var _this$vars = this.vars,
313
317
  SCOPE = _this$vars.SCOPE,
314
318
  SAFE = _this$vars.SAFE,
315
- BUFFER = _this$vars.BUFFER;
319
+ BUFFER = _this$vars.BUFFER,
320
+ COMPONENT = _this$vars.COMPONENT;
316
321
  if (this.rmWhitespace) {
317
322
  content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
318
323
  }
@@ -335,8 +340,8 @@ var Compiler = /*#__PURE__*/function () {
335
340
  source += "\n//# sourceURL=".concat(path);
336
341
  var result = null;
337
342
  try {
338
- result = new Function(SCOPE, BUFFER, SAFE, source);
339
- result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
343
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
344
+ result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
340
345
  } catch (e) {
341
346
  e.filename = path;
342
347
  e.source = source;
@@ -482,7 +487,8 @@ var Context = /*#__PURE__*/function () {
482
487
  LAYOUT = _config$vars.LAYOUT,
483
488
  BLOCKS = _config$vars.BLOCKS,
484
489
  BUFFER = _config$vars.BUFFER,
485
- MACRO = _config$vars.MACRO;
490
+ MACRO = _config$vars.MACRO,
491
+ COMPONENT = _config$vars.COMPONENT;
486
492
  this.create = function (data) {
487
493
  return new Scope(data);
488
494
  };
@@ -524,6 +530,9 @@ var Context = /*#__PURE__*/function () {
524
530
  Scope.method('getBuffer', function () {
525
531
  return this[BUFFER];
526
532
  });
533
+ Scope.method('getComponent', function () {
534
+ return this[COMPONENT];
535
+ });
527
536
  Scope.method('getBlocks', function () {
528
537
  return this[BLOCKS];
529
538
  });
@@ -656,6 +665,7 @@ var Context = /*#__PURE__*/function () {
656
665
  }
657
666
  each(object, callback);
658
667
  });
668
+ Scope.method(COMPONENT, function () {}, true);
659
669
  }
660
670
  }]);
661
671
  return Context;
@@ -747,7 +757,7 @@ var init = function init(options) {
747
757
  };
748
758
  var output = function output(path, scope) {
749
759
  return template.get(path).then(function (callback) {
750
- return callback.call(scope, scope, scope.getBuffer(), safeValue);
760
+ return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
751
761
  });
752
762
  };
753
763
  var _require = function require(name) {
package/dist/ejs.js CHANGED
@@ -16,6 +16,7 @@
16
16
  defaults.withObject = false;
17
17
  defaults.vars = {
18
18
  SCOPE: 'ejs',
19
+ COMPONENT: 'ui',
19
20
  EXTEND: '$$e',
20
21
  BUFFER: '$$a',
21
22
  LAYOUT: '$$l',
@@ -43,6 +44,9 @@
43
44
  var isBoolean = function isBoolean(v) {
44
45
  return typeof v === 'boolean';
45
46
  };
47
+ var isUndefined = function isUndefined(v) {
48
+ return typeof v === 'undefined';
49
+ };
46
50
 
47
51
  var isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
48
52
  var isNode = function isNode() {
@@ -123,7 +127,7 @@
123
127
  var result = [];
124
128
  each(object, function (value, key, object) {
125
129
  var item = callback(value, key, object);
126
- if (item !== undefined) {
130
+ if (isUndefined(item) === false) {
127
131
  result.push(item);
128
132
  }
129
133
  });
@@ -134,7 +138,7 @@
134
138
  var result = isArray ? [] : {};
135
139
  each(object, function (value, key, object) {
136
140
  var item = callback(value, key, object);
137
- if (item !== undefined) {
141
+ if (isUndefined(item) === false) {
138
142
  if (isArray) {
139
143
  result.push(item);
140
144
  } else {
@@ -306,7 +310,8 @@
306
310
  var _this$vars = this.vars,
307
311
  SCOPE = _this$vars.SCOPE,
308
312
  SAFE = _this$vars.SAFE,
309
- BUFFER = _this$vars.BUFFER;
313
+ BUFFER = _this$vars.BUFFER,
314
+ COMPONENT = _this$vars.COMPONENT;
310
315
  if (this.rmWhitespace) {
311
316
  content = content.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
312
317
  }
@@ -329,8 +334,8 @@
329
334
  source += "\n//# sourceURL=".concat(path);
330
335
  var result = null;
331
336
  try {
332
- result = new Function(SCOPE, BUFFER, SAFE, source);
333
- result.source = "(function(".concat(SCOPE, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
337
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
338
+ result.source = "(function(".concat(SCOPE, ",").concat(COMPONENT, ",").concat(BUFFER, ",").concat(SAFE, "){\n").concat(source, "\n})");
334
339
  } catch (e) {
335
340
  e.filename = path;
336
341
  e.source = source;
@@ -476,7 +481,8 @@
476
481
  LAYOUT = _config$vars.LAYOUT,
477
482
  BLOCKS = _config$vars.BLOCKS,
478
483
  BUFFER = _config$vars.BUFFER,
479
- MACRO = _config$vars.MACRO;
484
+ MACRO = _config$vars.MACRO,
485
+ COMPONENT = _config$vars.COMPONENT;
480
486
  this.create = function (data) {
481
487
  return new Scope(data);
482
488
  };
@@ -518,6 +524,9 @@
518
524
  Scope.method('getBuffer', function () {
519
525
  return this[BUFFER];
520
526
  });
527
+ Scope.method('getComponent', function () {
528
+ return this[COMPONENT];
529
+ });
521
530
  Scope.method('getBlocks', function () {
522
531
  return this[BLOCKS];
523
532
  });
@@ -650,6 +659,7 @@
650
659
  }
651
660
  each(object, callback);
652
661
  });
662
+ Scope.method(COMPONENT, function () {}, true);
653
663
  }
654
664
  }]);
655
665
  return Context;
@@ -741,7 +751,7 @@
741
751
  };
742
752
  var output = function output(path, scope) {
743
753
  return template.get(path).then(function (callback) {
744
- return callback.call(scope, scope, scope.getBuffer(), safeValue);
754
+ return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
745
755
  });
746
756
  };
747
757
  var _require = function require(name) {
package/dist/ejs.min.js CHANGED
@@ -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";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,vars:{SCOPE:"ejs",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},r=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),s=function(){return u},a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},h={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},f=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=f(h),p=f(a),v=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(l,(function(t){return h[t]}))},d=function(t,e,n){return null==(n=t)?"":e?v(n):n},m=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},g=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},y=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)},b=function(){},w=function(t,e){var n;for(n in t)x(t,n)&&e(t[n],n,t)},j=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return w(t,(function(t,n,o){var c=e(t,n,o);void 0!==c&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},k=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},x=function(t,e){return t&&t.hasOwnProperty(e)},E=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],O=" ",F='"',P="/",B="<",R=">",S=function(t,e,n){var r=[],i=-1===E.indexOf(t),o=function(t,e,n){var r=[];return w(t,(function(t,n,i){var o=e(t,n,i);void 0!==o&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[v(e),[F,v(t),F].join("")].join("=")})).join(O);return r.push([B,t,O,o,R].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([B,P,t,R].join("")),r.join("")};function $(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function U(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,M(r.key),r)}}function A(t,e,n){return e&&U(t.prototype,e),n&&U(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function M(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 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,"('")}}],_=function(){function t(e){$(this,t),this.configure(e)}return A(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]},T.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;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 u,s,h,f="".concat(c,"('");u=this.regex,s=function(e,r,i){f+=(""+t.slice(r,i)).replace(p,(function(t){return"\\"+a[t]})),e.forEach((function(t,e){t&&(f+=n.formats[e](t))}))},h=0,t.replace(u,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return s(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,c,o,f)).source="(function(".concat(i,",").concat(c,",").concat(o,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),L=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},W=function(t,e){return fetch(L(t,e)).then((function(t){return t.text()}))},C=function(t,n){return new Promise((function(r,i){e.readFile(L(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){$(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return A(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:s()?C:W,(n=this.watcher)&&n.unwatch("."),t.watch&&s()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+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 i(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=function(t){return Promise.all(t).then((function(t){return t.join("")}))},D=function(){function t(e){$(this,t),this.configure(e)}return A(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO;function h(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),y(this,t)}this.create=function(t){return new h(t)},this.helpers=function(t){y(h.prototype,t)},h.prototype=y({},e||{}),h.defineProp=h.method=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(h.prototype,t,{value:e,writable:n,configurable:r,enumerable:i})},h.defineProp(s,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(),N(n)},n.error=function(t){throw t},n.end=function(){return N(e)},n}()),h.defineProp(u,{},!0),h.defineProp(a,{},!0),h.defineProp(c,!1,!0),h.defineProp(r,!1,!0),h.method("initBlocks",(function(){this[u]={}})),h.method("initMacro",(function(){this[a]={}})),h.method("getMacro",(function(){return this[a]})),h.method("getBuffer",(function(){return this[s]})),h.method("getBlocks",(function(){return this[u]})),h.method("setExtend",(function(t){this[r]=t})),h.method("getExtend",(function(){return this[r]})),h.method("setLayout",(function(t){this[c]=t})),h.method("getLayout",(function(){return this[c]})),h.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),j(this,e)})),h.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),h.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),h.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),h.method("get",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return x(r,i)?r[i]:e})),h.method("set",(function(t,e){var n=m(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&x(r,i)?r[i]:r[i]=e})),h.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))}})),h.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),h.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()))}:b}()))}})),h.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=y(r,e||{}),o=this.render(t,i);this.echo(o)})),h.method("use",(function(t,e){var n=this.require(t);this.echo(k(n,(function(t){var n=this.getMacro();w(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),h.method("async",(function(t,e){this.echo(k(t,(function(t){return this.fn(e)(t)}),this))})),h.method("node",(function(t,e,n){return S(t,e,n)})),h.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(k(n,(function(n){return S(t,e,n)}),this))})),h.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),w(t,e)}))}}]),t}(),K="undefined"!=typeof globalThis?globalThis:window||self,X=function(){function t(e){var n,r,i;$(this,t),n=this,i={},(r=M(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===s()&&this.load(K[this.namespace])}return A(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return y(this.list,t),this}},{key:"exist",value:function(t){return x(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}(),Y=function(t,e){y(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:y({},n.token,t.token,e.token),vars:y({},n.vars,t.vars,e.vars)})},V=function t(u){var s={},a={};Y(s,u||{});var h=new D(s),f=new _(s),l=new X(s),p=new q(s,l,f),v=function(t){return Y(s,t),h.configure(s,a),f.configure(s),l.configure(s),p.configure(s),s},m=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getBuffer(),d)}))},b=function(t,e){var n=g(t,s.extension),r=h.create(e);return m(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return b(e,n)}return t}))},w=function(t){h.helpers(y(a,t||{}))};return w({require:function(t){return function(t){var e=g(t,s.extension),n=h.create({});return m(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return b(t,e)}}),{render:b,helpers:w,configure:v,compile:function(t,e){return f.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=y({},(u=u||{}).settings),h=r(o,n.path,a.views),f=r(c,n.cache,a["view cache"]),l=y({},a["view options"]),p=e.relative(h,t);return l.path=h,l.cache=f,v(l),b(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),z=V.render,G=V.helpers,H=V.configure,I=V.wrapper,J=V.compile,Q=V.create,Z=V.preload,tt=V.__express;t.__express=tt,t.compile=J,t.configure=H,t.create=Q,t.element=S,t.helpers=G,t.preload=Z,t.render=z,t.safeValue=d,t.wrapper=I,Object.defineProperty(t,"__esModule",{value:!0})}));
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";var e={},n={export:"ejsPrecompiled",cache:!0,path:"views",resolver:null,extension:"ejs",rmWhitespace:!0,withObject:!1,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(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},i=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},c=function(t){return"boolean"==typeof t},u=function(t){return void 0===t},s="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a=function(){return s},h={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},f={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},l=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},p=l(f),v=l(h),d=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(p,(function(t){return f[t]}))},m=function(t,e,n){return null==(n=t)?"":e?d(n):n},g=function(t,e){var n=t,r=e.split("."),i=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,i]},y=function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t},b=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)},w=function(){},j=function(t,e){var n;for(n in t)E(t,n)&&e(t[n],n,t)},k=function(t,e){return function(t,e,n){var r=t instanceof Array,i=r?[]:{};return j(t,(function(t,n,o){var c=e(t,n,o);!1===u(c)&&(r?i.push(c):i[n]=c)})),i}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},x=function(t,e,n){return Promise.resolve(t).then(e.bind(n))},E=function(t,e){return t&&t.hasOwnProperty(e)},O=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",P='"',B="/",R="<",S=">",$=function(t,e,n){var r=[],i=-1===O.indexOf(t),o=function(t,e,n){var r=[];return j(t,(function(t,n,i){var o=e(t,n,i);!1===u(o)&&r.push(o)})),r}(e,(function(t,e){if(null!=t)return[d(e),[P,d(t),P].join("")].join("=")})).join(F);return r.push([R,t,F,o,S].join("")),n&&r.push(n instanceof Array?n.join(""):n),i&&r.push([R,B,t,S].join("")),r.join("")};function M(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(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,U(r.key),r)}}function C(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function U(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=[{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,"('")}}],_=function(){function t(e){M(this,t),this.configure(e)}return C(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,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,f,l="".concat(c,"('");s=this.regex,a=function(e,r,i){l+=(""+t.slice(r,i)).replace(v,(function(t){return"\\"+h[t]})),e.forEach((function(t,e){t&&(l+=n.formats[e](t))}))},f=0,t.replace(s,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return a(t,f,e),f=e+n.length,n})),l="try{".concat(l+="');","}catch(e){console.info(e)}"),this.withObject&&(l="with(".concat(i,"){").concat(l,"}")),l="".concat(c,".start();").concat(l,"return ").concat(c,".end();"),l+="\n//# sourceURL=".concat(e);var p=null;try{(p=new Function(i,u,c,o,l)).source="(function(".concat(i,",").concat(u,",").concat(c,",").concat(o,"){\n").concat(l,"\n})")}catch(t){throw t.filename=e,t.source=l,t}return p}}]),t}(),L=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},N=function(t,e){return fetch(L(t,e)).then((function(t){return t.text()}))},W=function(t,n){return new Promise((function(r,i){e.readFile(L(t,n),(function(t,e){t?i(t):r(e.toString())}))}))},q=function(){function t(e,n,r){M(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return C(t,[{key:"configure",value:function(t){var n,r,o;this.path=t.path,this.resolver=i(t.resolver)?t.resolver:a()?W:N,(n=this.watcher)&&n.unwatch("."),t.watch&&a()&&(this.watcher=(r=this.cache,o=this.path,e.watch(".",{cwd:r}).on("change",(function(t){o.remove(t)})).on("error",(function(t){console.log("watcher error: "+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 i(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}(),D=function(t){return Promise.all(t).then((function(t){return t.join("")}))},K=function(){function t(e){M(this,t),this.configure(e)}return C(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,c=n.LAYOUT,u=n.BLOCKS,s=n.BUFFER,a=n.MACRO,h=n.COMPONENT;function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.initBlocks(),this.initMacro(),b(this,t)}this.create=function(t){return new f(t)},this.helpers=function(t){b(f.prototype,t)},f.prototype=b({},e||{}),f.defineProp=f.method=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];Object.defineProperty(f.prototype,t,{value:e,writable:n,configurable:r,enumerable:i})},f.defineProp(s,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(),D(n)},n.error=function(t){throw t},n.end=function(){return D(e)},n}()),f.defineProp(u,{},!0),f.defineProp(a,{},!0),f.defineProp(c,!1,!0),f.defineProp(r,!1,!0),f.method("initBlocks",(function(){this[u]={}})),f.method("initMacro",(function(){this[a]={}})),f.method("getMacro",(function(){return this[a]})),f.method("getBuffer",(function(){return this[s]})),f.method("getComponent",(function(){return this[h]})),f.method("getBlocks",(function(){return this[u]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[c]=t})),f.method("getLayout",(function(){return this[c]})),f.method("clone",(function(t){var e=[c,r,s];return!0===t&&e.push(u),k(this,e)})),f.method("extend",(function(t){this.setExtend(!0),this.setLayout(t)})),f.method("echo",(function(){var t=this.getBuffer(),e=[].slice.call(arguments);e.forEach(t)})),f.method("fn",(function(t){var e=this.getBuffer(),n=this;return function(){return e.backup(),i(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return E(r,i)?r[i]:e})),f.method("set",(function(t,e){var n=g(this,t),r=n.shift(),i=n.pop();return this.getExtend()&&E(r,i)?r[i]:r[i]=e})),f.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))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(i(n))return n.apply(n,r)})),f.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()))}:w}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),i=b(r,e||{}),o=this.render(t,i);this.echo(o)})),f.method("use",(function(t,e){var n=this.require(t);this.echo(x(n,(function(t){var n=this.getMacro();j(t,(function(t,r){n[[e,r].join(".")]=t}))}),this))})),f.method("async",(function(t,e){this.echo(x(t,(function(t){return this.fn(e)(t)}),this))})),f.method("node",(function(t,e,n){return $(t,e,n)})),f.method("el",(function(t,e,n){i(n)&&(n=this.fn(n)()),this.echo(x(n,(function(n){return $(t,e,n)}),this))})),f.method("each",(function(t,e){o(t)&&(t=this.get(t,[])),j(t,e)})),f.method(h,(function(){}),!0)}}]),t}(),X="undefined"!=typeof globalThis?globalThis:window||self,Y=function(){function t(e){var n,r,i;M(this,t),n=this,i={},(r=U(r="list"))in n?Object.defineProperty(n,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[r]=i,this.configure(e),!1===a()&&this.load(X[this.namespace])}return C(t,[{key:"configure",value:function(t){this.list={},this.namespace=t.export}},{key:"load",value:function(t){return b(this.list,t),this}},{key:"exist",value:function(t){return E(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}(),V=function(t,e){b(t,{export:r(o,n.export,t.export,e.export),path:r(o,n.path,t.path,e.path),resolver:r(i,n.resolver,t.resolver,e.resolver),extension:r(o,n.extension,t.extension,e.extension),withObject:r(c,n.withObject,t.withObject,e.withObject),rmWhitespace:r(c,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),token:b({},n.token,t.token,e.token),vars:b({},n.vars,t.vars,e.vars)})},z=function t(u){var s={},a={};V(s,u||{});var h=new K(s),f=new _(s),l=new Y(s),p=new q(s,l,f),v=function(t){return V(s,t),h.configure(s,a),f.configure(s),l.configure(s),p.configure(s),s},d=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),m)}))},g=function(t,e){var n=y(t,s.extension),r=h.create(e);return d(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return g(e,n)}return t}))},w=function(t){h.helpers(b(a,t||{}))};return w({require:function(t){return function(t){var e=y(t,s.extension),n=h.create({});return d(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return g(t,e)}}),{render:g,helpers:w,configure:v,compile:function(t,e){return f.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},__express:function(t,u,s){i(u)&&(s=u,u={});var a=b({},(u=u||{}).settings),h=r(o,n.path,a.views),f=r(c,n.cache,a["view cache"]),l=b({},a["view options"]),p=e.relative(h,t);return l.path=h,l.cache=f,v(l),g(p,u).then((function(t){s(null,t)})).catch((function(t){s(t)}))}}}({}),G=z.render,H=z.helpers,I=z.configure,J=z.wrapper,Q=z.compile,Z=z.create,tt=z.preload,et=z.__express;t.__express=et,t.compile=Q,t.configure=I,t.create=Z,t.element=$,t.helpers=H,t.preload=tt,t.render=G,t.safeValue=m,t.wrapper=J,Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/ejs.mjs CHANGED
@@ -20,6 +20,7 @@ defaults.withObject = false;
20
20
 
21
21
  defaults.vars = {
22
22
  SCOPE: 'ejs',
23
+ COMPONENT: 'ui',
23
24
  EXTEND: '$$e',
24
25
  BUFFER: '$$a',
25
26
  LAYOUT: '$$l',
@@ -42,8 +43,12 @@ const typeProp = function () {
42
43
  const isFunction = (v) => typeof v === 'function';
43
44
  const isString = (v) => typeof v === 'string';
44
45
  const isBoolean = (v) => typeof v === 'boolean';
46
+ const isUndefined = (v) => typeof v === 'undefined';
45
47
 
46
- const isNodeEnv = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
48
+ const isNodeEnv =
49
+ Object.prototype.toString.call(
50
+ typeof process !== 'undefined' ? process : 0
51
+ ) === '[object process]';
47
52
 
48
53
  const isNode = () => isNodeEnv;
49
54
 
@@ -134,7 +139,7 @@ const map = (object, callback, context) => {
134
139
  object,
135
140
  (value, key, object) => {
136
141
  let item = callback(value, key, object);
137
- if (item !== undefined) {
142
+ if (isUndefined(item) === false) {
138
143
  result.push(item);
139
144
  }
140
145
  });
@@ -148,7 +153,7 @@ const filter = (object, callback, context) => {
148
153
  object,
149
154
  (value, key, object) => {
150
155
  let item = callback(value, key, object);
151
- if (item !== undefined) {
156
+ if (isUndefined(item) === false) {
152
157
  if (isArray) {
153
158
  result.push(item);
154
159
  } else {
@@ -167,7 +172,7 @@ const omit = (object, list) => {
167
172
  })
168
173
  };
169
174
 
170
- const resolve$1 = (value,callback,context) =>
175
+ const resolve$1 = (value, callback, context) =>
171
176
  Promise.resolve(value).then(callback.bind(context));
172
177
 
173
178
  const hasProp = (object, prop) => {
@@ -262,6 +267,7 @@ class Compiler {
262
267
  constructor(config) {
263
268
  this.configure(config);
264
269
  }
270
+
265
271
  configure(config) {
266
272
  this.withObject = config.withObject;
267
273
  this.rmWhitespace = config.rmWhitespace;
@@ -293,11 +299,13 @@ class Compiler {
293
299
  'gm'
294
300
  );
295
301
  }
302
+
296
303
  truncate(value) {
297
304
  return value && value.replace(/^(?:\r\n|\r|\n)/, '')
298
305
  }
306
+
299
307
  compile(content, path) {
300
- const { SCOPE, SAFE, BUFFER } = this.vars;
308
+ const { SCOPE, SAFE, BUFFER, COMPONENT } = this.vars;
301
309
  if (this.rmWhitespace) {
302
310
  content = content
303
311
  .replace(/[\r\n]+/g, '\n')
@@ -324,8 +332,8 @@ class Compiler {
324
332
  source += `\n//# sourceURL=${path}`;
325
333
  let result = null;
326
334
  try {
327
- result = new Function(SCOPE, BUFFER, SAFE, source);
328
- result.source = `(function(${SCOPE},${BUFFER},${SAFE}){\n${source}\n})`;
335
+ result = new Function(SCOPE, COMPONENT, BUFFER, SAFE, source);
336
+ result.source = `(function(${SCOPE},${COMPONENT},${BUFFER},${SAFE}){\n${source}\n})`;
329
337
  } catch (e) {
330
338
  e.filename = path;
331
339
  e.source = source;
@@ -455,20 +463,26 @@ class Context {
455
463
  constructor(config) {
456
464
  this.configure(config);
457
465
  }
466
+
458
467
  configure(config, methods) {
459
- const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO } = config.vars;
468
+ const { EXTEND, LAYOUT, BLOCKS, BUFFER, MACRO, COMPONENT } = config.vars;
469
+
460
470
  this.create = (data) => {
461
471
  return new Scope(data)
462
472
  };
473
+
463
474
  this.helpers = (methods) => {
464
475
  extend(Scope.prototype, methods);
465
476
  };
477
+
466
478
  function Scope(data = {}) {
467
479
  this.initBlocks();
468
480
  this.initMacro();
469
481
  extend(this, data);
470
482
  }
483
+
471
484
  Scope.prototype = extend({}, methods || {});
485
+
472
486
  Scope.defineProp = Scope.method = (
473
487
  name,
474
488
  value,
@@ -483,38 +497,57 @@ class Context {
483
497
  enumerable,
484
498
  });
485
499
  };
500
+
486
501
  Scope.defineProp(BUFFER, createBuffer());
502
+
487
503
  Scope.defineProp(BLOCKS, {}, true);
504
+
488
505
  Scope.defineProp(MACRO, {}, true);
506
+
489
507
  Scope.defineProp(LAYOUT, false, true);
508
+
490
509
  Scope.defineProp(EXTEND, false, true);
510
+
491
511
  Scope.method('initBlocks', function () {
492
512
  this[BLOCKS] = {};
493
513
  });
514
+
494
515
  Scope.method('initMacro', function () {
495
516
  this[MACRO] = {};
496
517
  });
518
+
497
519
  Scope.method('getMacro', function () {
498
520
  return this[MACRO]
499
521
  });
522
+
500
523
  Scope.method('getBuffer', function () {
501
524
  return this[BUFFER]
502
525
  });
526
+
527
+ Scope.method('getComponent', function () {
528
+ return this[COMPONENT]
529
+ });
530
+
503
531
  Scope.method('getBlocks', function () {
504
532
  return this[BLOCKS]
505
533
  });
534
+
506
535
  Scope.method('setExtend', function (value) {
507
536
  this[EXTEND] = value;
508
537
  });
538
+
509
539
  Scope.method('getExtend', function () {
510
540
  return this[EXTEND]
511
541
  });
542
+
512
543
  Scope.method('setLayout', function (layout) {
513
544
  this[LAYOUT] = layout;
514
545
  });
546
+
515
547
  Scope.method('getLayout', function () {
516
548
  return this[LAYOUT]
517
549
  });
550
+
518
551
  Scope.method('clone', function (exclude_blocks) {
519
552
  const filter = [LAYOUT, EXTEND, BUFFER];
520
553
  if (exclude_blocks === true) {
@@ -522,15 +555,18 @@ class Context {
522
555
  }
523
556
  return omit(this, filter)
524
557
  });
558
+
525
559
  Scope.method('extend', function (layout) {
526
560
  this.setExtend(true);
527
561
  this.setLayout(layout);
528
562
  });
563
+
529
564
  Scope.method('echo', function () {
530
565
  const buffer = this.getBuffer();
531
566
  const params = [].slice.call(arguments);
532
567
  params.forEach(buffer);
533
568
  });
569
+
534
570
  Scope.method('fn', function (callback) {
535
571
  const buffer = this.getBuffer();
536
572
  const context = this;
@@ -542,12 +578,14 @@ class Context {
542
578
  return buffer.restore()
543
579
  }
544
580
  });
581
+
545
582
  Scope.method('get', function (name, defaults) {
546
583
  const path = getPath(this, name);
547
584
  const result = path.shift();
548
585
  const prop = path.pop();
549
586
  return hasProp(result, prop) ? result[prop] : defaults
550
587
  });
588
+
551
589
  Scope.method('set', function (name, value) {
552
590
  const path = getPath(this, name);
553
591
  const result = path.shift();
@@ -557,6 +595,7 @@ class Context {
557
595
  }
558
596
  return (result[prop] = value)
559
597
  });
598
+
560
599
  Scope.method('macro', function (name, callback) {
561
600
  const list = this.getMacro();
562
601
  const macro = this.fn(callback);
@@ -565,6 +604,7 @@ class Context {
565
604
  return context.echo(macro.apply(undefined, arguments))
566
605
  };
567
606
  });
607
+
568
608
  Scope.method('call', function (name) {
569
609
  const list = this.getMacro();
570
610
  const macro = list[name];
@@ -573,6 +613,7 @@ class Context {
573
613
  return macro.apply(macro, params)
574
614
  }
575
615
  });
616
+
576
617
  Scope.method('block', function (name, callback) {
577
618
  const blocks = this.getBlocks();
578
619
  blocks[name] = blocks[name] || [];
@@ -594,12 +635,14 @@ class Context {
594
635
  };
595
636
  this.echo(current()(next()));
596
637
  });
638
+
597
639
  Scope.method('include', function (path, data, cx) {
598
640
  const context = cx === false ? {} : this.clone(true);
599
641
  const params = extend(context, data || {});
600
642
  const promise = this.render(path, params);
601
643
  this.echo(promise);
602
644
  });
645
+
603
646
  Scope.method('use', function (path, namespace) {
604
647
  const promise = this.require(path);
605
648
  this.echo(
@@ -615,6 +658,7 @@ class Context {
615
658
  )
616
659
  );
617
660
  });
661
+
618
662
  Scope.method('async', function (promise, callback) {
619
663
  this.echo(
620
664
  resolve$1(
@@ -626,9 +670,11 @@ class Context {
626
670
  )
627
671
  );
628
672
  });
673
+
629
674
  Scope.method('node', function (tag, attr, content) {
630
675
  return element(tag, attr, content)
631
676
  });
677
+
632
678
  Scope.method('el', function (tag, attr, content) {
633
679
  if (isFunction(content)) {
634
680
  content = this.fn(content)();
@@ -643,12 +689,15 @@ class Context {
643
689
  )
644
690
  );
645
691
  });
692
+
646
693
  Scope.method('each', function (object, callback) {
647
694
  if (isString(object)) {
648
695
  object = this.get(object, []);
649
696
  }
650
697
  each(object, callback);
651
698
  });
699
+
700
+ Scope.method(COMPONENT, function () {}, true);
652
701
  }
653
702
  }
654
703
 
@@ -752,7 +801,13 @@ const init = (options) => {
752
801
 
753
802
  const output = (path, scope) => {
754
803
  return template.get(path).then(function (callback) {
755
- return callback.call(scope, scope, scope.getBuffer(), safeValue)
804
+ return callback.call(
805
+ scope,
806
+ scope,
807
+ scope.getComponent(),
808
+ scope.getBuffer(),
809
+ safeValue
810
+ )
756
811
  })
757
812
  };
758
813
 
package/global.d.ts CHANGED
@@ -3,42 +3,42 @@ declare global {
3
3
  * extend layout with blocks in current template file
4
4
  * @param layout
5
5
  */
6
- function extend(layout: string);
6
+ function extend(layout: string)
7
7
 
8
8
  /**
9
9
  * define block with custom **name** and callback
10
10
  * @param name
11
11
  * @param [callback]
12
12
  */
13
- function block(name: string, callback?);
13
+ function block(name: string, callback?)
14
14
 
15
15
  /**
16
16
  * set property in current scope
17
17
  * @param path
18
18
  * @param value
19
19
  */
20
- function set(path: string, value: any);
20
+ function set(path: string, value: any)
21
21
 
22
22
  /**
23
23
  * get property in current scope
24
24
  * @param path
25
25
  * @param defaults
26
26
  */
27
- function get(path: string, defaults?: any);
27
+ function get(path: string, defaults?: any)
28
28
 
29
29
  /**
30
30
  * import macro from file **path** and set to current scope **name** property
31
31
  * @param path
32
32
  * @param name
33
33
  */
34
- function use(path: string, name: string);
34
+ function use(path: string, name: string)
35
35
 
36
36
  /**
37
37
  * define macro function with custom **name**
38
38
  * @param name
39
39
  * @param callback
40
40
  */
41
- function macro(name: string, callback);
41
+ function macro(name: string, callback)
42
42
 
43
43
  /**
44
44
  * call macro function
@@ -46,20 +46,20 @@ declare global {
46
46
  * @param props
47
47
  * @param callback
48
48
  */
49
- function call(name: string, props?: object, callback?);
49
+ function call(name: string, props?: object, callback?)
50
50
 
51
51
  /**
52
52
  * asynchronous template execution
53
53
  * @param promise
54
54
  * @param callback
55
55
  */
56
- function async(promise: Promise<any>, callback?);
56
+ function async(promise: Promise<any>, callback?)
57
57
 
58
58
  /**
59
59
  * asynchronous template execution
60
60
  * @param callback
61
61
  */
62
- function fn(callback: Function);
62
+ function fn(callback: Function)
63
63
 
64
64
  /**
65
65
  *
@@ -67,13 +67,13 @@ declare global {
67
67
  * @param {object} attrs
68
68
  * @param {function} content
69
69
  */
70
- function el(tag: string, attrs?: object, content?: any);
70
+ function el(tag: string, attrs?: object, content?: any)
71
71
 
72
72
  /**
73
73
  * buffer output
74
74
  * @param any
75
75
  */
76
- function echo(...any);
76
+ function echo(...any)
77
77
 
78
78
  /**
79
79
  * append rendered template from file
@@ -81,16 +81,21 @@ declare global {
81
81
  * @param data
82
82
  * @param cx
83
83
  */
84
- function include(path: string, data?: object, cx?: boolean);
84
+ function include(path: string, data?: object, cx?: boolean)
85
85
 
86
86
  /**
87
87
  *
88
88
  * @param value
89
89
  * @param callback
90
90
  */
91
- function each(value:any,callback:Function);
91
+ function each(value: any, callback: Function)
92
92
 
93
+ /**
94
+ * define block with custom **name** and callback
95
+ * @param {string} name
96
+ * @param {object} [props]
97
+ */
98
+ function ui(name: string, props?)
93
99
  }
94
100
 
95
101
  export = global
96
-
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@kosatyi/ejs",
3
3
  "description": "EJS Templates",
4
4
  "homepage": "https://github.com/kosatyi/ejs",
5
- "version": "0.0.34",
5
+ "version": "0.0.35",
6
6
  "main": "dist/ejs.cjs",
7
7
  "module": "dist/ejs.mjs",
8
8
  "browser": "dist/ejs.js",
@@ -26,7 +26,8 @@
26
26
  "devDependencies": {
27
27
  "@babel/core": "^7.20.12",
28
28
  "@babel/preset-env": "^7.20.2",
29
- "@kosatyi/ejs-bundle": "^1.0.6",
29
+ "@kosatyi/ejs-bundle": "^1.0.8",
30
+ "@kosatyi/ejs": "file:./",
30
31
  "@kosatyi/rollup": "^0.0.1"
31
32
  },
32
33
  "license": "MIT",