Last active
January 25, 2016 12:48
-
-
Save Alex1990/6e25f1383f5d0e8b8977 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
/** | |
* Transfrom the keys of an object by an filter object, then return a new object. | |
* ToDo: support deep transforming. | |
*/ | |
function transKeys(src, filter) { | |
var dest = {}; | |
var keys = Object.keys(filter); | |
for (var p in src) { | |
if (src.hasOwnProperty(p)) { | |
var key = keys.indexOf(p) > -1 ? filter[p] : p; | |
dest[key] = src[p]; | |
} | |
} | |
return dest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment