Published
Edited
Jun 13, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
source =
({ a: html`<div>`,
b: [ new Set(),{ sub:{ tab:{ b:[null] } } }],
c: { c: 2, d: new Map([['a',0]]) } })
Insert cell
detype(source)
Insert cell
Insert cell
function detype(ent, tree = {}, dict = {}, prev = "") {

// pre|post order using .reverse()
// move assign to pre/post recursion
if(check(ent,{},[])) ent = Object.entries(ent)
// entity
for(let [key,val] of ent) {
let path = [prev,!isNaN(key) ? `[${key}]` : key].join(prev && isNaN(key) ? '.' : '')
let desc = {prop: key, type:Object.prototype.toString.call(val)}

if (check(val, {}, [], new Map)) {
tree[path] = {}
dict[path] = desc
detype(val, tree[path], dict, path)

} else { tree[path] = dict[path] = desc }
} return new Map(Object.entries(dict)) // or tree
}
Insert cell
check = (prop, ...types) =>
types.some((type) =>
Object.prototype.toString.call(prop) ===
Object.prototype.toString.call(type));
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more