Skip to content

Instantly share code, notes, and snippets.

@4lun
Created November 30, 2023 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4lun/cafe916f77a1b1b150badffe35a80a0d to your computer and use it in GitHub Desktop.
Save 4lun/cafe916f77a1b1b150badffe35a80a0d to your computer and use it in GitHub Desktop.
Generate a quick and dirty type "blueprint" of a JS object/array/variable
function toBlueprint(obj) {
if (!obj || typeof obj !== 'object') {
return obj;
}
if(Array.isArray(obj)) {
return obj.map(toBlueprint) // nit: won't unify common props
}
return Object.keys(obj).reduce((acc, key) => {
let blueprint = typeof obj[key];
if (blueprint === "object" && blueprint) {
blueprint = toBlueprint(obj[key])
}
acc[key] = blueprint;
return acc;
},
{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment