Created
April 18, 2020 22:03
-
-
Save ltwlf/be61fd596d293ad9cc161f94f540880c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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