Skip to content

Instantly share code, notes, and snippets.

@ltwlf
Created April 18, 2020 22:03
Show Gist options
  • Save ltwlf/be61fd596d293ad9cc161f94f540880c to your computer and use it in GitHub Desktop.
Save ltwlf/be61fd596d293ad9cc161f94f540880c to your computer and use it in GitHub Desktop.
export function transform(o: any, fn: (obj: any, prop: string, value: any) => any) {
if (o && typeof o === 'object') {
Object.keys(o).forEach((k, i) => {
o[k] = fn.apply(this, [o, k, o[k]])
if (o[k] && typeof o[k] === 'object') {
return transform(o[k], fn)
}
return o[k]
})
return o
}
return o
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment