Last active
August 7, 2023 15:49
-
-
Save davemackintosh/3b9c446e8681f7bbe7c5 to your computer and use it in GitHub Desktop.
Convert ES6 `Map`s to a standard JSON object without effing Babel.
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
/** | |
* Convert a `Map` to a standard | |
* JS object recursively. | |
* | |
* @param {Map} map to convert. | |
* @returns {Object} converted object. | |
*/ | |
function map_to_object(map) { | |
const out = Object.create(null) | |
map.forEach((value, key) => { | |
if (value instanceof Map) { | |
out[key] = map_to_object(value) | |
} | |
else { | |
out[key] = value | |
} | |
}) | |
return out | |
} |
Thanks!!!
Thanks !!!
Thanks!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!