Skip to content

Instantly share code, notes, and snippets.

@rjerue
Created March 2, 2019 01:54
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 rjerue/df334582116ab9ac449e893605f36fd4 to your computer and use it in GitHub Desktop.
Save rjerue/df334582116ab9ac449e893605f36fd4 to your computer and use it in GitHub Desktop.
function decode(input) {
return input && typeof input === 'object'
? Object.entries(input).reduce(async (accum, [key, value]) => {
const [resolvedAccum, resolvedValue] = await Promise.all([accum, value])
let decodedValue = resolvedValue
if (Array.isArray(resolvedValue)) {
decodedValue = await Promise.all(resolvedValue.map(decode))
}
if (resolvedValue && typeof resolvedValue === 'object') {
decodedValue = await decode(resolvedValue)
}
return {
...resolvedAccum,
[key]: decodedValue,
}
}, {})
: input
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment