1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function array(array, body) {
|
4 | Array.prototype.forEach.call(array, body);
|
5 | }
|
6 | exports.array = array;
|
7 | function object(o, body) {
|
8 | array(Object.keys(o), function (key) {
|
9 | body(o[key], key);
|
10 | });
|
11 | }
|
12 | exports.object = object;
|
13 | function each(it, body) {
|
14 | if (isArrayLike(it))
|
15 | return array(it, body);
|
16 | return object(it, body);
|
17 | }
|
18 | exports.each = each;
|
19 | function 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 | }
|
27 | exports.grepArray = grepArray;
|
28 | function 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 | }
|
42 | exports.grepObject = grepObject;
|
43 | function isArrayLike(it) {
|
44 | return Array.isArray(it) || typeof (it) != 'undefined' && typeof (it['length']) != 'undefined';
|
45 | }
|
46 | function grep(it, body, asArray) {
|
47 | if (isArrayLike(it))
|
48 | return grepArray(it, body);
|
49 | return grepObject(it, body, asArray);
|
50 | }
|
51 | exports.grep = grep;
|
52 | function mapArray(it, body) {
|
53 | var result = [];
|
54 | array(it, function (el, i) {
|
55 | result.push(body(el, i));
|
56 | });
|
57 | return result;
|
58 | }
|
59 | exports.mapArray = mapArray;
|
60 | function 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 | }
|
73 | exports.mapObject = mapObject;
|
74 | function map(it, body, asArray) {
|
75 | if (isArrayLike(it))
|
76 | return mapArray(it, body);
|
77 | return mapObject(it, body, asArray);
|
78 | }
|
79 | exports.map = map;
|
80 |
|
\ | No newline at end of file |