@kosatyi/ejs 0.0.113 → 0.0.115

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.
@@ -0,0 +1,58 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { j as joinPath, t as typeProp, c as isString, d as isBoolean, i as isFunction } from './element-CEdJaM42.js';
4
+ export { e as element, a as escapeValue } from './element-CEdJaM42.js';
5
+ import { E as EjsInstance, e as ejsDefaults } from './index-BiIhwNBq.js';
6
+
7
+ const resolver = async (path, template, error) => {
8
+ return fs
9
+ .readFile(joinPath(path, template))
10
+ .then((contents) => contents.toString())
11
+ .catch((e) => {
12
+ if (e.code === 'ENOENT') {
13
+ return error(1, `template ${template} not found`)
14
+ }
15
+ return error(0, e)
16
+ })
17
+ };
18
+
19
+ const {
20
+ render,
21
+ helpers,
22
+ configure,
23
+ create,
24
+ createContext,
25
+ compile,
26
+ preload,
27
+ } = new EjsInstance({
28
+ resolver,
29
+ });
30
+
31
+ const __express = function (name, options, callback) {
32
+ if (isFunction(options)) {
33
+ callback = options;
34
+ options = {};
35
+ }
36
+ options = options || {};
37
+ const settings = Object.assign({}, options.settings);
38
+ const viewPath = typeProp(isString, ejsDefaults.path, settings['views']);
39
+ const viewCache = typeProp(
40
+ isBoolean,
41
+ ejsDefaults.cache,
42
+ settings['view cache'],
43
+ );
44
+ const viewOptions = Object.assign({}, settings['view options']);
45
+ const filename = path.relative(viewPath, name);
46
+ viewOptions.path = viewPath;
47
+ viewOptions.cache = viewCache;
48
+ configure(viewOptions);
49
+ return render(filename, options)
50
+ .then((content) => {
51
+ callback(null, content);
52
+ })
53
+ .catch((error) => {
54
+ callback(error);
55
+ })
56
+ };
57
+
58
+ export { __express, compile, configure, create, createContext, helpers, preload, render };
@@ -0,0 +1,46 @@
1
+ import { i as isFunction } from './element-CEdJaM42.js';
2
+ export { e as element, a as escapeValue } from './element-CEdJaM42.js';
3
+ import { E as EjsInstance } from './index-BiIhwNBq.js';
4
+
5
+ const templateCache = {};
6
+
7
+ const getOrigin = (url, secure) => {
8
+ url = URL.parse(url);
9
+ url.protocol = secure ? 'https:' : 'http:';
10
+ return url.origin
11
+ };
12
+
13
+ const resolver = async (path, name, error) => {
14
+ if (isFunction(templateCache[name])) {
15
+ return templateCache[name]
16
+ }
17
+ error(1, `template ${name} not found`);
18
+ };
19
+
20
+ const { render, createContext, helpers, configure } = new EjsInstance({
21
+ cache: false,
22
+ strict: true,
23
+ resolver,
24
+ });
25
+
26
+ function useTemplates(templates = {}) {
27
+ Object.assign(templateCache, templates);
28
+ }
29
+
30
+ function useRenderer(options = {}) {
31
+ useTemplates(options.templates ?? {});
32
+ return async (c, next) => {
33
+ c.data = createContext({});
34
+ c.data.set('version', options.version);
35
+ c.data.set('origin', getOrigin(c.req.url, options.secure ?? true));
36
+ c.data.set('path', c.req.path);
37
+ c.data.set('query', c.req.query());
38
+ c.ejs = async (name, data) =>
39
+ render(name, Object.assign({ param: c.req.param() }, c.data, data));
40
+ c.helpers = (methods) => helpers(methods);
41
+ c.render = async (name, data) => c.html(c.ejs(name, data));
42
+ await next();
43
+ }
44
+ }
45
+
46
+ export { configure, createContext, helpers, render, useRenderer, useTemplates };
@@ -880,7 +880,8 @@
880
880
  _defineProperty(EjsInstance, "exports", ['configure', 'create', 'createContext', 'render', 'require', 'preload', 'compile', 'helpers']);
881
881
 
882
882
  const resolver = async (path, template, error) => {
883
- return fetch(joinPath(path, template)).then(response => {
883
+ const url = new URL(joinPath(path, template), location.origin);
884
+ return fetch(url).then(response => {
884
885
  if (response.ok) return response.text();
885
886
  return error(1, "template ".concat(template, " not found"));
886
887
  }, reason => error(0, reason));
@@ -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).ejsInstance={})}(this,(function(t){"use strict";function e(t,e,s){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:s;throw new TypeError("Private element is not present on this object")}function s(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function n(t,s){return t.get(e(t,s))}function r(t,e,n){s(t,e),e.set(t,n)}function i(t,s,n){return t.set(e(t,s),n),n}function o(t,e){s(t,e),e.add(t)}function c(t,e,s){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var n=s.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function a(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,n)}return s}const h="ejsPrecompiled",l=!0,u="views",p="ejs",f=!0,g=!0,v=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),b=[],d={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},m={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},w=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,y=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},j=t=>Array.isArray(t),O=t=>"function"==typeof t,E=t=>"string"==typeof t,x=t=>"boolean"==typeof t,k=(t,e)=>{return Object.assign(t,{path:y(E,u,t.path,e.path),precompiled:y(E,h,t.export,e.export),resolver:y(O,v,t.resolver,e.resolver),extension:y(E,p,t.extension,e.extension),strict:y(x,g,t.strict,e.strict),rmWhitespace:y(x,f,t.rmWhitespace,e.rmWhitespace),cache:y(x,l,t.cache,e.cache),globals:y(j,b,t.globals,(s=e.globals,!!j(s)&&s.filter((t=>{const e=w.test(t);return!1===e&&console.log("ejsConfig.globals: expected '".concat(t,"' to be valid variable name --\x3e skipped")),e})))),token:Object.assign({},m,t.token,e.token),vars:Object.assign({},d,t.vars,e.vars)});var s},P={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},M={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},S=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),C=S(M),W=S(P),T=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(C,(t=>M[t]))},$=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?T(s):s},N=(t,e,s)=>{let n=t,r=String(e).split("."),i=r.pop();for(let t=0;t<r.length;t++){const e=r[t];if(O(n.toJSON)&&(n=n.toJSON()),s&&!1===n.hasOwnProperty(e)){n={};break}n=n[e]=n[e]||{}}return O(n.toJSON)&&(n=n.toJSON()),[n,i]},B=(t,e)=>{let s;for(s in t)L(t,s)&&e(t[s],s,t)},A=(t,e)=>{const s=function(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?a(Object(s),!0).forEach((function(e){c(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):a(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}({},t);for(const t of e)delete s[t];return s},L=(t,e)=>t&&Object.hasOwn(t,e),F=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,n=e.length;s<n;s++){const n=e[s];n in t&&(t[n]=t[n].bind(t))}};class R extends Error{constructor(t,e){super(e),this.code=t,e instanceof Error&&(this.stack=e.stack,this.message=e.message)}}const q=(t,e)=>{throw new R(t,e)};var D=new WeakMap,U=new WeakMap,V=new WeakMap,J=new WeakMap,_=new WeakSet;class z{constructor(t,e,s){o(this,_),r(this,D,void 0),r(this,U,void 0),r(this,V,void 0),r(this,J,void 0),F(this,this.constructor.exports),i(V,this,e),i(J,this,s),this.configure(null!=t?t:{})}configure(t){i(D,this,t.path),O(t.resolver)&&i(U,this,t.resolver)}get(t){return e(_,this,K).call(this,t).then((s=>e(_,this,X).call(this,s,t)))}}function K(t){const e=n(V,this).get(t);if(e instanceof Promise)return e;const s=Promise.resolve(n(U,this).call(this,n(D,this),t,q));return n(V,this).set(t,s),s}function X(t,e){const s=n(V,this).get(e);return"function"==typeof s?s:("string"==typeof t&&(t=n(J,this).compile(t,e)),"function"==typeof t?(n(V,this).set(e,t),t):void 0)}c(z,"exports",["configure","get"]);const Y=[["-",(t,e,s)=>"')\n".concat(e,"(").concat(s,"(").concat(t,",1))\n").concat(e,"('")],["=",(t,e,s)=>"')\n".concat(e,"(").concat(s,"(").concat(t,"))\n").concat(e,"('")],["#",(t,e)=>"')\n/**".concat(t,"**/\n").concat(e,"('")],["",(t,e)=>"')\n".concat(t,"\n").concat(e,"('")]];var Z=new WeakMap;class I{constructor(t){r(this,Z,{}),F(this,this.constructor.exports),this.configure(t)}configure(t){var e;n(Z,this).strict=t.strict,n(Z,this).rmWhitespace=t.rmWhitespace,n(Z,this).token=t.token,n(Z,this).vars=t.vars,n(Z,this).globals=t.globals,n(Z,this).legacy=null===(e=t.legacy)||void 0===e||e,n(Z,this).slurp={match:"[s\t\n]*",start:[n(Z,this).token.start,"_"],end:["_",n(Z,this).token.end]},n(Z,this).matches=[],n(Z,this).formats=[];for(const[t,e]of Y)n(Z,this).matches.push(n(Z,this).token.start.concat(t).concat(n(Z,this).token.regex).concat(n(Z,this).token.end)),n(Z,this).formats.push(e);n(Z,this).regex=new RegExp(n(Z,this).matches.join("|").concat("|$"),"g"),n(Z,this).slurpStart=new RegExp([n(Z,this).slurp.match,n(Z,this).slurp.start.join("")].join(""),"gm"),n(Z,this).slurpEnd=new RegExp([n(Z,this).slurp.end.join(""),n(Z,this).slurp.match].join(""),"gm"),n(Z,this).globals.length&&(n(Z,this).legacy?n(Z,this).globalVariables="const ".concat(n(Z,this).globals.map((t=>"".concat(t,"=").concat(n(Z,this).vars.SCOPE,".").concat(t))).join(","),";"):n(Z,this).globalVariables="const {".concat(n(Z,this).globals.join(","),"} = ").concat(n(Z,this).vars.SCOPE,";"))}compile(t,e){const s=n(Z,this).globalVariables,{SCOPE:r,SAFE:i,BUFFER:o,COMPONENT:c,ELEMENT:a}=n(Z,this).vars;n(Z,this).rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(n(Z,this).slurpStart,n(Z,this).token.start).replace(n(Z,this).slurpEnd,n(Z,this).token.end);let h="".concat(o,"('");((t,e,s)=>{let n=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),r=t.shift();return s(t,n,e),n=e+r.length,r}))})(n(Z,this).regex,t,((e,s,r)=>{h+=(""+t.slice(s,r)).replace(W,(t=>"\\"+P[t])),e.forEach(((t,e)=>{t&&(h+=n(Z,this).formats[e](t.trim(),o,i))}))})),h+="');",h="try{".concat(h,"}catch(e){return ").concat(o,".error(e)}"),!1===n(Z,this).strict&&(h="with(".concat(r,"){").concat(h,"}")),h="".concat(o,".start();").concat(h,"return ").concat(o,".end();"),h+="\n//# sourceURL=".concat(e),s&&(h="".concat(s,"\n").concat(h));try{const t=[r,c,a,o,i],e=Function.apply(null,t.concat(h));return e.source="(function(".concat(t.join(","),"){\n").concat(h,"\n});"),e}catch(t){t.filename=e,t.source=h,q(0,t)}}}c(I,"exports",["configure","compile"]);var G=new WeakMap,H=new WeakMap,Q=new WeakMap;class tt{constructor(t){r(this,G,!0),r(this,H,void 0),r(this,Q,{}),F(this,this.constructor.exports),this.configure(t)}get(t){if(n(G,this))return n(Q,this)[t]}set(t,e){n(G,this)&&(n(Q,this)[t]=e)}exist(t){if(n(G,this))return n(Q,this).hasOwnProperty(t)}clear(){Object.keys(n(Q,this)).forEach(this.remove)}remove(t){delete n(Q,this)[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){n(G,this)&&Object.assign(n(Q,this),t||{})}configure(t){i(G,this,t.cache),i(H,this,t.precompiled),"object"==typeof window&&this.load(window[n(H,this)])}}c(tt,"exports",["load","set","get","exist","clear","remove","resolve"]);const et=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],st=" ",nt='"',rt="/",it="<",ot=">",ct=t=>{let[e,s]=t;if(null!=s)return[T(e),[nt,T(s),nt].join("")].join("=")},at=(t,e,s)=>{const n=[],r=-1===et.indexOf(t),i=Object.entries(null!=e?e:{}).map(ct).filter((t=>t)).join(st);return n.push([it,t,st,i,ot].join("")),s&&r&&n.push(Array.isArray(s)?s.join(""):s),r&&n.push([it,rt,t,ot].join("")),n.join("")},ht=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>q(0,t))),lt=()=>{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(),ht(s)},s.error=t=>(t=>Promise.reject(q(0,t)))(t),s.end=()=>ht(e),s},ut=Symbol("EjsContext.parentTemplate"),pt=(t,e)=>{const s=t.globals||[],{BLOCKS:n,MACRO:r,EXTEND:i,LAYOUT:o,BUFFER:c,SAFE:a,SCOPE:h,COMPONENT:l,ELEMENT:u}=t.vars;class p{constructor(t){this[ut]=null,this[n]={},this[r]={},Object.assign(this,A(t,[h,c,a,l,u]))}}return Object.defineProperties(p.prototype,{[c]:{value:lt()},[n]:{value:{},writable:!0},[r]:{value:{},writable:!0},[o]:{value:!1,writable:!0},[i]:{value:!1,writable:!0},[ut]:{value:null,writable:!0},setParentTemplate:{value(t){return this[ut]=t,this}},getParentTemplate:{value(){return this[ut]}},useEscapeValue:{value:()=>$},useComponent:{value(){return O(this[l])?this[l].bind(this):function(){q(2,"".concat(l," must be a function"))}}},useElement:{value(){return O(this[u])?this[u].bind(this):()=>{q(2,"".concat(u," must be a function"))}}},useBuffer:{value(){return this[c]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[n]}},setExtend:{value(t){return this[i]=t,this}},getExtend:{value(){return this[i]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,i,c];return!0===t&&e.push(n),A(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer())}},fn:{value(t){const e=this.useBuffer(),s=this;return function(){if(O(t))return e.backup(),e(t.apply(s,arguments)),e.restore()}}},macro:{value(t,e){const s=this.getMacro(),n=this.fn(e),r=this;s[t]=function(){return r.echo(n.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(O(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 n=this,r=Object.assign([],s[t]),i=function(){return r.shift()},o=function(){const t=i();return t?function(){n.echo(t(o()))}:function(){}};this.echo(i()(o()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const n=!1===s?{}:this.clone(!0),r=Object.assign(n,e||{}),i=this.render(t,r);this.echo(i)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();B(t,((t,n)=>{s[[e,n].join(".")]=t}))})))}},get:{value(t,e){const s=N(this,t,!0),n=s.shift(),r=s.pop();return L(n,r)?n[r]:e}},set:{value(t,e){const s=N(this,t,!1),n=s.shift(),r=s.pop();return this.getParentTemplate()&&L(n,r)?n[r]:n[r]=e}},each:{value(t,e){E(t)&&(t=this.get(t,[])),B(t,e)},writable:!0},el:{value(t,e,s){s=O(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>at(t,e,s))))},writable:!0},ui:{value(){},writable:!0},require:{value(){},writable:!0},render:{value(){},writable:!0}}),Object.entries(e).forEach((t=>{let[e,n]=t;O(n)&&s.includes(e)&&(n=n.bind(p.prototype)),p.prototype[e]=n})),p};var ft=new WeakMap;class gt{constructor(t,e){r(this,ft,void 0),F(this,this.constructor.exports),this.configure(t,e)}create(t){return new(n(ft,this))(t)}helpers(t){Object.assign(n(ft,this).prototype,t)}configure(t,e){i(ft,this,pt(t,e))}}c(gt,"exports",["create","globals","helpers"]);var vt=new WeakMap,bt=new WeakMap,dt=new WeakMap,mt=new WeakMap,wt=new WeakMap,yt=new WeakMap,jt=new WeakSet;class Ot{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,jt),r(this,vt,void 0),r(this,bt,void 0),r(this,dt,void 0),r(this,mt,void 0),r(this,wt,{}),r(this,yt,{}),F(this,this.constructor.exports),i(yt,this,{}),i(wt,this,k({},t)),i(bt,this,new gt(n(wt,this),n(yt,this))),i(dt,this,new I(n(wt,this))),i(vt,this,new tt(n(wt,this))),i(mt,this,new z(n(wt,this),n(vt,this),n(dt,this))),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(k(n(wt,this),t),n(bt,this).configure(n(wt,this),n(yt,this)),n(dt,this).configure(n(wt,this)),n(vt,this).configure(n(wt,this)),n(mt,this).configure(n(wt,this))),n(wt,this)}createContext(t){return n(bt,this).create(t)}preload(t){return n(vt,this).load(t||{})}compile(t,e){return n(dt,this).compile(t,e)}helpers(t){n(bt,this).helpers(Object.assign(n(yt,this),t))}async render(t,s){const n=this.createContext(s);return e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),n).then(e(jt,this,Pt).call(this,t,n))}async require(t){const s=this.createContext({});return e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),s).then((()=>s.getMacro()))}}function Et(t){return t.split(".").pop()!==n(wt,this).extension&&(t=[t,n(wt,this).extension].join(".")),t}function xt(t,e){return n(mt,this).get(t).then((t=>t.apply(e,[e,e.useComponent(),e.useElement(),e.useBuffer(),e.useEscapeValue()])))}function kt(t,s,n){const r=this.createContext(s);return n&&r.setParentTemplate(n),e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),r).then(e(jt,this,Pt).call(this,t,r))}function Pt(t,s){return n=>s.getExtend()?(s.setExtend(!1),e(jt,this,kt).call(this,s.getLayout(),s,t)):n}c(Ot,"exports",["configure","create","createContext","render","require","preload","compile","helpers"]);const{render:Mt,configure:St,create:Ct,helpers:Wt,createContext:Tt,compile:$t,preload:Nt}=new Ot({resolver:async(t,e,s)=>fetch(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((t=>t.ok?t.text():s(1,"template ".concat(e," not found"))),(t=>s(0,t)))});t.compile=$t,t.configure=St,t.create=Ct,t.createContext=Tt,t.element=at,t.escapeValue=$,t.helpers=Wt,t.preload=Nt,t.render=Mt}));
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";function e(t,e,s){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:s;throw new TypeError("Private element is not present on this object")}function s(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}function n(t,s){return t.get(e(t,s))}function r(t,e,n){s(t,e),e.set(t,n)}function i(t,s,n){return t.set(e(t,s),n),n}function o(t,e){s(t,e),e.add(t)}function c(t,e,s){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var n=s.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function a(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,n)}return s}const h="ejsPrecompiled",l=!0,u="views",p="ejs",f=!0,g=!0,v=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),b=[],d={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},m={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},w=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,y=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},j=t=>Array.isArray(t),O=t=>"function"==typeof t,E=t=>"string"==typeof t,x=t=>"boolean"==typeof t,k=(t,e)=>{return Object.assign(t,{path:y(E,u,t.path,e.path),precompiled:y(E,h,t.export,e.export),resolver:y(O,v,t.resolver,e.resolver),extension:y(E,p,t.extension,e.extension),strict:y(x,g,t.strict,e.strict),rmWhitespace:y(x,f,t.rmWhitespace,e.rmWhitespace),cache:y(x,l,t.cache,e.cache),globals:y(j,b,t.globals,(s=e.globals,!!j(s)&&s.filter((t=>{const e=w.test(t);return!1===e&&console.log("ejsConfig.globals: expected '".concat(t,"' to be valid variable name --\x3e skipped")),e})))),token:Object.assign({},m,t.token,e.token),vars:Object.assign({},d,t.vars,e.vars)});var s},P={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},M={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"},S=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),C=S(M),W=S(P),T=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(C,(t=>M[t]))},$=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?T(s):s},N=(t,e,s)=>{let n=t,r=String(e).split("."),i=r.pop();for(let t=0;t<r.length;t++){const e=r[t];if(O(n.toJSON)&&(n=n.toJSON()),s&&!1===n.hasOwnProperty(e)){n={};break}n=n[e]=n[e]||{}}return O(n.toJSON)&&(n=n.toJSON()),[n,i]},B=(t,e)=>{let s;for(s in t)L(t,s)&&e(t[s],s,t)},A=(t,e)=>{const s=function(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?a(Object(s),!0).forEach((function(e){c(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):a(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}({},t);for(const t of e)delete s[t];return s},L=(t,e)=>t&&Object.hasOwn(t,e),R=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,n=e.length;s<n;s++){const n=e[s];n in t&&(t[n]=t[n].bind(t))}};class F extends Error{constructor(t,e){super(e),this.code=t,e instanceof Error&&(this.stack=e.stack,this.message=e.message)}}const q=(t,e)=>{throw new F(t,e)};var U=new WeakMap,D=new WeakMap,V=new WeakMap,J=new WeakMap,_=new WeakSet;class z{constructor(t,e,s){o(this,_),r(this,U,void 0),r(this,D,void 0),r(this,V,void 0),r(this,J,void 0),R(this,this.constructor.exports),i(V,this,e),i(J,this,s),this.configure(null!=t?t:{})}configure(t){i(U,this,t.path),O(t.resolver)&&i(D,this,t.resolver)}get(t){return e(_,this,K).call(this,t).then((s=>e(_,this,X).call(this,s,t)))}}function K(t){const e=n(V,this).get(t);if(e instanceof Promise)return e;const s=Promise.resolve(n(D,this).call(this,n(U,this),t,q));return n(V,this).set(t,s),s}function X(t,e){const s=n(V,this).get(e);return"function"==typeof s?s:("string"==typeof t&&(t=n(J,this).compile(t,e)),"function"==typeof t?(n(V,this).set(e,t),t):void 0)}c(z,"exports",["configure","get"]);const Y=[["-",(t,e,s)=>"')\n".concat(e,"(").concat(s,"(").concat(t,",1))\n").concat(e,"('")],["=",(t,e,s)=>"')\n".concat(e,"(").concat(s,"(").concat(t,"))\n").concat(e,"('")],["#",(t,e)=>"')\n/**".concat(t,"**/\n").concat(e,"('")],["",(t,e)=>"')\n".concat(t,"\n").concat(e,"('")]];var Z=new WeakMap;class I{constructor(t){r(this,Z,{}),R(this,this.constructor.exports),this.configure(t)}configure(t){var e;n(Z,this).strict=t.strict,n(Z,this).rmWhitespace=t.rmWhitespace,n(Z,this).token=t.token,n(Z,this).vars=t.vars,n(Z,this).globals=t.globals,n(Z,this).legacy=null===(e=t.legacy)||void 0===e||e,n(Z,this).slurp={match:"[s\t\n]*",start:[n(Z,this).token.start,"_"],end:["_",n(Z,this).token.end]},n(Z,this).matches=[],n(Z,this).formats=[];for(const[t,e]of Y)n(Z,this).matches.push(n(Z,this).token.start.concat(t).concat(n(Z,this).token.regex).concat(n(Z,this).token.end)),n(Z,this).formats.push(e);n(Z,this).regex=new RegExp(n(Z,this).matches.join("|").concat("|$"),"g"),n(Z,this).slurpStart=new RegExp([n(Z,this).slurp.match,n(Z,this).slurp.start.join("")].join(""),"gm"),n(Z,this).slurpEnd=new RegExp([n(Z,this).slurp.end.join(""),n(Z,this).slurp.match].join(""),"gm"),n(Z,this).globals.length&&(n(Z,this).legacy?n(Z,this).globalVariables="const ".concat(n(Z,this).globals.map((t=>"".concat(t,"=").concat(n(Z,this).vars.SCOPE,".").concat(t))).join(","),";"):n(Z,this).globalVariables="const {".concat(n(Z,this).globals.join(","),"} = ").concat(n(Z,this).vars.SCOPE,";"))}compile(t,e){const s=n(Z,this).globalVariables,{SCOPE:r,SAFE:i,BUFFER:o,COMPONENT:c,ELEMENT:a}=n(Z,this).vars;n(Z,this).rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(n(Z,this).slurpStart,n(Z,this).token.start).replace(n(Z,this).slurpEnd,n(Z,this).token.end);let h="".concat(o,"('");((t,e,s)=>{let n=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),r=t.shift();return s(t,n,e),n=e+r.length,r}))})(n(Z,this).regex,t,((e,s,r)=>{h+=(""+t.slice(s,r)).replace(W,(t=>"\\"+P[t])),e.forEach(((t,e)=>{t&&(h+=n(Z,this).formats[e](t.trim(),o,i))}))})),h+="');",h="try{".concat(h,"}catch(e){return ").concat(o,".error(e)}"),!1===n(Z,this).strict&&(h="with(".concat(r,"){").concat(h,"}")),h="".concat(o,".start();").concat(h,"return ").concat(o,".end();"),h+="\n//# sourceURL=".concat(e),s&&(h="".concat(s,"\n").concat(h));try{const t=[r,c,a,o,i],e=Function.apply(null,t.concat(h));return e.source="(function(".concat(t.join(","),"){\n").concat(h,"\n});"),e}catch(t){t.filename=e,t.source=h,q(0,t)}}}c(I,"exports",["configure","compile"]);var G=new WeakMap,H=new WeakMap,Q=new WeakMap;class tt{constructor(t){r(this,G,!0),r(this,H,void 0),r(this,Q,{}),R(this,this.constructor.exports),this.configure(t)}get(t){if(n(G,this))return n(Q,this)[t]}set(t,e){n(G,this)&&(n(Q,this)[t]=e)}exist(t){if(n(G,this))return n(Q,this).hasOwnProperty(t)}clear(){Object.keys(n(Q,this)).forEach(this.remove)}remove(t){delete n(Q,this)[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){n(G,this)&&Object.assign(n(Q,this),t||{})}configure(t){i(G,this,t.cache),i(H,this,t.precompiled),"object"==typeof window&&this.load(window[n(H,this)])}}c(tt,"exports",["load","set","get","exist","clear","remove","resolve"]);const et=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],st=" ",nt='"',rt="/",it="<",ot=">",ct=t=>{let[e,s]=t;if(null!=s)return[T(e),[nt,T(s),nt].join("")].join("=")},at=(t,e,s)=>{const n=[],r=-1===et.indexOf(t),i=Object.entries(null!=e?e:{}).map(ct).filter((t=>t)).join(st);return n.push([it,t,st,i,ot].join("")),s&&r&&n.push(Array.isArray(s)?s.join(""):s),r&&n.push([it,rt,t,ot].join("")),n.join("")},ht=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>q(0,t))),lt=()=>{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(),ht(s)},s.error=t=>(t=>Promise.reject(q(0,t)))(t),s.end=()=>ht(e),s},ut=Symbol("EjsContext.parentTemplate"),pt=(t,e)=>{const s=t.globals||[],{BLOCKS:n,MACRO:r,EXTEND:i,LAYOUT:o,BUFFER:c,SAFE:a,SCOPE:h,COMPONENT:l,ELEMENT:u}=t.vars;class p{constructor(t){this[ut]=null,this[n]={},this[r]={},Object.assign(this,A(t,[h,c,a,l,u]))}}return Object.defineProperties(p.prototype,{[c]:{value:lt()},[n]:{value:{},writable:!0},[r]:{value:{},writable:!0},[o]:{value:!1,writable:!0},[i]:{value:!1,writable:!0},[ut]:{value:null,writable:!0},setParentTemplate:{value(t){return this[ut]=t,this}},getParentTemplate:{value(){return this[ut]}},useEscapeValue:{value:()=>$},useComponent:{value(){return O(this[l])?this[l].bind(this):function(){q(2,"".concat(l," must be a function"))}}},useElement:{value(){return O(this[u])?this[u].bind(this):()=>{q(2,"".concat(u," must be a function"))}}},useBuffer:{value(){return this[c]}},getMacro:{value(){return this[r]}},getBlocks:{value(){return this[n]}},setExtend:{value(t){return this[i]=t,this}},getExtend:{value(){return this[i]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,i,c];return!0===t&&e.push(n),A(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer())}},fn:{value(t){const e=this.useBuffer(),s=this;return function(){if(O(t))return e.backup(),e(t.apply(s,arguments)),e.restore()}}},macro:{value(t,e){const s=this.getMacro(),n=this.fn(e),r=this;s[t]=function(){return r.echo(n.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(O(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 n=this,r=Object.assign([],s[t]),i=function(){return r.shift()},o=function(){const t=i();return t?function(){n.echo(t(o()))}:function(){}};this.echo(i()(o()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const n=!1===s?{}:this.clone(!0),r=Object.assign(n,e||{}),i=this.render(t,r);this.echo(i)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();B(t,((t,n)=>{s[[e,n].join(".")]=t}))})))}},get:{value(t,e){const s=N(this,t,!0),n=s.shift(),r=s.pop();return L(n,r)?n[r]:e}},set:{value(t,e){const s=N(this,t,!1),n=s.shift(),r=s.pop();return this.getParentTemplate()&&L(n,r)?n[r]:n[r]=e}},each:{value(t,e){E(t)&&(t=this.get(t,[])),B(t,e)},writable:!0},el:{value(t,e,s){s=O(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>at(t,e,s))))},writable:!0},ui:{value(){},writable:!0},require:{value(){},writable:!0},render:{value(){},writable:!0}}),Object.entries(e).forEach((t=>{let[e,n]=t;O(n)&&s.includes(e)&&(n=n.bind(p.prototype)),p.prototype[e]=n})),p};var ft=new WeakMap;class gt{constructor(t,e){r(this,ft,void 0),R(this,this.constructor.exports),this.configure(t,e)}create(t){return new(n(ft,this))(t)}helpers(t){Object.assign(n(ft,this).prototype,t)}configure(t,e){i(ft,this,pt(t,e))}}c(gt,"exports",["create","globals","helpers"]);var vt=new WeakMap,bt=new WeakMap,dt=new WeakMap,mt=new WeakMap,wt=new WeakMap,yt=new WeakMap,jt=new WeakSet;class Ot{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,jt),r(this,vt,void 0),r(this,bt,void 0),r(this,dt,void 0),r(this,mt,void 0),r(this,wt,{}),r(this,yt,{}),R(this,this.constructor.exports),i(yt,this,{}),i(wt,this,k({},t)),i(bt,this,new gt(n(wt,this),n(yt,this))),i(dt,this,new I(n(wt,this))),i(vt,this,new tt(n(wt,this))),i(mt,this,new z(n(wt,this),n(vt,this),n(dt,this))),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(k(n(wt,this),t),n(bt,this).configure(n(wt,this),n(yt,this)),n(dt,this).configure(n(wt,this)),n(vt,this).configure(n(wt,this)),n(mt,this).configure(n(wt,this))),n(wt,this)}createContext(t){return n(bt,this).create(t)}preload(t){return n(vt,this).load(t||{})}compile(t,e){return n(dt,this).compile(t,e)}helpers(t){n(bt,this).helpers(Object.assign(n(yt,this),t))}async render(t,s){const n=this.createContext(s);return e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),n).then(e(jt,this,Pt).call(this,t,n))}async require(t){const s=this.createContext({});return e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),s).then((()=>s.getMacro()))}}function Et(t){return t.split(".").pop()!==n(wt,this).extension&&(t=[t,n(wt,this).extension].join(".")),t}function xt(t,e){return n(mt,this).get(t).then((t=>t.apply(e,[e,e.useComponent(),e.useElement(),e.useBuffer(),e.useEscapeValue()])))}function kt(t,s,n){const r=this.createContext(s);return n&&r.setParentTemplate(n),e(jt,this,xt).call(this,e(jt,this,Et).call(this,t),r).then(e(jt,this,Pt).call(this,t,r))}function Pt(t,s){return n=>s.getExtend()?(s.setExtend(!1),e(jt,this,kt).call(this,s.getLayout(),s,t)):n}c(Ot,"exports",["configure","create","createContext","render","require","preload","compile","helpers"]);const{render:Mt,configure:St,create:Ct,helpers:Wt,createContext:Tt,compile:$t,preload:Nt}=new Ot({resolver:async(t,e,s)=>{const n=new URL(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e),location.origin);return fetch(n).then((t=>t.ok?t.text():s(1,"template ".concat(e," not found"))),(t=>s(0,t)))}});t.compile=$t,t.configure=St,t.create=Ct,t.createContext=Tt,t.element=at,t.escapeValue=$,t.helpers=Wt,t.preload=Nt,t.render=Mt}));
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.113",
6
+ "version": "0.0.115",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "browser": "dist/umd/browser.js",
@@ -1,6 +1,4 @@
1
- import { EjsMethods } from './ejs'
2
-
3
- export interface EjsContext extends EjsMethods {
1
+ export interface EjsContext {
4
2
  /**
5
3
  * extend layout with blocks in current template file
6
4
  * @param layout
package/types/ejs.d.ts CHANGED
@@ -78,8 +78,6 @@ declare type configure = <T extends EjsConfig>(options?: T) => EjsConfig & T
78
78
 
79
79
  declare type compile = (content: string, path: string) => Function
80
80
 
81
- declare type EjsMethods = { [p: string]: any }
82
-
83
81
  declare type createContext = (data: { [p: string]: any }) => EjsContext
84
82
 
85
83
  declare type render = (
@@ -91,9 +89,7 @@ declare type require = (name: string) => Promise<{ [x: string]: any }>
91
89
 
92
90
  declare type preload = (list: { [p: string]: any }) => void
93
91
 
94
- declare type helpers<T extends EjsMethods> = (
95
- extendMethods: T,
96
- ) => EjsContext & T
92
+ declare type helpers = (extendMethods: Record<string, any>) => EjsContext
97
93
 
98
94
  declare type create = (config: EjsConfig) => EjsInstance
99
95
 
@@ -105,7 +101,7 @@ declare type EjsInterface = {
105
101
  require: require
106
102
  preload: preload
107
103
  compile: compile
108
- helpers: helpers<EjsMethods>
104
+ helpers: helpers
109
105
  }
110
106
 
111
107
  declare type EjsInstance = (config: EjsConfig) => EjsInterface
@@ -120,7 +116,7 @@ export const require: require
120
116
 
121
117
  export const preload: preload
122
118
 
123
- export const helpers: helpers<EjsMethods>
119
+ export const helpers: helpers
124
120
 
125
121
  export const compile: compile
126
122