Created
March 2, 2019 01:54
-
-
Save rjerue/df334582116ab9ac449e893605f36fd4 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
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