1 |
|
2 | function info(options) {
|
3 | return function(message) {
|
4 | (options.logger || console.log)(message);
|
5 | };
|
6 | }
|
7 |
|
8 | function warn(options) {
|
9 | return function(message) {
|
10 | (options.warnlogger || options.logger || console.warn)(message);
|
11 | };
|
12 | }
|
13 |
|
14 | exports.pick = function(p, keys) {
|
15 | var result = {};
|
16 | keys.forEach(function(k) {
|
17 | if (p.hasOwnProperty(k)) {
|
18 | result[k] = p[k];
|
19 | }
|
20 | });
|
21 | return result;
|
22 | };
|
23 |
|
24 | exports.extend = function(o, a) {
|
25 | var result = exports.pick(o, Object.keys(o));
|
26 | exports.map(a, function(v,k){ result[k] = v; });
|
27 | return result;
|
28 | };
|
29 |
|
30 | exports.map = function(o, fn) {
|
31 | return Object.keys(o).map(function(k) { return fn(o[k], k); });
|
32 | };
|
33 |
|
34 | exports.find = function(ar, fn) {
|
35 | for(var i in ar) {
|
36 | if (fn(ar[i])) return ar[i];
|
37 | }
|
38 | return undefined;
|
39 | };
|
40 |
|
41 | exports.detect = exports.find;
|
42 |
|
43 | exports.flatten = function(e) {
|
44 | return e.reduce(function(x,y) { return x.concat(y); }, []);
|
45 | };
|
46 |
|
47 | exports.forwardEvent = function(emitter, evt) {
|
48 | return function() {
|
49 | emitter.emit(evt, arguments[0]);
|
50 | };
|
51 | };
|
52 |
|
53 | exports.every = function(things, predicate){
|
54 | return Object.keys(things)
|
55 | .map(function(k) { return predicate(k, things[k]); })
|
56 | .reduce(function(x,y) { return x && y; }, true);
|
57 | };
|