Created
October 5, 2012 01:13
-
-
Save allenwb/3837490 to your computer and use it in GitHub Desktop.
A JSON.parse reviver from ES6 maps
This file contains hidden or 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 mapReviver(key, value) { | |
if (typeof value != "object") return value; | |
switch (value["<kind>"]){ | |
case undefined: return value; | |
case "Map": { | |
let newValue = new Map; | |
let mapData = value["<mapData>"]; | |
if (!mapData) return value; | |
mapData.forEach(e=>newValue.set(e[0], e[1])); | |
return newValue; | |
} | |
default: return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks much. Why this isn't just built-in, I have no idea :-(