UNPKG

2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function array(array, body) {
4 Array.prototype.forEach.call(array, body);
5}
6exports.array = array;
7function object(o, body) {
8 array(Object.keys(o), function (key) {
9 body(o[key], key);
10 });
11}
12exports.object = object;
13function each(it, body) {
14 if (isArrayLike(it))
15 return array(it, body);
16 return object(it, body);
17}
18exports.each = each;
19function grepArray(it, body) {
20 var result = [];
21 array(it, function (el, i) {
22 if (body(el, i))
23 result.push(el);
24 });
25 return result;
26}
27exports.grepArray = grepArray;
28function grepObject(o, body, asArray) {
29 var result = {};
30 var resultArray = [];
31 object(o, function (el, i) {
32 if (body(el, i))
33 if (asArray)
34 resultArray.push(el);
35 else
36 result[i] = el;
37 });
38 if (asArray)
39 return resultArray;
40 return result;
41}
42exports.grepObject = grepObject;
43function isArrayLike(it) {
44 return Array.isArray(it) || typeof (it) != 'undefined' && typeof (it['length']) != 'undefined';
45}
46function grep(it, body, asArray) {
47 if (isArrayLike(it))
48 return grepArray(it, body);
49 return grepObject(it, body, asArray);
50}
51exports.grep = grep;
52function mapArray(it, body) {
53 var result = [];
54 array(it, function (el, i) {
55 result.push(body(el, i));
56 });
57 return result;
58}
59exports.mapArray = mapArray;
60function mapObject(o, body, asArray) {
61 var result = {};
62 var resultArray = [];
63 object(o, function (el, i) {
64 if (asArray)
65 resultArray.push(body(el, i));
66 else
67 result[i] = body(el, i);
68 });
69 if (asArray)
70 return resultArray;
71 return result;
72}
73exports.mapObject = mapObject;
74function map(it, body, asArray) {
75 if (isArrayLike(it))
76 return mapArray(it, body);
77 return mapObject(it, body, asArray);
78}
79exports.map = map;
80//# sourceMappingURL=each.js.map
\No newline at end of file