ts-prime
Version:
A utility library for JavaScript and Typescript.
22 lines (21 loc) • 694 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var purry_1 = require("./purry");
function indexBy() {
return purry_1.purry(_indexBy(false), arguments);
}
exports.indexBy = indexBy;
var _indexBy = function (indexed) { return function (array, fn) {
return array.reduce(function (ret, item, index) {
var value = indexed ? fn(item, index, array) : fn(item);
var key = String(value);
ret[key] = item;
return ret;
}, {});
}; };
(function (indexBy) {
function indexed() {
return purry_1.purry(_indexBy(true), arguments);
}
indexBy.indexed = indexed;
})(indexBy = exports.indexBy || (exports.indexBy = {}));