Skip to content

Instantly share code, notes, and snippets.

@joduplessis
Created October 14, 2022 12:57
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 joduplessis/33721f810110ce07effb9cb99fe11e70 to your computer and use it in GitHub Desktop.
Save joduplessis/33721f810110ce07effb9cb99fe11e70 to your computer and use it in GitHub Desktop.
Recursively create tokens from JS objects
import { objects } from './objects'
const createTokenObject = (obj) => {
let o = {}
Object.keys(obj).map((key) => {
if (typeof obj[key] == "object") {
o[String(key)] = createTokenObject(obj[key])
} else {
o[String(key)] = { value: obj[key] }
}
})
return o
}
console.log(JSON.stringify(createTokenObject(objects)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment