@kosatyi/ejs 0.0.106 → 0.0.108

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.
@@ -1,3 +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,e){this.v=t,this.k=e}function n(t,e,n,r,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void n(t)}c.done?e(a):Promise.resolve(a).then(r,o)}function r(){
2
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function u(n,r,o,i){var u=r&&r.prototype instanceof s?r:s,f=Object.create(u.prototype);return c(f,"_invoke",function(n,r,o){var i,u,c,s=0,f=o||[],l=!1,p={p:0,n:0,v:t,a:h,f:h.bind(t,4),d:function(e,n){return i=e,u=0,c=t,p.n=n,a}};function h(n,r){for(u=n,c=r,e=0;!l&&s&&!o&&e<f.length;e++){var o,i=f[e],h=p.p,v=i[2];n>3?(o=v===r)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=t):i[0]<=h&&((o=n<2&&h<i[1])?(u=0,p.v=r,p.n=i[1]):h<v&&(o=n<3||i[0]>r||r>v)&&(i[4]=n,i[5]=r,p.n=v,u=0))}if(o||n>1)return a;throw l=!0,r}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&h(f,v),u=f,c=v;(e=u<2?t:c)||!l;){i||(u?u<3?(u>1&&(p.n=-1),h(u,c)):p.n=c:p.v=c);try{if(s=2,i){if(u||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,u<2&&(u=0)}else 1===u&&(e=i.return)&&e.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=t}else if((e=(l=p.n<0)?c:n.call(r,p))!==a)break}catch(e){i=t,u=1,c=e}finally{s=1}}return{value:e,done:l}}}(n,o,i),!0),f}var a={};function s(){}function f(){}function l(){}e=Object.getPrototypeOf;var p=[][o]?e(e([][o]())):(c(e={},o,(function(){return this})),e),h=l.prototype=s.prototype=Object.create(p);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,c(t,i,"GeneratorFunction")),t.prototype=Object.create(h),t}return f.prototype=l,c(h,"constructor",l),c(l,"constructor",f),f.displayName="GeneratorFunction",c(l,i,"GeneratorFunction"),c(h),c(h,i,"Generator"),c(h,o,(function(){return this})),c(h,"toString",(function(){return"[object Generator]"})),(r=function(){return{w:u,m:v}})()}function o(t,e,n,r,o){var u=i(t,e,n,r,o);return u.next().then((function(t){return t.done?t.value:u.next()}))}function i(t,e,n,o,i){return new u(r().w(t,e,n,o),i||Promise)}function u(t,n){function r(o,i,u,c){try{var a=t[o](i),s=a.value;return s instanceof e?n.resolve(s.v).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):n.resolve(s).then((function(t){a.value=t,u(a)}),(function(t){return r("throw",t,u,c)}))}catch(t){c(t)}}var o;this.next||(c(u.prototype),c(u.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",(function(){return this}))),c(this,"_invoke",(function(t,e,i){function u(){return new n((function(e,n){r(t,i,e,n)}))}return o=o?o.then(u,u):u()}),!0)}function c(t,e,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}c=function(t,e,n,r){function i(e,n){c(t,e,(function(t){return this._invoke(e,n,t)}))}e?o?o(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},c(t,e,n,r)}function a(t){var e=Object(t),n=[];for(var r in e)n.unshift(r);return function t(){for(;n.length;)if((r=n.pop())in e)return t.value=r,t.done=!1,t;return t.done=!0,t}}function s(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}throw new TypeError(typeof t+" is not iterable")}function f(){var t=r(),n=t.m(f),c=(Object.getPrototypeOf?Object.getPrototypeOf(n):n.__proto__).constructor;function l(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===c||"GeneratorFunction"===(e.displayName||e.name))}var p={throw:1,return:2,break:3,continue:3};function h(t){var e,n;return function(r){e||(e={stop:function(){return n(r.a,2)},catch:function(){return r.v},abrupt:function(t,e){return n(r.a,p[t],e)},delegateYield:function(t,o,i){return e.resultName=o,n(r.d,s(t),i)},finish:function(t){return n(r.f,t)}},n=function(t,n,o){r.p=e.prev,r.n=e.next;try{return t(n,o)}finally{e.next=r.n}}),e.resultName&&(e[e.resultName]=r.v,e.resultName=void 0),e.sent=r.v,e.next=r.n;try{return t.call(this,e)}finally{r.p=e.prev,r.n=e.next}}}return(f=function(){return{wrap:function(e,n,r,o){return t.w(h(e),n,r,o&&o.reverse())},isGeneratorFunction:l,mark:t.m,awrap:function(t,n){return new e(t,n)},AsyncIterator:u,async:function(t,e,n,r,u){return(l(e)?i:o)(h(t),e,n,r,u)},keys:a,values:s}})()}var l=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},p=function(t){return Array.isArray(t)},h=function(t){return"function"==typeof t},v=function(t){return"string"==typeof t},y=function(t){return"boolean"==typeof t},g=function(t){return void 0===t},d="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},m={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},O=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},j=O(m),w=O(b),E=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(function(t){return m[t]}))},x=function(t,e){var n=t;return null==n?"":!0===Boolean(e)?E(n):n},P=function(t,e,n){for(var r=t,o=String(e).split("."),i=o.pop(),u=0;u<o.length;u++){var c=o[u];if(h(r.toJSON)&&(r=r.toJSON()),n&&!1===r.hasOwnProperty(c)){r={};break}r=r[c]=r[c]||{}}return h(r.toJSON)&&(r=r.toJSON()),[r,i]},k=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),t)},S=function(){},T=function(t,e){var n;for(n in t)N(t,n)&&e(t[n],n,t)},F=function(t,e){return function(t,e){var n=t instanceof Array,r=n?[]:{};return T(t,(function(t,o,i){var u=e(t,o,i);!1===g(u)&&(n?r.push(u):r[o]=u)})),r}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},N=function(t,e){return t&&t.hasOwnProperty(e)},B={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(t,e){return Promise.resolve(["resolver is not defined",t,e].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},R=function(t,e){return k(t,{path:l(v,B.path,t.path,e.path),export:l(v,B.export,t.export,e.export),resolver:l(h,B.resolver,t.resolver,e.resolver),extension:l(v,B.extension,t.extension,e.extension),withObject:l(y,B.withObject,t.withObject,e.withObject),rmWhitespace:l(y,B.rmWhitespace,t.rmWhitespace,e.rmWhitespace),cache:l(y,B.cache,t.cache,e.cache),token:k({},B.token,t.token,e.token),vars:k({},B.vars,t.vars,e.vars),globalHelpers:l(p,B.globalHelpers,t.globalHelpers,e.globalHelpers)})},C=function(t,e,n){var r={path:null,resolver:null},o=function(t,e){return h(t)?t:n.compile(t,e)},i=function(t){r.path=t.path,h(t.resolver)&&(r.resolver=t.resolver)};return i(t),{get:function(t){return e.exist(t)?e.resolve(t):(n=t,r.resolver(r.path,n)).then((function(n){return function(t,n){return e.set(t,n),n}(t,o(n,t))}));var n},configure:i,compile:o}},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,"('")}}],M=function(t){var e={},n=function(t){e.withObject=t.withObject,e.rmWhitespace=t.rmWhitespace,e.token=t.token,e.vars=t.vars,e.globalHelpers=t.globalHelpers,e.matches=[],e.formats=[],e.slurp={match:"[s\t\n]*",start:[e.token.start,"_"],end:["_",e.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))})),e.regex=new RegExp(e.matches.join("|").concat("|$"),"g"),e.slurpStart=new RegExp([e.slurp.match,e.slurp.start.join("")].join(""),"gm"),e.slurpEnd=new RegExp([e.slurp.end.join(""),e.slurp.match].join(""),"gm")};return n(t),{configure:n,compile:function(t,n){var r=e.vars,o=r.SCOPE,i=r.SAFE,u=r.BUFFER,c=r.COMPONENT,a=r.ELEMENT,s=e.globalHelpers;e.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(e.slurpStart,e.token.start).replace(e.slurpEnd,e.token.end);var f,l,p,h="".concat(u,"('");f=e.regex,l=function(n,r,o){h+=(""+t.slice(r,o)).replace(w,(function(t){return"\\"+b[t]})),n.forEach((function(t,n){t&&(h+=e.formats[n](t))}))},p=0,t.replace(f,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return l(t,p,e),p=e+n.length,n})),h="try{".concat(h+="');","}catch(e){return ").concat(u,".error(e)}"),e.withObject&&(h="with(".concat(o,"){").concat(h,"}")),h="".concat(u,".start();").concat(h,"return ").concat(u,".end();"),h+="\n//# sourceURL=".concat(n);var v=null,y=[o,c,a,u,i].concat(s);try{(v=Function.apply(null,y.concat(h))).source="(function(".concat(y.join(","),"){\n").concat(h,"\n});")}catch(t){throw t.filename=n,t.source=h,t}return v}}},$="undefined"!=typeof globalThis?globalThis:window||self,L=function(){var t={},e={},n=function(n){t.enabled&&k(e,n||{})},r=function(n){if(t.enabled)return e[n]},o=function(t){delete e[t]},i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.enabled=e.cache,t.export=e.export,!1===d&&n($[t.export])};return i(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{configure:i,load:n,set:function(n,r){t.enabled&&(e[n]=r)},get:r,exist:function(n){if(t.enabled)return N(e,n)},clear:function(){Object.keys(e).forEach(o)},remove:o,resolve:function(t){return Promise.resolve(r(t))}}},U=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],_=" ",q='"',H="/",G="<",W=">",J=function(t,e,n){var r=[],o=-1===U.indexOf(t),i=function(t,e){var n=[];return T(t,(function(t,r,o){var i=e(t,r,o);!1===g(i)&&n.push(i)})),n}(e,(function(t,e){if(null!=t)return[E(e),[q,E(t),q].join("")].join("=")})).join(_);return r.push([G,t,_,i,W].join("")),n&&o&&r.push(n instanceof Array?n.join(""):n),o&&r.push([G,H,t,W].join("")),r.join("")};function I(){I.call(this)}function Y(){I.call(this)}function D(){I.call(this)}function K(t){return Promise.all(t||[]).then((function(t){return t.join("")})).catch((function(t){return t}))}function V(){var t=[],e=[],n=function(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(),K(n)},n.error=function(t){return e=t,Promise.reject(new D(e.message));var e},n.end=function(){return K(e)},n}Object.setPrototypeOf(I.prototype,Error.prototype),Object.assign(I.prototype,{code:0,getCode:function(){return this.code},getMessage:function(){return this.message},toString:function(){return this.getMessage()}}),Object.setPrototypeOf(Y.prototype,I.prototype),Object.assign(Y.prototype,{code:404}),Object.setPrototypeOf(D.prototype,I.prototype),Object.assign(D.prototype,{code:500});var X=Symbol("ContextScope.parentTemplate"),z=function(t,e){var n,r=function(t,e){n=function(t,e){var n=t.vars,r=n.BLOCKS,o=n.MACRO,i=n.EXTEND,u=n.LAYOUT,c=n.BUFFER,a=n.SAFE,s=n.SCOPE,f=n.COMPONENT,l=n.ELEMENT;function p(t){this[X]=null,this[r]={},this[o]={},Object.assign(this,F(t,[s,c,a,f,l]))}return Object.assign(p.prototype,e),Object.defineProperty(p.prototype,c,{value:V()}),Object.defineProperty(p.prototype,r,{value:{},writable:!0}),Object.defineProperty(p.prototype,o,{value:{},writable:!0}),Object.defineProperty(p.prototype,u,{value:!1,writable:!0}),Object.defineProperty(p.prototype,i,{value:!1,writable:!0}),Object.defineProperty(p.prototype,X,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value:function(t){return this[X]=t,this}},getParentTemplate:{value:function(){return this[X]}},useSafeValue:{get:function(){return x}},useComponent:{get:function(){return h(this[f])?this[f].bind(this):function(){throw new Error("".concat(f," must be a function"))}}},useElement:{get:function(){return h(this[l])?this[l].bind(this):function(){throw new Error("".concat(l," must be a function"))}}},getMacro:{value:function(){return this[o]}},getBuffer:{value:function(){return this[c]}},getBlocks:{value:function(){return this[r]}},setExtend:{value:function(t){return this[i]=t,this}},getExtend:{value:function(){return this[i]}},setLayout:{value:function(t){return this[u]=t,this}},getLayout:{value:function(){return this[u]}},clone:{value:function(t){var e=[u,i,c];return!0===t&&e.push(r),F(this,e)}},extend:{value:function(t){this.setExtend(!0),this.setLayout(t)}},echo:{value:function(t){var e=this.getBuffer();[].slice.call(arguments).forEach(e)}},fn:{value:function(t){var e=this.getBuffer(),n=this;return function(){if(h(t))return e.backup(),e(t.apply(n,arguments)),e.restore()}}},macro:{value:function(t,e){var n=this.getMacro(),r=this.fn(e),o=this;n[t]=function(){return o.echo(r.apply(void 0,arguments))}}},call:{value:function(t){var e=this.getMacro()[t],n=[].slice.call(arguments,1);if(h(e))return e.apply(e,n)}},block:{value: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()},u=function(){var t=i();return t?function(){n.echo(t(u()))}:S};this.echo(i()(u()))}}},hasBlock:{value:function(t){return this.getBlocks().hasOwnProperty(t)}},include:{value:function(t,e,n){var r=!1===n?{}:this.clone(!0),o=k(r,e||{}),i=this.render(t,o);this.echo(i)}},use:{value:function(t,e){var n=this;this.echo(Promise.resolve(this.require(t)).then((function(t){var r=n.getMacro();T(t,(function(t,n){r[[e,n].join(".")]=t}))})))}},async:{value:function(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value:function(t,e){var n=P(this,t,!0),r=n.shift(),o=n.pop();return N(r,o)?r[o]:e}},set:{value:function(t,e){var n=P(this,t,!1),r=n.shift(),o=n.pop();return this.getParentTemplate()&&N(r,o)?r[o]:r[o]=e}},each:{value:function(t,e){v(t)&&(t=this.get(t,[])),T(t,e)},writable:!0},el:{value:function(t,e,n){n=h(n)?this.fn(n)():n,this.echo(Promise.resolve(n).then((function(n){return J(t,e,n)})))},writable:!0},ui:{value:function(t){},writable:!0}}),p}(t,e)};return r(t,e),{configure:r,create:function(t){return new n(t)},helpers:function(t){k(n.prototype,t||{})}}},Q=function(){var t=R({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),e={},n=z(t,e),r=M(t),o=L(t),i=C(t,o,r),u=function(e){return function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t}(e,t.extension)},c=function(t){var e=p({});return v(u(t),e).then((function(){return e.getMacro()}))},a=function(t,e){var n=p(e);return v(u(t),n).then(s(t,n))},s=function(t,e){return function(n){return e.getExtend()?(e.setExtend(!1),f(e.getLayout(),e,t)):n}},f=function(t,e,n){var r=p(e);return n&&r.setParentTemplate(n),v(u(t),r).then(s(t,r))},l=function(t){n.helpers(k(e,t))},p=function(t){return n.create(t)},v=function(e,n){var r=[n,n.useComponent,n.useElement,n.getBuffer(),n.useSafeValue],o=t.globalHelpers.filter((function(t){return h(n[t])})).map((function(t){return n[t].bind(n)}));return i.get(e).then((function(t){return t.apply(n,r.concat(o))}))};return l({render:a,require:c}),{configure:function(){return R(t,(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})||{}),n.configure(t,e),r.configure(t),o.configure(t),i.configure(t),t},create:function(t){return Q(t)},createContext:p,render:a,require:c,preload:function(t){return o.load(t||{})},compile:function(t,e){return r.compile(t,e)},helpers:l}},Z={},tt=function(t,e){return(t=URL.parse(t)).protocol=e?"https:":"http:",t.origin},et=Q({cache:!1,withObject:!1,resolver:function(t,e){return new Promise((function(t,n){h(Z[e])?t(Z[e]):n(new Y)}))}}),nt=et.render,rt=et.createContext,ot=et.helpers,it=et.configure;function ut(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(Z,t)}var ct=ut;function at(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.templates,r=void 0===e?{}:e,o=t.version,i=t.secure,u=void 0===i||i;return ut(r),function(){var t,e=(t=f().mark((function t(e,n){return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e.data=rt({}),e.data.set("version",o),e.data.set("origin",tt(e.req.url,u)),e.data.set("path",e.req.path),e.data.set("query",e.req.query()),e.ejs=function(t,n){return nt(t,Object.assign({param:e.req.param()},e.data,n))},e.helpers=function(t){return ot(t)},e.render=function(t,n){return e.html(e.ejs(t,n))},t.next=10,n();case 10:case"end":return t.stop()}}),t)})),function(){var e=this,r=arguments;return new Promise((function(o,i){var u=t.apply(e,r);function c(t){n(u,o,i,c,a,"next",t)}function a(t){n(u,o,i,c,a,"throw",t)}c(void 0)}))});return function(t,n){return e.apply(this,arguments)}}()}var st=at;t.TemplateError=I,t.TemplateNotFound=Y,t.TemplateSyntaxError=D,t.configure=it,t.createContext=rt,t.helpers=ot,t.render=nt,t.setRenderer=st,t.setTemplates=ct,t.useRenderer=at,t.useTemplates=ut}));
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).ejsInstance={})}(this,(function(t){"use strict";const e=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,s=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},r=t=>Array.isArray(t),i=t=>"function"==typeof t,n=t=>"string"==typeof t,o=t=>"boolean"==typeof t,c="ejsPrecompiled",a=!0,h="views",l="ejs",u=!0,p=!0,f=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),g=[],m={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},d={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},v=(t,v)=>{return Object.assign(t,{path:s(n,h,t.path,v.path),precompiled:s(n,c,t.export,v.export),resolver:s(i,f,t.resolver,v.resolver),extension:s(n,l,t.extension,v.extension),strict:s(o,p,t.strict,v.strict),rmWhitespace:s(o,u,t.rmWhitespace,v.rmWhitespace),cache:s(o,a,t.cache,v.cache),globals:s(r,g,t.globals,(b=v.globals,!!r(b)&&b.filter((t=>{const s=e.test(t);return!1===s&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),s})))),token:Object.assign({},d,t.token,v.token),vars:Object.assign({},m,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},y={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},x=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=x(y),E=x(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>y[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let r=t,n=String(e).split("."),o=n.pop();for(let t=0;t<n.length;t++){const e=n[t];if(i(r.toJSON)&&(r=r.toJSON()),s&&!1===r.hasOwnProperty(e)){r={};break}r=r[e]=r[e]||{}}return i(r.toJSON)&&(r=r.toJSON()),[r,o]},P=(t,e)=>{let s;for(s in t)C(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},C=(t,e)=>t&&Object.hasOwn(t,e),S=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,r=e.length;s<r;s++){const r=e[s];r in t&&(t[r]=t[r].bind(t))}};class T{#t;#e;#s;#r;static exports=["configure","get","compile"];constructor(t,e,s){S(this,this.constructor.exports),this.#s=e,this.#r=s,this.configure(t??{})}configure(t){this.#t=t.path,i(t.resolver)&&(this.#e=t.resolver)}#i(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t));return this.#s.set(t,s),s}compile(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#r.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#i(t).then((e=>this.compile(e,t)))}}const N=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class B{#n={};static exports=["compile"];constructor(t){S(this,this.constructor.exports),this.configure(t)}configure(t){this.#n.strict=t.strict,this.#n.rmWhitespace=t.rmWhitespace,this.#n.token=t.token,this.#n.vars=t.vars,this.#n.globals=t.globals,this.#n.legacy=t.legacy??!0,this.#n.slurp={match:"[s\t\n]*",start:[this.#n.token.start,"_"],end:["_",this.#n.token.end]},this.#n.matches=[],this.#n.formats=[];for(const[t,e]of N)this.#n.matches.push(this.#n.token.start.concat(t).concat(this.#n.token.regex).concat(this.#n.token.end)),this.#n.formats.push(e);this.#n.regex=new RegExp(this.#n.matches.join("|").concat("|$"),"g"),this.#n.slurpStart=new RegExp([this.#n.slurp.match,this.#n.slurp.start.join("")].join(""),"gm"),this.#n.slurpEnd=new RegExp([this.#n.slurp.end.join(""),this.#n.slurp.match].join(""),"gm"),this.#n.globals.length&&(this.#n.legacy?this.#n.globalVariables=`const ${this.#n.globals.map((t=>`${t}=${this.#n.vars.SCOPE}.${t}`)).join(",")};`:this.#n.globalVariables=`const {${this.#n.globals.join(",")}} = ${this.#n.vars.SCOPE};`)}compile(t,e){const s=this.#n.globalVariables,{SCOPE:r,SAFE:i,BUFFER:n,COMPONENT:o,ELEMENT:c}=this.#n.vars;this.#n.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#n.slurpStart,this.#n.token.start).replace(this.#n.slurpEnd,this.#n.token.end);let a=`${n}('`;((t,e,s)=>{let r=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),i=t.shift();return s(t,r,e),r=e+i.length,i}))})(this.#n.regex,t,((e,s,r)=>{a+=(""+t.slice(s,r)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(a+=this.#n.formats[e](t.trim(),n,i))}))})),a+="');",a=`try{${a}}catch(e){return ${n}.error(e,'${e}')}`,!1===this.#n.strict&&(a=`with(${r}){${a}}`),a=`${n}.start();${a}return ${n}.end();`,a+=`\n//# sourceURL=${e}`,s&&(a=`${s}\n${a}`);try{const t=[r,o,c,n,i],e=Function.apply(null,t.concat(a));return e.source=`(function(${t.join(",")}){\n${a}\n});`,e}catch(t){throw t.filename=e,t.source=a,t}}}class L{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#o;#c={};constructor(t){S(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#c[t]}set(t,e){this.#s&&(this.#c[t]=e)}exist(t){if(this.#s)return this.#c.hasOwnProperty(t)}clear(){Object.keys(this.#c).forEach(this.remove)}remove(t){delete this.#c[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#c,t||{})}configure(t){this.#s=t.cache,this.#o=t.precompiled,"object"==typeof window&&this.load(window[this.#o])}}const A=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],M=" ",q='"',F="/",R="<",U=">",W=t=>{let[e,s]=t;if(null!=s)return[$(e),[q,$(s),q].join("")].join("=")};class V extends Error{name="TemplateError";constructor(t){super(t),t instanceof Error&&(this.stack=t.stack,this.filename=t.filename,this.lineno=t.lineno)}}class J extends V{name="TemplateNotFound";code=404}class _ extends V{name="TemplateSyntaxError";code=500}const z=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>t)),D=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),z(s)},s.error=(t,e)=>{return s=t,Promise.reject(new _(s));var s},s.end=()=>z(e),s},K=Symbol("EjsContext.parentTemplate"),X=(t,e)=>{const{BLOCKS:s,MACRO:r,EXTEND:o,LAYOUT:c,BUFFER:a,SAFE:h,SCOPE:l,COMPONENT:u,ELEMENT:p}=t.vars,f=t.globals||[];function g(t){this[K]=null,this[s]={},this[r]={},Object.assign(this,k(t,[l,a,h,u,p]))}return Object.entries(e).forEach((t=>{let[e,s]=t;i(s)&&f.includes(e)&&(s=s.bind(g.prototype)),g.prototype[e]=s})),Object.defineProperty(g.prototype,a,{value:D()}),Object.defineProperty(g.prototype,s,{value:{},writable:!0}),Object.defineProperty(g.prototype,r,{value:{},writable:!0}),Object.defineProperty(g.prototype,c,{value:!1,writable:!0}),Object.defineProperty(g.prototype,o,{value:!1,writable:!0}),Object.defineProperty(g.prototype,K,{value:null,writable:!0}),Object.defineProperties(g.prototype,{setParentTemplate:{value(t){return this[K]=t,this}},getParentTemplate:{value(){return this[K]}},useSafeValue:{get:()=>O},useComponent:{get(){return i(this[u])?this[u].bind(this):()=>{throw new Error(`${u} must be a function`)}}},useElement:{get(){return i(this[p])?this[p].bind(this):()=>{throw new Error(`${p} must be a function`)}}},useBuffer:{get(){return this[a]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[o]=t,this}},getExtend:{value(){return this[o]}},setLayout:{value(t){return this[c]=t,this}},getLayout:{value(){return this[c]}},clone:{value(t){const e=[c,o,a];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){return()=>{if(i(t))return this.useBuffer.backup(),this.useBuffer(t.apply(this,arguments)),this.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),r=this.fn(e),i=this;s[t]=function(){return i.echo(r.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(i(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const r=Object.assign([],s[t]),i=()=>r.shift(),n=()=>{const t=i();return t?()=>{this.echo(t(n()))}:()=>{}};this.echo(i()(n()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const r=!1===s?{}:this.clone(!0),i=Object.assign(r,e||{}),n=this.render(t,i);this.echo(n)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,r)=>{s[[e,r].join(".")]=t}))})))}},async:{value(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value(t,e){const s=w(this,t,!0),r=s.shift(),i=s.pop();return C(r,i)?r[i]:e}},set:{value(t,e){const s=w(this,t,!1),r=s.shift(),i=s.pop();return this.getParentTemplate()&&C(r,i)?r[i]:r[i]=e}},each:{value(t,e){n(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=i(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const r=[],i=-1===A.indexOf(t),n=Object.entries(e??{}).map(W).filter((t=>t)).join(M);return r.push([R,t,M,n,U].join("")),s&&i&&r.push(Array.isArray(s)?s.join(""):s),i&&r.push([R,F,t,U].join("")),r.join("")})(t,e,s))))},writable:!0},ui:{value(t){},writable:!0}}),g};class Y{#a;static exports=["create","globals","helpers"];constructor(t,e){S(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#a(t)}helpers(t){Object.assign(this.#a.prototype,t)}configure(t,e){this.#a=X(t,e)}}const Z={},{render:I,createContext:G,helpers:H,configure:Q}=new class{#s;#a;#r;#h;#n={};#l={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};S(this,this.constructor.exports),this.#l={},this.#n=v({},t),this.#a=new Y(this.#n,this.#l),this.#r=new B(this.#n),this.#s=new L(this.#n),this.#h=new T(this.#n,this.#s,this.#r),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#n,t),this.#a.configure(this.#n,this.#l),this.#r.configure(this.#n),this.#s.configure(this.#n),this.#h.configure(this.#n)),this.#n}createContext(t){return this.#a.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#r.compile(t,e)}helpers(t){this.#a.helpers(Object.assign(this.#l,t))}async render(t,e){const s=this.createContext(e);return this.#u(this.#t(t),s).then(this.#p(t,s))}async require(t){const e=this.createContext({});return this.#u(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#n.extension&&(t=[t,this.#n.extension].join(".")),t}#u(t,e){return this.#h.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useSafeValue])))}#f(t,e,s){const r=this.createContext(e);return s&&r.setParentTemplate(s),this.#u(this.#t(t),r).then(this.#p(t,r))}#p(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#f(e.getLayout(),e,t)):s}}({cache:!1,strict:!0,async resolver(t,e){if(i(Z[e]))return Z[e];throw new J(`template ${e} not found`)}});function tt(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object.assign(Z,t)}t.TemplateError=V,t.TemplateNotFound=J,t.TemplateSyntaxError=_,t.configure=Q,t.createContext=G,t.helpers=H,t.render=I,t.useRenderer=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return tt(t.templates??{}),async(e,s)=>{var r,i;e.data=G({}),e.data.set("version",t.version),e.data.set("origin",(r=e.req.url,i=t.secure??!0,(r=URL.parse(r)).protocol=i?"https:":"http:",r.origin)),e.data.set("path",e.req.path),e.data.set("query",e.req.query()),e.ejs=async(t,s)=>I(t,Object.assign({param:e.req.param()},e.data,s)),e.helpers=t=>H(t),e.render=async(t,s)=>e.html(e.ejs(t,s)),await s()}},t.useTemplates=tt}));
package/package.json CHANGED
@@ -1,78 +1,87 @@
1
1
  {
2
- "name": "@kosatyi/ejs",
3
- "description": "EJS Templates",
4
- "homepage": "https://github.com/kosatyi/ejs",
5
- "type": "module",
6
- "version": "0.0.106",
7
- "main": "dist/cjs/index.js",
8
- "module": "dist/esm/index.js",
9
- "browser": "dist/umd/browser.js",
10
- "minified": "dist/umd/browser.min.js",
11
- "author": "Stepan Kosatyi (https://kosatyi.com)",
12
- "bin": {
13
- "ejs-bundler": "bin/bundler.js"
14
- },
15
- "exports": {
16
- ".": {
17
- "import": "./dist/esm/index.js",
18
- "require": "./dist/cjs/index.js"
2
+ "name": "@kosatyi/ejs",
3
+ "description": "EJS Templates",
4
+ "homepage": "https://github.com/kosatyi/ejs",
5
+ "type": "module",
6
+ "version": "0.0.108",
7
+ "main": "dist/cjs/index.js",
8
+ "module": "dist/esm/index.js",
9
+ "browser": "dist/umd/browser.js",
10
+ "minified": "dist/umd/browser.min.js",
11
+ "author": "Stepan Kosatyi (https://kosatyi.com)",
12
+ "browserslist": [
13
+ "> 0.25%, not dead"
14
+ ],
15
+ "bin": {
16
+ "ejs-bundler": "bin/bundler.js"
19
17
  },
20
- "./browser": {
21
- "import": "./dist/esm/browser.js",
22
- "require": "./dist/cjs/browser.js"
18
+ "exports": {
19
+ ".": {
20
+ "types": "./types/index.d.ts",
21
+ "import": "./dist/esm/index.js",
22
+ "require": "./dist/cjs/index.js"
23
+ },
24
+ "./browser": {
25
+ "types": "./types/browser.d.ts",
26
+ "import": "./dist/esm/browser.js",
27
+ "require": "./dist/cjs/browser.js"
28
+ },
29
+ "./worker": {
30
+ "types": "./types/worker.d.ts",
31
+ "import": "./dist/esm/worker.js",
32
+ "require": "./dist/cjs/worker.js"
33
+ },
34
+ "./element": {
35
+ "types": "./types/element.d.ts",
36
+ "import": "./dist/esm/element.js",
37
+ "require": "./dist/cjs/element.js"
38
+ },
39
+ "./bundler": {
40
+ "types": "./types/bundler.d.ts",
41
+ "import": "./dist/esm/bundler.js",
42
+ "require": "./dist/cjs/bundler.js"
43
+ }
23
44
  },
24
- "./worker": {
25
- "import": "./dist/esm/worker.js",
26
- "require": "./dist/cjs/worker.js"
45
+ "files": [
46
+ "bin",
47
+ "dist",
48
+ "types"
49
+ ],
50
+ "scripts": {
51
+ "build": "rollup -c",
52
+ "watch": "rollup -c -w",
53
+ "pack": "npm pack --pack-destination dist",
54
+ "version": "npm run build",
55
+ "prepublishOnly": "npm i && rollup -c",
56
+ "postversion": "git push && git push --tags"
27
57
  },
28
- "./element": {
29
- "import": "./dist/esm/element.js",
30
- "require": "./dist/cjs/element.js"
58
+ "license": "MIT",
59
+ "bugs": {
60
+ "url": "https://github.com/kosatyi/ejs/issues"
31
61
  },
32
- "./bundler": {
33
- "import": "./dist/esm/bundler.js",
34
- "require": "./dist/cjs/bundler.js"
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/kosatyi/ejs.git"
65
+ },
66
+ "keywords": [
67
+ "ejs",
68
+ "ejs-express",
69
+ "ejs-cloudflare",
70
+ "ejs-template-engine"
71
+ ],
72
+ "peerDependencies": {
73
+ "glob": "11.x || 12.x || 13.x",
74
+ "glob-watcher": "6.x",
75
+ "process.argv": "1.x"
76
+ },
77
+ "devDependencies": {
78
+ "@babel/preset-env": "^7.28.6",
79
+ "@rollup/plugin-babel": "^6.1.0",
80
+ "@rollup/plugin-commonjs": "^29.0.0",
81
+ "@rollup/plugin-node-resolve": "^16.0.3",
82
+ "@rollup/plugin-terser": "^0.4.4",
83
+ "rollup": "^4.57.0",
84
+ "rollup-plugin-copy": "^3.5.0",
85
+ "rollup-plugin-ignore": "^1.0.10"
35
86
  }
36
- },
37
- "files": [
38
- "bin",
39
- "dist",
40
- "types"
41
- ],
42
- "scripts": {
43
- "build": "rollup -c",
44
- "watch": "rollup -c -w",
45
- "version": "npm run build",
46
- "prepublishOnly": "npm i && rollup -c",
47
- "postversion": "git push && git push --tags"
48
- },
49
- "license": "MIT",
50
- "bugs": {
51
- "url": "https://github.com/kosatyi/ejs/issues"
52
- },
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/kosatyi/ejs.git"
56
- },
57
- "keywords": [
58
- "ejs",
59
- "ejs-express",
60
- "ejs-cloudflare",
61
- "ejs-template-engine"
62
- ],
63
- "peerDependencies": {
64
- "glob": "11.x || 12.x || 13.x",
65
- "process.argv": "1.x",
66
- "glob-watcher": "6.x"
67
- },
68
- "devDependencies": {
69
- "@babel/preset-env": "^7.26.0",
70
- "@rollup/plugin-babel": "^6.0.4",
71
- "@rollup/plugin-commonjs": "^28.0.1",
72
- "@rollup/plugin-node-resolve": "^15.3.0",
73
- "@rollup/plugin-terser": "^0.4.4",
74
- "rollup": "^4.28.1",
75
- "rollup-plugin-copy": "^3.5.0",
76
- "rollup-plugin-ignore": "^1.0.10"
77
- }
78
87
  }
@@ -0,0 +1,10 @@
1
+ export {
2
+ create,
3
+ render,
4
+ createContext,
5
+ configure,
6
+ helpers,
7
+ preload,
8
+ } from './ejs'
9
+
10
+ export { TemplateError, TemplateSyntaxError, TemplateNotFound } from './error'
@@ -1,24 +1,23 @@
1
1
  import type { Plugin } from 'rollup'
2
-
3
- export interface EjsConfig {
4
- path?: string
5
- export?: string | 'ejsPrecompiled'
6
- extension?: 'ejs'
7
- withObject?: false
8
- [key: string]: any
9
- }
2
+ import { EjsConfig } from './ejs'
10
3
 
11
4
  export interface BundlerOptions {
12
5
  target: string[] | string
13
6
  minify?: boolean
14
- umd?: boolean,
7
+ umd?: boolean
15
8
  }
16
9
 
17
10
  export function ejsBundle(
18
11
  options: BundlerOptions | object,
19
- config: EjsConfig | object
12
+ config: EjsConfig | object,
20
13
  ): Plugin
21
14
 
22
- export class Bundler {
23
- new(options: BundlerOptions, config: EjsConfig): Bundler
15
+ export function bundler(
16
+ options: BundlerOptions,
17
+ config: EjsConfig,
18
+ ): {
19
+ build(): Promise<void>
20
+ watch(): Promise<void>
21
+ concat(): Promise<void>
22
+ output(): Promise<void>
24
23
  }
@@ -0,0 +1,96 @@
1
+ export interface EjsContext {
2
+ /**
3
+ * extend layout with blocks in current template file
4
+ * @param layout
5
+ */
6
+ extend(layout: string): any
7
+ /**
8
+ * define block with custom **name** and callback
9
+ * @param name
10
+ * @param [callback]
11
+ */
12
+ block(name: string, callback?: Function): any
13
+ /**
14
+ * append rendered template from file
15
+ * @param path
16
+ * @param data
17
+ * @param cx
18
+ */
19
+ include(path: string, data?: object, cx?: boolean): any
20
+ /**
21
+ * set property in current scope
22
+ * @param path
23
+ * @param value
24
+ */
25
+ set(path: string, value: any): any
26
+ /**
27
+ * get property in current scope
28
+ * @param path
29
+ * @param defaults
30
+ */
31
+ get(path: string, defaults?: any): any
32
+ /**
33
+ * render ejs component
34
+ * @param {string} name
35
+ * @param {object} [props]
36
+ * @param {any} [content]
37
+ */
38
+ ui(name: string, props?: object, content?: any): any
39
+ /**
40
+ * render html element
41
+ * @param {string} tag
42
+ * @param {object} [attrs]
43
+ * @param {any} [content]
44
+ */
45
+ el(tag: string, attrs?: object, content?: any): any
46
+ /**
47
+ * buffered function execution
48
+ * @param callback
49
+ */
50
+ fn(callback: Function): any
51
+ /**
52
+ * import macro from file **path** and set to current scope **name** property
53
+ * @param path
54
+ * @param name
55
+ */
56
+ use(path: string, name: string): any
57
+ /**
58
+ * define macro function with custom **name**
59
+ * @param name
60
+ * @param callback
61
+ */
62
+ macro(name: string, callback: any): any
63
+ /**
64
+ * call macro function
65
+ * @param name
66
+ * @param props
67
+ * @param callback
68
+ */
69
+ call(name: string, props?: object, callback?: any): any
70
+ /**
71
+ * asynchronous template execution
72
+ * @param promise
73
+ * @param callback
74
+ */
75
+ async(promise: Promise<any>, callback?: any): any
76
+ /**
77
+ * buffer output
78
+ * @param args
79
+ */
80
+ echo(...args: any[]): any
81
+ /**
82
+ *
83
+ * @param value
84
+ * @param callback
85
+ */
86
+ each(value: any, callback: Function): any
87
+ /**
88
+ * check if block with `name` exists
89
+ * @param name
90
+ */
91
+ hasBlock(name: string): boolean
92
+ /**
93
+ *
94
+ */
95
+ getParentTemplate(): boolean
96
+ }
package/types/ejs.d.ts CHANGED
@@ -1,92 +1,130 @@
1
- export interface EJS {
2
- /**
3
- * extend layout with blocks in current template file
4
- * @param layout
5
- */
6
- extend(layout: string): any
7
- /**
8
- * define block with custom **name** and callback
9
- * @param name
10
- * @param [callback]
11
- */
12
- block(name: string, callback?: Function): any
13
- /**
14
- * append rendered template from file
15
- * @param path
16
- * @param data
17
- * @param cx
18
- */
19
- include(path: string, data?: object, cx?: boolean): any
20
- /**
21
- * set property in current scope
22
- * @param path
23
- * @param value
24
- */
25
- set(path: string, value: any): any
26
- /**
27
- * get property in current scope
28
- * @param path
29
- * @param defaults
30
- */
31
- get(path: string, defaults?: any): any
32
- /**
33
- * render ejs component
34
- * @param {string} name
35
- * @param {object} [props]
36
- * @param {any} [content]
37
- */
38
- ui(name: string, props?: object, content?: any): any
1
+ import { EjsContext } from './context'
2
+ import { TemplateError } from './error'
3
+
4
+ export declare type EjsConfigVars = {
5
+ SCOPE: string
6
+ COMPONENT: string
7
+ ELEMENT: string
8
+ EXTEND: string
9
+ BUFFER: string
10
+ LAYOUT: string
11
+ BLOCKS: string
12
+ MACRO: string
13
+ SAFE: string
14
+ }
15
+
16
+ export declare type EjsConfigToken = {
17
+ start: string
18
+ end: string
19
+ regex: string
20
+ }
21
+
22
+ export declare type EjsConfig = {
39
23
  /**
40
- * render html element
41
- * @param {string} tag
42
- * @param {object} [attrs]
43
- * @param {any} [content]
24
+ * Global variable where the compiled templates are stored
25
+ * @default 'ejsPrecompiled'
44
26
  */
45
- el(tag: string, attrs?: object, content?: any): any
27
+ precompiled?: string
46
28
  /**
47
- * buffered function execution
48
- * @param callback
29
+ * Cache templates after compiling use false in development only
30
+ * @default true
49
31
  */
50
- fn(callback: Function): any
32
+ cache?: boolean
51
33
  /**
52
- * import macro from file **path** and set to current scope **name** property
53
- * @param path
54
- * @param name
34
+ * folder where templates are stored
35
+ * @default 'views'
55
36
  */
56
- use(path: string, name: string): any
37
+ path?: string
57
38
  /**
58
- * define macro function with custom **name**
59
- * @param name
60
- * @param callback
39
+ * Template extension in filesystem
40
+ * @default 'ejs'
61
41
  */
62
- macro(name: string, callback: any): any
42
+ extension?: string
63
43
  /**
64
- * call macro function
65
- * @param name
66
- * @param props
67
- * @param callback
44
+ * Remove all safe-to-remove whitespace, including leading and trailing
45
+ * whitespace. It also enables a safer version of `-%>` line slurping for all
46
+ * scriptlet tags (it does not strip new lines of tags in the middle of a
47
+ * line).
48
+ * @default true
68
49
  */
69
- call(name: string, props?: object, callback?: any): any
50
+ rmWhitespace?: boolean
70
51
  /**
71
- * asynchronous template execution
72
- * @param promise
73
- * @param callback
52
+ * Whether to use the `with () {}` construct in generated function templates
53
+ * If set to `false`, data is still accessible through an object whose name
54
+ * is determined in `EjsConfig.vars.SCOPE`
55
+ * @default false
74
56
  */
75
- async(promise: Promise<any>, callback?: any): any
57
+ strict?: boolean
76
58
  /**
77
- * buffer output
78
- * @param args
59
+ * Template source resolver function
60
+ * - For server templates using fs.promises.readFile
61
+ * - For client templates using window.fetch
62
+ * - For worker templates using precompiled Map of templates
79
63
  */
80
- echo(...args: any[]): any
64
+ resolver?: (
65
+ path: string,
66
+ template: string,
67
+ ) => Promise<string | TemplateError>
81
68
  /**
82
- *
83
- * @param value
84
- * @param callback
69
+ * An array of local variables that are always destructured from helpers
70
+ * available even in strict mode.
85
71
  */
86
- each(value: any, callback: Function): any
72
+ globals?: string[]
87
73
  /**
88
- * check if block with `name` exists
89
- * @param name
74
+ * Template variables
90
75
  */
91
- hasBlock(name: string): boolean
76
+ vars?: Partial<EjsConfigVars>
77
+ token?: Partial<EjsConfigToken>
78
+ }
79
+
80
+ declare type configure = <T extends EjsConfig>(options?: T) => EjsConfig & T
81
+
82
+ declare type compile = (content: string, path: string) => Function
83
+
84
+ declare type EjsMethods = { [p: string]: any }
85
+
86
+ declare type createContext = (data: { [p: string]: any }) => EjsContext
87
+
88
+ declare type render = (
89
+ name: string,
90
+ data?: { [x: string]: any },
91
+ ) => Promise<string>
92
+
93
+ declare type require = (name: string) => Promise<{ [x: string]: any }>
94
+
95
+ declare type preload = (list: { [p: string]: any }) => void
96
+
97
+ declare type helpers<T extends EjsMethods> = (
98
+ extendMethods: T,
99
+ ) => EjsContext & T
100
+
101
+ declare type create = (config: EjsConfig) => EjsInstance
102
+
103
+ declare type EjsInterface = {
104
+ configure: configure
105
+ create: create
106
+ createContext: createContext
107
+ render: render
108
+ require: require
109
+ preload: preload
110
+ compile: compile
111
+ helpers: helpers<EjsMethods>
92
112
  }
113
+
114
+ declare type EjsInstance = (config: EjsConfig) => EjsInterface
115
+
116
+ export const configure: configure
117
+
118
+ export const createContext: createContext
119
+
120
+ export const render: render
121
+
122
+ export const require: require
123
+
124
+ export const preload: preload
125
+
126
+ export const helpers: helpers<EjsMethods>
127
+
128
+ export const compile: compile
129
+
130
+ export const create: EjsInstance
@@ -0,0 +1,9 @@
1
+ export function safeValue(value: string, escape?: boolean): string | any
2
+
3
+ export function element(
4
+ tag: string,
5
+ attrs?: {
6
+ [x: string]: any
7
+ },
8
+ content?: string[] | string,
9
+ ): string
@@ -0,0 +1,14 @@
1
+ export class TemplateError extends Error {
2
+ code
3
+ new(message: string): TemplateError
4
+ toString(): string
5
+ getCode(): number
6
+ }
7
+
8
+ export class TemplateNotFound extends TemplateError {
9
+ code: 404
10
+ }
11
+
12
+ export class TemplateSyntaxError extends TemplateError {
13
+ code: 500
14
+ }
package/types/global.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import type { EJS } from './ejs'
2
-
1
+ import type { EjsContext } from './context'
2
+ import type { EjsInterface } from './ejs'
3
3
  declare global {
4
- const ejs: EJS
5
- interface Window extends EJS {}
4
+ const ejs: EjsContext
5
+ const ejsInstance: EjsInterface
6
+ interface Window extends EjsContext {}
6
7
  namespace NodeJS {
7
- interface Global extends EJS {}
8
+ interface Global extends EjsContext {}
8
9
  }
9
10
  }
10
-
11
11
  export = global
@@ -0,0 +1,16 @@
1
+ export {
2
+ create,
3
+ render,
4
+ createContext,
5
+ configure,
6
+ helpers,
7
+ preload,
8
+ } from './ejs'
9
+
10
+ export { TemplateError, TemplateSyntaxError, TemplateNotFound } from './error'
11
+
12
+ export const __express: (
13
+ name: string,
14
+ options: object,
15
+ callback: Function,
16
+ ) => any