Created
September 18, 2018 00:28
-
-
Save lizzymendivil/d4ce517e7b71d3db9349f2d7a1a38de7 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 flattenMessages(nestedMessages, prefix = '') { | |
return Object.keys(nestedMessages).reduce((messages, key) => { | |
const value = nestedMessages[key]; | |
const prefixedKey = prefix ? `${prefix}.${key}` : key; | |
if (typeof value === 'string') { | |
messages[prefixedKey] = value; | |
} else { | |
Object.assign(messages, flattenMessages(value, prefixedKey)); | |
} | |
return messages; | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment