@kosatyi/ejs 0.0.50 → 0.0.52

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.
@@ -34,6 +34,9 @@ var entities = function entities() {
34
34
  return htmlEntities[match];
35
35
  });
36
36
  };
37
+ var safeValue = function safeValue(value, escape, check) {
38
+ return (check = value) == null ? '' : escape ? entities(check) : check;
39
+ };
37
40
  var each = function each(object, callback) {
38
41
  var prop;
39
42
  for (prop in object) {
@@ -82,3 +85,4 @@ var element = function element(tag, attrs, content) {
82
85
  };
83
86
 
84
87
  exports.element = element;
88
+ exports.safeValue = safeValue;
package/dist/cjs/index.js CHANGED
@@ -754,11 +754,7 @@ var configSchema = function configSchema(config, options) {
754
754
  vars: extend({}, defaults.vars, config.vars, options.vars)
755
755
  });
756
756
  };
757
- var init = function init(options) {
758
- /**
759
- * EJS template
760
- * @module ejs
761
- */
757
+ var create = function create(options) {
762
758
  var config = {};
763
759
  var scope = {};
764
760
  configSchema(config, options || {});
@@ -779,14 +775,14 @@ var init = function init(options) {
779
775
  return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
780
776
  });
781
777
  };
782
- var _require = function require(name) {
778
+ var require = function require(name) {
783
779
  var filepath = ext(name, config.extension);
784
780
  var scope = context.create({});
785
781
  return output(filepath, scope).then(function () {
786
782
  return scope.getMacro();
787
783
  });
788
784
  };
789
- var _render = function render(name, data) {
785
+ var render = function render(name, data) {
790
786
  var filepath = ext(name, config.extension);
791
787
  var scope = context.create(data);
792
788
  return output(filepath, scope).then(function (content) {
@@ -794,7 +790,7 @@ var init = function init(options) {
794
790
  scope.setExtend(false);
795
791
  var layout = scope.getLayout();
796
792
  var _data = scope.clone();
797
- return _render(layout, _data);
793
+ return render(layout, _data);
798
794
  }
799
795
  return content;
800
796
  });
@@ -816,7 +812,7 @@ var init = function init(options) {
816
812
  viewOptions.path = viewPath;
817
813
  viewOptions.cache = viewCache;
818
814
  configure(viewOptions);
819
- return _render(filename, options).then(function (content) {
815
+ return render(filename, options).then(function (content) {
820
816
  callback(null, content);
821
817
  })["catch"](function (error) {
822
818
  callback(error);
@@ -828,37 +824,29 @@ var init = function init(options) {
828
824
  var compile = function compile(content, path) {
829
825
  return compiler.compile(content, path);
830
826
  };
831
- var create = function create(options) {
832
- return init(options);
833
- };
834
827
  helpers({
835
- require: function require(name) {
836
- return _require(name);
837
- },
838
- render: function render(name, data) {
839
- return _render(name, data);
840
- }
828
+ require: require,
829
+ render: render
841
830
  });
842
831
  return {
843
- render: _render,
832
+ context: context,
833
+ render: render,
844
834
  helpers: helpers,
845
835
  configure: configure,
846
836
  compile: compile,
847
837
  create: create,
848
838
  preload: preload,
849
- context: context,
850
839
  __express: __express
851
840
  };
852
841
  };
853
- var _init = init({}),
854
- context = _init.context,
855
- render = _init.render,
856
- helpers = _init.helpers,
857
- configure = _init.configure,
858
- compile = _init.compile,
859
- create = _init.create,
860
- preload = _init.preload,
861
- __express = _init.__express;
842
+ var _create = create({}),
843
+ context = _create.context,
844
+ render = _create.render,
845
+ helpers = _create.helpers,
846
+ configure = _create.configure,
847
+ compile = _create.compile,
848
+ preload = _create.preload,
849
+ __express = _create.__express;
862
850
 
863
851
  exports.__express = __express;
864
852
  exports.compile = compile;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -36,6 +36,10 @@ const entities = (string = '') => {
36
36
  )
37
37
  };
38
38
 
39
+ const safeValue = (value, escape, check) => {
40
+ return (check = value) == null ? '' : escape ? entities(check) : check
41
+ };
42
+
39
43
  const each = (object, callback) => {
40
44
  let prop;
41
45
  for (prop in object) {
@@ -107,4 +111,4 @@ const element = (tag, attrs, content) => {
107
111
  return result.join('')
108
112
  };
109
113
 
110
- export { element };
114
+ export { element, safeValue };
package/dist/esm/index.js CHANGED
@@ -780,11 +780,7 @@ const configSchema = (config, options) => {
780
780
  });
781
781
  };
782
782
 
783
- const init = (options) => {
784
- /**
785
- * EJS template
786
- * @module ejs
787
- */
783
+ const create = (options) => {
788
784
  const config = {};
789
785
  const scope = {};
790
786
 
@@ -868,27 +864,21 @@ const init = (options) => {
868
864
  callback(error);
869
865
  })
870
866
  };
867
+
871
868
  const preload = (list) => cache.load(list);
869
+
872
870
  const compile = (content, path) => compiler.compile(content, path);
873
- const create = (options) => {
874
- return init(options)
875
- };
876
- helpers({
877
- require(name) {
878
- return require(name)
879
- },
880
- render(name, data) {
881
- return render(name, data)
882
- },
883
- });
871
+
872
+ helpers({ require, render });
873
+
884
874
  return {
875
+ context,
885
876
  render,
886
877
  helpers,
887
878
  configure,
888
879
  compile,
889
880
  create,
890
881
  preload,
891
- context,
892
882
  __express,
893
883
  }
894
884
  };
@@ -899,9 +889,8 @@ const {
899
889
  helpers,
900
890
  configure,
901
891
  compile,
902
- create,
903
892
  preload,
904
893
  __express,
905
- } = init({});
894
+ } = create({});
906
895
 
907
896
  export { __express, compile, configure, context, create, element, helpers, preload, render, safeValue };
package/dist/umd/index.js CHANGED
@@ -750,11 +750,7 @@
750
750
  vars: extend({}, defaults.vars, config.vars, options.vars)
751
751
  });
752
752
  };
753
- var init = function init(options) {
754
- /**
755
- * EJS template
756
- * @module ejs
757
- */
753
+ var create = function create(options) {
758
754
  var config = {};
759
755
  var scope = {};
760
756
  configSchema(config, options || {});
@@ -775,14 +771,14 @@
775
771
  return callback.call(scope, scope, scope.getComponent(), scope.getBuffer(), safeValue);
776
772
  });
777
773
  };
778
- var _require = function require(name) {
774
+ var require = function require(name) {
779
775
  var filepath = ext(name, config.extension);
780
776
  var scope = context.create({});
781
777
  return output(filepath, scope).then(function () {
782
778
  return scope.getMacro();
783
779
  });
784
780
  };
785
- var _render = function render(name, data) {
781
+ var render = function render(name, data) {
786
782
  var filepath = ext(name, config.extension);
787
783
  var scope = context.create(data);
788
784
  return output(filepath, scope).then(function (content) {
@@ -790,7 +786,7 @@
790
786
  scope.setExtend(false);
791
787
  var layout = scope.getLayout();
792
788
  var _data = scope.clone();
793
- return _render(layout, _data);
789
+ return render(layout, _data);
794
790
  }
795
791
  return content;
796
792
  });
@@ -812,7 +808,7 @@
812
808
  viewOptions.path = viewPath;
813
809
  viewOptions.cache = viewCache;
814
810
  configure(viewOptions);
815
- return _render(filename, options).then(function (content) {
811
+ return render(filename, options).then(function (content) {
816
812
  callback(null, content);
817
813
  })["catch"](function (error) {
818
814
  callback(error);
@@ -824,37 +820,29 @@
824
820
  var compile = function compile(content, path) {
825
821
  return compiler.compile(content, path);
826
822
  };
827
- var create = function create(options) {
828
- return init(options);
829
- };
830
823
  helpers({
831
- require: function require(name) {
832
- return _require(name);
833
- },
834
- render: function render(name, data) {
835
- return _render(name, data);
836
- }
824
+ require: require,
825
+ render: render
837
826
  });
838
827
  return {
839
- render: _render,
828
+ context: context,
829
+ render: render,
840
830
  helpers: helpers,
841
831
  configure: configure,
842
832
  compile: compile,
843
833
  create: create,
844
834
  preload: preload,
845
- context: context,
846
835
  __express: __express
847
836
  };
848
837
  };
849
- var _init = init({}),
850
- context = _init.context,
851
- render = _init.render,
852
- helpers = _init.helpers,
853
- configure = _init.configure,
854
- compile = _init.compile,
855
- create = _init.create,
856
- preload = _init.preload,
857
- __express = _init.__express;
838
+ var _create = create({}),
839
+ context = _create.context,
840
+ render = _create.render,
841
+ helpers = _create.helpers,
842
+ configure = _create.configure,
843
+ compile = _create.compile,
844
+ preload = _create.preload,
845
+ __express = _create.__express;
858
846
 
859
847
  exports.__express = __express;
860
848
  exports.compile = compile;
@@ -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={};function r(t){return r="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},r(t)}function o(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 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&&i(t.prototype,e),n&&i(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)}n.export="ejsPrecompiled",n.watch=!1,n.path="views",n.resolver=null,n.extension="ejs",n.rmWhitespace=!0,n.withObject=!0,n.vars={SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},n.token={start:"<%",end:"%>",regex:"([\\s\\S]+?)"};var s=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},a=function(t){return"function"==typeof t},h=function(t){return"string"==typeof t},f=function(t){return"boolean"==typeof t},l=function(t){return"object"===r(t)},p=function(t){return void 0===t},v="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),m=function(){return v},d={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},g={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},y=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},b=y(g),w=y(d),x=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(b,(function(t){return g[t]}))},k=function(t,e,n){return null==(n=t)?"":e?x(n):n},j=function(t,e){var n=t,r=e.split("."),o=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,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 r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},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 r=t instanceof Array,o=r?[]:{};return S(t,(function(t,n,i){var c=e(t,n,i);!1===p(c)&&(r?o.push(c):o[n]=c)})),o}(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)},$=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],M=" ",T='"',C="/",U="<",A=">",_=function(t,e,n){var r=[],o=-1===$.indexOf(t),i=function(t,e,n){var r=[];return S(t,(function(t,n,o){var i=e(t,n,o);!1===p(i)&&r.push(i)})),r}(e,(function(t,e){if(null!=t)return[x(e),[T,x(t),T].join("")].join("=")})).join(M);return r.push([U,t,M,i,A].join("")),n&&r.push(n instanceof Array?n.join(""):n),o&&r.push([U,C,t,A].join("")),r.join("")},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){o(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]},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,r=this.vars,o=r.SCOPE,i=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,o){f+=(""+t.slice(r,o)).replace(w,(function(t){return"\\"+d[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(o,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(o,u,c,i,f)).source="(function(".concat(o,",").concat(u,",").concat(c,",").concat(i,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),W=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},q=function(t,e){return fetch(W(t,e)).then((function(t){return t.text()}))},D=function(t,n){return new Promise((function(r,o){e.readFile(W(t,n),(function(t,e){t?o(t):r(e.toString())}))}))},K=function(){function t(e,n,r){o(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return c(t,[{key:"configure",value:function(t){var e=this;this.path=t.path,this.chokidar=t.chokidar,this.resolver=a(t.resolver)?t.resolver:m()?D:q,t.watch&&t.chokidar&&m()&&(this.watcher&&this.watcher.unwatch("."),this.watcher=this.chokidar.watch(".",{cwd:this.path}).on("change",(function(t){e.cache.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 a(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}(),X=function(t){return Promise.all(t).then((function(t){return t.join("")}))},Y=function(){function t(e){o(this,t),this.configure(e)}return c(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,o=n.LAYOUT,i=n.BLOCKS,c=n.BUFFER,u=n.MACRO,s=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,r,o){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:o||!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(),X(n)},n.error=function(t){throw t},n.end=function(){return X(e)},n}()),f.define(i,{},!0),f.define(u,{},!0),f.define(o,!1,!0),f.define(r,!1,!0),f.method("initBlocks",(function(){this[i]={}})),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 s in t?function(){return t[s].apply(t,arguments)}:function(){console.log("%s function not defined",s)}})),f.method("getBlocks",(function(){return this[i]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[o]=t})),f.method("getLayout",(function(){return this[o]})),f.method("clone",(function(t){var e=[o,r,c];return!0===t&&e.push(i),B(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(),a(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=j(this,t),r=n.shift(),o=n.pop();return R(r,o)?r[o]:e})),f.method("set",(function(t,e){var n=j(this,t),r=n.shift(),o=n.pop();return this.getExtend()&&R(r,o)?r[o]:r[o]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),o=this;n[t]=function(){return o.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(a(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 o=Object.assign([],r[t]),i=function(){return o.shift()};this.echo(i()(function t(){var e=i();return e?function(){n.echo(e(t()))}:F}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),o=O(r,e||{}),i=this.render(t,o);this.echo(i)})),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,r){n[[e,r].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 _(t,e,n)})),f.method("el",(function(t,e,n){a(n)&&(n=this.fn(n)()),this.echo(P(n,(function(n){return _(t,e,n)}),this))})),f.method("each",(function(t,e){h(t)&&(t=this.get(t,[])),S(t,e)}))}}]),t}(),V="undefined"!=typeof globalThis?globalThis:window||self,z=function(){function t(e){var n,r,i;o(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===m()&&this.load(V[this.namespace])}return c(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}(),G=function(t,e){O(t,{path:s(h,n.path,t.path,e.path),export:s(h,n.export,t.export,e.export),resolver:s(a,n.resolver,t.resolver,e.resolver),extension:s(h,n.extension,t.extension,e.extension),withObject:s(f,n.withObject,t.withObject,e.withObject),rmWhitespace:s(f,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:s(f,n.watch,t.watch,e.watch),chokidar:s(l,n.export,t.export,e.export),token:O({},n.token,t.token,e.token),vars:O({},n.vars,t.vars,e.vars)})},H=function t(r){var o={},i={};G(o,r||{});var c=new Y(o),u=new N(o),l=new z(o),p=new K(o,l,u),v=function(t){return G(o,t),c.configure(o,i),u.configure(o),l.configure(o),p.configure(o),o},m=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),k)}))},d=function(t,e){var n=E(t,o.extension),r=c.create(e);return m(n,r).then((function(t){if(r.getExtend()){r.setExtend(!1);var e=r.getLayout(),n=r.clone();return d(e,n)}return t}))},g=function(t){c.helpers(O(i,t||{}))};return g({require:function(t){return function(t){var e=E(t,o.extension),n=c.create({});return m(e,n).then((function(){return n.getMacro()}))}(t)},render:function(t,e){return d(t,e)}}),{render:d,helpers:g,configure:v,compile:function(t,e){return u.compile(t,e)},create:function(e){return t(e)},preload:function(t){return l.load(t)},context:c,__express:function(t,r,o){a(r)&&(o=r,r={});var i=O({},(r=r||{}).settings),c=s(h,n.path,i.views),u=s(f,n.cache,i["view cache"]),l=O({},i["view options"]),p=e.relative(c,t);return l.path=c,l.cache=u,v(l),d(p,r).then((function(t){o(null,t)})).catch((function(t){o(t)}))}}}({}),I=H.context,J=H.render,Q=H.helpers,Z=H.configure,tt=H.compile,et=H.create,nt=H.preload,rt=H.__express;t.__express=rt,t.compile=tt,t.configure=Z,t.context=I,t.create=et,t.element=_,t.helpers=Q,t.preload=nt,t.render=J,t.safeValue=k,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={};function r(t){return r="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},r(t)}function o(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 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&&i(t.prototype,e),n&&i(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)}n.export="ejsPrecompiled",n.watch=!1,n.path="views",n.resolver=null,n.extension="ejs",n.rmWhitespace=!0,n.withObject=!0,n.vars={SCOPE:"ejs",COMPONENT:"ui",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},n.token={start:"<%",end:"%>",regex:"([\\s\\S]+?)"};var s=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},a=function(t){return"function"==typeof t},h=function(t){return"string"==typeof t},f=function(t){return"boolean"==typeof t},l=function(t){return"object"===r(t)},p=function(t){return void 0===t},v="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),m=function(){return v},d={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},g={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},y=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},b=y(g),w=y(d),x=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return(""+t).replace(b,(function(t){return g[t]}))},k=function(t,e,n){return null==(n=t)?"":e?x(n):n},j=function(t,e){var n=t,r=e.split("."),o=r.pop();return r.forEach((function(t){n=n[t]=n[t]||{}})),[n,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 r=e.shift();return e.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),r)},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 r=t instanceof Array,o=r?[]:{};return S(t,(function(t,n,i){var c=e(t,n,i);!1===p(c)&&(r?o.push(c):o[n]=c)})),o}(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)},$=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],M=" ",T='"',C="/",U="<",A=">",_=function(t,e,n){var r=[],o=-1===$.indexOf(t),i=function(t,e,n){var r=[];return S(t,(function(t,n,o){var i=e(t,n,o);!1===p(i)&&r.push(i)})),r}(e,(function(t,e){if(null!=t)return[x(e),[T,x(t),T].join("")].join("=")})).join(M);return r.push([U,t,M,i,A].join("")),n&&r.push(n instanceof Array?n.join(""):n),o&&r.push([U,C,t,A].join("")),r.join("")},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){o(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]},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,r=this.vars,o=r.SCOPE,i=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,o){f+=(""+t.slice(r,o)).replace(w,(function(t){return"\\"+d[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(o,"){").concat(f,"}")),f="".concat(c,".start();").concat(f,"return ").concat(c,".end();"),f+="\n//# sourceURL=".concat(e);var l=null;try{(l=new Function(o,u,c,i,f)).source="(function(".concat(o,",").concat(u,",").concat(c,",").concat(i,"){\n").concat(f,"\n})")}catch(t){throw t.filename=e,t.source=f,t}return l}}]),t}(),W=function(t,e){return e=(e=[t,e].join("/")).replace(/\/\//g,"/")},q=function(t,e){return fetch(W(t,e)).then((function(t){return t.text()}))},D=function(t,n){return new Promise((function(r,o){e.readFile(W(t,n),(function(t,e){t?o(t):r(e.toString())}))}))},K=function(){function t(e,n,r){o(this,t),this.cache=n,this.watcher=null,this.compiler=r,this.configure(e)}return c(t,[{key:"configure",value:function(t){var e=this;this.path=t.path,this.chokidar=t.chokidar,this.resolver=a(t.resolver)?t.resolver:m()?D:q,t.watch&&t.chokidar&&m()&&(this.watcher&&this.watcher.unwatch("."),this.watcher=this.chokidar.watch(".",{cwd:this.path}).on("change",(function(t){e.cache.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 a(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}(),X=function(t){return Promise.all(t).then((function(t){return t.join("")}))},Y=function(){function t(e){o(this,t),this.configure(e)}return c(t,[{key:"configure",value:function(t,e){var n=t.vars,r=n.EXTEND,o=n.LAYOUT,i=n.BLOCKS,c=n.BUFFER,u=n.MACRO,s=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,r,o){return Object.defineProperty(f.prototype,t,{value:e,writable:n||!1,configurable:r||!1,enumerable:o||!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(),X(n)},n.error=function(t){throw t},n.end=function(){return X(e)},n}()),f.define(i,{},!0),f.define(u,{},!0),f.define(o,!1,!0),f.define(r,!1,!0),f.method("initBlocks",(function(){this[i]={}})),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 s in t?function(){return t[s].apply(t,arguments)}:function(){console.log("%s function not defined",s)}})),f.method("getBlocks",(function(){return this[i]})),f.method("setExtend",(function(t){this[r]=t})),f.method("getExtend",(function(){return this[r]})),f.method("setLayout",(function(t){this[o]=t})),f.method("getLayout",(function(){return this[o]})),f.method("clone",(function(t){var e=[o,r,c];return!0===t&&e.push(i),B(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(),a(t)&&t.apply(n,arguments),e.restore()}})),f.method("get",(function(t,e){var n=j(this,t),r=n.shift(),o=n.pop();return R(r,o)?r[o]:e})),f.method("set",(function(t,e){var n=j(this,t),r=n.shift(),o=n.pop();return this.getExtend()&&R(r,o)?r[o]:r[o]=e})),f.method("macro",(function(t,e){var n=this.getMacro(),r=this.fn(e),o=this;n[t]=function(){return o.echo(r.apply(void 0,arguments))}})),f.method("call",(function(t){var e=this.getMacro(),n=e[t],r=[].slice.call(arguments,1);if(a(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 o=Object.assign([],r[t]),i=function(){return o.shift()};this.echo(i()(function t(){var e=i();return e?function(){n.echo(e(t()))}:F}()))}})),f.method("include",(function(t,e,n){var r=!1===n?{}:this.clone(!0),o=O(r,e||{}),i=this.render(t,o);this.echo(i)})),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,r){n[[e,r].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 _(t,e,n)})),f.method("el",(function(t,e,n){a(n)&&(n=this.fn(n)()),this.echo(P(n,(function(n){return _(t,e,n)}),this))})),f.method("each",(function(t,e){h(t)&&(t=this.get(t,[])),S(t,e)}))}}]),t}(),V="undefined"!=typeof globalThis?globalThis:window||self,z=function(){function t(e){var n,r,i;o(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===m()&&this.load(V[this.namespace])}return c(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}(),G=function(t,e){O(t,{path:s(h,n.path,t.path,e.path),export:s(h,n.export,t.export,e.export),resolver:s(a,n.resolver,t.resolver,e.resolver),extension:s(h,n.extension,t.extension,e.extension),withObject:s(f,n.withObject,t.withObject,e.withObject),rmWhitespace:s(f,n.rmWhitespace,t.rmWhitespace,e.rmWhitespace),watch:s(f,n.watch,t.watch,e.watch),chokidar:s(l,n.export,t.export,e.export),token:O({},n.token,t.token,e.token),vars:O({},n.vars,t.vars,e.vars)})},H=function t(r){var o={},i={};G(o,r||{});var c=new Y(o),u=new N(o),l=new z(o),p=new K(o,l,u),v=function(t){return G(o,t),c.configure(o,i),u.configure(o),l.configure(o),p.configure(o),o},m=function(t,e){return p.get(t).then((function(t){return t.call(e,e,e.getComponent(),e.getBuffer(),k)}))},d=function t(e,n){var r=E(e,o.extension),i=c.create(n);return m(r,i).then((function(e){if(i.getExtend()){i.setExtend(!1);var n=i.getLayout(),r=i.clone();return t(n,r)}return e}))},g=function(t){c.helpers(O(i,t||{}))};return g({require:function(t){var e=E(t,o.extension),n=c.create({});return m(e,n).then((function(){return n.getMacro()}))},render:d}),{context:c,render:d,helpers:g,configure:v,compile:function(t,e){return u.compile(t,e)},create:t,preload:function(t){return l.load(t)},__express:function(t,r,o){a(r)&&(o=r,r={});var i=O({},(r=r||{}).settings),c=s(h,n.path,i.views),u=s(f,n.cache,i["view cache"]),l=O({},i["view options"]),p=e.relative(c,t);return l.path=c,l.cache=u,v(l),d(p,r).then((function(t){o(null,t)})).catch((function(t){o(t)}))}}},I=H({}),J=I.context,Q=I.render,Z=I.helpers,tt=I.configure,et=I.compile,nt=I.preload,rt=I.__express;t.__express=rt,t.compile=et,t.configure=tt,t.context=J,t.create=H,t.element=_,t.helpers=Z,t.preload=nt,t.render=Q,t.safeValue=k,Object.defineProperty(t,"__esModule",{value:!0})}));
package/element.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ export declare const safeValue: (
2
+ value: string,
3
+ escape: boolean,
4
+ check: any
5
+ ) => string
6
+
1
7
  export declare const element: (
2
8
  tag: string,
3
9
  attrs: object,
package/global.d.ts CHANGED
@@ -1,44 +1,91 @@
1
+ declare function expressCallback(
2
+ error: null | object,
3
+ content: string
4
+ ): undefined
5
+
1
6
  declare global {
7
+ /**
8
+ *
9
+ */
10
+ export const context: any
11
+
12
+ /**
13
+ *
14
+ * @param name
15
+ * @param options
16
+ * @param callback
17
+ */
18
+ export function __express(
19
+ name: string,
20
+ options: object,
21
+ callback: typeof expressCallback
22
+ ): Promise<any>
23
+
24
+ /**
25
+ *
26
+ * @param name
27
+ * @param data
28
+ */
29
+ export function render(name: string, data: object): Promise<any>
30
+
31
+ /**
32
+ *
33
+ * @param options
34
+ */
35
+ export function configure(options: object): object
36
+
37
+ /**
38
+ *
39
+ * @param methods
40
+ */
41
+ export function helpers(methods: object): any
42
+
43
+ /**
44
+ *
45
+ * @param list
46
+ */
47
+ export function preload(list: object): any
48
+
2
49
  /**
3
50
  * extend layout with blocks in current template file
4
51
  * @param layout
5
52
  */
6
- function extend(layout: string)
53
+ function extend(layout: string): any
7
54
 
8
55
  /**
9
56
  * define block with custom **name** and callback
10
57
  * @param name
11
58
  * @param [callback]
12
59
  */
13
- function block(name: string, callback?)
60
+ function block(name: string, callback?): any
14
61
 
15
62
  /**
16
63
  * set property in current scope
17
64
  * @param path
18
65
  * @param value
19
66
  */
20
- function set(path: string, value: any)
67
+ function set(path: string, value: any): any
21
68
 
22
69
  /**
23
70
  * get property in current scope
24
71
  * @param path
25
72
  * @param defaults
26
73
  */
27
- function get(path: string, defaults?: any)
74
+ function get(path: string, defaults?: any): any
28
75
 
29
76
  /**
30
77
  * import macro from file **path** and set to current scope **name** property
31
78
  * @param path
32
79
  * @param name
33
80
  */
34
- function use(path: string, name: string)
81
+ function use(path: string, name: string): any
35
82
 
36
83
  /**
37
84
  * define macro function with custom **name**
38
85
  * @param name
39
86
  * @param callback
40
87
  */
41
- function macro(name: string, callback)
88
+ function macro(name: string, callback: any): any
42
89
 
43
90
  /**
44
91
  * call macro function
@@ -46,20 +93,20 @@ declare global {
46
93
  * @param props
47
94
  * @param callback
48
95
  */
49
- function call(name: string, props?: object, callback?)
96
+ function call(name: string, props?: object, callback?: any): any
50
97
 
51
98
  /**
52
99
  * asynchronous template execution
53
100
  * @param promise
54
101
  * @param callback
55
102
  */
56
- function async(promise: Promise<any>, callback?)
103
+ function async(promise: Promise<any>, callback?: any): any
57
104
 
58
105
  /**
59
106
  * asynchronous template execution
60
107
  * @param callback
61
108
  */
62
- function fn(callback: Function)
109
+ function fn(callback: Function): any
63
110
 
64
111
  /**
65
112
  *
@@ -67,13 +114,13 @@ declare global {
67
114
  * @param {object} attrs
68
115
  * @param {function} content
69
116
  */
70
- function el(tag: string, attrs?: object, content?: any)
117
+ function el(tag: string, attrs?: object, content?: any): any
71
118
 
72
119
  /**
73
120
  * buffer output
74
- * @param any
121
+ * @param args
75
122
  */
76
- function echo(...any)
123
+ function echo(...args: any[]): any
77
124
 
78
125
  /**
79
126
  * append rendered template from file
@@ -81,21 +128,21 @@ declare global {
81
128
  * @param data
82
129
  * @param cx
83
130
  */
84
- function include(path: string, data?: object, cx?: boolean)
131
+ function include(path: string, data?: object, cx?: boolean): any
85
132
 
86
133
  /**
87
134
  *
88
135
  * @param value
89
136
  * @param callback
90
137
  */
91
- function each(value: any, callback: Function)
138
+ function each(value: any, callback: Function): any
92
139
 
93
140
  /**
94
141
  * define block with custom **name** and callback
95
142
  * @param {string} name
96
143
  * @param {object} [props]
97
144
  */
98
- function ui(name: string, props?)
145
+ function ui(name: string, props?: object): any
99
146
  }
100
147
 
101
148
  export = global
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.50",
6
+ "version": "0.0.52",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "browser": "dist/umd/index.js",