json-summary
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -271,3 +271,3 @@ let JsonSummary = require("../index"); | ||
{b: 2, c: 3}, | ||
{a: 2, b: 4, c: 6}, | ||
{a: 2, b: null, c: 6}, | ||
{a: 3, c: 9, d: 12}, | ||
@@ -292,5 +292,5 @@ {d: 2, e: 5} | ||
b: { | ||
count: 2, | ||
count: 1, | ||
example: expect.any(Number), | ||
range: [2, 4], | ||
range: [2, 2], | ||
type: "number" | ||
@@ -297,0 +297,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
// https://andrewtburks.dev/json-summary v0.2.3 Copyright 2019 Andrew Burks | ||
// https://andrewtburks.dev/json-summary v0.2.4 Copyright 2019 Andrew Burks | ||
const summarizer = (function() { | ||
@@ -8,3 +8,4 @@ let defaultOptions = { | ||
showExampleValue: true, | ||
startExpanded: false | ||
startExpanded: false, | ||
theme: "dark" | ||
}; | ||
@@ -18,3 +19,4 @@ | ||
showExampleValue = true, | ||
startExpanded = false | ||
startExpanded = false, | ||
theme = "dark" | ||
} = defaultOptions) { | ||
@@ -27,3 +29,4 @@ | ||
showExampleValue, | ||
startExpanded | ||
startExpanded, | ||
theme | ||
}; | ||
@@ -300,3 +303,3 @@ | ||
// start at 0 indentation | ||
return printSummaryLevel(summary, 0, 1); | ||
return `<div class='json-summary-wrapper ${options.theme}'>` + printSummaryLevel(summary, 0, 1); | ||
} | ||
@@ -303,0 +306,0 @@ |
@@ -1,2 +0,2 @@ | ||
// https://andrewtburks.dev/json-summary v0.2.3 Copyright 2019 Andrew Burks | ||
// https://andrewtburks.dev/json-summary v0.2.4 Copyright 2019 Andrew Burks | ||
(function (global, factory) { | ||
@@ -14,3 +14,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
showExampleValue: true, | ||
startExpanded: false | ||
startExpanded: false, | ||
theme: "dark" | ||
}; | ||
@@ -24,3 +25,4 @@ | ||
showExampleValue = true, | ||
startExpanded = false | ||
startExpanded = false, | ||
theme = "dark" | ||
} = defaultOptions) { | ||
@@ -33,3 +35,4 @@ | ||
showExampleValue, | ||
startExpanded | ||
startExpanded, | ||
theme | ||
}; | ||
@@ -306,3 +309,3 @@ | ||
// start at 0 indentation | ||
return printSummaryLevel(summary, 0, 1); | ||
return `<div class='json-summary-wrapper ${options.theme}'>` + printSummaryLevel(summary, 0, 1); | ||
} | ||
@@ -309,0 +312,0 @@ |
@@ -1,2 +0,2 @@ | ||
// https://andrewtburks.dev/json-summary v0.2.3 Copyright 2019 Andrew Burks | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).jsonSummary=t()}(this,function(){"use strict";return function(){let e={arraySampleCount:10,indentation:" ",indentCount:2,showExampleValue:!0,startExpanded:!1};return function({arraySampleCount:t=10,indentation:n=" ",indentCount:r=2,showExampleValue:a=!0,startExpanded:s=!1}=e){let o={arraySampleCount:t,indentation:n,indentCount:r,showExampleValue:a,startExpanded:s};function u(e){let t={Array:!0,Object:!0,boolean:!0,string:!0,number:!0},n=e.filter(e=>t[e.type]);if(n.length){let e=n[0].type;return function(e,t){return e=e.filter(e=>e.type===t),{string:function(e){let t=e.reduce((e,t)=>Math.min(e,t.range[0]),1/0),n=e.reduce((e,t)=>Math.max(e,t.range[1]),-1/0);return{type:"string",example:e[0].example,range:[t,n],count:e.reduce((e,t)=>e+t.count,0)}},number:function(e){let t=e.reduce((e,t)=>Math.min(e,t.range[0]),1/0),n=e.reduce((e,t)=>Math.max(e,t.range[1]),-1/0);return{type:"number",example:e[0].example,range:[t,n],count:e.reduce((e,t)=>e+t.count,0)}},boolean:function(e){return{type:"boolean",example:e[0].example,count:e.reduce((e,t)=>e+t.count,0)}},Object:function(e){let t={};for(let n of e)if(!n.circular)for(let e of n.keys)!t[e]&&(t[e]=[]),t[e].push(n.items[e]);let n={type:"Object",keys:[],items:{},count:e.length};for(let e of Object.keys(t))n.keys.push(e),n.items[e]=u(t[e]);return n},Array:function(e){let t=u(e.map(e=>e.items[0]).filter(e=>e));return{count:e.length,items:{0:t},length:t.count/e.length,type:"Array"}}}[t](e)}(n.filter(t=>t.type===e),e)}return{count:0}}function l(e,t,n){return{type:()=>`<span class="json-summary json-summary-type json-summary-type-${e}"><${e}></span>`,value:()=>`<span class="json-summary json-summary-value json-summary-value-${n}">${e}</span>`,range:()=>`<span class="json-summary json-summary-range json-summary-range-${n}">[${e[0]}, ${e[1]}]</span>`,name:()=>`<span class="json-summary json-summary-name">${e}</span>`,length:()=>`<span class="json-summary json-summary-length">(${e})</span>`,circular:()=>`<span class="json-summary json-summary-circular">${e}</span>`,layer:()=>`<span class="json-summary json-summary-checkbox ${o.startExpanded?"checked":""}">\n <input type="checkbox" ${o.startExpanded?"checked":""}>\n <span class="json-summary-checkboxmarker" onclick="(function(me){\n me.parentNode.classList.toggle('checked');\n })(this)"></span>\n </span><div class="json-summary json-summary-layer">${e}</div>`,child:()=>`<div class="json-summary json-summary-child">${e}</div>`,keys:()=>`<span class="json-summary json-summary-keys">${e}</span>`}[t]()}return{summarize:function(e){let n=function e(n){let r={Array:n=>{let r={count:1,type:"Array",length:n.length};if(n.length)if(t>0){let a=Math.min(t,n.length),s={};for(;a>0;){let e=Math.floor(Math.random()*n.length);s.hasOwnProperty(e)||(s[e]=n[e],a--)}let o=[];for(let[t,n]of Object.entries(s))o.push(e(n));let l=u(o);r.items={0:l}}else r.items={0:e(n[0])};else r.items={0:void 0};return r},Object:t=>{let n={count:1,type:"Object",keys:Object.keys(t),items:{}};for(let r of n.keys)n.items[r]=e(t[r]);return n},Other:e=>{let t;return"string"==typeof e?t=[e.length,e.length]:"number"==typeof e&&(t=[e,e]),{type:typeof e,example:e,count:1,range:t}}},a="Other";return n instanceof Array?a="Array":n instanceof Object&&(a="Object"),n&&n["*snippets_mark*"]?{type:a,circular:!0}:("Other"!==a&&(Object.defineProperty(n,"*snippets_mark*",{enumerable:!1,writable:!0,configurable:!0}),n["*snippets_mark*"]=!0),r[a](n))}(e);return function e(t){if(t&&t["*snippets_mark*"])if(delete t["*snippets_mark*"],t instanceof Array&&t.length)e(t[0]);else if(t instanceof Object)for(let n of Object.keys(t))e(t[n])}(e),n},printSummary:function(e){return function e(t,n,r){let a="";if(t.circular)a+=l("(circular reference)","circular");else if("Object"===t.type){a+="{";let r=t.keys.map(e=>`'${e}'`).join(", ");a+=l(r,"keys");let u=t.keys.map(r=>e(t.items[r],n+1,t.count));if(u.length){let e="\n";for(let r=0;r<t.keys.length;r++)e+=o.indentation.repeat((n+1)*o.indentCount),e+=l(t.keys[r],"name")+": ",t.count>1&&(e+=`<div class="json-summary json-summary-bar" title="${(s=t.items[t.keys[r]].count/t.count*100).toFixed(2)}%"><div class="json-summary json-summary-percentage" style="width:${s}%;"></div></div>`),e+=u[r],r<t.keys.length-1&&(e+=","),e+="\n";e+=o.indentation.repeat(n*o.indentCount),a+=l(e,"child")}a=l(a+="}","layer")}else if("Array"===t.type){if(a+=l(t.count>1?"μ = "+t.length.toFixed(1):t.length,"length")+" [",t.length){let r="Object"===t.items[0].type||"Array"===t.items[0].type;r&&(a+="\n"+o.indentation.repeat((n+1)*o.indentCount)),a+=e(t.items[0],n+1,t.count),r&&(a+="\n"+o.indentation.repeat(n*o.indentCount))}a+="]"}else null==t.example||null==t.example?a+=l("?","type"):a+=l(t.type,"type"),o.showExampleValue&&(a+=l(t.example,"value",t.type),t.count>1&&t.range&&(a+=l(t.range,"range",t.type)));var s;return a}(e,0)}}}}()}); | ||
// https://andrewtburks.dev/json-summary v0.2.4 Copyright 2019 Andrew Burks | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).jsonSummary=t()}(this,function(){"use strict";return function(){let e={arraySampleCount:10,indentation:" ",indentCount:2,showExampleValue:!0,startExpanded:!1,theme:"dark"};return function({arraySampleCount:t=10,indentation:n=" ",indentCount:r=2,showExampleValue:a=!0,startExpanded:s=!1,theme:o="dark"}=e){let u={arraySampleCount:t,indentation:n,indentCount:r,showExampleValue:a,startExpanded:s,theme:o};function l(e){let t={Array:!0,Object:!0,boolean:!0,string:!0,number:!0},n=e.filter(e=>t[e.type]);if(n.length){let e=n[0].type;return function(e,t){return e=e.filter(e=>e.type===t),{string:function(e){let t=e.reduce((e,t)=>Math.min(e,t.range[0]),1/0),n=e.reduce((e,t)=>Math.max(e,t.range[1]),-1/0);return{type:"string",example:e[0].example,range:[t,n],count:e.reduce((e,t)=>e+t.count,0)}},number:function(e){let t=e.reduce((e,t)=>Math.min(e,t.range[0]),1/0),n=e.reduce((e,t)=>Math.max(e,t.range[1]),-1/0);return{type:"number",example:e[0].example,range:[t,n],count:e.reduce((e,t)=>e+t.count,0)}},boolean:function(e){return{type:"boolean",example:e[0].example,count:e.reduce((e,t)=>e+t.count,0)}},Object:function(e){let t={};for(let n of e)if(!n.circular)for(let e of n.keys)!t[e]&&(t[e]=[]),t[e].push(n.items[e]);let n={type:"Object",keys:[],items:{},count:e.length};for(let e of Object.keys(t))n.keys.push(e),n.items[e]=l(t[e]);return n},Array:function(e){let t=l(e.map(e=>e.items[0]).filter(e=>e));return{count:e.length,items:{0:t},length:t.count/e.length,type:"Array"}}}[t](e)}(n.filter(t=>t.type===e),e)}return{count:0}}function i(e,t,n){return{type:()=>`<span class="json-summary json-summary-type json-summary-type-${e}"><${e}></span>`,value:()=>`<span class="json-summary json-summary-value json-summary-value-${n}">${e}</span>`,range:()=>`<span class="json-summary json-summary-range json-summary-range-${n}">[${e[0]}, ${e[1]}]</span>`,name:()=>`<span class="json-summary json-summary-name">${e}</span>`,length:()=>`<span class="json-summary json-summary-length">(${e})</span>`,circular:()=>`<span class="json-summary json-summary-circular">${e}</span>`,layer:()=>`<span class="json-summary json-summary-checkbox ${u.startExpanded?"checked":""}">\n <input type="checkbox" ${u.startExpanded?"checked":""}>\n <span class="json-summary-checkboxmarker" onclick="(function(me){\n me.parentNode.classList.toggle('checked');\n })(this)"></span>\n </span><div class="json-summary json-summary-layer">${e}</div>`,child:()=>`<div class="json-summary json-summary-child">${e}</div>`,keys:()=>`<span class="json-summary json-summary-keys">${e}</span>`}[t]()}return{summarize:function(e){let n=function e(n){let r={Array:n=>{let r={count:1,type:"Array",length:n.length};if(n.length)if(t>0){let a=Math.min(t,n.length),s={};for(;a>0;){let e=Math.floor(Math.random()*n.length);s.hasOwnProperty(e)||(s[e]=n[e],a--)}let o=[];for(let[t,n]of Object.entries(s))o.push(e(n));let u=l(o);r.items={0:u}}else r.items={0:e(n[0])};else r.items={0:void 0};return r},Object:t=>{let n={count:1,type:"Object",keys:Object.keys(t),items:{}};for(let r of n.keys)n.items[r]=e(t[r]);return n},Other:e=>{let t;return"string"==typeof e?t=[e.length,e.length]:"number"==typeof e&&(t=[e,e]),{type:typeof e,example:e,count:1,range:t}}},a="Other";return n instanceof Array?a="Array":n instanceof Object&&(a="Object"),n&&n["*snippets_mark*"]?{type:a,circular:!0}:("Other"!==a&&(Object.defineProperty(n,"*snippets_mark*",{enumerable:!1,writable:!0,configurable:!0}),n["*snippets_mark*"]=!0),r[a](n))}(e);return function e(t){if(t&&t["*snippets_mark*"])if(delete t["*snippets_mark*"],t instanceof Array&&t.length)e(t[0]);else if(t instanceof Object)for(let n of Object.keys(t))e(t[n])}(e),n},printSummary:function(e){return`<div class='json-summary-wrapper ${u.theme}'>`+function e(t,n,r){let a="";if(t.circular)a+=i("(circular reference)","circular");else if("Object"===t.type){a+="{";let r=t.keys.map(e=>`'${e}'`).join(", ");a+=i(r,"keys");let o=t.keys.map(r=>e(t.items[r],n+1,t.count));if(o.length){let e="\n";for(let r=0;r<t.keys.length;r++)e+=u.indentation.repeat((n+1)*u.indentCount),e+=i(t.keys[r],"name")+": ",t.count>1&&(e+=`<div class="json-summary json-summary-bar" title="${(s=t.items[t.keys[r]].count/t.count*100).toFixed(2)}%"><div class="json-summary json-summary-percentage" style="width:${s}%;"></div></div>`),e+=o[r],r<t.keys.length-1&&(e+=","),e+="\n";e+=u.indentation.repeat(n*u.indentCount),a+=i(e,"child")}a=i(a+="}","layer")}else if("Array"===t.type){if(a+=i(t.count>1?"μ = "+t.length.toFixed(1):t.length,"length")+" [",t.length){let r="Object"===t.items[0].type||"Array"===t.items[0].type;r&&(a+="\n"+u.indentation.repeat((n+1)*u.indentCount)),a+=e(t.items[0],n+1,t.count),r&&(a+="\n"+u.indentation.repeat(n*u.indentCount))}a+="]"}else null==t.example||null==t.example?a+=i("?","type"):a+=i(t.type,"type"),u.showExampleValue&&(a+=i(t.example,"value",t.type),t.count>1&&t.range&&(a+=i(t.range,"range",t.type)));var s;return a}(e,0)}}}}()}); |
@@ -1,2 +0,2 @@ | ||
// https://andrewtburks.dev/json-summary v0.2.3 Copyright 2019 Andrew Burks | ||
// https://andrewtburks.dev/json-summary v0.2.4 Copyright 2019 Andrew Burks | ||
(function (global, factory) { | ||
@@ -14,3 +14,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
showExampleValue: true, | ||
startExpanded: false | ||
startExpanded: false, | ||
theme: "dark" | ||
}; | ||
@@ -24,3 +25,4 @@ | ||
showExampleValue = true, | ||
startExpanded = false | ||
startExpanded = false, | ||
theme = "dark" | ||
} = defaultOptions) { | ||
@@ -33,3 +35,4 @@ | ||
showExampleValue, | ||
startExpanded | ||
startExpanded, | ||
theme | ||
}; | ||
@@ -306,3 +309,3 @@ | ||
// start at 0 indentation | ||
return printSummaryLevel(summary, 0, 1); | ||
return `<div class='json-summary-wrapper ${options.theme}'>` + printSummaryLevel(summary, 0, 1); | ||
} | ||
@@ -309,0 +312,0 @@ |
11
index.js
@@ -7,3 +7,4 @@ const summarizer = (function() { | ||
showExampleValue: true, | ||
startExpanded: false | ||
startExpanded: false, | ||
theme: "dark" | ||
}; | ||
@@ -17,3 +18,4 @@ | ||
showExampleValue = true, | ||
startExpanded = false | ||
startExpanded = false, | ||
theme = "dark" | ||
} = defaultOptions) { | ||
@@ -26,3 +28,4 @@ | ||
showExampleValue, | ||
startExpanded | ||
startExpanded, | ||
theme | ||
}; | ||
@@ -299,3 +302,3 @@ | ||
// start at 0 indentation | ||
return printSummaryLevel(summary, 0, 1); | ||
return `<div class='json-summary-wrapper ${options.theme}'>` + printSummaryLevel(summary, 0, 1); | ||
} | ||
@@ -302,0 +305,0 @@ |
{ | ||
"name": "json-summary", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A simple JSON summarizer to extract the structure from a JSON object", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
88511
2341