UNPKG

@akala/core

Version:
80 lines 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function array(array, body) { Array.prototype.forEach.call(array, body); } exports.array = array; function object(o, body) { array(Object.keys(o), function (key) { body(o[key], key); }); } exports.object = object; function each(it, body) { if (isArrayLike(it)) return array(it, body); return object(it, body); } exports.each = each; function grepArray(it, body) { var result = []; array(it, function (el, i) { if (body(el, i)) result.push(el); }); return result; } exports.grepArray = grepArray; function grepObject(o, body, asArray) { var result = {}; var resultArray = []; object(o, function (el, i) { if (body(el, i)) if (asArray) resultArray.push(el); else result[i] = el; }); if (asArray) return resultArray; return result; } exports.grepObject = grepObject; function isArrayLike(it) { return Array.isArray(it) || typeof (it) != 'undefined' && typeof (it['length']) != 'undefined'; } function grep(it, body, asArray) { if (isArrayLike(it)) return grepArray(it, body); return grepObject(it, body, asArray); } exports.grep = grep; function mapArray(it, body) { var result = []; array(it, function (el, i) { result.push(body(el, i)); }); return result; } exports.mapArray = mapArray; function mapObject(o, body, asArray) { var result = {}; var resultArray = []; object(o, function (el, i) { if (asArray) resultArray.push(body(el, i)); else result[i] = body(el, i); }); if (asArray) return resultArray; return result; } exports.mapObject = mapObject; function map(it, body, asArray) { if (isArrayLike(it)) return mapArray(it, body); return mapObject(it, body, asArray); } exports.map = map; //# sourceMappingURL=each.js.map