Published unlisted
Edited
Dec 24, 2020
Importers
10 stars
Insert cell
Insert cell
Insert cell
function linkViews(target, views, descriptor = {enumerable: true}) {
Object.entries(views).forEach(([name, view]) => {
Object.defineProperty(target, name, Object.assign({
get() { return view.value; }
}, descriptor));
});
return target;
}
Insert cell
Insert cell
// Recursively inlines Function, RegExp and undefined.
function serialize(value) {
const type = typeof value;
const json = JSON.stringify;

if(type === 'function') {
return value.toString();
}
if(type === 'object') {
if(value === null) {
return json(value);
}
if(value instanceof RegExp) {
return value.toString();
}
if(Array.isArray(value)) {
return '[' + value.map(serialize).join(',') + ']';
}
const body = Object.keys(value).map(name => json(name) + ':' + serialize(value[name]));
return '{' + body.join(',') + '}';
}
if(type === 'undefined') {
return type;
}
return json(value);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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