You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
448 B
19 lines
448 B
module.exports = function sortObjectByKeyNameList(object, sortWith) {
|
|
var keys;
|
|
var sortFn;
|
|
|
|
if (typeof sortWith === 'function') {
|
|
sortFn = sortWith;
|
|
} else {
|
|
keys = sortWith;
|
|
}
|
|
|
|
var objectKeys = Object.keys(object);
|
|
return (keys || []).concat(objectKeys.sort(sortFn)).reduce(function(total, key) {
|
|
if (objectKeys.indexOf(key) !== -1) {
|
|
total[key] = object[key];
|
|
}
|
|
return total;
|
|
}, Object.create(null));
|
|
}
|