This commit is contained in:
2020-10-07 17:33:37 +00:00
parent 0185b6941c
commit 2a2bcc5f7f
7 changed files with 80 additions and 39 deletions

View File

@@ -383,6 +383,30 @@ export default {
sleepAsync: function(milliseconds) {
// eslint-disable-next-line
return new Promise((resolve) => setTimeout(resolve, milliseconds));
},
///////////////////////////////////////////////
// sortByKey lodash "sortBy" replacement
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_sortby-and-_orderby
//usage:
// The native sort modifies the array in place. `_.orderBy` and `_.sortBy` do not, so we use `.concat()` to
// copy the array, then sort.
// fruits.concat().sort(sortBy("name"));
// => [{name:"apple", amount: 4}, {name:"banana", amount: 2}, {name:"mango", amount: 1}, {name:"pineapple", amount: 2}]
sortByKey: key => {
return (a, b) => (a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0);
},
///////////////////////////////////////////////
// "has" lodash replacement
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_has
//
has: function(obj, key) {
var keyParts = key.split(".");
return (
!!obj &&
(keyParts.length > 1
? has(obj[key.split(".")[0]], keyParts.slice(1).join("."))
: hasOwnProperty.call(obj, key))
);
}
/**