This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·154 lines (131 loc) · 3.56 KB
/
index.js
File metadata and controls
executable file
·154 lines (131 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var Scrubber, Traverse, daisy, global, slowDaisy,
__slice = [].slice;
Traverse = require('traverse');
global = typeof window !== "undefined" && window !== null ? window : this;
/**
* @helper daisy
* @description - serial async helper
*/
daisy = function(args) {
return process.nextTick(args.next = function() {
var fn;
if (fn = args.shift()) {
return !!fn(args);
}
});
};
slowDaisy = function(args) {
return console.log("it's a slow daisy", args);
};
module.exports = Scrubber = (function() {
var seemsTooComplex,
_this = this;
Scrubber.use = function() {
var middleware;
middleware = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (this.stack == null) {
return this.stack = middleware;
} else {
return this.stack = this.stack.concat(middleware);
}
};
/**
* @constructor Scrubber
* @description - initializes the Scrubber instance.
*/
function Scrubber() {
var middleware;
middleware = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if ('function' === typeof middleware[0]) {
this.stack = middleware;
} else {
this.stack = middleware[0];
}
}
/**
* @method Scrubber#scrub
* @description - traverses an arbitrary JS object and applies the middleware
* stack, serially, to each node encountered during the walk.
*/
Scrubber.prototype.scrub = function(obj, callback) {
var nodes, queue, scrubber, steps;
scrubber = this;
queue = [];
steps = this.stack.map(function(fn) {
switch (fn.length) {
case 0:
case 1:
return function(cursor, next) {
fn.call(this, cursor);
return next();
};
case 2:
return fn;
default:
throw new TypeError('Scrubber requires a callback with 1- or 2-arity. ' + ("User provided a " + fn.length + "-arity callback"));
}
});
nodes = [];
this.out = new Traverse(obj).map(function() {
var cursor;
cursor = this;
steps.forEach(function(step) {
return queue.push(function() {
return step.call(scrubber, cursor, function() {
return queue.next();
});
});
});
});
queue.push(function() {
return callback.call(scrubber);
});
return daisy(queue);
};
seemsTooComplex = (function() {
var f, i, maxStackSize;
maxStackSize = (function() {
try {
i = 0;
return (f = function() {
i++;
return f();
})();
} catch (e) {
return i;
}
})();
return function(length, weight) {
var guess;
guess = length * weight;
return guess > maxStackSize;
};
})();
/**
* @method Scrubber#forEach
* @method Scrubber#indexOfå
* @method Scrubber#join
* @method Scrubber#pop
* @method Scrubber#reverse
* @method Scrubber#shift
* @method Scrubber#sort
* @method Scrubber#splice
* @method Scrubber#unshift
* @method Scrubber#push
* @description - proxies for the native Array methods; they apply themselves
* to the middleware stack
*/
['forEach', 'indexOf', 'join', 'pop', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'push'].forEach(function(method) {
return Scrubber.prototype[method] = function() {
var rest;
rest = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this.stack[method].apply(this.stack, rest);
};
});
/**
* @method Scrubber#use
* @description alias for push.
*/
Scrubber.prototype.use = Scrubber.prototype.push;
return Scrubber;
}).call(this);