@peter.naydenov/morph 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +15 -1
- package/dist/morph.cjs +1 -1
- package/dist/morph.esm.mjs +1 -1
- package/dist/morph.umd.js +1 -1
- package/package.json +1 -1
- package/src/methods/_renderHolder.js +1 -1
- package/src/methods/build.js +3 -2
package/Changelog.md
CHANGED
|
@@ -2,20 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
### 2.1.3 ( 2025-04-12 )
|
|
6
|
+
- [x] Fix: Wrong set of arguments for helper functions when data is a primitive value;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 2.1.2 ( 2025-04-12 )
|
|
11
|
+
- [x] Fix: Helper templates should ignore value 'null' and 'undefined';
|
|
12
|
+
- [ ] Bug: Wrong set of arguments for helper functions when data is a primitive value;
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
### 2.1.1 ( 2025-04-11 )
|
|
6
16
|
- [x] Fix: Value '0' is not rendered in helper templates;
|
|
7
|
-
|
|
17
|
+
- [ ] Bug: Helper templates should ignore value 'null' and 'undefined';
|
|
18
|
+
- [ ] Bug: Wrong set of arguments for helper functions when data is a primitive value;
|
|
8
19
|
|
|
9
20
|
|
|
10
21
|
### 2.1.0 (2025-04-01)
|
|
11
22
|
- [x] Feature: Access a deep property as a breadcrumbs;
|
|
12
23
|
- [ ] Bug: Value '0' is not rendered in helper templates;
|
|
24
|
+
- [ ] Bug: Wrong set of arguments for helper functions when data is a primitive value;
|
|
13
25
|
|
|
14
26
|
|
|
15
27
|
|
|
16
28
|
### 2.0.1 (2025-03-25)
|
|
17
29
|
- [x] Fix: Deep data render index;
|
|
18
30
|
- [ ] Bug: Value '0' is not rendered in helper templates;
|
|
31
|
+
- [ ] Bug: Wrong set of arguments for helper functions when data is a primitive value;
|
|
19
32
|
|
|
20
33
|
|
|
21
34
|
|
|
@@ -25,6 +38,7 @@
|
|
|
25
38
|
- [x] Overwrite action introduced - when change in data should be available for all placeholders;
|
|
26
39
|
- [ ] Bug: Fix: Deep data render index;
|
|
27
40
|
- [ ] Bug: Value '0' is not rendered in helper templates;
|
|
41
|
+
- [ ] Bug: Wrong set of arguments for helper functions when data is a primitive value;
|
|
28
42
|
|
|
29
43
|
|
|
30
44
|
### 1.2.3 (2025-03-17)
|
package/dist/morph.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@peter.naydenov/walk"),t=require("@peter.naydenov/stack");function r(e){return function t(r){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:s,TG_SIZE_S:c}=e;let l,i,u,
|
|
1
|
+
"use strict";var e=require("@peter.naydenov/walk"),t=require("@peter.naydenov/stack");function r(e){return function t(r){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:s,TG_SIZE_S:c}=e;let l,i,u,d=[];if("string"!=typeof r)return n("notAString");if(0==r.length)return[];if(l=r.indexOf(a),0<l&&d.push(r.slice(0,l)),-1==l)return d.push(r),d;{if(u=r.indexOf(a,l+s),i=r.indexOf(o),-1==i)return n("missingClosing");if(i<l)return n("closedBeforeOpened");if(i+=c,-1!=u&&u<i)return n("newBeforeClosed");d.push(r.slice(l,i));let e=t(r.slice(i));return d.concat(e)}}}function n(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}var a={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function o(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function s(e,t,n,...o){e instanceof Object&&Object.entries(e).forEach((([t,r])=>{r instanceof Object&&(e[t]=r.text),r instanceof Array&&(e[t]=r[0])}));const s="function"==typeof n[t];return e=function(e={}){return"string"==typeof e?{text:e}:e}(e),s?n[t](e,...o):function(e,t){if(null==t)return null;const n=r(a)(e),o=a;return n.forEach(((e,r)=>{if(e.includes(o.TG_PRX)){const a=e.replace(o.TG_PRX,"").replace(o.TG_SFX,"").trim();t.hasOwnProperty(a)&&null!=t[a]&&(n[r]=t[a])}})),n.join("")}(n[t],e)}function c(n,c=!1,l={}){const{hasError:i,placeholders:u,chop:d,helpers:f,handshake:p}=function(e){const{template:t,helpers:n={},handshake:o}=e,{TG_PRX:s,TG_SFX:c}=a,l=[],i="string"==typeof t?t.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):t;let u=null;const d=r(a)(i);return"string"==typeof d?u=d:d.forEach(((e,t)=>{const r=RegExp(s+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?"+c,"g");if(e.includes(s)){const a=r.exec(e);l.push({index:t,data:(n=a[1],n||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null})}var n})),l.forEach((e=>{e.action&&e.action.every((e=>"#"===e||"^^"===e||!(!e.startsWith("^")||"^^"===e)||(e.startsWith("?")&&(e=e.replace("?","")),e.startsWith("+")&&(e=e.replace("+","")),e.startsWith("[]")&&(e=e.replace("[]","")),e.startsWith(">")&&(e=e.replace(">","")),""===e||!!n[e]||(u=`Error: Missing helper: ${e}`,!1))))})),{hasError:u,placeholders:l,chop:d,helpers:n,handshake:o}}(n);if(i){function h(){return i}return c?[!1,h]:h}{let b=structuredClone(d);function m(r={},n={},...a){const c=[],i={};let d=o(r),h={...l,...n};if(r=e({data:r}),"null"===d)return b.join("");if("string"==typeof r)switch(r){case"raw":return b.join("");case"demo":if(!p)return"Error: No handshake data.";d=o(r=p);break;case"handshake":return p?structuredClone(p):"Error: No handshake data.";case"placeholders":return u.map((e=>b[e.index])).join(", ");default:return`Error: Wrong command "${r}". Available commands: raw, demo, handshake, placeholders.`}return"array"!==d&&(r=[r]),"null"===d?b.join(""):(r.forEach((r=>{u.forEach((n=>{const{index:a,data:c,action:l}=n,u=!l&&c,d=structuredClone(i),p={dependencies:h,memory:d};let m=r;if(c&&c.includes("/")?c.split("/").forEach((e=>{m=m.hasOwnProperty(e)?m[e]:[]})):"@all"===c||null===c||"@root"===c?m=r:c&&(m=m[c]),u){switch(o(m)){case"function":return void(b[a]=m());case"primitive":return void(b[a]=m);case"array":return void("primitive"===o(m[0])&&(b[a]=m[0]));case"object":return void(m.text&&(b[a]=m.text))}}else{let{dataDeepLevel:n,nestedData:c}=function(t,r){const n=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const o=structuredClone(t);return r.includes("#")?(e({data:o,objectCallback:function({key:e,value:t,breadcrumbs:r}){return e===r?(n[0]=[t],t):(a=r.split("/").length-1,n[a]||(n[a]=[]),n[a].push(t),t)}}),{dataDeepLevel:a,nestedData:n}):(n.push([o]),{dataDeepLevel:0,nestedData:n})}(m,l),u=function*(e,r){let n=t({type:"LIFO"});for(let t=0;t<=r;t++)n.push(e[t]);for(;n&&!n.isEmpty();){let e=yield n.pull();e&&n.push(e)}}(function(e,t=10){let r={},n=[...e],a=0,o=0,s=0;n.forEach((e=>{"#"===e&&s++})),s<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${s} level markers in actions: ${e.join(", ")}`);do{r[o]=[],o++}while(o<=t);return n.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("?")?(r[a].push({type:"route",name:e.replace("?",""),level:a}),!0):e.startsWith("^")&&"^^"!==e?(r[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(r[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(r[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(r[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(r[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||r[a].push({type:"render",name:e,level:a}),!0))),r}(l,n),n);for(let t of u){let{type:n,name:a,level:l}=t;(c[l]||[]).forEach(((t,u)=>{let d=o(t);switch(n){case"route":switch(d){case"array":t.forEach(((e,r)=>{if(null==e)return;const n=o(e),c=f[a]({data:e,...p});null!=c&&("object"===n?t[r].text=s(e,c,f,h):t[r]=s(e,c,f,h))}));break;case"object":t.text=s(t,a,f,h)}break;case"save":i[a]=structuredClone(t);break;case"overwrite":r=structuredClone(t);break;case"data":switch(d){case"array":t.forEach(((e,r)=>t[r]=e instanceof Function?f[a]({data:e(),...p}):f[a]({data:e,...p})));break;case"object":c[l]=[f[a]({data:t,...p})];break;case"function":c[l]=[f[a]({data:t(),...p})];break;case"primitive":c[l]=f[a]({data:t,...p})}break;case"render":const b="function"==typeof f[a];switch(d){case"array":b?t.forEach(((e,r)=>{if(null==e)return;const n=o(e),s=f[a]({data:e,...p});null==s&&(t[r]=null),"object"===n?e.text=s:t[r]=s})):t.forEach(((e,r)=>{if(null==e)return;const n=o(e),c=s(e,a,f,h);null==c?t[r]=null:"object"===n?e.text=c:t[r]=c}));break;case"function":c[l]=f[a]({data:t(),...p});break;case"primitive":c[l]=b?f[a]({data:t,...p}):s(t,a,f,h);break;case"object":b?c[l][u].text=f[a]({data:t,...p}):t.text=s(t,a,f,h)}break;case"extendedRender":"function"==typeof f[a]&&c[0].forEach(((e,t)=>c[0][t]=f[a]({data:e,...p})));break;case"mix":if(""===a)switch(d){case"object":Object.keys(t).find((e=>e.includes("/")))?Object.entries(t).forEach((([e,t])=>c[l][e]=t.text)):c[l]=t.text;for(let y=l-1;y>=0;y--)c[y]=e({data:c[y],objectCallback:m});function m({value:e,breadcrumbs:t}){return c[l][t]?c[l][t]:e}break;case"array":t.forEach(((e,r)=>{if(r>0){let n=o(e);if(null==e)return;t[0]+="object"===n?`${e.text}`:`${e}`,t.toSpliced(r,1)}else{let r=o(e);if(t[0]="",null===r)return;t[0]="object"===r?`${e.text}`:`${e}`}})),t.length=1}else{let v=f[a]({data:t,...p}),g=o(v);switch(t.forEach(((e,r)=>t.splice(r,1))),t.length=0,g){case"primitive":t[0]=v;break;case"array":t.push(...v)}}}}))}if(c instanceof Array&&1===c.length&&c[0]instanceof Array&&(c=c[0]),null==c[0])return;let d=o(c[0]),y=c[0];switch(d){case"primitive":if(null==y)return;b[a]=y;break;case"object":if(null==y.text)return;b[a]=y.text;break;case"array":const e=o(y[0]);b[a]="object"===e?y.map((e=>e.text)).join(""):y.join("")}}})),c.push(b.join(""))})),"array"===d?c:a?a.reduce(((e,t)=>"function"!=typeof t?e:t(e,h)),c.join("")):c.join(""))}return c?[!0,m]:m}}const l={default:{}};const i={build:c,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,r="default"]=e;return l[r]?l[r][t]?l[r][t]:function(){return`Error: Template "${t}" does not exist in storage "${r}".`}:function(){return`Error: Storage "${r}" does not exist.`}},add:function(e,t,...r){const[n,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${n} is not added to storage. The template is null.`);let o=t,s=!0;if(l[a]||(l[a]={}),"function"!=typeof t){let e=c(t,!0,...r);s=e[0],o=e[1]}s?l[a][n]=o:console.error(`Error: Template "${n}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>l[e]?Object.keys(l[e]):[])).flat()},clear:function(){Object.keys(l).forEach((e=>{"default"!=e?delete l[e]:l.default={}}))},remove:function(e){const[t,r="default"]=e;return l[r]?l[r][t]?void delete l[r][t]:`Error: Template "${t}" does not exist in storage "${r}".`:`Error: Storage "${r}" does not exist.`}};module.exports=i;
|
package/dist/morph.esm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@peter.naydenov/walk";import t from"@peter.naydenov/stack";function r(e){return function t(r){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:s,TG_SIZE_S:
|
|
1
|
+
import e from"@peter.naydenov/walk";import t from"@peter.naydenov/stack";function r(e){return function t(r){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:s,TG_SIZE_S:l}=e;let c,i,u,f=[];if("string"!=typeof r)return n("notAString");if(0==r.length)return[];if(c=r.indexOf(a),0<c&&f.push(r.slice(0,c)),-1==c)return f.push(r),f;{if(u=r.indexOf(a,c+s),i=r.indexOf(o),-1==i)return n("missingClosing");if(i<c)return n("closedBeforeOpened");if(i+=l,-1!=u&&u<i)return n("newBeforeClosed");f.push(r.slice(c,i));let e=t(r.slice(i));return f.concat(e)}}}function n(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}var a={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function o(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function s(e,t,n,...o){e instanceof Object&&Object.entries(e).forEach((([t,r])=>{r instanceof Object&&(e[t]=r.text),r instanceof Array&&(e[t]=r[0])}));const s="function"==typeof n[t];return e=function(e={}){return"string"==typeof e?{text:e}:e}(e),s?n[t](e,...o):function(e,t){if(null==t)return null;const n=r(a)(e),o=a;return n.forEach(((e,r)=>{if(e.includes(o.TG_PRX)){const a=e.replace(o.TG_PRX,"").replace(o.TG_SFX,"").trim();t.hasOwnProperty(a)&&null!=t[a]&&(n[r]=t[a])}})),n.join("")}(n[t],e)}function l(n,l=!1,c={}){const{hasError:i,placeholders:u,chop:f,helpers:d,handshake:p}=function(e){const{template:t,helpers:n={},handshake:o}=e,{TG_PRX:s,TG_SFX:l}=a,c=[],i="string"==typeof t?t.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):t;let u=null;const f=r(a)(i);return"string"==typeof f?u=f:f.forEach(((e,t)=>{const r=RegExp(s+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?"+l,"g");if(e.includes(s)){const a=r.exec(e);c.push({index:t,data:(n=a[1],n||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null})}var n})),c.forEach((e=>{e.action&&e.action.every((e=>"#"===e||"^^"===e||!(!e.startsWith("^")||"^^"===e)||(e.startsWith("?")&&(e=e.replace("?","")),e.startsWith("+")&&(e=e.replace("+","")),e.startsWith("[]")&&(e=e.replace("[]","")),e.startsWith(">")&&(e=e.replace(">","")),""===e||!!n[e]||(u=`Error: Missing helper: ${e}`,!1))))})),{hasError:u,placeholders:c,chop:f,helpers:n,handshake:o}}(n);if(i){function h(){return i}return l?[!1,h]:h}{let m=structuredClone(f);function b(r={},n={},...a){const l=[],i={};let f=o(r),h={...c,...n};if(r=e({data:r}),"null"===f)return m.join("");if("string"==typeof r)switch(r){case"raw":return m.join("");case"demo":if(!p)return"Error: No handshake data.";f=o(r=p);break;case"handshake":return p?structuredClone(p):"Error: No handshake data.";case"placeholders":return u.map((e=>m[e.index])).join(", ");default:return`Error: Wrong command "${r}". Available commands: raw, demo, handshake, placeholders.`}return"array"!==f&&(r=[r]),"null"===f?m.join(""):(r.forEach((r=>{u.forEach((n=>{const{index:a,data:l,action:c}=n,u=!c&&l,f=structuredClone(i),p={dependencies:h,memory:f};let b=r;if(l&&l.includes("/")?l.split("/").forEach((e=>{b=b.hasOwnProperty(e)?b[e]:[]})):"@all"===l||null===l||"@root"===l?b=r:l&&(b=b[l]),u){switch(o(b)){case"function":return void(m[a]=b());case"primitive":return void(m[a]=b);case"array":return void("primitive"===o(b[0])&&(m[a]=b[0]));case"object":return void(b.text&&(m[a]=b.text))}}else{let{dataDeepLevel:n,nestedData:l}=function(t,r){const n=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const o=structuredClone(t);return r.includes("#")?(e({data:o,objectCallback:function({key:e,value:t,breadcrumbs:r}){return e===r?(n[0]=[t],t):(a=r.split("/").length-1,n[a]||(n[a]=[]),n[a].push(t),t)}}),{dataDeepLevel:a,nestedData:n}):(n.push([o]),{dataDeepLevel:0,nestedData:n})}(b,c),u=function*(e,r){let n=t({type:"LIFO"});for(let t=0;t<=r;t++)n.push(e[t]);for(;n&&!n.isEmpty();){let e=yield n.pull();e&&n.push(e)}}(function(e,t=10){let r={},n=[...e],a=0,o=0,s=0;n.forEach((e=>{"#"===e&&s++})),s<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${s} level markers in actions: ${e.join(", ")}`);do{r[o]=[],o++}while(o<=t);return n.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("?")?(r[a].push({type:"route",name:e.replace("?",""),level:a}),!0):e.startsWith("^")&&"^^"!==e?(r[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(r[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(r[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(r[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(r[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||r[a].push({type:"render",name:e,level:a}),!0))),r}(c,n),n);for(let t of u){let{type:n,name:a,level:c}=t;(l[c]||[]).forEach(((t,u)=>{let f=o(t);switch(n){case"route":switch(f){case"array":t.forEach(((e,r)=>{if(null==e)return;const n=o(e),l=d[a]({data:e,...p});null!=l&&("object"===n?t[r].text=s(e,l,d,h):t[r]=s(e,l,d,h))}));break;case"object":t.text=s(t,a,d,h)}break;case"save":i[a]=structuredClone(t);break;case"overwrite":r=structuredClone(t);break;case"data":switch(f){case"array":t.forEach(((e,r)=>t[r]=e instanceof Function?d[a]({data:e(),...p}):d[a]({data:e,...p})));break;case"object":l[c]=[d[a]({data:t,...p})];break;case"function":l[c]=[d[a]({data:t(),...p})];break;case"primitive":l[c]=d[a]({data:t,...p})}break;case"render":const m="function"==typeof d[a];switch(f){case"array":m?t.forEach(((e,r)=>{if(null==e)return;const n=o(e),s=d[a]({data:e,...p});null==s&&(t[r]=null),"object"===n?e.text=s:t[r]=s})):t.forEach(((e,r)=>{if(null==e)return;const n=o(e),l=s(e,a,d,h);null==l?t[r]=null:"object"===n?e.text=l:t[r]=l}));break;case"function":l[c]=d[a]({data:t(),...p});break;case"primitive":l[c]=m?d[a]({data:t,...p}):s(t,a,d,h);break;case"object":m?l[c][u].text=d[a]({data:t,...p}):t.text=s(t,a,d,h)}break;case"extendedRender":"function"==typeof d[a]&&l[0].forEach(((e,t)=>l[0][t]=d[a]({data:e,...p})));break;case"mix":if(""===a)switch(f){case"object":Object.keys(t).find((e=>e.includes("/")))?Object.entries(t).forEach((([e,t])=>l[c][e]=t.text)):l[c]=t.text;for(let y=c-1;y>=0;y--)l[y]=e({data:l[y],objectCallback:b});function b({value:e,breadcrumbs:t}){return l[c][t]?l[c][t]:e}break;case"array":t.forEach(((e,r)=>{if(r>0){let n=o(e);if(null==e)return;t[0]+="object"===n?`${e.text}`:`${e}`,t.toSpliced(r,1)}else{let r=o(e);if(t[0]="",null===r)return;t[0]="object"===r?`${e.text}`:`${e}`}})),t.length=1}else{let v=d[a]({data:t,...p}),g=o(v);switch(t.forEach(((e,r)=>t.splice(r,1))),t.length=0,g){case"primitive":t[0]=v;break;case"array":t.push(...v)}}}}))}if(l instanceof Array&&1===l.length&&l[0]instanceof Array&&(l=l[0]),null==l[0])return;let f=o(l[0]),y=l[0];switch(f){case"primitive":if(null==y)return;m[a]=y;break;case"object":if(null==y.text)return;m[a]=y.text;break;case"array":const e=o(y[0]);m[a]="object"===e?y.map((e=>e.text)).join(""):y.join("")}}})),l.push(m.join(""))})),"array"===f?l:a?a.reduce(((e,t)=>"function"!=typeof t?e:t(e,h)),l.join("")):l.join(""))}return l?[!0,b]:b}}const c={default:{}};const i={build:l,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,r="default"]=e;return c[r]?c[r][t]?c[r][t]:function(){return`Error: Template "${t}" does not exist in storage "${r}".`}:function(){return`Error: Storage "${r}" does not exist.`}},add:function(e,t,...r){const[n,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${n} is not added to storage. The template is null.`);let o=t,s=!0;if(c[a]||(c[a]={}),"function"!=typeof t){let e=l(t,!0,...r);s=e[0],o=e[1]}s?c[a][n]=o:console.error(`Error: Template "${n}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>c[e]?Object.keys(c[e]):[])).flat()},clear:function(){Object.keys(c).forEach((e=>{"default"!=e?delete c[e]:c.default={}}))},remove:function(e){const[t,r="default"]=e;return c[r]?c[r][t]?void delete c[r][t]:`Error: Template "${t}" does not exist in storage "${r}".`:`Error: Storage "${r}" does not exist.`}};export{i as default};
|
package/dist/morph.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@peter.naydenov/walk")):"function"==typeof define&&define.amd?define(["@peter.naydenov/walk"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).morph=t(e.walk)}(this,(function(e){"use strict";function t(e){return function t(n){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:l,TG_SIZE_S:s}=e;let i,c,u,f=[];if("string"!=typeof n)return r("notAString");if(0==n.length)return[];if(i=n.indexOf(a),0<i&&f.push(n.slice(0,i)),-1==i)return f.push(n),f;{if(u=n.indexOf(a,i+l),c=n.indexOf(o),-1==c)return r("missingClosing");if(c<i)return r("closedBeforeOpened");if(c+=s,-1!=u&&u<c)return r("newBeforeClosed");f.push(n.slice(i,c));let e=t(n.slice(c));return f.concat(e)}}}function r(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}function*n(e,t){let r=function(e={}){let t=[],{type:r,limit:n,onLimit:a}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),o="LIFO"===r.toUpperCase(),l=!1;function s(e=1,r=0){let n=[];return r>0&&Array.from({length:r}).map((()=>t.pop())),1==e?t.pop():(Array.from({length:e}).map((()=>{let e=t.pop();null!=e&&n.push(e)})),n)}function i(e=1,r=0){let n=[],a=t.length-r;return e>1&&Array.from({length:e}).map((()=>{null!=t[a-1]&&n.push(t[a-1]),a--})),1==e?t[t.length-1]:n}function c(){}return c.prototype={pull:s,pullReverse:function(e=1,t=0){let r=s(e,t);return r instanceof Array?r.reverse():r},peek:i,peekReverse:function(e=1,t=0){const r=i(e,t);return r instanceof Array?r.reverse():r},getSize:()=>t.length,isEmpty:()=>0==t.length,reset:()=>(t=[],!0),debug:()=>[...t]},c.prototype.push=o?function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(0,-o+n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=e instanceof Array?t.concat(e):t.concat([e]),l=!!n&&t.length===n,i||void 0}}:function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(o-n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=r?e.reduce(((e,t)=>[t,...e]),t):[e].reduce(((e,t)=>[t,...e]),t),l=!!n&&t.length===n,i||void 0}},new c}({type:"LIFO"});for(let n=0;n<=t;n++)r.push(e[n]);for(;r&&!r.isEmpty();){let e=yield r.pull();e&&r.push(e)}}var a={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function o(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function l(e,r,n,...o){e instanceof Object&&Object.entries(e).forEach((([t,r])=>{r instanceof Object&&(e[t]=r.text),r instanceof Array&&(e[t]=r[0])}));const l="function"==typeof n[r];return e=function(e={}){return"string"==typeof e?{text:e}:e}(e),l?n[r](e,...o):function(e,r){if(null==r)return null;const n=t(a)(e),o=a;return n.forEach(((e,t)=>{if(e.includes(o.TG_PRX)){const a=e.replace(o.TG_PRX,"").replace(o.TG_SFX,"").trim();r.hasOwnProperty(a)&&(n[t]=r[a])}})),n.join("")}(n[r],e)}function s(r,s=!1,i={}){const{hasError:c,placeholders:u,chop:f,helpers:d,handshake:p}=function(e){const{template:r,helpers:n={},handshake:o}=e,{TG_PRX:l,TG_SFX:s}=a,i=[],c="string"==typeof r?r.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):r;let u=null;const f=t(a)(c);return"string"==typeof f?u=f:f.forEach(((e,t)=>{const r=RegExp(l+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?"+s,"g");if(e.includes(l)){const a=r.exec(e);i.push({index:t,data:(n=a[1],n||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null})}var n})),i.forEach((e=>{e.action&&e.action.every((e=>"#"===e||"^^"===e||!(!e.startsWith("^")||"^^"===e)||(e.startsWith("?")&&(e=e.replace("?","")),e.startsWith("+")&&(e=e.replace("+","")),e.startsWith("[]")&&(e=e.replace("[]","")),e.startsWith(">")&&(e=e.replace(">","")),""===e||!!n[e]||(u=`Error: Missing helper: ${e}`,!1))))})),{hasError:u,placeholders:i,chop:f,helpers:n,handshake:o}}(r);if(c){function h(){return c}return s?[!1,h]:h}{let y=structuredClone(f);function m(t={},r={},...a){const s=[],c={};let f=o(t),h={...i,...r};if(t=e({data:t}),"null"===f)return y.join("");if("string"==typeof t)switch(t){case"raw":return y.join("");case"demo":if(!p)return"Error: No handshake data.";f=o(t=p);break;case"handshake":return p?structuredClone(p):"Error: No handshake data.";case"placeholders":return u.map((e=>y[e.index])).join(", ");default:return`Error: Wrong command "${t}". Available commands: raw, demo, handshake, placeholders.`}return"array"!==f&&(t=[t]),"null"===f?y.join(""):(t.forEach((t=>{u.forEach((r=>{const{index:a,data:s,action:i}=r,u=!i&&s,f=structuredClone(c),p={dependencies:h,memory:f};let m=t;if(s&&s.includes("/")?s.split("/").forEach((e=>{m=m.hasOwnProperty(e)?m[e]:[]})):"@all"===s||null===s||"@root"===s?m=t:s&&(m=m[s]),u){switch(o(m)){case"function":return void(y[a]=m());case"primitive":return void(y[a]=m);case"array":return void("primitive"===o(m[0])&&(y[a]=m[0]));case"object":return void(m.text&&(y[a]=m.text))}}else{let{dataDeepLevel:r,nestedData:s}=function(t,r){const n=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const o=structuredClone(t);return r.includes("#")?(e({data:o,objectCallback:function({key:e,value:t,breadcrumbs:r}){return e===r?(n[0]=[t],t):(a=r.split("/").length-1,n[a]||(n[a]=[]),n[a].push(t),t)}}),{dataDeepLevel:a,nestedData:n}):(n.push([o]),{dataDeepLevel:0,nestedData:n})}(m,i),u=n(function(e,t=10){let r={},n=[...e],a=0,o=0,l=0;n.forEach((e=>{"#"===e&&l++})),l<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${l} level markers in actions: ${e.join(", ")}`);do{r[o]=[],o++}while(o<=t);return n.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("?")?(r[a].push({type:"route",name:e.replace("?",""),level:a}),!0):e.startsWith("^")&&"^^"!==e?(r[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(r[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(r[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(r[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(r[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||r[a].push({type:"render",name:e,level:a}),!0))),r}(i,r),r);for(let r of u){let{type:n,name:a,level:i}=r;(s[i]||[]).forEach(((r,u)=>{let f=o(r);switch(n){case"route":switch(f){case"array":r.forEach(((e,t)=>{if(null==e)return;const n=o(e),s=d[a]({data:e,...p});null!=s&&("object"===n?r[t].text=l(e,s,d,h):r[t]=l(e,s,d,h))}));break;case"object":r.text=l(r,a,d,h)}break;case"save":c[a]=structuredClone(r);break;case"overwrite":t=structuredClone(r);break;case"data":switch(f){case"array":r.forEach(((e,t)=>r[t]=e instanceof Function?d[a]({data:e(),...p}):d[a]({data:e,...p})));break;case"object":s[i]=[d[a]({data:r,...p})];break;case"function":s[i]=[d[a]({data:r(),...p})];break;case"primitive":s[i]=d[a]({data:r,...p})}break;case"render":const y="function"==typeof d[a];switch(f){case"array":y?r.forEach(((e,t)=>{if(null==e)return;const n=o(e),l=d[a]({data:e,...p});null==l&&(r[t]=null),"object"===n?e.text=l:r[t]=l})):r.forEach(((e,t)=>{if(null==e)return;const n=o(e),s=l(e,a,d,h);null==s?r[t]=null:"object"===n?e.text=s:r[t]=s}));break;case"function":s[i]=d[a]({data:r(),...p});break;case"primitive":s[i]=l(r,a,d,h);break;case"object":y?s[i][u].text=d[a]({data:r,...p}):r.text=l(r,a,d,h)}break;case"extendedRender":"function"==typeof d[a]&&s[0].forEach(((e,t)=>s[0][t]=d[a]({data:e,...p})));break;case"mix":if(""===a)switch(f){case"object":Object.keys(r).find((e=>e.includes("/")))?Object.entries(r).forEach((([e,t])=>s[i][e]=t.text)):s[i]=r.text;for(let g=i-1;g>=0;g--)s[g]=e({data:s[g],objectCallback:m});function m({value:e,breadcrumbs:t}){return s[i][t]?s[i][t]:e}break;case"array":r.forEach(((e,t)=>{if(t>0){let n=o(e);if(null==e)return;r[0]+="object"===n?`${e.text}`:`${e}`,r.toSpliced(t,1)}else{let t=o(e);if(r[0]="",null===t)return;r[0]="object"===t?`${e.text}`:`${e}`}})),r.length=1}else{let b=d[a]({data:r,...p}),v=o(b);switch(r.forEach(((e,t)=>r.splice(t,1))),r.length=0,v){case"primitive":r[0]=b;break;case"array":r.push(...b)}}}}))}if(s instanceof Array&&1===s.length&&s[0]instanceof Array&&(s=s[0]),null==s[0])return;let f=o(s[0]),g=s[0];switch(f){case"primitive":if(null==g)return;y[a]=g;break;case"object":if(null==g.text)return;y[a]=g.text;break;case"array":const e=o(g[0]);y[a]="object"===e?g.map((e=>e.text)).join(""):g.join("")}}})),s.push(y.join(""))})),"array"===f?s:a?a.reduce(((e,t)=>"function"!=typeof t?e:t(e,h)),s.join("")):s.join(""))}return s?[!0,m]:m}}const i={default:{}};return{build:s,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,r="default"]=e;return i[r]?i[r][t]?i[r][t]:function(){return`Error: Template "${t}" does not exist in storage "${r}".`}:function(){return`Error: Storage "${r}" does not exist.`}},add:function(e,t,...r){const[n,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${n} is not added to storage. The template is null.`);let o=t,l=!0;if(i[a]||(i[a]={}),"function"!=typeof t){let e=s(t,!0,...r);l=e[0],o=e[1]}l?i[a][n]=o:console.error(`Error: Template "${n}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>i[e]?Object.keys(i[e]):[])).flat()},clear:function(){Object.keys(i).forEach((e=>{"default"!=e?delete i[e]:i.default={}}))},remove:function(e){const[t,r="default"]=e;return i[r]?i[r][t]?void delete i[r][t]:`Error: Template "${t}" does not exist in storage "${r}".`:`Error: Storage "${r}" does not exist.`}}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@peter.naydenov/walk")):"function"==typeof define&&define.amd?define(["@peter.naydenov/walk"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).morph=t(e.walk)}(this,(function(e){"use strict";function t(e){return function t(n){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:l,TG_SIZE_S:s}=e;let i,c,u,f=[];if("string"!=typeof n)return r("notAString");if(0==n.length)return[];if(i=n.indexOf(a),0<i&&f.push(n.slice(0,i)),-1==i)return f.push(n),f;{if(u=n.indexOf(a,i+l),c=n.indexOf(o),-1==c)return r("missingClosing");if(c<i)return r("closedBeforeOpened");if(c+=s,-1!=u&&u<c)return r("newBeforeClosed");f.push(n.slice(i,c));let e=t(n.slice(c));return f.concat(e)}}}function r(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}function*n(e,t){let r=function(e={}){let t=[],{type:r,limit:n,onLimit:a}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),o="LIFO"===r.toUpperCase(),l=!1;function s(e=1,r=0){let n=[];return r>0&&Array.from({length:r}).map((()=>t.pop())),1==e?t.pop():(Array.from({length:e}).map((()=>{let e=t.pop();null!=e&&n.push(e)})),n)}function i(e=1,r=0){let n=[],a=t.length-r;return e>1&&Array.from({length:e}).map((()=>{null!=t[a-1]&&n.push(t[a-1]),a--})),1==e?t[t.length-1]:n}function c(){}return c.prototype={pull:s,pullReverse:function(e=1,t=0){let r=s(e,t);return r instanceof Array?r.reverse():r},peek:i,peekReverse:function(e=1,t=0){const r=i(e,t);return r instanceof Array?r.reverse():r},getSize:()=>t.length,isEmpty:()=>0==t.length,reset:()=>(t=[],!0),debug:()=>[...t]},c.prototype.push=o?function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(0,-o+n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=e instanceof Array?t.concat(e):t.concat([e]),l=!!n&&t.length===n,i||void 0}}:function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(o-n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=r?e.reduce(((e,t)=>[t,...e]),t):[e].reduce(((e,t)=>[t,...e]),t),l=!!n&&t.length===n,i||void 0}},new c}({type:"LIFO"});for(let n=0;n<=t;n++)r.push(e[n]);for(;r&&!r.isEmpty();){let e=yield r.pull();e&&r.push(e)}}var a={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function o(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function l(e,r,n,...o){e instanceof Object&&Object.entries(e).forEach((([t,r])=>{r instanceof Object&&(e[t]=r.text),r instanceof Array&&(e[t]=r[0])}));const l="function"==typeof n[r];return e=function(e={}){return"string"==typeof e?{text:e}:e}(e),l?n[r](e,...o):function(e,r){if(null==r)return null;const n=t(a)(e),o=a;return n.forEach(((e,t)=>{if(e.includes(o.TG_PRX)){const a=e.replace(o.TG_PRX,"").replace(o.TG_SFX,"").trim();r.hasOwnProperty(a)&&null!=r[a]&&(n[t]=r[a])}})),n.join("")}(n[r],e)}function s(r,s=!1,i={}){const{hasError:c,placeholders:u,chop:f,helpers:d,handshake:p}=function(e){const{template:r,helpers:n={},handshake:o}=e,{TG_PRX:l,TG_SFX:s}=a,i=[],c="string"==typeof r?r.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):r;let u=null;const f=t(a)(c);return"string"==typeof f?u=f:f.forEach(((e,t)=>{const r=RegExp(l+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?"+s,"g");if(e.includes(l)){const a=r.exec(e);i.push({index:t,data:(n=a[1],n||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null})}var n})),i.forEach((e=>{e.action&&e.action.every((e=>"#"===e||"^^"===e||!(!e.startsWith("^")||"^^"===e)||(e.startsWith("?")&&(e=e.replace("?","")),e.startsWith("+")&&(e=e.replace("+","")),e.startsWith("[]")&&(e=e.replace("[]","")),e.startsWith(">")&&(e=e.replace(">","")),""===e||!!n[e]||(u=`Error: Missing helper: ${e}`,!1))))})),{hasError:u,placeholders:i,chop:f,helpers:n,handshake:o}}(r);if(c){function h(){return c}return s?[!1,h]:h}{let y=structuredClone(f);function m(t={},r={},...a){const s=[],c={};let f=o(t),h={...i,...r};if(t=e({data:t}),"null"===f)return y.join("");if("string"==typeof t)switch(t){case"raw":return y.join("");case"demo":if(!p)return"Error: No handshake data.";f=o(t=p);break;case"handshake":return p?structuredClone(p):"Error: No handshake data.";case"placeholders":return u.map((e=>y[e.index])).join(", ");default:return`Error: Wrong command "${t}". Available commands: raw, demo, handshake, placeholders.`}return"array"!==f&&(t=[t]),"null"===f?y.join(""):(t.forEach((t=>{u.forEach((r=>{const{index:a,data:s,action:i}=r,u=!i&&s,f=structuredClone(c),p={dependencies:h,memory:f};let m=t;if(s&&s.includes("/")?s.split("/").forEach((e=>{m=m.hasOwnProperty(e)?m[e]:[]})):"@all"===s||null===s||"@root"===s?m=t:s&&(m=m[s]),u){switch(o(m)){case"function":return void(y[a]=m());case"primitive":return void(y[a]=m);case"array":return void("primitive"===o(m[0])&&(y[a]=m[0]));case"object":return void(m.text&&(y[a]=m.text))}}else{let{dataDeepLevel:r,nestedData:s}=function(t,r){const n=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const o=structuredClone(t);return r.includes("#")?(e({data:o,objectCallback:function({key:e,value:t,breadcrumbs:r}){return e===r?(n[0]=[t],t):(a=r.split("/").length-1,n[a]||(n[a]=[]),n[a].push(t),t)}}),{dataDeepLevel:a,nestedData:n}):(n.push([o]),{dataDeepLevel:0,nestedData:n})}(m,i),u=n(function(e,t=10){let r={},n=[...e],a=0,o=0,l=0;n.forEach((e=>{"#"===e&&l++})),l<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${l} level markers in actions: ${e.join(", ")}`);do{r[o]=[],o++}while(o<=t);return n.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("?")?(r[a].push({type:"route",name:e.replace("?",""),level:a}),!0):e.startsWith("^")&&"^^"!==e?(r[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(r[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(r[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(r[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(r[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||r[a].push({type:"render",name:e,level:a}),!0))),r}(i,r),r);for(let r of u){let{type:n,name:a,level:i}=r;(s[i]||[]).forEach(((r,u)=>{let f=o(r);switch(n){case"route":switch(f){case"array":r.forEach(((e,t)=>{if(null==e)return;const n=o(e),s=d[a]({data:e,...p});null!=s&&("object"===n?r[t].text=l(e,s,d,h):r[t]=l(e,s,d,h))}));break;case"object":r.text=l(r,a,d,h)}break;case"save":c[a]=structuredClone(r);break;case"overwrite":t=structuredClone(r);break;case"data":switch(f){case"array":r.forEach(((e,t)=>r[t]=e instanceof Function?d[a]({data:e(),...p}):d[a]({data:e,...p})));break;case"object":s[i]=[d[a]({data:r,...p})];break;case"function":s[i]=[d[a]({data:r(),...p})];break;case"primitive":s[i]=d[a]({data:r,...p})}break;case"render":const y="function"==typeof d[a];switch(f){case"array":y?r.forEach(((e,t)=>{if(null==e)return;const n=o(e),l=d[a]({data:e,...p});null==l&&(r[t]=null),"object"===n?e.text=l:r[t]=l})):r.forEach(((e,t)=>{if(null==e)return;const n=o(e),s=l(e,a,d,h);null==s?r[t]=null:"object"===n?e.text=s:r[t]=s}));break;case"function":s[i]=d[a]({data:r(),...p});break;case"primitive":s[i]=y?d[a]({data:r,...p}):l(r,a,d,h);break;case"object":y?s[i][u].text=d[a]({data:r,...p}):r.text=l(r,a,d,h)}break;case"extendedRender":"function"==typeof d[a]&&s[0].forEach(((e,t)=>s[0][t]=d[a]({data:e,...p})));break;case"mix":if(""===a)switch(f){case"object":Object.keys(r).find((e=>e.includes("/")))?Object.entries(r).forEach((([e,t])=>s[i][e]=t.text)):s[i]=r.text;for(let g=i-1;g>=0;g--)s[g]=e({data:s[g],objectCallback:m});function m({value:e,breadcrumbs:t}){return s[i][t]?s[i][t]:e}break;case"array":r.forEach(((e,t)=>{if(t>0){let n=o(e);if(null==e)return;r[0]+="object"===n?`${e.text}`:`${e}`,r.toSpliced(t,1)}else{let t=o(e);if(r[0]="",null===t)return;r[0]="object"===t?`${e.text}`:`${e}`}})),r.length=1}else{let b=d[a]({data:r,...p}),v=o(b);switch(r.forEach(((e,t)=>r.splice(t,1))),r.length=0,v){case"primitive":r[0]=b;break;case"array":r.push(...b)}}}}))}if(s instanceof Array&&1===s.length&&s[0]instanceof Array&&(s=s[0]),null==s[0])return;let f=o(s[0]),g=s[0];switch(f){case"primitive":if(null==g)return;y[a]=g;break;case"object":if(null==g.text)return;y[a]=g.text;break;case"array":const e=o(g[0]);y[a]="object"===e?g.map((e=>e.text)).join(""):g.join("")}}})),s.push(y.join(""))})),"array"===f?s:a?a.reduce(((e,t)=>"function"!=typeof t?e:t(e,h)),s.join("")):s.join(""))}return s?[!0,m]:m}}const i={default:{}};return{build:s,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,r="default"]=e;return i[r]?i[r][t]?i[r][t]:function(){return`Error: Template "${t}" does not exist in storage "${r}".`}:function(){return`Error: Storage "${r}" does not exist.`}},add:function(e,t,...r){const[n,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${n} is not added to storage. The template is null.`);let o=t,l=!0;if(i[a]||(i[a]={}),"function"!=typeof t){let e=s(t,!0,...r);l=e[0],o=e[1]}l?i[a][n]=o:console.error(`Error: Template "${n}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>i[e]?Object.keys(i[e]):[])).flat()},clear:function(){Object.keys(i).forEach((e=>{"default"!=e?delete i[e]:i.default={}}))},remove:function(e){const[t,r="default"]=e;return i[r]?i[r][t]?void delete i[r][t]:`Error: Template "${t}" does not exist in storage "${r}".`:`Error: Storage "${r}" does not exist.`}}}));
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ function _renderHolder ( template, data ) {
|
|
|
15
15
|
const isPlaceholder = item.includes ( set.TG_PRX )
|
|
16
16
|
if ( isPlaceholder ) {
|
|
17
17
|
const field = item.replace ( set.TG_PRX, '' ).replace ( set.TG_SFX, '' ).trim();
|
|
18
|
-
if ( data.hasOwnProperty (field) ) chop[i] = data[field]
|
|
18
|
+
if ( data.hasOwnProperty (field) && data[field] != null ) chop[i] = data[field]
|
|
19
19
|
} // if isPlaceholder
|
|
20
20
|
}) // forEach chop
|
|
21
21
|
return chop.join ( '' )
|
package/src/methods/build.js
CHANGED
|
@@ -196,7 +196,7 @@ function build ( tpl, extra=false, buildDependencies={} ) {
|
|
|
196
196
|
if ( isRenderFunction ) theData.forEach ( (d,i) => {
|
|
197
197
|
if ( d == null ) return
|
|
198
198
|
const dType = _defineDataType ( d );
|
|
199
|
-
const text = helpers[name]( {data:d, ...extendArguments}
|
|
199
|
+
const text = helpers[name]( {data:d, ...extendArguments });
|
|
200
200
|
|
|
201
201
|
if ( text == null ) theData[i] = null
|
|
202
202
|
if ( dType === 'object' ) d['text'] = text
|
|
@@ -217,7 +217,8 @@ function build ( tpl, extra=false, buildDependencies={} ) {
|
|
|
217
217
|
nestedData[level] = helpers[name]( {data:theData(), ...extendArguments} )
|
|
218
218
|
break
|
|
219
219
|
case 'primitive':
|
|
220
|
-
nestedData[level] =
|
|
220
|
+
if ( isRenderFunction ) nestedData[level] = helpers[name]({ data:theData, ...extendArguments} )
|
|
221
|
+
else nestedData[level] = render ( theData, name, helpers, deps )
|
|
221
222
|
break
|
|
222
223
|
case 'object':
|
|
223
224
|
if ( isRenderFunction ) nestedData[level][iData]['text'] = helpers[name]({ data:theData, ...extendArguments} )
|