object-treeify
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -10,5 +10,5 @@ import assert from './assert.js'; | ||
keyNeighbour: '├─ ', | ||
renderFn: (node) => (['boolean', 'string', 'number'].includes(typeof node) ? `: ${node}` : ''), | ||
sortFn: null, | ||
breakCircularWith: ' (circular ref.)', | ||
renderFn: (node) => (['boolean', 'string', 'number'].includes(typeof node) ? `: ${node}` : ''), | ||
...opts | ||
@@ -22,2 +22,3 @@ }; | ||
assert(typeof ctx.keyNeighbour === 'string', 'Option "keyNeighbour" has invalid format'); | ||
assert(typeof ctx.renderFn === 'function', 'Option "renderFn" has invalid format'); | ||
assert(typeof ctx.sortFn === 'function' || ctx.sortFn === null, 'Option "sortFn" has invalid format'); | ||
@@ -28,3 +29,2 @@ assert( | ||
); | ||
assert(typeof ctx.renderFn === 'function', 'Option "renderFn" has invalid format'); | ||
return ctx; | ||
@@ -31,0 +31,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
var e={};(()=>{e.d=(r,t)=>{for(var o in t){if(e.o(t,o)&&!e.o(r,o)){Object.defineProperty(r,o,{enumerable:true,get:t[o]})}}}})();(()=>{e.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r)})();if(typeof e!=="undefined")e.ab=new URL(".",import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/)?1:0,-1)+"/";var r={};e.d(r,{Z:()=>lib});const assert=(e,r)=>{if(!e){throw new Error(r)}};const buildCtx=e=>{const r={joined:true,spacerNoNeighbour:" ",spacerNeighbour:"│ ",keyNoNeighbour:"└─ ",keyNeighbour:"├─ ",sortFn:null,breakCircularWith:" (circular ref.)",renderFn:e=>["boolean","string","number"].includes(typeof e)?`: ${e}`:"",...e};assert(Object.keys(r).length===8,"Unexpected Option(s) provided");assert(typeof r.joined==="boolean",'Option "joined" has invalid format');assert(typeof r.spacerNoNeighbour==="string",'Option "spacerNoNeighbour" has invalid format');assert(typeof r.spacerNeighbour==="string",'Option "spacerNeighbour" has invalid format');assert(typeof r.keyNoNeighbour==="string",'Option "keyNoNeighbour" has invalid format');assert(typeof r.keyNeighbour==="string",'Option "keyNeighbour" has invalid format');assert(typeof r.sortFn==="function"||r.sortFn===null,'Option "sortFn" has invalid format');assert(typeof r.breakCircularWith==="string"||r.breakCircularWith===null,'Option "breakCircularWith" has invalid format');assert(typeof r.renderFn==="function",'Option "renderFn" has invalid format');return r};const lib=(e,r={})=>{const t=buildCtx(r);const o=[];const sort=e=>t.sortFn===null?e.reverse():e.sort(((e,r)=>t.sortFn(r,e)));const n=[];const i=sort(Object.keys(e)).map((e=>[e]));const a=[e];while(i.length!==0){const e=i.pop();const r=a[e.length-1][e[e.length-1]];const s=t.breakCircularWith!==null&&a.includes(r);n[e.length-1]=i.length!==0&&i[i.length-1].length===e.length;o.push([n.slice(0,e.length-1).map((e=>e?t.spacerNeighbour:t.spacerNoNeighbour)).join(""),n[e.length-1]?t.keyNeighbour:t.keyNoNeighbour,e[e.length-1],t.renderFn(r),s?t.breakCircularWith:""].join(""));if(r instanceof Object&&!Array.isArray(r)&&!s){i.push(...sort(Object.keys(r)).map((r=>e.concat(r))));a[e.length]=r}}return t.joined===true?o.join("\n"):o};var t=r.Z;export{t as default}; | ||
var e={};(()=>{e.d=(r,t)=>{for(var o in t){if(e.o(t,o)&&!e.o(r,o)){Object.defineProperty(r,o,{enumerable:true,get:t[o]})}}}})();(()=>{e.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r)})();if(typeof e!=="undefined")e.ab=new URL(".",import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/)?1:0,-1)+"/";var r={};e.d(r,{Z:()=>lib});const assert=(e,r)=>{if(!e){throw new Error(r)}};const buildCtx=e=>{const r={joined:true,spacerNoNeighbour:" ",spacerNeighbour:"│ ",keyNoNeighbour:"└─ ",keyNeighbour:"├─ ",renderFn:e=>["boolean","string","number"].includes(typeof e)?`: ${e}`:"",sortFn:null,breakCircularWith:" (circular ref.)",...e};assert(Object.keys(r).length===8,"Unexpected Option(s) provided");assert(typeof r.joined==="boolean",'Option "joined" has invalid format');assert(typeof r.spacerNoNeighbour==="string",'Option "spacerNoNeighbour" has invalid format');assert(typeof r.spacerNeighbour==="string",'Option "spacerNeighbour" has invalid format');assert(typeof r.keyNoNeighbour==="string",'Option "keyNoNeighbour" has invalid format');assert(typeof r.keyNeighbour==="string",'Option "keyNeighbour" has invalid format');assert(typeof r.renderFn==="function",'Option "renderFn" has invalid format');assert(typeof r.sortFn==="function"||r.sortFn===null,'Option "sortFn" has invalid format');assert(typeof r.breakCircularWith==="string"||r.breakCircularWith===null,'Option "breakCircularWith" has invalid format');return r};const lib=(e,r={})=>{const t=buildCtx(r);const o=[];const sort=e=>t.sortFn===null?e.reverse():e.sort(((e,r)=>t.sortFn(r,e)));const n=[];const i=sort(Object.keys(e)).map((e=>[e]));const a=[e];while(i.length!==0){const e=i.pop();const r=a[e.length-1][e[e.length-1]];const s=t.breakCircularWith!==null&&a.includes(r);n[e.length-1]=i.length!==0&&i[i.length-1].length===e.length;o.push([n.slice(0,e.length-1).map((e=>e?t.spacerNeighbour:t.spacerNoNeighbour)).join(""),n[e.length-1]?t.keyNeighbour:t.keyNoNeighbour,e[e.length-1],t.renderFn(r),s?t.breakCircularWith:""].join(""));if(r instanceof Object&&!Array.isArray(r)&&!s){i.push(...sort(Object.keys(r)).map((r=>e.concat(r))));a[e.length]=r}}return t.joined===true?o.join("\n"):o};var t=r.Z;export{t as default}; |
{ | ||
"name": "object-treeify", | ||
"type": "module", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Stringify Object as tree structure", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -112,2 +112,9 @@ # object-treeify | ||
#### renderFn | ||
Type: `function`<br> | ||
Default: ``(node) => (['boolean', 'string', 'number'].includes(typeof node) ? `: ${node}` : '')`` | ||
Can be used to overwrite the node rendering logic. | ||
#### sortFn | ||
@@ -127,11 +134,4 @@ | ||
#### renderFn | ||
Type: `function`<br> | ||
Default: `(node) => (['boolean', 'string', 'number'].includes(typeof node) ? `: ${node}` : '')` | ||
Can be used to overwrite the node rendering logic. | ||
## Examples | ||
More examples can be found in the tests. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12537