Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active January 25, 2016 12:48
Show Gist options
  • Save Alex1990/6e25f1383f5d0e8b8977 to your computer and use it in GitHub Desktop.
Save Alex1990/6e25f1383f5d0e8b8977 to your computer and use it in GitHub Desktop.
/**
* 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