dt-toolbox 7.4.1 → 7.4.2
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 +9 -0
- package/dist/dtbox.cjs +1 -0
- package/dist/dtbox.esm.mjs +1 -0
- package/dist/dtbox.umd.js +1 -0
- package/package.json +31 -16
- package/rollup.config.js +41 -0
- package/src/flatData/export.js +1 -1
- package/src/mainLib.js +1 -1
package/Changelog.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
## Release History
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
### 7.4.2 ( 2024-01-30)
|
|
5
|
+
- [x] Dependencies updates. @peter.naydenov/walk to version 4.2.3;
|
|
6
|
+
- [x] Dev dependencies updates. Chai to version 5.0.3;
|
|
7
|
+
- [x] Dev dependencies updates. C8 to version 9.1.0;
|
|
8
|
+
- [x] Folder 'dist' was added to the project. Includes commonjs, umd and esm versions of the library;
|
|
9
|
+
- [x] Package.json: "exports" section was added. Allows you to use package as commonjs or es6 module without additional configuration;
|
|
10
|
+
- [x] Rollup was added to the project. Used to build the library versions;
|
|
11
|
+
|
|
12
|
+
|
|
4
13
|
|
|
5
14
|
### 7.4.1 ( 2024-01-10)
|
|
6
15
|
- [x] Dependencies updates. @peter.naydenov/walk to version 4.2.1;
|
package/dist/dtbox.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("@peter.naydenov/walk");function e(t,e){return function(n,r){const{convert:o,isDTO:s,isDTM:c,walk:a}=t();let u,i;s(r)?(u=r.export(),i=r.copy()):c(r)?(u=a({data:r}),i=a({data:r})):([i,,u]=o.from("std").toFlat(t,r),console.warn('A non "dt-object" data segment was inserted. Autoconverted to "dt-object".'));const l=new RegExp("^root/");u.forEach((t=>{t[0]===t[2]&&(t[0]=n,t[2]=n),t[2]=t[2].replace(l,`${n}/`),t[3].forEach(((e,r)=>t[3][r]=e.replace(l,`${n}/`)))})),e.insert([i,,u])}}function n(t,e){return t=>e.export(t)}function r(t,e){return function(n="root"){const r=e.getCopy(n),{walk:o}=t();return r?o({data:r}):null}}function o(t,e,n){return function(){let r=[],o={};const{convert:s,draft:c,INIT_DATA_TYPES:a,main:{load:u}}=t(),i={set:c.set(r,o),connect:c.connect(o),save:c.save(o),push:c.push(o)},[l,...f]=arguments,{as:p}=l({...n,...i},...f)||{},d=0===r.length?e.export():r,h=!!p&&a.includes(p);let m;return"dt-object"===p?u(d):p&&!h?(console.error(`Model '${p}' is unknown data-model.`),null):(m=p?s.to(p,t,d):u(d),e.resetScan(),m)}}function s(t,e,n){return function(){const{main:{load:r},draft:o}=t(),[s,...c]=arguments;let a=[],u={};const i={set:o.set(a,u),connect:o.connect(u),save:o.save(u),push:o.push(u)};return s({...n,...i},...c),e.resetScan(),0===a.length?this:r(a)}}function c(t){return function(e,n){t.setupFilter(e,n)}}function a(t,a){const{flatData:u}=t(),[i,l]=u(t,a),f={insertSegment:e(t,i),export:n(0,i),copy:r(t,i),model:o(t,i,l),query:s(t,i,l),setupFilter:c(i),listSegments:()=>Object.keys(i.getIndexes()).reduce(((t,e)=>(e.includes("/")||t.push(e),t)),[]),index:p};function p(t){if(null==t)return null;let e=i.getLine(t);if(e){let t,[n,r,o,s]=e;return t=r instanceof Array?[...r]:{...r},[n,t,o,[...s]]}return null}return f.extractList=function(t,e,n){return function(r,o){const s=n("root"),{main:{load:c},INIT_DATA_TYPES:a}=t(),u=[...a,"dt-object"];let i=!1,l="";if(o&&(o.as||(i=!0,l='Options should be an object and property "as" is required'),i||u.includes(o.as)||(i=!0,l=`Invalid option "as" value: ${o.as}.`),i))throw new Error(l);return r.map((t=>{let n=e.export(t);return 0===n.length?s[1].hasOwnProperty(t)?s[1][t]:null:n})).map((t=>null==t?null:t instanceof Array?c(t).model((()=>o)):t))}}(t,i,p),f}function u(t,e,n){return function(r){const[o,,s]=r,c=s[0][0],[a,u,i]=t,l=n();a[c]=o,s.forEach((t=>{const[,,n]=t;u[n]=t,i.push(t),l.forEach((n=>e(n,t)))}))}}function i(t){return function(e){const[,n,r]=t;if(e&&!n[e])return[];if(!e){const t=[];return r.forEach((e=>{const[n,r,o,s]=e,c=r instanceof Array?[...r]:{...r};t.push([n,c,o,[...s]])})),t}const o=[];return r.forEach((t=>{const[n,r,s,c]=t,a=new RegExp(`^${e}/`);if(s===e||s.match(a)){let t=n===s?"root":n,e=r instanceof Array?[...r]:{...r},u=s.includes("/")?s.replace(a,"root/"):"root",i=c.map((t=>t.replace(a,"root/")));o.push([t,e,u,i])}})),o}}function l(t,e,n,r){return function(o,s){const c=r(),[,,a]=t;if(c.includes(o))return console.error(`Filter name "${o}" is already defined`),this;e[o]=s,a.forEach((t=>n(o,t)))}}function f(t){return function(e){const n=t.getIndexes(),r=n[e],o=[];return r?(o.push(r),p(n,o,r[3]),t.setupScanList(o),this):(t.setupScanList([]),this)}}function p(t,e,n){n.forEach((n=>{const r=t[n];r&&(e.push(r),p(t,e,r[3]))}))}function d(t){return function(e){const n=[];return t.getScanList().forEach((t=>{t[0]===e&&n.push(t)})),t.setupScanList(n),this}}function h(t){return function(e){const n=[],r=e instanceof Array?e:[e];return t.getScanList().forEach((t=>{const e=t[0];r.forEach((r=>{e.includes(r)&&n.push(t)}))})),t.setupScanList(n),this}}function m(t){return function(e){t.getScanList().forEach((n=>{const[r,o,s,c]=n,a=o instanceof Array,u=()=>"$__NEXT__LOOK_",i=()=>"$__FINISH__WITH__THE__LOOKING_";let l=!1;const f=c.map((t=>{let e=t.replace(`${s}/`,"");return[r,e]}));if(a)0===o.length?p([]):o.every(((t,n)=>{if(l)return!1;const c=e({value:t,key:n,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}));else{const t=Object.entries(o);0===t.length?p({}):t.every((([t,n])=>{if(l)return!1;const c=e({value:n,key:t,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}))}function p(t){e({value:null,key:null,name:r,flatData:t,breadcrumbs:s,links:f,empty:!0,next:u,finish:i})}t.resetScan()}))}}function b(t){return function(e){const n=[];return t.getScanList().every((t=>t[2]!==e||(n.push(t),!1))),t.setupScanList(n),this}}function _({flatData:t}){return t instanceof Array}function y({name:t,flatData:e}){return!(e instanceof Array)&&!isNaN(t)}function g({flatData:t}){return!(t instanceof Array)}function $({name:t,breadcrumbs:e}){return t===e}function E(t,e){const[n,r,o]=e,s=[n,r,o],c={},a={list:_,listObject:y,object:g,root:$};let p=o;const E=()=>Object.keys(a),v=(t,e)=>{if(a[t]){const[n,o,s,u]=e;if(c[t]||(c[t]=[]),a[t]({name:n,flatData:o,breadcrumbs:s,edges:u})){const e=r[s];c[t].push(e)}}};E().forEach((t=>o.forEach((e=>v(t,e)))));const j={insert:u(s,v,E),export:i(s),getCopy:t=>n[t]?n[t]:null,getIndexes:()=>r,getLine:t=>r[t]?r[t]:null,getFilters:()=>c,getScanList:()=>p,setupScanList:t=>p=t,setupFilter:l(s,a,v,E),resetScan:()=>{p=o}};var O;return[j,{from:f(j),use:(O=j,function(t){const e=O.getFilters()[t];return e&&O.setupScanList(e),this}),get:b(j),find:d(j),like:h(j),look:m(j)}]}var v={toFlat:function(t,e){const n=e instanceof Array?[]:{},{walk:r}=t(),o=[["root",n,"root",[]]],s={root:o[0]},c=r({data:e,keyCallback:function({value:t,key:e,breadcrumbs:n}){const r=new RegExp(`/${e}$`),o=n.replace(r,"");return s[o][1][e]=t,t},objectCallback:function({value:t,key:e,breadcrumbs:n}){const r=t instanceof Array?[]:{},c=e,a=new RegExp(`/${e}$`),u=n.replace(a,""),i=[c,r,n,[]];return s[u][3].push(n),o.push(i),s[n]=o.at(-1),t}});return[{root:c},s,o]},toType:function(t){let e={};return t.reverse().forEach((([t,n,r,o])=>{const s=n instanceof Array?[...n]:{...n};e[r]=s,o.forEach((t=>{if(e[t]){const n=t.replace(`${r}/`,"");e[r][n]=e[t]}}))})),e.root}};var j={toFlat:function(t,e){const n=Object.entries(e),{walk:r}=t(),o={},s=[],c={},a={};function u(t){c[t]||(c[t]="object");const e=t.split("/");1!=e.length&&(e.pop(),1!=e.length&&u(e.join("/")))}return n.forEach((([t,e])=>{t.startsWith("root")||(t=`root/${t}`),u(t),function(t,e){Object.keys(e).forEach((e=>{isNaN(e)||(c[t]="array")}))}(t,e),a[t]=e})),Object.entries(c).forEach((([t,e])=>{if("object"===a[t])return;if(a[t]){const n=a[t]instanceof Array;if("array"===e&&!n){const e=Object.values(a[t]);a[t]=e}return}const n="object"===e?{}:[];a[t]=n})),Object.entries(a).sort().forEach((([t,e])=>{const n=t.split("/").pop(),r=t.replace(`/${n}`,""),c=[n,e instanceof Array?[...e]:{...e},t,[]];o[t]=c,s.push(c),"root"!==t&&r&&o[r]&&o[r][3].push(t)})),[r({data:e}),o,s]},toType:function(t){const e={};return t.forEach((t=>{const[,n,r]=t;if(0===Object.keys(n).length)return;const o=r.replace("root/",""),s=n instanceof Array?[...n]:{...n};e[o]=s})),e}};var O={toFlat:function(t,e){const{walk:n}=t(),r={},o={root:[]},s=[];function c(t){if("root"===t)return;const e=t.split("/");e.pop();const n=e.join("/");o[n]||(o[n]=[]),n.includes("/")&&c(n)}e.forEach((t=>{const[e,n]=t,r="root"===e?"root":`root/${e}`;o[r]?o[r].push(n):o[r]=[n],c(r)}));let a=Object.entries(o).sort();const u={root:"object"};return a.forEach((([t,e])=>{if("root"===t)return;const n=t.split("/"),r=n.pop(),o=n.join("/");"array"!==u[o]&&!isNaN(r)&&(u[o]="array"),0===e.length&&(u[t]="object")})),a=Object.entries(o).sort(),a.forEach((([t,e])=>{const[n,o,c]=function(t){let e,n,r;if("root"==t)return e="root",n="root",r=null,[e,n,r];const o=t.split("/");return 2===o.length&&(e="root",n="root",r=o.pop()),o.length>2&&(r=o.pop(),e=o.pop(),n=0===o.length?`root/${e}`:`${o.join("/")}/${e}`),[e,n,r]}(t),a=0===e.length,i=1===e.length;let l,f;if(a){if(r[`${o}/${c}`])return;return null==c?(f="object"===u.root?{}:[],l=["root",f,"root",[]],r.root=l,void s.push(l)):(f="object"===u[`${o}/${c}`]?{}:[],l=[c,f,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l))}if(!i)return l=[c,e,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l);if(r[`${o}`])r[o][1][c]=e[0];else{const t={};t[c]=e[0],l=[n,t,o,[]],r[o]=l,s.push(l)}})),s.reverse(),s.forEach((t=>{const[e,n,o]=t,s=o.replace(`/${e}`,""),c=r[s];s!==o&&c&&c[3].push(o)})),s.reverse(),[n({data:e}),r,s]},toType:function(t){let e=[];return t.forEach((t=>{const[n,r,o]=t,s=r instanceof Array;let c="";if("root"!==n&&(c=o.replace("root/","")),s)return void(0==c.length?r.forEach(((t,n)=>e.push(["root",t]))):r.forEach((t=>e.push([c,t]))));Object.entries(r).forEach((([t,n])=>{0==c.length?e.push([t,n]):e.push([`${c}/${t}`,n])}))})),e}};const T=t=>(e,n)=>{switch(t){case"std":case"standard":return v.toFlat(e,n);case"tuple":case"tuples":return O.toFlat(e,n);case"breadcrumb":case"breadcrumbs":const t=Object.entries(n);return O.toFlat(e,t);case"file":case"files":const r=n.map((t=>{let e=t.split("/");1===e.length&&(e=["root"].concat(e));const n=e.pop();return[e.join("/"),n]}));return O.toFlat(e,r);case"midFlat":return j.toFlat(e,n)}return[["object",0],{}]};var I={from:function(t){return{toFlat:T(t)}},to:function(t,e,n){const r={},{walk:o}=e(),s=new Set,c=new Set;let a,u=0;switch(t){case"flat":case"dt-model":return o({data:n});case"std":case"standard":return v.toType(n);case"midflat":case"midFlat":return j.toType(n);case"tuple":case"tuples":return O.toType(n);case"files":return a=O.toType(n),a.map((([t,e])=>"function"==typeof e?`${t}/function:${e.name}`:e?.nodeType?`${t}/HtmlElement:${e.tagName?e.tagName.toLowerCase():"notSpecified"}`:"root"===t?e:`${t}/${e}`));case"breadcrumb":case"breadcrumbs":let t;return a=O.toType(n),a.forEach((([t,e])=>s.has(t)?c.add(t):s.add(t))),a.forEach((([e,n])=>{if(c.has(e)){t!==e&&(t=e,u=0),r["root"===e?u:`${e}/${u}`]=n,u++}else r[e]=n})),r}}};function S(t,e,n){const r=t[e],o=r[2];r[2]=n,t[o]=r,r[3].forEach(((e,r)=>{const s=new RegExp(`^${o}/`),c=e.replace(s,`${n}/`);S(t[e],e,c)}))}var k={push:function(t){return function(e,n){const r=!!t[e]&&t[e][1];return r&&r instanceof Array?("object"==typeof value||r.push(n),this):this}},set:function(t,e){return function(n,r){const o=r instanceof Array,s=[];return s.push(n),o?s.push([...r]):s.push({...r}),s.push(n),s.push([]),t.push(s),e[n]=s,this}},connect:function(t){return function(e){e.forEach((e=>{let n=e.split("/");const r=n.pop(),o=n.pop(),s=t[o];if(!t[r])return this;if(!s)return this;if(s[1][r])return this;let c=`${s[2]}/${r}`;return S(t,r,c),s[3].includes(c)||s[3].push(c),this}))}},save:function(t){return function(e,n,r){const o=!!t[e]&&t[e][1];return o?(o[n]||(o[n]=r),this):this}}};const A=["std","standard","tuple","tuples","breadcrumb","breadcrumbs","file","files","midFlat","midflat","flat","dt-model"],F={dependencies:()=>({walk:t,flatData:E,flatObject:a,convert:I,INIT_DATA_TYPES:A,main:{load:F.load},isDTO:t=>"function"==typeof t.insertSegment,isDTM:t=>t instanceof Array&&(t[0]instanceof Array&&(4===t[0].length&&"root"===t[0][0])),draft:k}),init(t,e={}){let{model:n}=Object.assign({},{model:"std"},e),r=F.dependencies;if(!A.includes(n))return console.error(`Can't understand your data-model: ${n}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox`),null;return a(r,["flat","dt-model"].includes(n)?F.load(t):I.from(n).toFlat(r,t))},load(e){const n={};e.forEach((t=>{const[,,e]=t;n[e]=t}));const r=t({data:e});return a(F.dependencies,[r,n,e])},flating(t,e={}){let{model:n}=Object.assign({},{model:"std"},e);if(!A.includes(n))return null;let[,,r]=I.from("std").toFlat(F.dependencies,t);return r},converting(t,e={}){let{model:n,as:r}=Object.assign({},{model:"std",as:"std"},e);if(!A.includes(n))return null;if(!A.includes(r))return null;let[,,o]=I.from("std").toFlat(F.dependencies,t);return I.to(r,F.dependencies,o)},getWalk:()=>t},{init:w,load:N,flating:L,converting:x,getWalk:D}=F,H={init:w,load:N,flat:L,convert:x,getWalk:D};module.exports=H;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"@peter.naydenov/walk";function e(t,e){return function(n,r){const{convert:o,isDTO:s,isDTM:c,walk:a}=t();let u,i;s(r)?(u=r.export(),i=r.copy()):c(r)?(u=a({data:r}),i=a({data:r})):([i,,u]=o.from("std").toFlat(t,r),console.warn('A non "dt-object" data segment was inserted. Autoconverted to "dt-object".'));const l=new RegExp("^root/");u.forEach((t=>{t[0]===t[2]&&(t[0]=n,t[2]=n),t[2]=t[2].replace(l,`${n}/`),t[3].forEach(((e,r)=>t[3][r]=e.replace(l,`${n}/`)))})),e.insert([i,,u])}}function n(t,e){return t=>e.export(t)}function r(t,e){return function(n="root"){const r=e.getCopy(n),{walk:o}=t();return r?o({data:r}):null}}function o(t,e,n){return function(){let r=[],o={};const{convert:s,draft:c,INIT_DATA_TYPES:a,main:{load:u}}=t(),i={set:c.set(r,o),connect:c.connect(o),save:c.save(o),push:c.push(o)},[l,...f]=arguments,{as:p}=l({...n,...i},...f)||{},d=0===r.length?e.export():r,h=!!p&&a.includes(p);let m;return"dt-object"===p?u(d):p&&!h?(console.error(`Model '${p}' is unknown data-model.`),null):(m=p?s.to(p,t,d):u(d),e.resetScan(),m)}}function s(t,e,n){return function(){const{main:{load:r},draft:o}=t(),[s,...c]=arguments;let a=[],u={};const i={set:o.set(a,u),connect:o.connect(u),save:o.save(u),push:o.push(u)};return s({...n,...i},...c),e.resetScan(),0===a.length?this:r(a)}}function c(t){return function(e,n){t.setupFilter(e,n)}}function a(t,a){const{flatData:u}=t(),[i,l]=u(t,a),f={insertSegment:e(t,i),export:n(0,i),copy:r(t,i),model:o(t,i,l),query:s(t,i,l),setupFilter:c(i),listSegments:()=>Object.keys(i.getIndexes()).reduce(((t,e)=>(e.includes("/")||t.push(e),t)),[]),index:p};function p(t){if(null==t)return null;let e=i.getLine(t);if(e){let t,[n,r,o,s]=e;return t=r instanceof Array?[...r]:{...r},[n,t,o,[...s]]}return null}return f.extractList=function(t,e,n){return function(r,o){const s=n("root"),{main:{load:c},INIT_DATA_TYPES:a}=t(),u=[...a,"dt-object"];let i=!1,l="";if(o&&(o.as||(i=!0,l='Options should be an object and property "as" is required'),i||u.includes(o.as)||(i=!0,l=`Invalid option "as" value: ${o.as}.`),i))throw new Error(l);return r.map((t=>{let n=e.export(t);return 0===n.length?s[1].hasOwnProperty(t)?s[1][t]:null:n})).map((t=>null==t?null:t instanceof Array?c(t).model((()=>o)):t))}}(t,i,p),f}function u(t,e,n){return function(r){const[o,,s]=r,c=s[0][0],[a,u,i]=t,l=n();a[c]=o,s.forEach((t=>{const[,,n]=t;u[n]=t,i.push(t),l.forEach((n=>e(n,t)))}))}}function i(t){return function(e){const[,n,r]=t;if(e&&!n[e])return[];if(!e){const t=[];return r.forEach((e=>{const[n,r,o,s]=e,c=r instanceof Array?[...r]:{...r};t.push([n,c,o,[...s]])})),t}const o=[];return r.forEach((t=>{const[n,r,s,c]=t,a=new RegExp(`^${e}/`);if(s===e||s.match(a)){let t=n===s?"root":n,e=r instanceof Array?[...r]:{...r},u=s.includes("/")?s.replace(a,"root/"):"root",i=c.map((t=>t.replace(a,"root/")));o.push([t,e,u,i])}})),o}}function l(t,e,n,r){return function(o,s){const c=r(),[,,a]=t;if(c.includes(o))return console.error(`Filter name "${o}" is already defined`),this;e[o]=s,a.forEach((t=>n(o,t)))}}function f(t){return function(e){const n=t.getIndexes(),r=n[e],o=[];return r?(o.push(r),p(n,o,r[3]),t.setupScanList(o),this):(t.setupScanList([]),this)}}function p(t,e,n){n.forEach((n=>{const r=t[n];r&&(e.push(r),p(t,e,r[3]))}))}function d(t){return function(e){const n=[];return t.getScanList().forEach((t=>{t[0]===e&&n.push(t)})),t.setupScanList(n),this}}function h(t){return function(e){const n=[],r=e instanceof Array?e:[e];return t.getScanList().forEach((t=>{const e=t[0];r.forEach((r=>{e.includes(r)&&n.push(t)}))})),t.setupScanList(n),this}}function m(t){return function(e){t.getScanList().forEach((n=>{const[r,o,s,c]=n,a=o instanceof Array,u=()=>"$__NEXT__LOOK_",i=()=>"$__FINISH__WITH__THE__LOOKING_";let l=!1;const f=c.map((t=>{let e=t.replace(`${s}/`,"");return[r,e]}));if(a)0===o.length?p([]):o.every(((t,n)=>{if(l)return!1;const c=e({value:t,key:n,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}));else{const t=Object.entries(o);0===t.length?p({}):t.every((([t,n])=>{if(l)return!1;const c=e({value:n,key:t,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}))}function p(t){e({value:null,key:null,name:r,flatData:t,breadcrumbs:s,links:f,empty:!0,next:u,finish:i})}t.resetScan()}))}}function b(t){return function(e){const n=[];return t.getScanList().every((t=>t[2]!==e||(n.push(t),!1))),t.setupScanList(n),this}}function _({flatData:t}){return t instanceof Array}function y({name:t,flatData:e}){return!(e instanceof Array)&&!isNaN(t)}function g({flatData:t}){return!(t instanceof Array)}function $({name:t,breadcrumbs:e}){return t===e}function E(t,e){const[n,r,o]=e,s=[n,r,o],c={},a={list:_,listObject:y,object:g,root:$};let p=o;const E=()=>Object.keys(a),j=(t,e)=>{if(a[t]){const[n,o,s,u]=e;if(c[t]||(c[t]=[]),a[t]({name:n,flatData:o,breadcrumbs:s,edges:u})){const e=r[s];c[t].push(e)}}};E().forEach((t=>o.forEach((e=>j(t,e)))));const v={insert:u(s,j,E),export:i(s),getCopy:t=>n[t]?n[t]:null,getIndexes:()=>r,getLine:t=>r[t]?r[t]:null,getFilters:()=>c,getScanList:()=>p,setupScanList:t=>p=t,setupFilter:l(s,a,j,E),resetScan:()=>{p=o}};var O;return[v,{from:f(v),use:(O=v,function(t){const e=O.getFilters()[t];return e&&O.setupScanList(e),this}),get:b(v),find:d(v),like:h(v),look:m(v)}]}var j={toFlat:function(t,e){const n=e instanceof Array?[]:{},{walk:r}=t(),o=[["root",n,"root",[]]],s={root:o[0]},c=r({data:e,keyCallback:function({value:t,key:e,breadcrumbs:n}){const r=new RegExp(`/${e}$`),o=n.replace(r,"");return s[o][1][e]=t,t},objectCallback:function({value:t,key:e,breadcrumbs:n}){const r=t instanceof Array?[]:{},c=e,a=new RegExp(`/${e}$`),u=n.replace(a,""),i=[c,r,n,[]];return s[u][3].push(n),o.push(i),s[n]=o.at(-1),t}});return[{root:c},s,o]},toType:function(t){let e={};return t.reverse().forEach((([t,n,r,o])=>{const s=n instanceof Array?[...n]:{...n};e[r]=s,o.forEach((t=>{if(e[t]){const n=t.replace(`${r}/`,"");e[r][n]=e[t]}}))})),e.root}};var v={toFlat:function(t,e){const n=Object.entries(e),{walk:r}=t(),o={},s=[],c={},a={};function u(t){c[t]||(c[t]="object");const e=t.split("/");1!=e.length&&(e.pop(),1!=e.length&&u(e.join("/")))}return n.forEach((([t,e])=>{t.startsWith("root")||(t=`root/${t}`),u(t),function(t,e){Object.keys(e).forEach((e=>{isNaN(e)||(c[t]="array")}))}(t,e),a[t]=e})),Object.entries(c).forEach((([t,e])=>{if("object"===a[t])return;if(a[t]){const n=a[t]instanceof Array;if("array"===e&&!n){const e=Object.values(a[t]);a[t]=e}return}const n="object"===e?{}:[];a[t]=n})),Object.entries(a).sort().forEach((([t,e])=>{const n=t.split("/").pop(),r=t.replace(`/${n}`,""),c=[n,e instanceof Array?[...e]:{...e},t,[]];o[t]=c,s.push(c),"root"!==t&&r&&o[r]&&o[r][3].push(t)})),[r({data:e}),o,s]},toType:function(t){const e={};return t.forEach((t=>{const[,n,r]=t;if(0===Object.keys(n).length)return;const o=r.replace("root/",""),s=n instanceof Array?[...n]:{...n};e[o]=s})),e}};var O={toFlat:function(t,e){const{walk:n}=t(),r={},o={root:[]},s=[];function c(t){if("root"===t)return;const e=t.split("/");e.pop();const n=e.join("/");o[n]||(o[n]=[]),n.includes("/")&&c(n)}e.forEach((t=>{const[e,n]=t,r="root"===e?"root":`root/${e}`;o[r]?o[r].push(n):o[r]=[n],c(r)}));let a=Object.entries(o).sort();const u={root:"object"};return a.forEach((([t,e])=>{if("root"===t)return;const n=t.split("/"),r=n.pop(),o=n.join("/");"array"!==u[o]&&!isNaN(r)&&(u[o]="array"),0===e.length&&(u[t]="object")})),a=Object.entries(o).sort(),a.forEach((([t,e])=>{const[n,o,c]=function(t){let e,n,r;if("root"==t)return e="root",n="root",r=null,[e,n,r];const o=t.split("/");return 2===o.length&&(e="root",n="root",r=o.pop()),o.length>2&&(r=o.pop(),e=o.pop(),n=0===o.length?`root/${e}`:`${o.join("/")}/${e}`),[e,n,r]}(t),a=0===e.length,i=1===e.length;let l,f;if(a){if(r[`${o}/${c}`])return;return null==c?(f="object"===u.root?{}:[],l=["root",f,"root",[]],r.root=l,void s.push(l)):(f="object"===u[`${o}/${c}`]?{}:[],l=[c,f,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l))}if(!i)return l=[c,e,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l);if(r[`${o}`])r[o][1][c]=e[0];else{const t={};t[c]=e[0],l=[n,t,o,[]],r[o]=l,s.push(l)}})),s.reverse(),s.forEach((t=>{const[e,n,o]=t,s=o.replace(`/${e}`,""),c=r[s];s!==o&&c&&c[3].push(o)})),s.reverse(),[n({data:e}),r,s]},toType:function(t){let e=[];return t.forEach((t=>{const[n,r,o]=t,s=r instanceof Array;let c="";if("root"!==n&&(c=o.replace("root/","")),s)return void(0==c.length?r.forEach(((t,n)=>e.push(["root",t]))):r.forEach((t=>e.push([c,t]))));Object.entries(r).forEach((([t,n])=>{0==c.length?e.push([t,n]):e.push([`${c}/${t}`,n])}))})),e}};const T=t=>(e,n)=>{switch(t){case"std":case"standard":return j.toFlat(e,n);case"tuple":case"tuples":return O.toFlat(e,n);case"breadcrumb":case"breadcrumbs":const t=Object.entries(n);return O.toFlat(e,t);case"file":case"files":const r=n.map((t=>{let e=t.split("/");1===e.length&&(e=["root"].concat(e));const n=e.pop();return[e.join("/"),n]}));return O.toFlat(e,r);case"midFlat":return v.toFlat(e,n)}return[["object",0],{}]};var I={from:function(t){return{toFlat:T(t)}},to:function(t,e,n){const r={},{walk:o}=e(),s=new Set,c=new Set;let a,u=0;switch(t){case"flat":case"dt-model":return o({data:n});case"std":case"standard":return j.toType(n);case"midflat":case"midFlat":return v.toType(n);case"tuple":case"tuples":return O.toType(n);case"files":return a=O.toType(n),a.map((([t,e])=>"function"==typeof e?`${t}/function:${e.name}`:e?.nodeType?`${t}/HtmlElement:${e.tagName?e.tagName.toLowerCase():"notSpecified"}`:"root"===t?e:`${t}/${e}`));case"breadcrumb":case"breadcrumbs":let t;return a=O.toType(n),a.forEach((([t,e])=>s.has(t)?c.add(t):s.add(t))),a.forEach((([e,n])=>{if(c.has(e)){t!==e&&(t=e,u=0),r["root"===e?u:`${e}/${u}`]=n,u++}else r[e]=n})),r}}};function S(t,e,n){const r=t[e],o=r[2];r[2]=n,t[o]=r,r[3].forEach(((e,r)=>{const s=new RegExp(`^${o}/`),c=e.replace(s,`${n}/`);S(t[e],e,c)}))}var k={push:function(t){return function(e,n){const r=!!t[e]&&t[e][1];return r&&r instanceof Array?("object"==typeof value||r.push(n),this):this}},set:function(t,e){return function(n,r){const o=r instanceof Array,s=[];return s.push(n),o?s.push([...r]):s.push({...r}),s.push(n),s.push([]),t.push(s),e[n]=s,this}},connect:function(t){return function(e){e.forEach((e=>{let n=e.split("/");const r=n.pop(),o=n.pop(),s=t[o];if(!t[r])return this;if(!s)return this;if(s[1][r])return this;let c=`${s[2]}/${r}`;return S(t,r,c),s[3].includes(c)||s[3].push(c),this}))}},save:function(t){return function(e,n,r){const o=!!t[e]&&t[e][1];return o?(o[n]||(o[n]=r),this):this}}};const A=["std","standard","tuple","tuples","breadcrumb","breadcrumbs","file","files","midFlat","midflat","flat","dt-model"],F={dependencies:()=>({walk:t,flatData:E,flatObject:a,convert:I,INIT_DATA_TYPES:A,main:{load:F.load},isDTO:t=>"function"==typeof t.insertSegment,isDTM:t=>t instanceof Array&&(t[0]instanceof Array&&(4===t[0].length&&"root"===t[0][0])),draft:k}),init(t,e={}){let{model:n}=Object.assign({},{model:"std"},e),r=F.dependencies;if(!A.includes(n))return console.error(`Can't understand your data-model: ${n}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox`),null;return a(r,["flat","dt-model"].includes(n)?F.load(t):I.from(n).toFlat(r,t))},load(e){const n={};e.forEach((t=>{const[,,e]=t;n[e]=t}));const r=t({data:e});return a(F.dependencies,[r,n,e])},flating(t,e={}){let{model:n}=Object.assign({},{model:"std"},e);if(!A.includes(n))return null;let[,,r]=I.from("std").toFlat(F.dependencies,t);return r},converting(t,e={}){let{model:n,as:r}=Object.assign({},{model:"std",as:"std"},e);if(!A.includes(n))return null;if(!A.includes(r))return null;let[,,o]=I.from("std").toFlat(F.dependencies,t);return I.to(r,F.dependencies,o)},getWalk:()=>t},{init:w,load:N,flating:L,converting:x,getWalk:D}=F,H={init:w,load:N,flat:L,convert:x,getWalk:D};export{H as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@peter.naydenov/walk")):"function"==typeof define&&define.amd?define(["@peter.naydenov/walk"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).dtbox=e(t.walk)}(this,(function(t){"use strict";function e(t,e){return function(n,r){const{convert:o,isDTO:s,isDTM:c,walk:a}=t();let u,i;s(r)?(u=r.export(),i=r.copy()):c(r)?(u=a({data:r}),i=a({data:r})):([i,,u]=o.from("std").toFlat(t,r),console.warn('A non "dt-object" data segment was inserted. Autoconverted to "dt-object".'));const l=new RegExp("^root/");u.forEach((t=>{t[0]===t[2]&&(t[0]=n,t[2]=n),t[2]=t[2].replace(l,`${n}/`),t[3].forEach(((e,r)=>t[3][r]=e.replace(l,`${n}/`)))})),e.insert([i,,u])}}function n(t,e){return t=>e.export(t)}function r(t,e){return function(n="root"){const r=e.getCopy(n),{walk:o}=t();return r?o({data:r}):null}}function o(t,e,n){return function(){let r=[],o={};const{convert:s,draft:c,INIT_DATA_TYPES:a,main:{load:u}}=t(),i={set:c.set(r,o),connect:c.connect(o),save:c.save(o),push:c.push(o)},[l,...f]=arguments,{as:d}=l({...n,...i},...f)||{},p=0===r.length?e.export():r,h=!!d&&a.includes(d);let b;return"dt-object"===d?u(p):d&&!h?(console.error(`Model '${d}' is unknown data-model.`),null):(b=d?s.to(d,t,p):u(p),e.resetScan(),b)}}function s(t,e,n){return function(){const{main:{load:r},draft:o}=t(),[s,...c]=arguments;let a=[],u={};const i={set:o.set(a,u),connect:o.connect(u),save:o.save(u),push:o.push(u)};return s({...n,...i},...c),e.resetScan(),0===a.length?this:r(a)}}function c(t){return function(e,n){t.setupFilter(e,n)}}function a(t,a){const{flatData:u}=t(),[i,l]=u(t,a),f={insertSegment:e(t,i),export:n(0,i),copy:r(t,i),model:o(t,i,l),query:s(t,i,l),setupFilter:c(i),listSegments:()=>Object.keys(i.getIndexes()).reduce(((t,e)=>(e.includes("/")||t.push(e),t)),[]),index:d};function d(t){if(null==t)return null;let e=i.getLine(t);if(e){let t,[n,r,o,s]=e;return t=r instanceof Array?[...r]:{...r},[n,t,o,[...s]]}return null}return f.extractList=function(t,e,n){return function(r,o){const s=n("root"),{main:{load:c},INIT_DATA_TYPES:a}=t(),u=[...a,"dt-object"];let i=!1,l="";if(o&&(o.as||(i=!0,l='Options should be an object and property "as" is required'),i||u.includes(o.as)||(i=!0,l=`Invalid option "as" value: ${o.as}.`),i))throw new Error(l);return r.map((t=>{let n=e.export(t);return 0===n.length?s[1].hasOwnProperty(t)?s[1][t]:null:n})).map((t=>null==t?null:t instanceof Array?c(t).model((()=>o)):t))}}(t,i,d),f}function u(t,e,n){return function(r){const[o,,s]=r,c=s[0][0],[a,u,i]=t,l=n();a[c]=o,s.forEach((t=>{const[,,n]=t;u[n]=t,i.push(t),l.forEach((n=>e(n,t)))}))}}function i(t){return function(e){const[,n,r]=t;if(e&&!n[e])return[];if(!e){const t=[];return r.forEach((e=>{const[n,r,o,s]=e,c=r instanceof Array?[...r]:{...r};t.push([n,c,o,[...s]])})),t}const o=[];return r.forEach((t=>{const[n,r,s,c]=t,a=new RegExp(`^${e}/`);if(s===e||s.match(a)){let t=n===s?"root":n,e=r instanceof Array?[...r]:{...r},u=s.includes("/")?s.replace(a,"root/"):"root",i=c.map((t=>t.replace(a,"root/")));o.push([t,e,u,i])}})),o}}function l(t,e,n,r){return function(o,s){const c=r(),[,,a]=t;if(c.includes(o))return console.error(`Filter name "${o}" is already defined`),this;e[o]=s,a.forEach((t=>n(o,t)))}}function f(t){return function(e){const n=t.getIndexes(),r=n[e],o=[];return r?(o.push(r),d(n,o,r[3]),t.setupScanList(o),this):(t.setupScanList([]),this)}}function d(t,e,n){n.forEach((n=>{const r=t[n];r&&(e.push(r),d(t,e,r[3]))}))}function p(t){return function(e){const n=[];return t.getScanList().forEach((t=>{t[0]===e&&n.push(t)})),t.setupScanList(n),this}}function h(t){return function(e){const n=[],r=e instanceof Array?e:[e];return t.getScanList().forEach((t=>{const e=t[0];r.forEach((r=>{e.includes(r)&&n.push(t)}))})),t.setupScanList(n),this}}function b(t){return function(e){t.getScanList().forEach((n=>{const[r,o,s,c]=n,a=o instanceof Array,u=()=>"$__NEXT__LOOK_",i=()=>"$__FINISH__WITH__THE__LOOKING_";let l=!1;const f=c.map((t=>{let e=t.replace(`${s}/`,"");return[r,e]}));if(a)0===o.length?d([]):o.every(((t,n)=>{if(l)return!1;const c=e({value:t,key:n,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}));else{const t=Object.entries(o);0===t.length?d({}):t.every((([t,n])=>{if(l)return!1;const c=e({value:n,key:t,name:r,flatData:o,breadcrumbs:s,links:f,next:u,finish:i});return"$__FINISH__WITH__THE__LOOKING_"===c&&(l=!0),!["$__FINISH__WITH__THE__LOOKING_","$__NEXT__LOOK_"].includes(c)}))}function d(t){e({value:null,key:null,name:r,flatData:t,breadcrumbs:s,links:f,empty:!0,next:u,finish:i})}t.resetScan()}))}}function m(t){return function(e){const n=[];return t.getScanList().every((t=>t[2]!==e||(n.push(t),!1))),t.setupScanList(n),this}}function y({flatData:t}){return t instanceof Array}function _({name:t,flatData:e}){return!(e instanceof Array)&&!isNaN(t)}function g({flatData:t}){return!(t instanceof Array)}function $({name:t,breadcrumbs:e}){return t===e}function E(t,e){const[n,r,o]=e,s=[n,r,o],c={},a={list:y,listObject:_,object:g,root:$};let d=o;const E=()=>Object.keys(a),j=(t,e)=>{if(a[t]){const[n,o,s,u]=e;if(c[t]||(c[t]=[]),a[t]({name:n,flatData:o,breadcrumbs:s,edges:u})){const e=r[s];c[t].push(e)}}};E().forEach((t=>o.forEach((e=>j(t,e)))));const v={insert:u(s,j,E),export:i(s),getCopy:t=>n[t]?n[t]:null,getIndexes:()=>r,getLine:t=>r[t]?r[t]:null,getFilters:()=>c,getScanList:()=>d,setupScanList:t=>d=t,setupFilter:l(s,a,j,E),resetScan:()=>{d=o}};var O;return[v,{from:f(v),use:(O=v,function(t){const e=O.getFilters()[t];return e&&O.setupScanList(e),this}),get:m(v),find:p(v),like:h(v),look:b(v)}]}var j={toFlat:function(t,e){const n=e instanceof Array?[]:{},{walk:r}=t(),o=[["root",n,"root",[]]],s={root:o[0]},c=r({data:e,keyCallback:function({value:t,key:e,breadcrumbs:n}){const r=new RegExp(`/${e}$`),o=n.replace(r,"");return s[o][1][e]=t,t},objectCallback:function({value:t,key:e,breadcrumbs:n}){const r=t instanceof Array?[]:{},c=e,a=new RegExp(`/${e}$`),u=n.replace(a,""),i=[c,r,n,[]];return s[u][3].push(n),o.push(i),s[n]=o.at(-1),t}});return[{root:c},s,o]},toType:function(t){let e={};return t.reverse().forEach((([t,n,r,o])=>{const s=n instanceof Array?[...n]:{...n};e[r]=s,o.forEach((t=>{if(e[t]){const n=t.replace(`${r}/`,"");e[r][n]=e[t]}}))})),e.root}};var v={toFlat:function(t,e){const n=Object.entries(e),{walk:r}=t(),o={},s=[],c={},a={};function u(t){c[t]||(c[t]="object");const e=t.split("/");1!=e.length&&(e.pop(),1!=e.length&&u(e.join("/")))}return n.forEach((([t,e])=>{t.startsWith("root")||(t=`root/${t}`),u(t),function(t,e){Object.keys(e).forEach((e=>{isNaN(e)||(c[t]="array")}))}(t,e),a[t]=e})),Object.entries(c).forEach((([t,e])=>{if("object"===a[t])return;if(a[t]){const n=a[t]instanceof Array;if("array"===e&&!n){const e=Object.values(a[t]);a[t]=e}return}const n="object"===e?{}:[];a[t]=n})),Object.entries(a).sort().forEach((([t,e])=>{const n=t.split("/").pop(),r=t.replace(`/${n}`,""),c=[n,e instanceof Array?[...e]:{...e},t,[]];o[t]=c,s.push(c),"root"!==t&&r&&o[r]&&o[r][3].push(t)})),[r({data:e}),o,s]},toType:function(t){const e={};return t.forEach((t=>{const[,n,r]=t;if(0===Object.keys(n).length)return;const o=r.replace("root/",""),s=n instanceof Array?[...n]:{...n};e[o]=s})),e}};var O={toFlat:function(t,e){const{walk:n}=t(),r={},o={root:[]},s=[];function c(t){if("root"===t)return;const e=t.split("/");e.pop();const n=e.join("/");o[n]||(o[n]=[]),n.includes("/")&&c(n)}e.forEach((t=>{const[e,n]=t,r="root"===e?"root":`root/${e}`;o[r]?o[r].push(n):o[r]=[n],c(r)}));let a=Object.entries(o).sort();const u={root:"object"};return a.forEach((([t,e])=>{if("root"===t)return;const n=t.split("/"),r=n.pop(),o=n.join("/");"array"!==u[o]&&!isNaN(r)&&(u[o]="array"),0===e.length&&(u[t]="object")})),a=Object.entries(o).sort(),a.forEach((([t,e])=>{const[n,o,c]=function(t){let e,n,r;if("root"==t)return e="root",n="root",r=null,[e,n,r];const o=t.split("/");return 2===o.length&&(e="root",n="root",r=o.pop()),o.length>2&&(r=o.pop(),e=o.pop(),n=0===o.length?`root/${e}`:`${o.join("/")}/${e}`),[e,n,r]}(t),a=0===e.length,i=1===e.length;let l,f;if(a){if(r[`${o}/${c}`])return;return null==c?(f="object"===u.root?{}:[],l=["root",f,"root",[]],r.root=l,void s.push(l)):(f="object"===u[`${o}/${c}`]?{}:[],l=[c,f,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l))}if(!i)return l=[c,e,`${o}/${c}`,[]],r[`${o}/${c}`]=l,void s.push(l);if(r[`${o}`])r[o][1][c]=e[0];else{const t={};t[c]=e[0],l=[n,t,o,[]],r[o]=l,s.push(l)}})),s.reverse(),s.forEach((t=>{const[e,n,o]=t,s=o.replace(`/${e}`,""),c=r[s];s!==o&&c&&c[3].push(o)})),s.reverse(),[n({data:e}),r,s]},toType:function(t){let e=[];return t.forEach((t=>{const[n,r,o]=t,s=r instanceof Array;let c="";if("root"!==n&&(c=o.replace("root/","")),s)return void(0==c.length?r.forEach(((t,n)=>e.push(["root",t]))):r.forEach((t=>e.push([c,t]))));Object.entries(r).forEach((([t,n])=>{0==c.length?e.push([t,n]):e.push([`${c}/${t}`,n])}))})),e}};const T=t=>(e,n)=>{switch(t){case"std":case"standard":return j.toFlat(e,n);case"tuple":case"tuples":return O.toFlat(e,n);case"breadcrumb":case"breadcrumbs":const t=Object.entries(n);return O.toFlat(e,t);case"file":case"files":const r=n.map((t=>{let e=t.split("/");1===e.length&&(e=["root"].concat(e));const n=e.pop();return[e.join("/"),n]}));return O.toFlat(e,r);case"midFlat":return v.toFlat(e,n)}return[["object",0],{}]};var k={from:function(t){return{toFlat:T(t)}},to:function(t,e,n){const r={},{walk:o}=e(),s=new Set,c=new Set;let a,u=0;switch(t){case"flat":case"dt-model":return o({data:n});case"std":case"standard":return j.toType(n);case"midflat":case"midFlat":return v.toType(n);case"tuple":case"tuples":return O.toType(n);case"files":return a=O.toType(n),a.map((([t,e])=>"function"==typeof e?`${t}/function:${e.name}`:e?.nodeType?`${t}/HtmlElement:${e.tagName?e.tagName.toLowerCase():"notSpecified"}`:"root"===t?e:`${t}/${e}`));case"breadcrumb":case"breadcrumbs":let t;return a=O.toType(n),a.forEach((([t,e])=>s.has(t)?c.add(t):s.add(t))),a.forEach((([e,n])=>{if(c.has(e)){t!==e&&(t=e,u=0),r["root"===e?u:`${e}/${u}`]=n,u++}else r[e]=n})),r}}};function I(t,e,n){const r=t[e],o=r[2];r[2]=n,t[o]=r,r[3].forEach(((e,r)=>{const s=new RegExp(`^${o}/`),c=e.replace(s,`${n}/`);I(t[e],e,c)}))}var S={push:function(t){return function(e,n){const r=!!t[e]&&t[e][1];return r&&r instanceof Array?("object"==typeof value||r.push(n),this):this}},set:function(t,e){return function(n,r){const o=r instanceof Array,s=[];return s.push(n),o?s.push([...r]):s.push({...r}),s.push(n),s.push([]),t.push(s),e[n]=s,this}},connect:function(t){return function(e){e.forEach((e=>{let n=e.split("/");const r=n.pop(),o=n.pop(),s=t[o];if(!t[r])return this;if(!s)return this;if(s[1][r])return this;let c=`${s[2]}/${r}`;return I(t,r,c),s[3].includes(c)||s[3].push(c),this}))}},save:function(t){return function(e,n,r){const o=!!t[e]&&t[e][1];return o?(o[n]||(o[n]=r),this):this}}};const A=["std","standard","tuple","tuples","breadcrumb","breadcrumbs","file","files","midFlat","midflat","flat","dt-model"],w={dependencies:()=>({walk:t,flatData:E,flatObject:a,convert:k,INIT_DATA_TYPES:A,main:{load:w.load},isDTO:t=>"function"==typeof t.insertSegment,isDTM:t=>t instanceof Array&&(t[0]instanceof Array&&(4===t[0].length&&"root"===t[0][0])),draft:S}),init(t,e={}){let{model:n}=Object.assign({},{model:"std"},e),r=w.dependencies;if(!A.includes(n))return console.error(`Can't understand your data-model: ${n}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox`),null;return a(r,["flat","dt-model"].includes(n)?w.load(t):k.from(n).toFlat(r,t))},load(e){const n={};e.forEach((t=>{const[,,e]=t;n[e]=t}));const r=t({data:e});return a(w.dependencies,[r,n,e])},flating(t,e={}){let{model:n}=Object.assign({},{model:"std"},e);if(!A.includes(n))return null;let[,,r]=k.from("std").toFlat(w.dependencies,t);return r},converting(t,e={}){let{model:n,as:r}=Object.assign({},{model:"std",as:"std"},e);if(!A.includes(n))return null;if(!A.includes(r))return null;let[,,o]=k.from("std").toFlat(w.dependencies,t);return k.to(r,w.dependencies,o)},getWalk:()=>t},{init:F,load:N,flating:L,converting:x,getWalk:D}=w;return{init:F,load:N,flat:L,convert:x,getWalk:D}}));
|
package/package.json
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dt-toolbox",
|
|
3
3
|
"description": "Data manipulation tool",
|
|
4
|
-
"version": "7.4.
|
|
4
|
+
"version": "7.4.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
|
-
"
|
|
8
|
-
"flatten",
|
|
9
|
-
"shallow",
|
|
10
|
-
"data",
|
|
11
|
-
"object",
|
|
12
|
-
"structure",
|
|
13
|
-
"dt"
|
|
14
|
-
],
|
|
15
|
-
"main": "src/main.js",
|
|
7
|
+
"main": "./dist/dtbox.umd.js",
|
|
16
8
|
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/dtbox.esm.mjs",
|
|
12
|
+
"require": "./dist/dtbox.cjs",
|
|
13
|
+
"default": "./dist/dtbox.umd.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
"./dist/*": "./dist/*",
|
|
17
|
+
"./src/*": "./src/*"
|
|
18
|
+
},
|
|
17
19
|
"scripts": {
|
|
18
20
|
"start": "node src/main.js",
|
|
19
21
|
"test": "mocha test",
|
|
20
|
-
"cover": "c8 mocha test"
|
|
22
|
+
"cover": "c8 mocha test",
|
|
23
|
+
"build": "rollup -c"
|
|
21
24
|
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
@@ -28,12 +31,16 @@
|
|
|
28
31
|
},
|
|
29
32
|
"homepage": "https://github.com/PeterNaydenov/dt-toolbox#readme",
|
|
30
33
|
"dependencies": {
|
|
31
|
-
"@peter.naydenov/walk": "4.2.
|
|
34
|
+
"@peter.naydenov/walk": "4.2.3"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
39
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
40
|
+
"c8": "^9.1.0",
|
|
41
|
+
"chai": "^5.0.3",
|
|
42
|
+
"mocha": "^10.2.0",
|
|
43
|
+
"rollup": "^4.9.6"
|
|
37
44
|
},
|
|
38
45
|
"c8": {
|
|
39
46
|
"include": [
|
|
@@ -48,5 +55,13 @@
|
|
|
48
55
|
"lcov",
|
|
49
56
|
"text-summary"
|
|
50
57
|
]
|
|
51
|
-
}
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"flatten",
|
|
61
|
+
"shallow",
|
|
62
|
+
"data",
|
|
63
|
+
"object",
|
|
64
|
+
"structure",
|
|
65
|
+
"dt"
|
|
66
|
+
]
|
|
52
67
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
+
import terser from '@rollup/plugin-terser';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
// browser-friendly UMD build
|
|
8
|
+
{
|
|
9
|
+
input: 'src/main.js',
|
|
10
|
+
output: {
|
|
11
|
+
name: 'dtbox',
|
|
12
|
+
file: 'dist/dtbox.umd.js',
|
|
13
|
+
format: 'umd',
|
|
14
|
+
globals: {
|
|
15
|
+
'@peter.naydenov/walk': 'walk'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
external: ['@peter.naydenov/walk'],
|
|
19
|
+
plugins: [
|
|
20
|
+
resolve(), // so Rollup can find `ms`
|
|
21
|
+
commonjs() // so Rollup can convert `ms` to an ES module
|
|
22
|
+
, terser()
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
// CommonJS (for Node) and ES module (for bundlers) build.
|
|
27
|
+
// (We could have three entries in the configuration array
|
|
28
|
+
// instead of two, but it's quicker to generate multiple
|
|
29
|
+
// builds from a single configuration where possible, using
|
|
30
|
+
// an array for the `output` option, where we can specify
|
|
31
|
+
// `file` and `format` for each target)
|
|
32
|
+
{
|
|
33
|
+
input: 'src/main.js',
|
|
34
|
+
external: ['@peter.naydenov/walk'],
|
|
35
|
+
output: [
|
|
36
|
+
{ file: 'dist/dtbox.cjs' , format: 'cjs' },
|
|
37
|
+
{ file: 'dist/dtbox.esm.mjs', format: 'es' }
|
|
38
|
+
],
|
|
39
|
+
plugins: [ terser() ]
|
|
40
|
+
}
|
|
41
|
+
];
|
package/src/flatData/export.js
CHANGED
package/src/mainLib.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
import walk
|
|
5
|
+
import walk from '@peter.naydenov/walk' // Docs: https://github.com/PeterNaydenov/walk#readme
|
|
6
6
|
|
|
7
7
|
import flatObject from './flatObject/index.js' // Flat data api.
|
|
8
8
|
import flatData from './flatData/index.js' // Query data api. Used in model functions
|