@withjoy/limiter 0.1.4-test → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,370 +0,0 @@
1
- module.exports = Yallist
2
-
3
- Yallist.Node = Node
4
- Yallist.create = Yallist
5
-
6
- function Yallist (list) {
7
- var self = this
8
- if (!(self instanceof Yallist)) {
9
- self = new Yallist()
10
- }
11
-
12
- self.tail = null
13
- self.head = null
14
- self.length = 0
15
-
16
- if (list && typeof list.forEach === 'function') {
17
- list.forEach(function (item) {
18
- self.push(item)
19
- })
20
- } else if (arguments.length > 0) {
21
- for (var i = 0, l = arguments.length; i < l; i++) {
22
- self.push(arguments[i])
23
- }
24
- }
25
-
26
- return self
27
- }
28
-
29
- Yallist.prototype.removeNode = function (node) {
30
- if (node.list !== this) {
31
- throw new Error('removing node which does not belong to this list')
32
- }
33
-
34
- var next = node.next
35
- var prev = node.prev
36
-
37
- if (next) {
38
- next.prev = prev
39
- }
40
-
41
- if (prev) {
42
- prev.next = next
43
- }
44
-
45
- if (node === this.head) {
46
- this.head = next
47
- }
48
- if (node === this.tail) {
49
- this.tail = prev
50
- }
51
-
52
- node.list.length--
53
- node.next = null
54
- node.prev = null
55
- node.list = null
56
- }
57
-
58
- Yallist.prototype.unshiftNode = function (node) {
59
- if (node === this.head) {
60
- return
61
- }
62
-
63
- if (node.list) {
64
- node.list.removeNode(node)
65
- }
66
-
67
- var head = this.head
68
- node.list = this
69
- node.next = head
70
- if (head) {
71
- head.prev = node
72
- }
73
-
74
- this.head = node
75
- if (!this.tail) {
76
- this.tail = node
77
- }
78
- this.length++
79
- }
80
-
81
- Yallist.prototype.pushNode = function (node) {
82
- if (node === this.tail) {
83
- return
84
- }
85
-
86
- if (node.list) {
87
- node.list.removeNode(node)
88
- }
89
-
90
- var tail = this.tail
91
- node.list = this
92
- node.prev = tail
93
- if (tail) {
94
- tail.next = node
95
- }
96
-
97
- this.tail = node
98
- if (!this.head) {
99
- this.head = node
100
- }
101
- this.length++
102
- }
103
-
104
- Yallist.prototype.push = function () {
105
- for (var i = 0, l = arguments.length; i < l; i++) {
106
- push(this, arguments[i])
107
- }
108
- return this.length
109
- }
110
-
111
- Yallist.prototype.unshift = function () {
112
- for (var i = 0, l = arguments.length; i < l; i++) {
113
- unshift(this, arguments[i])
114
- }
115
- return this.length
116
- }
117
-
118
- Yallist.prototype.pop = function () {
119
- if (!this.tail) {
120
- return undefined
121
- }
122
-
123
- var res = this.tail.value
124
- this.tail = this.tail.prev
125
- if (this.tail) {
126
- this.tail.next = null
127
- } else {
128
- this.head = null
129
- }
130
- this.length--
131
- return res
132
- }
133
-
134
- Yallist.prototype.shift = function () {
135
- if (!this.head) {
136
- return undefined
137
- }
138
-
139
- var res = this.head.value
140
- this.head = this.head.next
141
- if (this.head) {
142
- this.head.prev = null
143
- } else {
144
- this.tail = null
145
- }
146
- this.length--
147
- return res
148
- }
149
-
150
- Yallist.prototype.forEach = function (fn, thisp) {
151
- thisp = thisp || this
152
- for (var walker = this.head, i = 0; walker !== null; i++) {
153
- fn.call(thisp, walker.value, i, this)
154
- walker = walker.next
155
- }
156
- }
157
-
158
- Yallist.prototype.forEachReverse = function (fn, thisp) {
159
- thisp = thisp || this
160
- for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
161
- fn.call(thisp, walker.value, i, this)
162
- walker = walker.prev
163
- }
164
- }
165
-
166
- Yallist.prototype.get = function (n) {
167
- for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
168
- // abort out of the list early if we hit a cycle
169
- walker = walker.next
170
- }
171
- if (i === n && walker !== null) {
172
- return walker.value
173
- }
174
- }
175
-
176
- Yallist.prototype.getReverse = function (n) {
177
- for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
178
- // abort out of the list early if we hit a cycle
179
- walker = walker.prev
180
- }
181
- if (i === n && walker !== null) {
182
- return walker.value
183
- }
184
- }
185
-
186
- Yallist.prototype.map = function (fn, thisp) {
187
- thisp = thisp || this
188
- var res = new Yallist()
189
- for (var walker = this.head; walker !== null;) {
190
- res.push(fn.call(thisp, walker.value, this))
191
- walker = walker.next
192
- }
193
- return res
194
- }
195
-
196
- Yallist.prototype.mapReverse = function (fn, thisp) {
197
- thisp = thisp || this
198
- var res = new Yallist()
199
- for (var walker = this.tail; walker !== null;) {
200
- res.push(fn.call(thisp, walker.value, this))
201
- walker = walker.prev
202
- }
203
- return res
204
- }
205
-
206
- Yallist.prototype.reduce = function (fn, initial) {
207
- var acc
208
- var walker = this.head
209
- if (arguments.length > 1) {
210
- acc = initial
211
- } else if (this.head) {
212
- walker = this.head.next
213
- acc = this.head.value
214
- } else {
215
- throw new TypeError('Reduce of empty list with no initial value')
216
- }
217
-
218
- for (var i = 0; walker !== null; i++) {
219
- acc = fn(acc, walker.value, i)
220
- walker = walker.next
221
- }
222
-
223
- return acc
224
- }
225
-
226
- Yallist.prototype.reduceReverse = function (fn, initial) {
227
- var acc
228
- var walker = this.tail
229
- if (arguments.length > 1) {
230
- acc = initial
231
- } else if (this.tail) {
232
- walker = this.tail.prev
233
- acc = this.tail.value
234
- } else {
235
- throw new TypeError('Reduce of empty list with no initial value')
236
- }
237
-
238
- for (var i = this.length - 1; walker !== null; i--) {
239
- acc = fn(acc, walker.value, i)
240
- walker = walker.prev
241
- }
242
-
243
- return acc
244
- }
245
-
246
- Yallist.prototype.toArray = function () {
247
- var arr = new Array(this.length)
248
- for (var i = 0, walker = this.head; walker !== null; i++) {
249
- arr[i] = walker.value
250
- walker = walker.next
251
- }
252
- return arr
253
- }
254
-
255
- Yallist.prototype.toArrayReverse = function () {
256
- var arr = new Array(this.length)
257
- for (var i = 0, walker = this.tail; walker !== null; i++) {
258
- arr[i] = walker.value
259
- walker = walker.prev
260
- }
261
- return arr
262
- }
263
-
264
- Yallist.prototype.slice = function (from, to) {
265
- to = to || this.length
266
- if (to < 0) {
267
- to += this.length
268
- }
269
- from = from || 0
270
- if (from < 0) {
271
- from += this.length
272
- }
273
- var ret = new Yallist()
274
- if (to < from || to < 0) {
275
- return ret
276
- }
277
- if (from < 0) {
278
- from = 0
279
- }
280
- if (to > this.length) {
281
- to = this.length
282
- }
283
- for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
284
- walker = walker.next
285
- }
286
- for (; walker !== null && i < to; i++, walker = walker.next) {
287
- ret.push(walker.value)
288
- }
289
- return ret
290
- }
291
-
292
- Yallist.prototype.sliceReverse = function (from, to) {
293
- to = to || this.length
294
- if (to < 0) {
295
- to += this.length
296
- }
297
- from = from || 0
298
- if (from < 0) {
299
- from += this.length
300
- }
301
- var ret = new Yallist()
302
- if (to < from || to < 0) {
303
- return ret
304
- }
305
- if (from < 0) {
306
- from = 0
307
- }
308
- if (to > this.length) {
309
- to = this.length
310
- }
311
- for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
312
- walker = walker.prev
313
- }
314
- for (; walker !== null && i > from; i--, walker = walker.prev) {
315
- ret.push(walker.value)
316
- }
317
- return ret
318
- }
319
-
320
- Yallist.prototype.reverse = function () {
321
- var head = this.head
322
- var tail = this.tail
323
- for (var walker = head; walker !== null; walker = walker.prev) {
324
- var p = walker.prev
325
- walker.prev = walker.next
326
- walker.next = p
327
- }
328
- this.head = tail
329
- this.tail = head
330
- return this
331
- }
332
-
333
- function push (self, item) {
334
- self.tail = new Node(item, self.tail, null, self)
335
- if (!self.head) {
336
- self.head = self.tail
337
- }
338
- self.length++
339
- }
340
-
341
- function unshift (self, item) {
342
- self.head = new Node(item, null, self.head, self)
343
- if (!self.tail) {
344
- self.tail = self.head
345
- }
346
- self.length++
347
- }
348
-
349
- function Node (value, prev, next, list) {
350
- if (!(this instanceof Node)) {
351
- return new Node(value, prev, next, list)
352
- }
353
-
354
- this.list = list
355
- this.value = value
356
-
357
- if (prev) {
358
- prev.next = this
359
- this.prev = prev
360
- } else {
361
- this.prev = null
362
- }
363
-
364
- if (next) {
365
- next.prev = this
366
- this.next = next
367
- } else {
368
- this.next = null
369
- }
370
- }