Created
December 1, 2016 02:04
-
-
Save beatak/f58850cbcd38816dc1d9dad66d716a25 to your computer and use it in GitHub Desktop.
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 strMapToObj(strMap) { | |
var obj = Object.create(null); | |
strMap.forEach(function(val, key) { | |
console.log('strMapToObj: ' + key + ' -> ' + val); | |
obj[key] = val; | |
}); | |
return obj; | |
} | |
function objToStrMap(obj) { | |
var strMap = new Map(); | |
Object.keys(obj).forEach(function (key) { | |
strMap.set(key, obj[key]); | |
}); | |
return strMap; | |
} | |
function strMapToJson(strMap) { | |
return JSON.stringify(strMapToObj(strMap)); | |
} | |
function jsonToStrMap(jsonStr) { | |
return objToStrMap(JSON.parse(jsonStr)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment