my-idlers/node_modules/collect.js/dist/methods/keyBy.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

24 lines
519 B
JavaScript
Vendored

'use strict';
var nestedValue = require('../helpers/nestedValue');
var _require = require('../helpers/is'),
isFunction = _require.isFunction;
module.exports = function keyBy(key) {
var collection = {};
if (isFunction(key)) {
this.items.forEach(function (item) {
collection[key(item)] = item;
});
} else {
this.items.forEach(function (item) {
var keyValue = nestedValue(item, key);
collection[keyValue || ''] = item;
});
}
return new this.constructor(collection);
};