1 | !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.APIValidator=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var lodash = require('lodash'),
|
6 | jjv = require('jjv'),
|
7 | REQ = require('request'),
|
8 | when = require('when'),
|
9 |
|
10 | AValidator = {
|
11 | normalizeError: function (V, I) {
|
12 | return {
|
13 | type: 'validation',
|
14 | target: I,
|
15 | rule: V
|
16 | };
|
17 | },
|
18 | ApiValidator: function (list, cb) {
|
19 | lodash.map(list, this.promiseValidator, this);
|
20 | },
|
21 | all: function (list) {
|
22 | if (!lodash.isArray(list)) {
|
23 | return {
|
24 | error: [{
|
25 | 'type': 'input',
|
26 | message: 'Input is not array for all'
|
27 | }]
|
28 | };
|
29 | }
|
30 |
|
31 | return lodash.map(list, this.one, this);
|
32 | },
|
33 | one: function (D) {
|
34 | var E, err;
|
35 |
|
36 | if (!D) {
|
37 | return {
|
38 | error: [{
|
39 | 'type': 'internal',
|
40 | message: 'No input for one'
|
41 | }]
|
42 | };
|
43 | }
|
44 |
|
45 | if (!D.schema) {
|
46 | return {
|
47 | error: [{
|
48 | 'type': 'input',
|
49 | message: 'No schema in input for one'
|
50 | }]
|
51 | };
|
52 | }
|
53 |
|
54 | E = jjv();
|
55 | err = E.validate(D.schema, D.data);
|
56 |
|
57 | return err ? {error: lodash.map(err.validation, this.normalizeError, this)} : null;
|
58 | }
|
59 | };
|
60 |
|
61 | module.exports = AValidator;
|
62 |
|
63 | },{"jjv":52,"lodash":54,"request":55,"when":82}],2:[function(require,module,exports){
|
64 |
|
65 | },{}],3:[function(require,module,exports){
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var base64 = require('base64-js')
|
74 | var ieee754 = require('ieee754')
|
75 | var isArray = require('is-array')
|
76 |
|
77 | exports.Buffer = Buffer
|
78 | exports.SlowBuffer = Buffer
|
79 | exports.INSPECT_MAX_BYTES = 50
|
80 | Buffer.poolSize = 8192
|
81 |
|
82 | var kMaxLength = 0x3fffffff
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | Buffer.TYPED_ARRAY_SUPPORT = (function () {
|
107 | try {
|
108 | var buf = new ArrayBuffer(0)
|
109 | var arr = new Uint8Array(buf)
|
110 | arr.foo = function () { return 42 }
|
111 | return 42 === arr.foo() &&
|
112 | typeof arr.subarray === 'function' &&
|
113 | new Uint8Array(1).subarray(1, 1).byteLength === 0
|
114 | } catch (e) {
|
115 | return false
|
116 | }
|
117 | })()
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | function Buffer (subject, encoding, noZero) {
|
132 | if (!(this instanceof Buffer))
|
133 | return new Buffer(subject, encoding, noZero)
|
134 |
|
135 | var type = typeof subject
|
136 |
|
137 |
|
138 | var length
|
139 | if (type === 'number')
|
140 | length = subject > 0 ? subject >>> 0 : 0
|
141 | else if (type === 'string') {
|
142 | if (encoding === 'base64')
|
143 | subject = base64clean(subject)
|
144 | length = Buffer.byteLength(subject, encoding)
|
145 | } else if (type === 'object' && subject !== null) {
|
146 | if (subject.type === 'Buffer' && isArray(subject.data))
|
147 | subject = subject.data
|
148 | length = +subject.length > 0 ? Math.floor(+subject.length) : 0
|
149 | } else
|
150 | throw new TypeError('must start with number, buffer, array or string')
|
151 |
|
152 | if (this.length > kMaxLength)
|
153 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
154 | 'size: 0x' + kMaxLength.toString(16) + ' bytes')
|
155 |
|
156 | var buf
|
157 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
158 |
|
159 | buf = Buffer._augment(new Uint8Array(length))
|
160 | } else {
|
161 |
|
162 | buf = this
|
163 | buf.length = length
|
164 | buf._isBuffer = true
|
165 | }
|
166 |
|
167 | var i
|
168 | if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
|
169 |
|
170 | buf._set(subject)
|
171 | } else if (isArrayish(subject)) {
|
172 |
|
173 | if (Buffer.isBuffer(subject)) {
|
174 | for (i = 0; i < length; i++)
|
175 | buf[i] = subject.readUInt8(i)
|
176 | } else {
|
177 | for (i = 0; i < length; i++)
|
178 | buf[i] = ((subject[i] % 256) + 256) % 256
|
179 | }
|
180 | } else if (type === 'string') {
|
181 | buf.write(subject, 0, encoding)
|
182 | } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) {
|
183 | for (i = 0; i < length; i++) {
|
184 | buf[i] = 0
|
185 | }
|
186 | }
|
187 |
|
188 | return buf
|
189 | }
|
190 |
|
191 | Buffer.isBuffer = function (b) {
|
192 | return !!(b != null && b._isBuffer)
|
193 | }
|
194 |
|
195 | Buffer.compare = function (a, b) {
|
196 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
|
197 | throw new TypeError('Arguments must be Buffers')
|
198 |
|
199 | var x = a.length
|
200 | var y = b.length
|
201 | for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
|
202 | if (i !== len) {
|
203 | x = a[i]
|
204 | y = b[i]
|
205 | }
|
206 | if (x < y) return -1
|
207 | if (y < x) return 1
|
208 | return 0
|
209 | }
|
210 |
|
211 | Buffer.isEncoding = function (encoding) {
|
212 | switch (String(encoding).toLowerCase()) {
|
213 | case 'hex':
|
214 | case 'utf8':
|
215 | case 'utf-8':
|
216 | case 'ascii':
|
217 | case 'binary':
|
218 | case 'base64':
|
219 | case 'raw':
|
220 | case 'ucs2':
|
221 | case 'ucs-2':
|
222 | case 'utf16le':
|
223 | case 'utf-16le':
|
224 | return true
|
225 | default:
|
226 | return false
|
227 | }
|
228 | }
|
229 |
|
230 | Buffer.concat = function (list, totalLength) {
|
231 | if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])')
|
232 |
|
233 | if (list.length === 0) {
|
234 | return new Buffer(0)
|
235 | } else if (list.length === 1) {
|
236 | return list[0]
|
237 | }
|
238 |
|
239 | var i
|
240 | if (totalLength === undefined) {
|
241 | totalLength = 0
|
242 | for (i = 0; i < list.length; i++) {
|
243 | totalLength += list[i].length
|
244 | }
|
245 | }
|
246 |
|
247 | var buf = new Buffer(totalLength)
|
248 | var pos = 0
|
249 | for (i = 0; i < list.length; i++) {
|
250 | var item = list[i]
|
251 | item.copy(buf, pos)
|
252 | pos += item.length
|
253 | }
|
254 | return buf
|
255 | }
|
256 |
|
257 | Buffer.byteLength = function (str, encoding) {
|
258 | var ret
|
259 | str = str + ''
|
260 | switch (encoding || 'utf8') {
|
261 | case 'ascii':
|
262 | case 'binary':
|
263 | case 'raw':
|
264 | ret = str.length
|
265 | break
|
266 | case 'ucs2':
|
267 | case 'ucs-2':
|
268 | case 'utf16le':
|
269 | case 'utf-16le':
|
270 | ret = str.length * 2
|
271 | break
|
272 | case 'hex':
|
273 | ret = str.length >>> 1
|
274 | break
|
275 | case 'utf8':
|
276 | case 'utf-8':
|
277 | ret = utf8ToBytes(str).length
|
278 | break
|
279 | case 'base64':
|
280 | ret = base64ToBytes(str).length
|
281 | break
|
282 | default:
|
283 | ret = str.length
|
284 | }
|
285 | return ret
|
286 | }
|
287 |
|
288 |
|
289 | Buffer.prototype.length = undefined
|
290 | Buffer.prototype.parent = undefined
|
291 |
|
292 |
|
293 | Buffer.prototype.toString = function (encoding, start, end) {
|
294 | var loweredCase = false
|
295 |
|
296 | start = start >>> 0
|
297 | end = end === undefined || end === Infinity ? this.length : end >>> 0
|
298 |
|
299 | if (!encoding) encoding = 'utf8'
|
300 | if (start < 0) start = 0
|
301 | if (end > this.length) end = this.length
|
302 | if (end <= start) return ''
|
303 |
|
304 | while (true) {
|
305 | switch (encoding) {
|
306 | case 'hex':
|
307 | return hexSlice(this, start, end)
|
308 |
|
309 | case 'utf8':
|
310 | case 'utf-8':
|
311 | return utf8Slice(this, start, end)
|
312 |
|
313 | case 'ascii':
|
314 | return asciiSlice(this, start, end)
|
315 |
|
316 | case 'binary':
|
317 | return binarySlice(this, start, end)
|
318 |
|
319 | case 'base64':
|
320 | return base64Slice(this, start, end)
|
321 |
|
322 | case 'ucs2':
|
323 | case 'ucs-2':
|
324 | case 'utf16le':
|
325 | case 'utf-16le':
|
326 | return utf16leSlice(this, start, end)
|
327 |
|
328 | default:
|
329 | if (loweredCase)
|
330 | throw new TypeError('Unknown encoding: ' + encoding)
|
331 | encoding = (encoding + '').toLowerCase()
|
332 | loweredCase = true
|
333 | }
|
334 | }
|
335 | }
|
336 |
|
337 | Buffer.prototype.equals = function (b) {
|
338 | if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
339 | return Buffer.compare(this, b) === 0
|
340 | }
|
341 |
|
342 | Buffer.prototype.inspect = function () {
|
343 | var str = ''
|
344 | var max = exports.INSPECT_MAX_BYTES
|
345 | if (this.length > 0) {
|
346 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
|
347 | if (this.length > max)
|
348 | str += ' ... '
|
349 | }
|
350 | return '<Buffer ' + str + '>'
|
351 | }
|
352 |
|
353 | Buffer.prototype.compare = function (b) {
|
354 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
355 | return Buffer.compare(this, b)
|
356 | }
|
357 |
|
358 |
|
359 | Buffer.prototype.get = function (offset) {
|
360 | console.log('.get() is deprecated. Access using array indexes instead.')
|
361 | return this.readUInt8(offset)
|
362 | }
|
363 |
|
364 |
|
365 | Buffer.prototype.set = function (v, offset) {
|
366 | console.log('.set() is deprecated. Access using array indexes instead.')
|
367 | return this.writeUInt8(v, offset)
|
368 | }
|
369 |
|
370 | function hexWrite (buf, string, offset, length) {
|
371 | offset = Number(offset) || 0
|
372 | var remaining = buf.length - offset
|
373 | if (!length) {
|
374 | length = remaining
|
375 | } else {
|
376 | length = Number(length)
|
377 | if (length > remaining) {
|
378 | length = remaining
|
379 | }
|
380 | }
|
381 |
|
382 |
|
383 | var strLen = string.length
|
384 | if (strLen % 2 !== 0) throw new Error('Invalid hex string')
|
385 |
|
386 | if (length > strLen / 2) {
|
387 | length = strLen / 2
|
388 | }
|
389 | for (var i = 0; i < length; i++) {
|
390 | var byte = parseInt(string.substr(i * 2, 2), 16)
|
391 | if (isNaN(byte)) throw new Error('Invalid hex string')
|
392 | buf[offset + i] = byte
|
393 | }
|
394 | return i
|
395 | }
|
396 |
|
397 | function utf8Write (buf, string, offset, length) {
|
398 | var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
|
399 | return charsWritten
|
400 | }
|
401 |
|
402 | function asciiWrite (buf, string, offset, length) {
|
403 | var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
|
404 | return charsWritten
|
405 | }
|
406 |
|
407 | function binaryWrite (buf, string, offset, length) {
|
408 | return asciiWrite(buf, string, offset, length)
|
409 | }
|
410 |
|
411 | function base64Write (buf, string, offset, length) {
|
412 | var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
|
413 | return charsWritten
|
414 | }
|
415 |
|
416 | function utf16leWrite (buf, string, offset, length) {
|
417 | var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length)
|
418 | return charsWritten
|
419 | }
|
420 |
|
421 | Buffer.prototype.write = function (string, offset, length, encoding) {
|
422 |
|
423 |
|
424 | if (isFinite(offset)) {
|
425 | if (!isFinite(length)) {
|
426 | encoding = length
|
427 | length = undefined
|
428 | }
|
429 | } else {
|
430 | var swap = encoding
|
431 | encoding = offset
|
432 | offset = length
|
433 | length = swap
|
434 | }
|
435 |
|
436 | offset = Number(offset) || 0
|
437 | var remaining = this.length - offset
|
438 | if (!length) {
|
439 | length = remaining
|
440 | } else {
|
441 | length = Number(length)
|
442 | if (length > remaining) {
|
443 | length = remaining
|
444 | }
|
445 | }
|
446 | encoding = String(encoding || 'utf8').toLowerCase()
|
447 |
|
448 | var ret
|
449 | switch (encoding) {
|
450 | case 'hex':
|
451 | ret = hexWrite(this, string, offset, length)
|
452 | break
|
453 | case 'utf8':
|
454 | case 'utf-8':
|
455 | ret = utf8Write(this, string, offset, length)
|
456 | break
|
457 | case 'ascii':
|
458 | ret = asciiWrite(this, string, offset, length)
|
459 | break
|
460 | case 'binary':
|
461 | ret = binaryWrite(this, string, offset, length)
|
462 | break
|
463 | case 'base64':
|
464 | ret = base64Write(this, string, offset, length)
|
465 | break
|
466 | case 'ucs2':
|
467 | case 'ucs-2':
|
468 | case 'utf16le':
|
469 | case 'utf-16le':
|
470 | ret = utf16leWrite(this, string, offset, length)
|
471 | break
|
472 | default:
|
473 | throw new TypeError('Unknown encoding: ' + encoding)
|
474 | }
|
475 | return ret
|
476 | }
|
477 |
|
478 | Buffer.prototype.toJSON = function () {
|
479 | return {
|
480 | type: 'Buffer',
|
481 | data: Array.prototype.slice.call(this._arr || this, 0)
|
482 | }
|
483 | }
|
484 |
|
485 | function base64Slice (buf, start, end) {
|
486 | if (start === 0 && end === buf.length) {
|
487 | return base64.fromByteArray(buf)
|
488 | } else {
|
489 | return base64.fromByteArray(buf.slice(start, end))
|
490 | }
|
491 | }
|
492 |
|
493 | function utf8Slice (buf, start, end) {
|
494 | var res = ''
|
495 | var tmp = ''
|
496 | end = Math.min(buf.length, end)
|
497 |
|
498 | for (var i = start; i < end; i++) {
|
499 | if (buf[i] <= 0x7F) {
|
500 | res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
|
501 | tmp = ''
|
502 | } else {
|
503 | tmp += '%' + buf[i].toString(16)
|
504 | }
|
505 | }
|
506 |
|
507 | return res + decodeUtf8Char(tmp)
|
508 | }
|
509 |
|
510 | function asciiSlice (buf, start, end) {
|
511 | var ret = ''
|
512 | end = Math.min(buf.length, end)
|
513 |
|
514 | for (var i = start; i < end; i++) {
|
515 | ret += String.fromCharCode(buf[i])
|
516 | }
|
517 | return ret
|
518 | }
|
519 |
|
520 | function binarySlice (buf, start, end) {
|
521 | return asciiSlice(buf, start, end)
|
522 | }
|
523 |
|
524 | function hexSlice (buf, start, end) {
|
525 | var len = buf.length
|
526 |
|
527 | if (!start || start < 0) start = 0
|
528 | if (!end || end < 0 || end > len) end = len
|
529 |
|
530 | var out = ''
|
531 | for (var i = start; i < end; i++) {
|
532 | out += toHex(buf[i])
|
533 | }
|
534 | return out
|
535 | }
|
536 |
|
537 | function utf16leSlice (buf, start, end) {
|
538 | var bytes = buf.slice(start, end)
|
539 | var res = ''
|
540 | for (var i = 0; i < bytes.length; i += 2) {
|
541 | res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
|
542 | }
|
543 | return res
|
544 | }
|
545 |
|
546 | Buffer.prototype.slice = function (start, end) {
|
547 | var len = this.length
|
548 | start = ~~start
|
549 | end = end === undefined ? len : ~~end
|
550 |
|
551 | if (start < 0) {
|
552 | start += len;
|
553 | if (start < 0)
|
554 | start = 0
|
555 | } else if (start > len) {
|
556 | start = len
|
557 | }
|
558 |
|
559 | if (end < 0) {
|
560 | end += len
|
561 | if (end < 0)
|
562 | end = 0
|
563 | } else if (end > len) {
|
564 | end = len
|
565 | }
|
566 |
|
567 | if (end < start)
|
568 | end = start
|
569 |
|
570 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
571 | return Buffer._augment(this.subarray(start, end))
|
572 | } else {
|
573 | var sliceLen = end - start
|
574 | var newBuf = new Buffer(sliceLen, undefined, true)
|
575 | for (var i = 0; i < sliceLen; i++) {
|
576 | newBuf[i] = this[i + start]
|
577 | }
|
578 | return newBuf
|
579 | }
|
580 | }
|
581 |
|
582 |
|
583 |
|
584 |
|
585 | function checkOffset (offset, ext, length) {
|
586 | if ((offset % 1) !== 0 || offset < 0)
|
587 | throw new RangeError('offset is not uint')
|
588 | if (offset + ext > length)
|
589 | throw new RangeError('Trying to access beyond buffer length')
|
590 | }
|
591 |
|
592 | Buffer.prototype.readUInt8 = function (offset, noAssert) {
|
593 | if (!noAssert)
|
594 | checkOffset(offset, 1, this.length)
|
595 | return this[offset]
|
596 | }
|
597 |
|
598 | Buffer.prototype.readUInt16LE = function (offset, noAssert) {
|
599 | if (!noAssert)
|
600 | checkOffset(offset, 2, this.length)
|
601 | return this[offset] | (this[offset + 1] << 8)
|
602 | }
|
603 |
|
604 | Buffer.prototype.readUInt16BE = function (offset, noAssert) {
|
605 | if (!noAssert)
|
606 | checkOffset(offset, 2, this.length)
|
607 | return (this[offset] << 8) | this[offset + 1]
|
608 | }
|
609 |
|
610 | Buffer.prototype.readUInt32LE = function (offset, noAssert) {
|
611 | if (!noAssert)
|
612 | checkOffset(offset, 4, this.length)
|
613 |
|
614 | return ((this[offset]) |
|
615 | (this[offset + 1] << 8) |
|
616 | (this[offset + 2] << 16)) +
|
617 | (this[offset + 3] * 0x1000000)
|
618 | }
|
619 |
|
620 | Buffer.prototype.readUInt32BE = function (offset, noAssert) {
|
621 | if (!noAssert)
|
622 | checkOffset(offset, 4, this.length)
|
623 |
|
624 | return (this[offset] * 0x1000000) +
|
625 | ((this[offset + 1] << 16) |
|
626 | (this[offset + 2] << 8) |
|
627 | this[offset + 3])
|
628 | }
|
629 |
|
630 | Buffer.prototype.readInt8 = function (offset, noAssert) {
|
631 | if (!noAssert)
|
632 | checkOffset(offset, 1, this.length)
|
633 | if (!(this[offset] & 0x80))
|
634 | return (this[offset])
|
635 | return ((0xff - this[offset] + 1) * -1)
|
636 | }
|
637 |
|
638 | Buffer.prototype.readInt16LE = function (offset, noAssert) {
|
639 | if (!noAssert)
|
640 | checkOffset(offset, 2, this.length)
|
641 | var val = this[offset] | (this[offset + 1] << 8)
|
642 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
643 | }
|
644 |
|
645 | Buffer.prototype.readInt16BE = function (offset, noAssert) {
|
646 | if (!noAssert)
|
647 | checkOffset(offset, 2, this.length)
|
648 | var val = this[offset + 1] | (this[offset] << 8)
|
649 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
650 | }
|
651 |
|
652 | Buffer.prototype.readInt32LE = function (offset, noAssert) {
|
653 | if (!noAssert)
|
654 | checkOffset(offset, 4, this.length)
|
655 |
|
656 | return (this[offset]) |
|
657 | (this[offset + 1] << 8) |
|
658 | (this[offset + 2] << 16) |
|
659 | (this[offset + 3] << 24)
|
660 | }
|
661 |
|
662 | Buffer.prototype.readInt32BE = function (offset, noAssert) {
|
663 | if (!noAssert)
|
664 | checkOffset(offset, 4, this.length)
|
665 |
|
666 | return (this[offset] << 24) |
|
667 | (this[offset + 1] << 16) |
|
668 | (this[offset + 2] << 8) |
|
669 | (this[offset + 3])
|
670 | }
|
671 |
|
672 | Buffer.prototype.readFloatLE = function (offset, noAssert) {
|
673 | if (!noAssert)
|
674 | checkOffset(offset, 4, this.length)
|
675 | return ieee754.read(this, offset, true, 23, 4)
|
676 | }
|
677 |
|
678 | Buffer.prototype.readFloatBE = function (offset, noAssert) {
|
679 | if (!noAssert)
|
680 | checkOffset(offset, 4, this.length)
|
681 | return ieee754.read(this, offset, false, 23, 4)
|
682 | }
|
683 |
|
684 | Buffer.prototype.readDoubleLE = function (offset, noAssert) {
|
685 | if (!noAssert)
|
686 | checkOffset(offset, 8, this.length)
|
687 | return ieee754.read(this, offset, true, 52, 8)
|
688 | }
|
689 |
|
690 | Buffer.prototype.readDoubleBE = function (offset, noAssert) {
|
691 | if (!noAssert)
|
692 | checkOffset(offset, 8, this.length)
|
693 | return ieee754.read(this, offset, false, 52, 8)
|
694 | }
|
695 |
|
696 | function checkInt (buf, value, offset, ext, max, min) {
|
697 | if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
|
698 | if (value > max || value < min) throw new TypeError('value is out of bounds')
|
699 | if (offset + ext > buf.length) throw new TypeError('index out of range')
|
700 | }
|
701 |
|
702 | Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
|
703 | value = +value
|
704 | offset = offset >>> 0
|
705 | if (!noAssert)
|
706 | checkInt(this, value, offset, 1, 0xff, 0)
|
707 | if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
708 | this[offset] = value
|
709 | return offset + 1
|
710 | }
|
711 |
|
712 | function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
713 | if (value < 0) value = 0xffff + value + 1
|
714 | for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
|
715 | buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
716 | (littleEndian ? i : 1 - i) * 8
|
717 | }
|
718 | }
|
719 |
|
720 | Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
|
721 | value = +value
|
722 | offset = offset >>> 0
|
723 | if (!noAssert)
|
724 | checkInt(this, value, offset, 2, 0xffff, 0)
|
725 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
726 | this[offset] = value
|
727 | this[offset + 1] = (value >>> 8)
|
728 | } else objectWriteUInt16(this, value, offset, true)
|
729 | return offset + 2
|
730 | }
|
731 |
|
732 | Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
|
733 | value = +value
|
734 | offset = offset >>> 0
|
735 | if (!noAssert)
|
736 | checkInt(this, value, offset, 2, 0xffff, 0)
|
737 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
738 | this[offset] = (value >>> 8)
|
739 | this[offset + 1] = value
|
740 | } else objectWriteUInt16(this, value, offset, false)
|
741 | return offset + 2
|
742 | }
|
743 |
|
744 | function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
745 | if (value < 0) value = 0xffffffff + value + 1
|
746 | for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
|
747 | buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
|
748 | }
|
749 | }
|
750 |
|
751 | Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
|
752 | value = +value
|
753 | offset = offset >>> 0
|
754 | if (!noAssert)
|
755 | checkInt(this, value, offset, 4, 0xffffffff, 0)
|
756 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
757 | this[offset + 3] = (value >>> 24)
|
758 | this[offset + 2] = (value >>> 16)
|
759 | this[offset + 1] = (value >>> 8)
|
760 | this[offset] = value
|
761 | } else objectWriteUInt32(this, value, offset, true)
|
762 | return offset + 4
|
763 | }
|
764 |
|
765 | Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
|
766 | value = +value
|
767 | offset = offset >>> 0
|
768 | if (!noAssert)
|
769 | checkInt(this, value, offset, 4, 0xffffffff, 0)
|
770 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
771 | this[offset] = (value >>> 24)
|
772 | this[offset + 1] = (value >>> 16)
|
773 | this[offset + 2] = (value >>> 8)
|
774 | this[offset + 3] = value
|
775 | } else objectWriteUInt32(this, value, offset, false)
|
776 | return offset + 4
|
777 | }
|
778 |
|
779 | Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
|
780 | value = +value
|
781 | offset = offset >>> 0
|
782 | if (!noAssert)
|
783 | checkInt(this, value, offset, 1, 0x7f, -0x80)
|
784 | if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
785 | if (value < 0) value = 0xff + value + 1
|
786 | this[offset] = value
|
787 | return offset + 1
|
788 | }
|
789 |
|
790 | Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
|
791 | value = +value
|
792 | offset = offset >>> 0
|
793 | if (!noAssert)
|
794 | checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
795 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
796 | this[offset] = value
|
797 | this[offset + 1] = (value >>> 8)
|
798 | } else objectWriteUInt16(this, value, offset, true)
|
799 | return offset + 2
|
800 | }
|
801 |
|
802 | Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
|
803 | value = +value
|
804 | offset = offset >>> 0
|
805 | if (!noAssert)
|
806 | checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
807 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
808 | this[offset] = (value >>> 8)
|
809 | this[offset + 1] = value
|
810 | } else objectWriteUInt16(this, value, offset, false)
|
811 | return offset + 2
|
812 | }
|
813 |
|
814 | Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
|
815 | value = +value
|
816 | offset = offset >>> 0
|
817 | if (!noAssert)
|
818 | checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
819 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
820 | this[offset] = value
|
821 | this[offset + 1] = (value >>> 8)
|
822 | this[offset + 2] = (value >>> 16)
|
823 | this[offset + 3] = (value >>> 24)
|
824 | } else objectWriteUInt32(this, value, offset, true)
|
825 | return offset + 4
|
826 | }
|
827 |
|
828 | Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
|
829 | value = +value
|
830 | offset = offset >>> 0
|
831 | if (!noAssert)
|
832 | checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
833 | if (value < 0) value = 0xffffffff + value + 1
|
834 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
835 | this[offset] = (value >>> 24)
|
836 | this[offset + 1] = (value >>> 16)
|
837 | this[offset + 2] = (value >>> 8)
|
838 | this[offset + 3] = value
|
839 | } else objectWriteUInt32(this, value, offset, false)
|
840 | return offset + 4
|
841 | }
|
842 |
|
843 | function checkIEEE754 (buf, value, offset, ext, max, min) {
|
844 | if (value > max || value < min) throw new TypeError('value is out of bounds')
|
845 | if (offset + ext > buf.length) throw new TypeError('index out of range')
|
846 | }
|
847 |
|
848 | function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
849 | if (!noAssert)
|
850 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
851 | ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
852 | return offset + 4
|
853 | }
|
854 |
|
855 | Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
|
856 | return writeFloat(this, value, offset, true, noAssert)
|
857 | }
|
858 |
|
859 | Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
|
860 | return writeFloat(this, value, offset, false, noAssert)
|
861 | }
|
862 |
|
863 | function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
864 | if (!noAssert)
|
865 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
866 | ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
867 | return offset + 8
|
868 | }
|
869 |
|
870 | Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
|
871 | return writeDouble(this, value, offset, true, noAssert)
|
872 | }
|
873 |
|
874 | Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
|
875 | return writeDouble(this, value, offset, false, noAssert)
|
876 | }
|
877 |
|
878 |
|
879 | Buffer.prototype.copy = function (target, target_start, start, end) {
|
880 | var source = this
|
881 |
|
882 | if (!start) start = 0
|
883 | if (!end && end !== 0) end = this.length
|
884 | if (!target_start) target_start = 0
|
885 |
|
886 |
|
887 | if (end === start) return
|
888 | if (target.length === 0 || source.length === 0) return
|
889 |
|
890 |
|
891 | if (end < start) throw new TypeError('sourceEnd < sourceStart')
|
892 | if (target_start < 0 || target_start >= target.length)
|
893 | throw new TypeError('targetStart out of bounds')
|
894 | if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds')
|
895 | if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds')
|
896 |
|
897 |
|
898 | if (end > this.length)
|
899 | end = this.length
|
900 | if (target.length - target_start < end - start)
|
901 | end = target.length - target_start + start
|
902 |
|
903 | var len = end - start
|
904 |
|
905 | if (len < 100 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
906 | for (var i = 0; i < len; i++) {
|
907 | target[i + target_start] = this[i + start]
|
908 | }
|
909 | } else {
|
910 | target._set(this.subarray(start, start + len), target_start)
|
911 | }
|
912 | }
|
913 |
|
914 |
|
915 | Buffer.prototype.fill = function (value, start, end) {
|
916 | if (!value) value = 0
|
917 | if (!start) start = 0
|
918 | if (!end) end = this.length
|
919 |
|
920 | if (end < start) throw new TypeError('end < start')
|
921 |
|
922 |
|
923 | if (end === start) return
|
924 | if (this.length === 0) return
|
925 |
|
926 | if (start < 0 || start >= this.length) throw new TypeError('start out of bounds')
|
927 | if (end < 0 || end > this.length) throw new TypeError('end out of bounds')
|
928 |
|
929 | var i
|
930 | if (typeof value === 'number') {
|
931 | for (i = start; i < end; i++) {
|
932 | this[i] = value
|
933 | }
|
934 | } else {
|
935 | var bytes = utf8ToBytes(value.toString())
|
936 | var len = bytes.length
|
937 | for (i = start; i < end; i++) {
|
938 | this[i] = bytes[i % len]
|
939 | }
|
940 | }
|
941 |
|
942 | return this
|
943 | }
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 | Buffer.prototype.toArrayBuffer = function () {
|
950 | if (typeof Uint8Array !== 'undefined') {
|
951 | if (Buffer.TYPED_ARRAY_SUPPORT) {
|
952 | return (new Buffer(this)).buffer
|
953 | } else {
|
954 | var buf = new Uint8Array(this.length)
|
955 | for (var i = 0, len = buf.length; i < len; i += 1) {
|
956 | buf[i] = this[i]
|
957 | }
|
958 | return buf.buffer
|
959 | }
|
960 | } else {
|
961 | throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
|
962 | }
|
963 | }
|
964 |
|
965 |
|
966 |
|
967 |
|
968 | var BP = Buffer.prototype
|
969 |
|
970 |
|
971 |
|
972 |
|
973 | Buffer._augment = function (arr) {
|
974 | arr._isBuffer = true
|
975 |
|
976 |
|
977 | arr._get = arr.get
|
978 | arr._set = arr.set
|
979 |
|
980 |
|
981 | arr.get = BP.get
|
982 | arr.set = BP.set
|
983 |
|
984 | arr.write = BP.write
|
985 | arr.toString = BP.toString
|
986 | arr.toLocaleString = BP.toString
|
987 | arr.toJSON = BP.toJSON
|
988 | arr.equals = BP.equals
|
989 | arr.compare = BP.compare
|
990 | arr.copy = BP.copy
|
991 | arr.slice = BP.slice
|
992 | arr.readUInt8 = BP.readUInt8
|
993 | arr.readUInt16LE = BP.readUInt16LE
|
994 | arr.readUInt16BE = BP.readUInt16BE
|
995 | arr.readUInt32LE = BP.readUInt32LE
|
996 | arr.readUInt32BE = BP.readUInt32BE
|
997 | arr.readInt8 = BP.readInt8
|
998 | arr.readInt16LE = BP.readInt16LE
|
999 | arr.readInt16BE = BP.readInt16BE
|
1000 | arr.readInt32LE = BP.readInt32LE
|
1001 | arr.readInt32BE = BP.readInt32BE
|
1002 | arr.readFloatLE = BP.readFloatLE
|
1003 | arr.readFloatBE = BP.readFloatBE
|
1004 | arr.readDoubleLE = BP.readDoubleLE
|
1005 | arr.readDoubleBE = BP.readDoubleBE
|
1006 | arr.writeUInt8 = BP.writeUInt8
|
1007 | arr.writeUInt16LE = BP.writeUInt16LE
|
1008 | arr.writeUInt16BE = BP.writeUInt16BE
|
1009 | arr.writeUInt32LE = BP.writeUInt32LE
|
1010 | arr.writeUInt32BE = BP.writeUInt32BE
|
1011 | arr.writeInt8 = BP.writeInt8
|
1012 | arr.writeInt16LE = BP.writeInt16LE
|
1013 | arr.writeInt16BE = BP.writeInt16BE
|
1014 | arr.writeInt32LE = BP.writeInt32LE
|
1015 | arr.writeInt32BE = BP.writeInt32BE
|
1016 | arr.writeFloatLE = BP.writeFloatLE
|
1017 | arr.writeFloatBE = BP.writeFloatBE
|
1018 | arr.writeDoubleLE = BP.writeDoubleLE
|
1019 | arr.writeDoubleBE = BP.writeDoubleBE
|
1020 | arr.fill = BP.fill
|
1021 | arr.inspect = BP.inspect
|
1022 | arr.toArrayBuffer = BP.toArrayBuffer
|
1023 |
|
1024 | return arr
|
1025 | }
|
1026 |
|
1027 | var INVALID_BASE64_RE = /[^+\/0-9A-z]/g
|
1028 |
|
1029 | function base64clean (str) {
|
1030 |
|
1031 | str = stringtrim(str).replace(INVALID_BASE64_RE, '')
|
1032 |
|
1033 | while (str.length % 4 !== 0) {
|
1034 | str = str + '='
|
1035 | }
|
1036 | return str
|
1037 | }
|
1038 |
|
1039 | function stringtrim (str) {
|
1040 | if (str.trim) return str.trim()
|
1041 | return str.replace(/^\s+|\s+$/g, '')
|
1042 | }
|
1043 |
|
1044 | function isArrayish (subject) {
|
1045 | return isArray(subject) || Buffer.isBuffer(subject) ||
|
1046 | subject && typeof subject === 'object' &&
|
1047 | typeof subject.length === 'number'
|
1048 | }
|
1049 |
|
1050 | function toHex (n) {
|
1051 | if (n < 16) return '0' + n.toString(16)
|
1052 | return n.toString(16)
|
1053 | }
|
1054 |
|
1055 | function utf8ToBytes (str) {
|
1056 | var byteArray = []
|
1057 | for (var i = 0; i < str.length; i++) {
|
1058 | var b = str.charCodeAt(i)
|
1059 | if (b <= 0x7F) {
|
1060 | byteArray.push(b)
|
1061 | } else {
|
1062 | var start = i
|
1063 | if (b >= 0xD800 && b <= 0xDFFF) i++
|
1064 | var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
|
1065 | for (var j = 0; j < h.length; j++) {
|
1066 | byteArray.push(parseInt(h[j], 16))
|
1067 | }
|
1068 | }
|
1069 | }
|
1070 | return byteArray
|
1071 | }
|
1072 |
|
1073 | function asciiToBytes (str) {
|
1074 | var byteArray = []
|
1075 | for (var i = 0; i < str.length; i++) {
|
1076 |
|
1077 | byteArray.push(str.charCodeAt(i) & 0xFF)
|
1078 | }
|
1079 | return byteArray
|
1080 | }
|
1081 |
|
1082 | function utf16leToBytes (str) {
|
1083 | var c, hi, lo
|
1084 | var byteArray = []
|
1085 | for (var i = 0; i < str.length; i++) {
|
1086 | c = str.charCodeAt(i)
|
1087 | hi = c >> 8
|
1088 | lo = c % 256
|
1089 | byteArray.push(lo)
|
1090 | byteArray.push(hi)
|
1091 | }
|
1092 |
|
1093 | return byteArray
|
1094 | }
|
1095 |
|
1096 | function base64ToBytes (str) {
|
1097 | return base64.toByteArray(str)
|
1098 | }
|
1099 |
|
1100 | function blitBuffer (src, dst, offset, length) {
|
1101 | for (var i = 0; i < length; i++) {
|
1102 | if ((i + offset >= dst.length) || (i >= src.length))
|
1103 | break
|
1104 | dst[i + offset] = src[i]
|
1105 | }
|
1106 | return i
|
1107 | }
|
1108 |
|
1109 | function decodeUtf8Char (str) {
|
1110 | try {
|
1111 | return decodeURIComponent(str)
|
1112 | } catch (err) {
|
1113 | return String.fromCharCode(0xFFFD)
|
1114 | }
|
1115 | }
|
1116 |
|
1117 | },{"base64-js":4,"ieee754":5,"is-array":6}],4:[function(require,module,exports){
|
1118 | var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
1119 |
|
1120 | ;(function (exports) {
|
1121 | 'use strict';
|
1122 |
|
1123 | var Arr = (typeof Uint8Array !== 'undefined')
|
1124 | ? Uint8Array
|
1125 | : Array
|
1126 |
|
1127 | var PLUS = '+'.charCodeAt(0)
|
1128 | var SLASH = '/'.charCodeAt(0)
|
1129 | var NUMBER = '0'.charCodeAt(0)
|
1130 | var LOWER = 'a'.charCodeAt(0)
|
1131 | var UPPER = 'A'.charCodeAt(0)
|
1132 |
|
1133 | function decode (elt) {
|
1134 | var code = elt.charCodeAt(0)
|
1135 | if (code === PLUS)
|
1136 | return 62
|
1137 | if (code === SLASH)
|
1138 | return 63
|
1139 | if (code < NUMBER)
|
1140 | return -1
|
1141 | if (code < NUMBER + 10)
|
1142 | return code - NUMBER + 26 + 26
|
1143 | if (code < UPPER + 26)
|
1144 | return code - UPPER
|
1145 | if (code < LOWER + 26)
|
1146 | return code - LOWER + 26
|
1147 | }
|
1148 |
|
1149 | function b64ToByteArray (b64) {
|
1150 | var i, j, l, tmp, placeHolders, arr
|
1151 |
|
1152 | if (b64.length % 4 > 0) {
|
1153 | throw new Error('Invalid string. Length must be a multiple of 4')
|
1154 | }
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 | var len = b64.length
|
1162 | placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
|
1163 |
|
1164 |
|
1165 | arr = new Arr(b64.length * 3 / 4 - placeHolders)
|
1166 |
|
1167 |
|
1168 | l = placeHolders > 0 ? b64.length - 4 : b64.length
|
1169 |
|
1170 | var L = 0
|
1171 |
|
1172 | function push (v) {
|
1173 | arr[L++] = v
|
1174 | }
|
1175 |
|
1176 | for (i = 0, j = 0; i < l; i += 4, j += 3) {
|
1177 | tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
|
1178 | push((tmp & 0xFF0000) >> 16)
|
1179 | push((tmp & 0xFF00) >> 8)
|
1180 | push(tmp & 0xFF)
|
1181 | }
|
1182 |
|
1183 | if (placeHolders === 2) {
|
1184 | tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
|
1185 | push(tmp & 0xFF)
|
1186 | } else if (placeHolders === 1) {
|
1187 | tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
|
1188 | push((tmp >> 8) & 0xFF)
|
1189 | push(tmp & 0xFF)
|
1190 | }
|
1191 |
|
1192 | return arr
|
1193 | }
|
1194 |
|
1195 | function uint8ToBase64 (uint8) {
|
1196 | var i,
|
1197 | extraBytes = uint8.length % 3,
|
1198 | output = "",
|
1199 | temp, length
|
1200 |
|
1201 | function encode (num) {
|
1202 | return lookup.charAt(num)
|
1203 | }
|
1204 |
|
1205 | function tripletToBase64 (num) {
|
1206 | return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
|
1207 | }
|
1208 |
|
1209 |
|
1210 | for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
|
1211 | temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
|
1212 | output += tripletToBase64(temp)
|
1213 | }
|
1214 |
|
1215 |
|
1216 | switch (extraBytes) {
|
1217 | case 1:
|
1218 | temp = uint8[uint8.length - 1]
|
1219 | output += encode(temp >> 2)
|
1220 | output += encode((temp << 4) & 0x3F)
|
1221 | output += '=='
|
1222 | break
|
1223 | case 2:
|
1224 | temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
|
1225 | output += encode(temp >> 10)
|
1226 | output += encode((temp >> 4) & 0x3F)
|
1227 | output += encode((temp << 2) & 0x3F)
|
1228 | output += '='
|
1229 | break
|
1230 | }
|
1231 |
|
1232 | return output
|
1233 | }
|
1234 |
|
1235 | exports.toByteArray = b64ToByteArray
|
1236 | exports.fromByteArray = uint8ToBase64
|
1237 | }(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
|
1238 |
|
1239 | },{}],5:[function(require,module,exports){
|
1240 | exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
1241 | var e, m,
|
1242 | eLen = nBytes * 8 - mLen - 1,
|
1243 | eMax = (1 << eLen) - 1,
|
1244 | eBias = eMax >> 1,
|
1245 | nBits = -7,
|
1246 | i = isLE ? (nBytes - 1) : 0,
|
1247 | d = isLE ? -1 : 1,
|
1248 | s = buffer[offset + i];
|
1249 |
|
1250 | i += d;
|
1251 |
|
1252 | e = s & ((1 << (-nBits)) - 1);
|
1253 | s >>= (-nBits);
|
1254 | nBits += eLen;
|
1255 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
|
1256 |
|
1257 | m = e & ((1 << (-nBits)) - 1);
|
1258 | e >>= (-nBits);
|
1259 | nBits += mLen;
|
1260 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
|
1261 |
|
1262 | if (e === 0) {
|
1263 | e = 1 - eBias;
|
1264 | } else if (e === eMax) {
|
1265 | return m ? NaN : ((s ? -1 : 1) * Infinity);
|
1266 | } else {
|
1267 | m = m + Math.pow(2, mLen);
|
1268 | e = e - eBias;
|
1269 | }
|
1270 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
1271 | };
|
1272 |
|
1273 | exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
1274 | var e, m, c,
|
1275 | eLen = nBytes * 8 - mLen - 1,
|
1276 | eMax = (1 << eLen) - 1,
|
1277 | eBias = eMax >> 1,
|
1278 | rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
|
1279 | i = isLE ? 0 : (nBytes - 1),
|
1280 | d = isLE ? 1 : -1,
|
1281 | s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
1282 |
|
1283 | value = Math.abs(value);
|
1284 |
|
1285 | if (isNaN(value) || value === Infinity) {
|
1286 | m = isNaN(value) ? 1 : 0;
|
1287 | e = eMax;
|
1288 | } else {
|
1289 | e = Math.floor(Math.log(value) / Math.LN2);
|
1290 | if (value * (c = Math.pow(2, -e)) < 1) {
|
1291 | e--;
|
1292 | c *= 2;
|
1293 | }
|
1294 | if (e + eBias >= 1) {
|
1295 | value += rt / c;
|
1296 | } else {
|
1297 | value += rt * Math.pow(2, 1 - eBias);
|
1298 | }
|
1299 | if (value * c >= 2) {
|
1300 | e++;
|
1301 | c /= 2;
|
1302 | }
|
1303 |
|
1304 | if (e + eBias >= eMax) {
|
1305 | m = 0;
|
1306 | e = eMax;
|
1307 | } else if (e + eBias >= 1) {
|
1308 | m = (value * c - 1) * Math.pow(2, mLen);
|
1309 | e = e + eBias;
|
1310 | } else {
|
1311 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
1312 | e = 0;
|
1313 | }
|
1314 | }
|
1315 |
|
1316 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
|
1317 |
|
1318 | e = (e << mLen) | m;
|
1319 | eLen += mLen;
|
1320 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
|
1321 |
|
1322 | buffer[offset + i - d] |= s * 128;
|
1323 | };
|
1324 |
|
1325 | },{}],6:[function(require,module,exports){
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 | var isArray = Array.isArray;
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 | var str = Object.prototype.toString;
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 | module.exports = isArray || function (val) {
|
1357 | return !! val && '[object Array]' == str.call(val);
|
1358 | };
|
1359 |
|
1360 | },{}],7:[function(require,module,exports){
|
1361 | (function (Buffer){
|
1362 | var createHash = require('sha.js')
|
1363 |
|
1364 | var md5 = toConstructor(require('./md5'))
|
1365 | var rmd160 = toConstructor(require('ripemd160'))
|
1366 |
|
1367 | function toConstructor (fn) {
|
1368 | return function () {
|
1369 | var buffers = []
|
1370 | var m= {
|
1371 | update: function (data, enc) {
|
1372 | if(!Buffer.isBuffer(data)) data = new Buffer(data, enc)
|
1373 | buffers.push(data)
|
1374 | return this
|
1375 | },
|
1376 | digest: function (enc) {
|
1377 | var buf = Buffer.concat(buffers)
|
1378 | var r = fn(buf)
|
1379 | buffers = null
|
1380 | return enc ? r.toString(enc) : r
|
1381 | }
|
1382 | }
|
1383 | return m
|
1384 | }
|
1385 | }
|
1386 |
|
1387 | module.exports = function (alg) {
|
1388 | if('md5' === alg) return new md5()
|
1389 | if('rmd160' === alg) return new rmd160()
|
1390 | return createHash(alg)
|
1391 | }
|
1392 |
|
1393 | }).call(this,require("buffer").Buffer)
|
1394 | },{"./md5":11,"buffer":3,"ripemd160":14,"sha.js":16}],8:[function(require,module,exports){
|
1395 | (function (Buffer){
|
1396 | var createHash = require('./create-hash')
|
1397 |
|
1398 | var zeroBuffer = new Buffer(128)
|
1399 | zeroBuffer.fill(0)
|
1400 |
|
1401 | module.exports = Hmac
|
1402 |
|
1403 | function Hmac (alg, key) {
|
1404 | if(!(this instanceof Hmac)) return new Hmac(alg, key)
|
1405 | this._opad = opad
|
1406 | this._alg = alg
|
1407 |
|
1408 | var blocksize = (alg === 'sha512') ? 128 : 64
|
1409 |
|
1410 | key = this._key = !Buffer.isBuffer(key) ? new Buffer(key) : key
|
1411 |
|
1412 | if(key.length > blocksize) {
|
1413 | key = createHash(alg).update(key).digest()
|
1414 | } else if(key.length < blocksize) {
|
1415 | key = Buffer.concat([key, zeroBuffer], blocksize)
|
1416 | }
|
1417 |
|
1418 | var ipad = this._ipad = new Buffer(blocksize)
|
1419 | var opad = this._opad = new Buffer(blocksize)
|
1420 |
|
1421 | for(var i = 0; i < blocksize; i++) {
|
1422 | ipad[i] = key[i] ^ 0x36
|
1423 | opad[i] = key[i] ^ 0x5C
|
1424 | }
|
1425 |
|
1426 | this._hash = createHash(alg).update(ipad)
|
1427 | }
|
1428 |
|
1429 | Hmac.prototype.update = function (data, enc) {
|
1430 | this._hash.update(data, enc)
|
1431 | return this
|
1432 | }
|
1433 |
|
1434 | Hmac.prototype.digest = function (enc) {
|
1435 | var h = this._hash.digest()
|
1436 | return createHash(this._alg).update(this._opad).update(h).digest(enc)
|
1437 | }
|
1438 |
|
1439 |
|
1440 | }).call(this,require("buffer").Buffer)
|
1441 | },{"./create-hash":7,"buffer":3}],9:[function(require,module,exports){
|
1442 | (function (Buffer){
|
1443 | var intSize = 4;
|
1444 | var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
|
1445 | var chrsz = 8;
|
1446 |
|
1447 | function toArray(buf, bigEndian) {
|
1448 | if ((buf.length % intSize) !== 0) {
|
1449 | var len = buf.length + (intSize - (buf.length % intSize));
|
1450 | buf = Buffer.concat([buf, zeroBuffer], len);
|
1451 | }
|
1452 |
|
1453 | var arr = [];
|
1454 | var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
|
1455 | for (var i = 0; i < buf.length; i += intSize) {
|
1456 | arr.push(fn.call(buf, i));
|
1457 | }
|
1458 | return arr;
|
1459 | }
|
1460 |
|
1461 | function toBuffer(arr, size, bigEndian) {
|
1462 | var buf = new Buffer(size);
|
1463 | var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
|
1464 | for (var i = 0; i < arr.length; i++) {
|
1465 | fn.call(buf, arr[i], i * 4, true);
|
1466 | }
|
1467 | return buf;
|
1468 | }
|
1469 |
|
1470 | function hash(buf, fn, hashSize, bigEndian) {
|
1471 | if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
|
1472 | var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
|
1473 | return toBuffer(arr, hashSize, bigEndian);
|
1474 | }
|
1475 |
|
1476 | module.exports = { hash: hash };
|
1477 |
|
1478 | }).call(this,require("buffer").Buffer)
|
1479 | },{"buffer":3}],10:[function(require,module,exports){
|
1480 | (function (Buffer){
|
1481 | var rng = require('./rng')
|
1482 |
|
1483 | function error () {
|
1484 | var m = [].slice.call(arguments).join(' ')
|
1485 | throw new Error([
|
1486 | m,
|
1487 | 'we accept pull requests',
|
1488 | 'http://github.com/dominictarr/crypto-browserify'
|
1489 | ].join('\n'))
|
1490 | }
|
1491 |
|
1492 | exports.createHash = require('./create-hash')
|
1493 |
|
1494 | exports.createHmac = require('./create-hmac')
|
1495 |
|
1496 | exports.randomBytes = function(size, callback) {
|
1497 | if (callback && callback.call) {
|
1498 | try {
|
1499 | callback.call(this, undefined, new Buffer(rng(size)))
|
1500 | } catch (err) { callback(err) }
|
1501 | } else {
|
1502 | return new Buffer(rng(size))
|
1503 | }
|
1504 | }
|
1505 |
|
1506 | function each(a, f) {
|
1507 | for(var i in a)
|
1508 | f(a[i], i)
|
1509 | }
|
1510 |
|
1511 | exports.getHashes = function () {
|
1512 | return ['sha1', 'sha256', 'sha512', 'md5', 'rmd160']
|
1513 | }
|
1514 |
|
1515 | var p = require('./pbkdf2')(exports)
|
1516 | exports.pbkdf2 = p.pbkdf2
|
1517 | exports.pbkdf2Sync = p.pbkdf2Sync
|
1518 |
|
1519 |
|
1520 |
|
1521 | each(['createCredentials'
|
1522 | , 'createCipher'
|
1523 | , 'createCipheriv'
|
1524 | , 'createDecipher'
|
1525 | , 'createDecipheriv'
|
1526 | , 'createSign'
|
1527 | , 'createVerify'
|
1528 | , 'createDiffieHellman'
|
1529 | ], function (name) {
|
1530 | exports[name] = function () {
|
1531 | error('sorry,', name, 'is not implemented yet')
|
1532 | }
|
1533 | })
|
1534 |
|
1535 | }).call(this,require("buffer").Buffer)
|
1536 | },{"./create-hash":7,"./create-hmac":8,"./pbkdf2":20,"./rng":21,"buffer":3}],11:[function(require,module,exports){
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 | var helpers = require('./helpers');
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 | function core_md5(x, len)
|
1552 | {
|
1553 |
|
1554 | x[len >> 5] |= 0x80 << ((len) % 32);
|
1555 | x[(((len + 64) >>> 9) << 4) + 14] = len;
|
1556 |
|
1557 | var a = 1732584193;
|
1558 | var b = -271733879;
|
1559 | var c = -1732584194;
|
1560 | var d = 271733878;
|
1561 |
|
1562 | for(var i = 0; i < x.length; i += 16)
|
1563 | {
|
1564 | var olda = a;
|
1565 | var oldb = b;
|
1566 | var oldc = c;
|
1567 | var oldd = d;
|
1568 |
|
1569 | a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
|
1570 | d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
|
1571 | c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
|
1572 | b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
|
1573 | a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
|
1574 | d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
|
1575 | c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
|
1576 | b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
|
1577 | a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
|
1578 | d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
|
1579 | c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
|
1580 | b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
|
1581 | a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
|
1582 | d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
|
1583 | c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
|
1584 | b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
|
1585 |
|
1586 | a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
|
1587 | d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
|
1588 | c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
|
1589 | b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
|
1590 | a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
|
1591 | d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
|
1592 | c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
|
1593 | b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
|
1594 | a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
|
1595 | d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
|
1596 | c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
|
1597 | b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
|
1598 | a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
|
1599 | d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
|
1600 | c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
|
1601 | b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
|
1602 |
|
1603 | a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
|
1604 | d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
|
1605 | c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
|
1606 | b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
|
1607 | a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
|
1608 | d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
|
1609 | c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
|
1610 | b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
|
1611 | a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
|
1612 | d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
|
1613 | c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
|
1614 | b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
|
1615 | a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
|
1616 | d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
|
1617 | c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
|
1618 | b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
|
1619 |
|
1620 | a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
|
1621 | d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
|
1622 | c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
|
1623 | b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
|
1624 | a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
|
1625 | d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
|
1626 | c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
|
1627 | b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
|
1628 | a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
|
1629 | d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
|
1630 | c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
|
1631 | b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
|
1632 | a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
|
1633 | d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
|
1634 | c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
|
1635 | b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
|
1636 |
|
1637 | a = safe_add(a, olda);
|
1638 | b = safe_add(b, oldb);
|
1639 | c = safe_add(c, oldc);
|
1640 | d = safe_add(d, oldd);
|
1641 | }
|
1642 | return Array(a, b, c, d);
|
1643 |
|
1644 | }
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 | function md5_cmn(q, a, b, x, s, t)
|
1650 | {
|
1651 | return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
|
1652 | }
|
1653 | function md5_ff(a, b, c, d, x, s, t)
|
1654 | {
|
1655 | return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
1656 | }
|
1657 | function md5_gg(a, b, c, d, x, s, t)
|
1658 | {
|
1659 | return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
1660 | }
|
1661 | function md5_hh(a, b, c, d, x, s, t)
|
1662 | {
|
1663 | return md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
1664 | }
|
1665 | function md5_ii(a, b, c, d, x, s, t)
|
1666 | {
|
1667 | return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
|
1668 | }
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 | function safe_add(x, y)
|
1675 | {
|
1676 | var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
1677 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
1678 | return (msw << 16) | (lsw & 0xFFFF);
|
1679 | }
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 | function bit_rol(num, cnt)
|
1685 | {
|
1686 | return (num << cnt) | (num >>> (32 - cnt));
|
1687 | }
|
1688 |
|
1689 | module.exports = function md5(buf) {
|
1690 | return helpers.hash(buf, core_md5, 16);
|
1691 | };
|
1692 |
|
1693 | },{"./helpers":9}],12:[function(require,module,exports){
|
1694 | var crypto = require('crypto')
|
1695 |
|
1696 | var exportFn = require('./pbkdf2')
|
1697 | var exported = exportFn(crypto)
|
1698 |
|
1699 | module.exports = {
|
1700 | pbkdf2: exported.pbkdf2,
|
1701 | pbkdf2Sync: exported.pbkdf2Sync,
|
1702 |
|
1703 |
|
1704 | __pbkdf2Export: exportFn
|
1705 | }
|
1706 |
|
1707 | },{"./pbkdf2":13,"crypto":10}],13:[function(require,module,exports){
|
1708 | (function (Buffer){
|
1709 | module.exports = function(crypto) {
|
1710 | function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
1711 | if ('function' === typeof digest) {
|
1712 | callback = digest
|
1713 | digest = undefined
|
1714 | }
|
1715 |
|
1716 | if ('function' !== typeof callback)
|
1717 | throw new Error('No callback provided to pbkdf2')
|
1718 |
|
1719 | setTimeout(function() {
|
1720 | var result
|
1721 |
|
1722 | try {
|
1723 | result = pbkdf2Sync(password, salt, iterations, keylen, digest)
|
1724 | } catch (e) {
|
1725 | return callback(e)
|
1726 | }
|
1727 |
|
1728 | callback(undefined, result)
|
1729 | })
|
1730 | }
|
1731 |
|
1732 | function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
1733 | if ('number' !== typeof iterations)
|
1734 | throw new TypeError('Iterations not a number')
|
1735 |
|
1736 | if (iterations < 0)
|
1737 | throw new TypeError('Bad iterations')
|
1738 |
|
1739 | if ('number' !== typeof keylen)
|
1740 | throw new TypeError('Key length not a number')
|
1741 |
|
1742 | if (keylen < 0)
|
1743 | throw new TypeError('Bad key length')
|
1744 |
|
1745 | digest = digest || 'sha1'
|
1746 |
|
1747 | if (!Buffer.isBuffer(password)) password = new Buffer(password)
|
1748 | if (!Buffer.isBuffer(salt)) salt = new Buffer(salt)
|
1749 |
|
1750 | var hLen, l = 1, r, T
|
1751 | var DK = new Buffer(keylen)
|
1752 | var block1 = new Buffer(salt.length + 4)
|
1753 | salt.copy(block1, 0, 0, salt.length)
|
1754 |
|
1755 | for (var i = 1; i <= l; i++) {
|
1756 | block1.writeUInt32BE(i, salt.length)
|
1757 |
|
1758 | var U = crypto.createHmac(digest, password).update(block1).digest()
|
1759 |
|
1760 | if (!hLen) {
|
1761 | hLen = U.length
|
1762 | T = new Buffer(hLen)
|
1763 | l = Math.ceil(keylen / hLen)
|
1764 | r = keylen - (l - 1) * hLen
|
1765 |
|
1766 | if (keylen > (Math.pow(2, 32) - 1) * hLen)
|
1767 | throw new TypeError('keylen exceeds maximum length')
|
1768 | }
|
1769 |
|
1770 | U.copy(T, 0, 0, hLen)
|
1771 |
|
1772 | for (var j = 1; j < iterations; j++) {
|
1773 | U = crypto.createHmac(digest, password).update(U).digest()
|
1774 |
|
1775 | for (var k = 0; k < hLen; k++) {
|
1776 | T[k] ^= U[k]
|
1777 | }
|
1778 | }
|
1779 |
|
1780 | var destPos = (i - 1) * hLen
|
1781 | var len = (i == l ? r : hLen)
|
1782 | T.copy(DK, destPos, 0, len)
|
1783 | }
|
1784 |
|
1785 | return DK
|
1786 | }
|
1787 |
|
1788 | return {
|
1789 | pbkdf2: pbkdf2,
|
1790 | pbkdf2Sync: pbkdf2Sync
|
1791 | }
|
1792 | }
|
1793 |
|
1794 | }).call(this,require("buffer").Buffer)
|
1795 | },{"buffer":3}],14:[function(require,module,exports){
|
1796 | (function (Buffer){
|
1797 |
|
1798 | module.exports = ripemd160
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 | var zl = [
|
1821 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
1822 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
1823 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
1824 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
1825 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
|
1826 | var zr = [
|
1827 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
1828 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
1829 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
1830 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
1831 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
|
1832 | var sl = [
|
1833 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
1834 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
1835 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
1836 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
1837 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ];
|
1838 | var sr = [
|
1839 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
1840 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
1841 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
1842 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
1843 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ];
|
1844 |
|
1845 | var hl = [ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E];
|
1846 | var hr = [ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000];
|
1847 |
|
1848 | var bytesToWords = function (bytes) {
|
1849 | var words = [];
|
1850 | for (var i = 0, b = 0; i < bytes.length; i++, b += 8) {
|
1851 | words[b >>> 5] |= bytes[i] << (24 - b % 32);
|
1852 | }
|
1853 | return words;
|
1854 | };
|
1855 |
|
1856 | var wordsToBytes = function (words) {
|
1857 | var bytes = [];
|
1858 | for (var b = 0; b < words.length * 32; b += 8) {
|
1859 | bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
|
1860 | }
|
1861 | return bytes;
|
1862 | };
|
1863 |
|
1864 | var processBlock = function (H, M, offset) {
|
1865 |
|
1866 |
|
1867 | for (var i = 0; i < 16; i++) {
|
1868 | var offset_i = offset + i;
|
1869 | var M_offset_i = M[offset_i];
|
1870 |
|
1871 |
|
1872 | M[offset_i] = (
|
1873 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
1874 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
1875 | );
|
1876 | }
|
1877 |
|
1878 |
|
1879 | var al, bl, cl, dl, el;
|
1880 | var ar, br, cr, dr, er;
|
1881 |
|
1882 | ar = al = H[0];
|
1883 | br = bl = H[1];
|
1884 | cr = cl = H[2];
|
1885 | dr = dl = H[3];
|
1886 | er = el = H[4];
|
1887 |
|
1888 | var t;
|
1889 | for (var i = 0; i < 80; i += 1) {
|
1890 | t = (al + M[offset+zl[i]])|0;
|
1891 | if (i<16){
|
1892 | t += f1(bl,cl,dl) + hl[0];
|
1893 | } else if (i<32) {
|
1894 | t += f2(bl,cl,dl) + hl[1];
|
1895 | } else if (i<48) {
|
1896 | t += f3(bl,cl,dl) + hl[2];
|
1897 | } else if (i<64) {
|
1898 | t += f4(bl,cl,dl) + hl[3];
|
1899 | } else {
|
1900 | t += f5(bl,cl,dl) + hl[4];
|
1901 | }
|
1902 | t = t|0;
|
1903 | t = rotl(t,sl[i]);
|
1904 | t = (t+el)|0;
|
1905 | al = el;
|
1906 | el = dl;
|
1907 | dl = rotl(cl, 10);
|
1908 | cl = bl;
|
1909 | bl = t;
|
1910 |
|
1911 | t = (ar + M[offset+zr[i]])|0;
|
1912 | if (i<16){
|
1913 | t += f5(br,cr,dr) + hr[0];
|
1914 | } else if (i<32) {
|
1915 | t += f4(br,cr,dr) + hr[1];
|
1916 | } else if (i<48) {
|
1917 | t += f3(br,cr,dr) + hr[2];
|
1918 | } else if (i<64) {
|
1919 | t += f2(br,cr,dr) + hr[3];
|
1920 | } else {
|
1921 | t += f1(br,cr,dr) + hr[4];
|
1922 | }
|
1923 | t = t|0;
|
1924 | t = rotl(t,sr[i]) ;
|
1925 | t = (t+er)|0;
|
1926 | ar = er;
|
1927 | er = dr;
|
1928 | dr = rotl(cr, 10);
|
1929 | cr = br;
|
1930 | br = t;
|
1931 | }
|
1932 |
|
1933 | t = (H[1] + cl + dr)|0;
|
1934 | H[1] = (H[2] + dl + er)|0;
|
1935 | H[2] = (H[3] + el + ar)|0;
|
1936 | H[3] = (H[4] + al + br)|0;
|
1937 | H[4] = (H[0] + bl + cr)|0;
|
1938 | H[0] = t;
|
1939 | };
|
1940 |
|
1941 | function f1(x, y, z) {
|
1942 | return ((x) ^ (y) ^ (z));
|
1943 | }
|
1944 |
|
1945 | function f2(x, y, z) {
|
1946 | return (((x)&(y)) | ((~x)&(z)));
|
1947 | }
|
1948 |
|
1949 | function f3(x, y, z) {
|
1950 | return (((x) | (~(y))) ^ (z));
|
1951 | }
|
1952 |
|
1953 | function f4(x, y, z) {
|
1954 | return (((x) & (z)) | ((y)&(~(z))));
|
1955 | }
|
1956 |
|
1957 | function f5(x, y, z) {
|
1958 | return ((x) ^ ((y) |(~(z))));
|
1959 | }
|
1960 |
|
1961 | function rotl(x,n) {
|
1962 | return (x<<n) | (x>>>(32-n));
|
1963 | }
|
1964 |
|
1965 | function ripemd160(message) {
|
1966 | var H = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0];
|
1967 |
|
1968 | if (typeof message == 'string')
|
1969 | message = new Buffer(message, 'utf8');
|
1970 |
|
1971 | var m = bytesToWords(message);
|
1972 |
|
1973 | var nBitsLeft = message.length * 8;
|
1974 | var nBitsTotal = message.length * 8;
|
1975 |
|
1976 |
|
1977 | m[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
1978 | m[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
1979 | (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
|
1980 | (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
|
1981 | );
|
1982 |
|
1983 | for (var i=0 ; i<m.length; i += 16) {
|
1984 | processBlock(H, m, i);
|
1985 | }
|
1986 |
|
1987 |
|
1988 | for (var i = 0; i < 5; i++) {
|
1989 |
|
1990 | var H_i = H[i];
|
1991 |
|
1992 |
|
1993 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
1994 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
1995 | }
|
1996 |
|
1997 | var digestbytes = wordsToBytes(H);
|
1998 | return new Buffer(digestbytes);
|
1999 | }
|
2000 |
|
2001 |
|
2002 |
|
2003 | }).call(this,require("buffer").Buffer)
|
2004 | },{"buffer":3}],15:[function(require,module,exports){
|
2005 | module.exports = function (Buffer) {
|
2006 |
|
2007 |
|
2008 | function Hash (blockSize, finalSize) {
|
2009 | this._block = new Buffer(blockSize)
|
2010 | this._finalSize = finalSize
|
2011 | this._blockSize = blockSize
|
2012 | this._len = 0
|
2013 | this._s = 0
|
2014 | }
|
2015 |
|
2016 | Hash.prototype.init = function () {
|
2017 | this._s = 0
|
2018 | this._len = 0
|
2019 | }
|
2020 |
|
2021 | Hash.prototype.update = function (data, enc) {
|
2022 | if ("string" === typeof data) {
|
2023 | enc = enc || "utf8"
|
2024 | data = new Buffer(data, enc)
|
2025 | }
|
2026 |
|
2027 | var l = this._len += data.length
|
2028 | var s = this._s = (this._s || 0)
|
2029 | var f = 0
|
2030 | var buffer = this._block
|
2031 |
|
2032 | while (s < l) {
|
2033 | var t = Math.min(data.length, f + this._blockSize - (s % this._blockSize))
|
2034 | var ch = (t - f)
|
2035 |
|
2036 | for (var i = 0; i < ch; i++) {
|
2037 | buffer[(s % this._blockSize) + i] = data[i + f]
|
2038 | }
|
2039 |
|
2040 | s += ch
|
2041 | f += ch
|
2042 |
|
2043 | if ((s % this._blockSize) === 0) {
|
2044 | this._update(buffer)
|
2045 | }
|
2046 | }
|
2047 | this._s = s
|
2048 |
|
2049 | return this
|
2050 | }
|
2051 |
|
2052 | Hash.prototype.digest = function (enc) {
|
2053 |
|
2054 | var l = this._len * 8
|
2055 |
|
2056 |
|
2057 | this._block[this._len % this._blockSize] = 0x80
|
2058 |
|
2059 |
|
2060 | this._block.fill(0, this._len % this._blockSize + 1)
|
2061 |
|
2062 | if (l % (this._blockSize * 8) >= this._finalSize * 8) {
|
2063 | this._update(this._block)
|
2064 | this._block.fill(0)
|
2065 | }
|
2066 |
|
2067 |
|
2068 |
|
2069 | this._block.writeInt32BE(l, this._blockSize - 4)
|
2070 |
|
2071 | var hash = this._update(this._block) || this._hash()
|
2072 |
|
2073 | return enc ? hash.toString(enc) : hash
|
2074 | }
|
2075 |
|
2076 | Hash.prototype._update = function () {
|
2077 | throw new Error('_update must be implemented by subclass')
|
2078 | }
|
2079 |
|
2080 | return Hash
|
2081 | }
|
2082 |
|
2083 | },{}],16:[function(require,module,exports){
|
2084 | var exports = module.exports = function (alg) {
|
2085 | var Alg = exports[alg]
|
2086 | if(!Alg) throw new Error(alg + ' is not supported (we accept pull requests)')
|
2087 | return new Alg()
|
2088 | }
|
2089 |
|
2090 | var Buffer = require('buffer').Buffer
|
2091 | var Hash = require('./hash')(Buffer)
|
2092 |
|
2093 | exports.sha1 = require('./sha1')(Buffer, Hash)
|
2094 | exports.sha256 = require('./sha256')(Buffer, Hash)
|
2095 | exports.sha512 = require('./sha512')(Buffer, Hash)
|
2096 |
|
2097 | },{"./hash":15,"./sha1":17,"./sha256":18,"./sha512":19,"buffer":3}],17:[function(require,module,exports){
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 | var inherits = require('util').inherits
|
2108 |
|
2109 | module.exports = function (Buffer, Hash) {
|
2110 |
|
2111 | var A = 0|0
|
2112 | var B = 4|0
|
2113 | var C = 8|0
|
2114 | var D = 12|0
|
2115 | var E = 16|0
|
2116 |
|
2117 | var W = new (typeof Int32Array === 'undefined' ? Array : Int32Array)(80)
|
2118 |
|
2119 | var POOL = []
|
2120 |
|
2121 | function Sha1 () {
|
2122 | if(POOL.length)
|
2123 | return POOL.pop().init()
|
2124 |
|
2125 | if(!(this instanceof Sha1)) return new Sha1()
|
2126 | this._w = W
|
2127 | Hash.call(this, 16*4, 14*4)
|
2128 |
|
2129 | this._h = null
|
2130 | this.init()
|
2131 | }
|
2132 |
|
2133 | inherits(Sha1, Hash)
|
2134 |
|
2135 | Sha1.prototype.init = function () {
|
2136 | this._a = 0x67452301
|
2137 | this._b = 0xefcdab89
|
2138 | this._c = 0x98badcfe
|
2139 | this._d = 0x10325476
|
2140 | this._e = 0xc3d2e1f0
|
2141 |
|
2142 | Hash.prototype.init.call(this)
|
2143 | return this
|
2144 | }
|
2145 |
|
2146 | Sha1.prototype._POOL = POOL
|
2147 | Sha1.prototype._update = function (X) {
|
2148 |
|
2149 | var a, b, c, d, e, _a, _b, _c, _d, _e
|
2150 |
|
2151 | a = _a = this._a
|
2152 | b = _b = this._b
|
2153 | c = _c = this._c
|
2154 | d = _d = this._d
|
2155 | e = _e = this._e
|
2156 |
|
2157 | var w = this._w
|
2158 |
|
2159 | for(var j = 0; j < 80; j++) {
|
2160 | var W = w[j] = j < 16 ? X.readInt32BE(j*4)
|
2161 | : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1)
|
2162 |
|
2163 | var t = add(
|
2164 | add(rol(a, 5), sha1_ft(j, b, c, d)),
|
2165 | add(add(e, W), sha1_kt(j))
|
2166 | )
|
2167 |
|
2168 | e = d
|
2169 | d = c
|
2170 | c = rol(b, 30)
|
2171 | b = a
|
2172 | a = t
|
2173 | }
|
2174 |
|
2175 | this._a = add(a, _a)
|
2176 | this._b = add(b, _b)
|
2177 | this._c = add(c, _c)
|
2178 | this._d = add(d, _d)
|
2179 | this._e = add(e, _e)
|
2180 | }
|
2181 |
|
2182 | Sha1.prototype._hash = function () {
|
2183 | if(POOL.length < 100) POOL.push(this)
|
2184 | var H = new Buffer(20)
|
2185 |
|
2186 | H.writeInt32BE(this._a|0, A)
|
2187 | H.writeInt32BE(this._b|0, B)
|
2188 | H.writeInt32BE(this._c|0, C)
|
2189 | H.writeInt32BE(this._d|0, D)
|
2190 | H.writeInt32BE(this._e|0, E)
|
2191 | return H
|
2192 | }
|
2193 |
|
2194 | |
2195 |
|
2196 |
|
2197 |
|
2198 | function sha1_ft(t, b, c, d) {
|
2199 | if(t < 20) return (b & c) | ((~b) & d);
|
2200 | if(t < 40) return b ^ c ^ d;
|
2201 | if(t < 60) return (b & c) | (b & d) | (c & d);
|
2202 | return b ^ c ^ d;
|
2203 | }
|
2204 |
|
2205 | |
2206 |
|
2207 |
|
2208 | function sha1_kt(t) {
|
2209 | return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
2210 | (t < 60) ? -1894007588 : -899497514;
|
2211 | }
|
2212 |
|
2213 | |
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 | function add(x, y) {
|
2220 | return (x + y ) | 0
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 | }
|
2226 |
|
2227 | |
2228 |
|
2229 |
|
2230 | function rol(num, cnt) {
|
2231 | return (num << cnt) | (num >>> (32 - cnt));
|
2232 | }
|
2233 |
|
2234 | return Sha1
|
2235 | }
|
2236 |
|
2237 | },{"util":51}],18:[function(require,module,exports){
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 | var inherits = require('util').inherits
|
2248 |
|
2249 | module.exports = function (Buffer, Hash) {
|
2250 |
|
2251 | var K = [
|
2252 | 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
2253 | 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
2254 | 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
2255 | 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
2256 | 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
2257 | 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
2258 | 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
2259 | 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
2260 | 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
2261 | 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
2262 | 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
2263 | 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
2264 | 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
2265 | 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
2266 | 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
2267 | 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
2268 | ]
|
2269 |
|
2270 | var W = new Array(64)
|
2271 |
|
2272 | function Sha256() {
|
2273 | this.init()
|
2274 |
|
2275 | this._w = W
|
2276 |
|
2277 | Hash.call(this, 16*4, 14*4)
|
2278 | }
|
2279 |
|
2280 | inherits(Sha256, Hash)
|
2281 |
|
2282 | Sha256.prototype.init = function () {
|
2283 |
|
2284 | this._a = 0x6a09e667|0
|
2285 | this._b = 0xbb67ae85|0
|
2286 | this._c = 0x3c6ef372|0
|
2287 | this._d = 0xa54ff53a|0
|
2288 | this._e = 0x510e527f|0
|
2289 | this._f = 0x9b05688c|0
|
2290 | this._g = 0x1f83d9ab|0
|
2291 | this._h = 0x5be0cd19|0
|
2292 |
|
2293 | this._len = this._s = 0
|
2294 |
|
2295 | return this
|
2296 | }
|
2297 |
|
2298 | function S (X, n) {
|
2299 | return (X >>> n) | (X << (32 - n));
|
2300 | }
|
2301 |
|
2302 | function R (X, n) {
|
2303 | return (X >>> n);
|
2304 | }
|
2305 |
|
2306 | function Ch (x, y, z) {
|
2307 | return ((x & y) ^ ((~x) & z));
|
2308 | }
|
2309 |
|
2310 | function Maj (x, y, z) {
|
2311 | return ((x & y) ^ (x & z) ^ (y & z));
|
2312 | }
|
2313 |
|
2314 | function Sigma0256 (x) {
|
2315 | return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
|
2316 | }
|
2317 |
|
2318 | function Sigma1256 (x) {
|
2319 | return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
|
2320 | }
|
2321 |
|
2322 | function Gamma0256 (x) {
|
2323 | return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
|
2324 | }
|
2325 |
|
2326 | function Gamma1256 (x) {
|
2327 | return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
|
2328 | }
|
2329 |
|
2330 | Sha256.prototype._update = function(M) {
|
2331 |
|
2332 | var W = this._w
|
2333 | var a, b, c, d, e, f, g, h
|
2334 | var T1, T2
|
2335 |
|
2336 | a = this._a | 0
|
2337 | b = this._b | 0
|
2338 | c = this._c | 0
|
2339 | d = this._d | 0
|
2340 | e = this._e | 0
|
2341 | f = this._f | 0
|
2342 | g = this._g | 0
|
2343 | h = this._h | 0
|
2344 |
|
2345 | for (var j = 0; j < 64; j++) {
|
2346 | var w = W[j] = j < 16
|
2347 | ? M.readInt32BE(j * 4)
|
2348 | : Gamma1256(W[j - 2]) + W[j - 7] + Gamma0256(W[j - 15]) + W[j - 16]
|
2349 |
|
2350 | T1 = h + Sigma1256(e) + Ch(e, f, g) + K[j] + w
|
2351 |
|
2352 | T2 = Sigma0256(a) + Maj(a, b, c);
|
2353 | h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2;
|
2354 | }
|
2355 |
|
2356 | this._a = (a + this._a) | 0
|
2357 | this._b = (b + this._b) | 0
|
2358 | this._c = (c + this._c) | 0
|
2359 | this._d = (d + this._d) | 0
|
2360 | this._e = (e + this._e) | 0
|
2361 | this._f = (f + this._f) | 0
|
2362 | this._g = (g + this._g) | 0
|
2363 | this._h = (h + this._h) | 0
|
2364 |
|
2365 | };
|
2366 |
|
2367 | Sha256.prototype._hash = function () {
|
2368 | var H = new Buffer(32)
|
2369 |
|
2370 | H.writeInt32BE(this._a, 0)
|
2371 | H.writeInt32BE(this._b, 4)
|
2372 | H.writeInt32BE(this._c, 8)
|
2373 | H.writeInt32BE(this._d, 12)
|
2374 | H.writeInt32BE(this._e, 16)
|
2375 | H.writeInt32BE(this._f, 20)
|
2376 | H.writeInt32BE(this._g, 24)
|
2377 | H.writeInt32BE(this._h, 28)
|
2378 |
|
2379 | return H
|
2380 | }
|
2381 |
|
2382 | return Sha256
|
2383 |
|
2384 | }
|
2385 |
|
2386 | },{"util":51}],19:[function(require,module,exports){
|
2387 | var inherits = require('util').inherits
|
2388 |
|
2389 | module.exports = function (Buffer, Hash) {
|
2390 | var K = [
|
2391 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
2392 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
2393 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
2394 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
2395 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
2396 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
2397 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
2398 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
2399 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
2400 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
2401 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
2402 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
2403 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
2404 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
2405 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
2406 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
2407 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
2408 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
2409 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
2410 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
2411 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
2412 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
2413 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
2414 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
2415 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
2416 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
2417 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
2418 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
2419 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
2420 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
2421 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
2422 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
2423 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
2424 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
2425 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
2426 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
2427 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
2428 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
2429 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
2430 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
2431 | ]
|
2432 |
|
2433 | var W = new Array(160)
|
2434 |
|
2435 | function Sha512() {
|
2436 | this.init()
|
2437 | this._w = W
|
2438 |
|
2439 | Hash.call(this, 128, 112)
|
2440 | }
|
2441 |
|
2442 | inherits(Sha512, Hash)
|
2443 |
|
2444 | Sha512.prototype.init = function () {
|
2445 |
|
2446 | this._a = 0x6a09e667|0
|
2447 | this._b = 0xbb67ae85|0
|
2448 | this._c = 0x3c6ef372|0
|
2449 | this._d = 0xa54ff53a|0
|
2450 | this._e = 0x510e527f|0
|
2451 | this._f = 0x9b05688c|0
|
2452 | this._g = 0x1f83d9ab|0
|
2453 | this._h = 0x5be0cd19|0
|
2454 |
|
2455 | this._al = 0xf3bcc908|0
|
2456 | this._bl = 0x84caa73b|0
|
2457 | this._cl = 0xfe94f82b|0
|
2458 | this._dl = 0x5f1d36f1|0
|
2459 | this._el = 0xade682d1|0
|
2460 | this._fl = 0x2b3e6c1f|0
|
2461 | this._gl = 0xfb41bd6b|0
|
2462 | this._hl = 0x137e2179|0
|
2463 |
|
2464 | this._len = this._s = 0
|
2465 |
|
2466 | return this
|
2467 | }
|
2468 |
|
2469 | function S (X, Xl, n) {
|
2470 | return (X >>> n) | (Xl << (32 - n))
|
2471 | }
|
2472 |
|
2473 | function Ch (x, y, z) {
|
2474 | return ((x & y) ^ ((~x) & z));
|
2475 | }
|
2476 |
|
2477 | function Maj (x, y, z) {
|
2478 | return ((x & y) ^ (x & z) ^ (y & z));
|
2479 | }
|
2480 |
|
2481 | Sha512.prototype._update = function(M) {
|
2482 |
|
2483 | var W = this._w
|
2484 | var a, b, c, d, e, f, g, h
|
2485 | var al, bl, cl, dl, el, fl, gl, hl
|
2486 |
|
2487 | a = this._a | 0
|
2488 | b = this._b | 0
|
2489 | c = this._c | 0
|
2490 | d = this._d | 0
|
2491 | e = this._e | 0
|
2492 | f = this._f | 0
|
2493 | g = this._g | 0
|
2494 | h = this._h | 0
|
2495 |
|
2496 | al = this._al | 0
|
2497 | bl = this._bl | 0
|
2498 | cl = this._cl | 0
|
2499 | dl = this._dl | 0
|
2500 | el = this._el | 0
|
2501 | fl = this._fl | 0
|
2502 | gl = this._gl | 0
|
2503 | hl = this._hl | 0
|
2504 |
|
2505 | for (var i = 0; i < 80; i++) {
|
2506 | var j = i * 2
|
2507 |
|
2508 | var Wi, Wil
|
2509 |
|
2510 | if (i < 16) {
|
2511 | Wi = W[j] = M.readInt32BE(j * 4)
|
2512 | Wil = W[j + 1] = M.readInt32BE(j * 4 + 4)
|
2513 |
|
2514 | } else {
|
2515 | var x = W[j - 15*2]
|
2516 | var xl = W[j - 15*2 + 1]
|
2517 | var gamma0 = S(x, xl, 1) ^ S(x, xl, 8) ^ (x >>> 7)
|
2518 | var gamma0l = S(xl, x, 1) ^ S(xl, x, 8) ^ S(xl, x, 7)
|
2519 |
|
2520 | x = W[j - 2*2]
|
2521 | xl = W[j - 2*2 + 1]
|
2522 | var gamma1 = S(x, xl, 19) ^ S(xl, x, 29) ^ (x >>> 6)
|
2523 | var gamma1l = S(xl, x, 19) ^ S(x, xl, 29) ^ S(xl, x, 6)
|
2524 |
|
2525 |
|
2526 | var Wi7 = W[j - 7*2]
|
2527 | var Wi7l = W[j - 7*2 + 1]
|
2528 |
|
2529 | var Wi16 = W[j - 16*2]
|
2530 | var Wi16l = W[j - 16*2 + 1]
|
2531 |
|
2532 | Wil = gamma0l + Wi7l
|
2533 | Wi = gamma0 + Wi7 + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0)
|
2534 | Wil = Wil + gamma1l
|
2535 | Wi = Wi + gamma1 + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0)
|
2536 | Wil = Wil + Wi16l
|
2537 | Wi = Wi + Wi16 + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0)
|
2538 |
|
2539 | W[j] = Wi
|
2540 | W[j + 1] = Wil
|
2541 | }
|
2542 |
|
2543 | var maj = Maj(a, b, c)
|
2544 | var majl = Maj(al, bl, cl)
|
2545 |
|
2546 | var sigma0h = S(a, al, 28) ^ S(al, a, 2) ^ S(al, a, 7)
|
2547 | var sigma0l = S(al, a, 28) ^ S(a, al, 2) ^ S(a, al, 7)
|
2548 | var sigma1h = S(e, el, 14) ^ S(e, el, 18) ^ S(el, e, 9)
|
2549 | var sigma1l = S(el, e, 14) ^ S(el, e, 18) ^ S(e, el, 9)
|
2550 |
|
2551 |
|
2552 | var Ki = K[j]
|
2553 | var Kil = K[j + 1]
|
2554 |
|
2555 | var ch = Ch(e, f, g)
|
2556 | var chl = Ch(el, fl, gl)
|
2557 |
|
2558 | var t1l = hl + sigma1l
|
2559 | var t1 = h + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0)
|
2560 | t1l = t1l + chl
|
2561 | t1 = t1 + ch + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0)
|
2562 | t1l = t1l + Kil
|
2563 | t1 = t1 + Ki + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0)
|
2564 | t1l = t1l + Wil
|
2565 | t1 = t1 + Wi + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0)
|
2566 |
|
2567 |
|
2568 | var t2l = sigma0l + majl
|
2569 | var t2 = sigma0h + maj + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0)
|
2570 |
|
2571 | h = g
|
2572 | hl = gl
|
2573 | g = f
|
2574 | gl = fl
|
2575 | f = e
|
2576 | fl = el
|
2577 | el = (dl + t1l) | 0
|
2578 | e = (d + t1 + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
|
2579 | d = c
|
2580 | dl = cl
|
2581 | c = b
|
2582 | cl = bl
|
2583 | b = a
|
2584 | bl = al
|
2585 | al = (t1l + t2l) | 0
|
2586 | a = (t1 + t2 + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0
|
2587 | }
|
2588 |
|
2589 | this._al = (this._al + al) | 0
|
2590 | this._bl = (this._bl + bl) | 0
|
2591 | this._cl = (this._cl + cl) | 0
|
2592 | this._dl = (this._dl + dl) | 0
|
2593 | this._el = (this._el + el) | 0
|
2594 | this._fl = (this._fl + fl) | 0
|
2595 | this._gl = (this._gl + gl) | 0
|
2596 | this._hl = (this._hl + hl) | 0
|
2597 |
|
2598 | this._a = (this._a + a + ((this._al >>> 0) < (al >>> 0) ? 1 : 0)) | 0
|
2599 | this._b = (this._b + b + ((this._bl >>> 0) < (bl >>> 0) ? 1 : 0)) | 0
|
2600 | this._c = (this._c + c + ((this._cl >>> 0) < (cl >>> 0) ? 1 : 0)) | 0
|
2601 | this._d = (this._d + d + ((this._dl >>> 0) < (dl >>> 0) ? 1 : 0)) | 0
|
2602 | this._e = (this._e + e + ((this._el >>> 0) < (el >>> 0) ? 1 : 0)) | 0
|
2603 | this._f = (this._f + f + ((this._fl >>> 0) < (fl >>> 0) ? 1 : 0)) | 0
|
2604 | this._g = (this._g + g + ((this._gl >>> 0) < (gl >>> 0) ? 1 : 0)) | 0
|
2605 | this._h = (this._h + h + ((this._hl >>> 0) < (hl >>> 0) ? 1 : 0)) | 0
|
2606 | }
|
2607 |
|
2608 | Sha512.prototype._hash = function () {
|
2609 | var H = new Buffer(64)
|
2610 |
|
2611 | function writeInt64BE(h, l, offset) {
|
2612 | H.writeInt32BE(h, offset)
|
2613 | H.writeInt32BE(l, offset + 4)
|
2614 | }
|
2615 |
|
2616 | writeInt64BE(this._a, this._al, 0)
|
2617 | writeInt64BE(this._b, this._bl, 8)
|
2618 | writeInt64BE(this._c, this._cl, 16)
|
2619 | writeInt64BE(this._d, this._dl, 24)
|
2620 | writeInt64BE(this._e, this._el, 32)
|
2621 | writeInt64BE(this._f, this._fl, 40)
|
2622 | writeInt64BE(this._g, this._gl, 48)
|
2623 | writeInt64BE(this._h, this._hl, 56)
|
2624 |
|
2625 | return H
|
2626 | }
|
2627 |
|
2628 | return Sha512
|
2629 |
|
2630 | }
|
2631 |
|
2632 | },{"util":51}],20:[function(require,module,exports){
|
2633 | var pbkdf2Export = require('pbkdf2-compat').__pbkdf2Export
|
2634 |
|
2635 | module.exports = function (crypto, exports) {
|
2636 | exports = exports || {}
|
2637 |
|
2638 | var exported = pbkdf2Export(crypto)
|
2639 |
|
2640 | exports.pbkdf2 = exported.pbkdf2
|
2641 | exports.pbkdf2Sync = exported.pbkdf2Sync
|
2642 |
|
2643 | return exports
|
2644 | }
|
2645 |
|
2646 | },{"pbkdf2-compat":12}],21:[function(require,module,exports){
|
2647 | (function (global,Buffer){
|
2648 | (function() {
|
2649 | var g = ('undefined' === typeof window ? global : window) || {}
|
2650 | var foolBrowserify = require
|
2651 | _crypto = (
|
2652 | g.crypto || g.msCrypto || foolBrowserify('crypto')
|
2653 | )
|
2654 | module.exports = function(size) {
|
2655 |
|
2656 | if(_crypto.getRandomValues) {
|
2657 | var bytes = new Buffer(size);
|
2658 | |
2659 |
|
2660 |
|
2661 |
|
2662 | _crypto.getRandomValues(bytes);
|
2663 | return bytes;
|
2664 | }
|
2665 | else if (_crypto.randomBytes) {
|
2666 | return _crypto.randomBytes(size)
|
2667 | }
|
2668 | else
|
2669 | throw new Error(
|
2670 | 'secure random number generation not supported by this browser\n'+
|
2671 | 'use chrome, FireFox or Internet Explorer 11'
|
2672 | )
|
2673 | }
|
2674 | }())
|
2675 |
|
2676 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
|
2677 | },{"buffer":3}],22:[function(require,module,exports){
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 |
|
2685 |
|
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 | function EventEmitter() {
|
2700 | this._events = this._events || {};
|
2701 | this._maxListeners = this._maxListeners || undefined;
|
2702 | }
|
2703 | module.exports = EventEmitter;
|
2704 |
|
2705 |
|
2706 | EventEmitter.EventEmitter = EventEmitter;
|
2707 |
|
2708 | EventEmitter.prototype._events = undefined;
|
2709 | EventEmitter.prototype._maxListeners = undefined;
|
2710 |
|
2711 |
|
2712 |
|
2713 | EventEmitter.defaultMaxListeners = 10;
|
2714 |
|
2715 |
|
2716 |
|
2717 | EventEmitter.prototype.setMaxListeners = function(n) {
|
2718 | if (!isNumber(n) || n < 0 || isNaN(n))
|
2719 | throw TypeError('n must be a positive number');
|
2720 | this._maxListeners = n;
|
2721 | return this;
|
2722 | };
|
2723 |
|
2724 | EventEmitter.prototype.emit = function(type) {
|
2725 | var er, handler, len, args, i, listeners;
|
2726 |
|
2727 | if (!this._events)
|
2728 | this._events = {};
|
2729 |
|
2730 |
|
2731 | if (type === 'error') {
|
2732 | if (!this._events.error ||
|
2733 | (isObject(this._events.error) && !this._events.error.length)) {
|
2734 | er = arguments[1];
|
2735 | if (er instanceof Error) {
|
2736 | throw er;
|
2737 | }
|
2738 | throw TypeError('Uncaught, unspecified "error" event.');
|
2739 | }
|
2740 | }
|
2741 |
|
2742 | handler = this._events[type];
|
2743 |
|
2744 | if (isUndefined(handler))
|
2745 | return false;
|
2746 |
|
2747 | if (isFunction(handler)) {
|
2748 | switch (arguments.length) {
|
2749 |
|
2750 | case 1:
|
2751 | handler.call(this);
|
2752 | break;
|
2753 | case 2:
|
2754 | handler.call(this, arguments[1]);
|
2755 | break;
|
2756 | case 3:
|
2757 | handler.call(this, arguments[1], arguments[2]);
|
2758 | break;
|
2759 |
|
2760 | default:
|
2761 | len = arguments.length;
|
2762 | args = new Array(len - 1);
|
2763 | for (i = 1; i < len; i++)
|
2764 | args[i - 1] = arguments[i];
|
2765 | handler.apply(this, args);
|
2766 | }
|
2767 | } else if (isObject(handler)) {
|
2768 | len = arguments.length;
|
2769 | args = new Array(len - 1);
|
2770 | for (i = 1; i < len; i++)
|
2771 | args[i - 1] = arguments[i];
|
2772 |
|
2773 | listeners = handler.slice();
|
2774 | len = listeners.length;
|
2775 | for (i = 0; i < len; i++)
|
2776 | listeners[i].apply(this, args);
|
2777 | }
|
2778 |
|
2779 | return true;
|
2780 | };
|
2781 |
|
2782 | EventEmitter.prototype.addListener = function(type, listener) {
|
2783 | var m;
|
2784 |
|
2785 | if (!isFunction(listener))
|
2786 | throw TypeError('listener must be a function');
|
2787 |
|
2788 | if (!this._events)
|
2789 | this._events = {};
|
2790 |
|
2791 |
|
2792 |
|
2793 | if (this._events.newListener)
|
2794 | this.emit('newListener', type,
|
2795 | isFunction(listener.listener) ?
|
2796 | listener.listener : listener);
|
2797 |
|
2798 | if (!this._events[type])
|
2799 |
|
2800 | this._events[type] = listener;
|
2801 | else if (isObject(this._events[type]))
|
2802 |
|
2803 | this._events[type].push(listener);
|
2804 | else
|
2805 |
|
2806 | this._events[type] = [this._events[type], listener];
|
2807 |
|
2808 |
|
2809 | if (isObject(this._events[type]) && !this._events[type].warned) {
|
2810 | var m;
|
2811 | if (!isUndefined(this._maxListeners)) {
|
2812 | m = this._maxListeners;
|
2813 | } else {
|
2814 | m = EventEmitter.defaultMaxListeners;
|
2815 | }
|
2816 |
|
2817 | if (m && m > 0 && this._events[type].length > m) {
|
2818 | this._events[type].warned = true;
|
2819 | console.error('(node) warning: possible EventEmitter memory ' +
|
2820 | 'leak detected. %d listeners added. ' +
|
2821 | 'Use emitter.setMaxListeners() to increase limit.',
|
2822 | this._events[type].length);
|
2823 | if (typeof console.trace === 'function') {
|
2824 |
|
2825 | console.trace();
|
2826 | }
|
2827 | }
|
2828 | }
|
2829 |
|
2830 | return this;
|
2831 | };
|
2832 |
|
2833 | EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
2834 |
|
2835 | EventEmitter.prototype.once = function(type, listener) {
|
2836 | if (!isFunction(listener))
|
2837 | throw TypeError('listener must be a function');
|
2838 |
|
2839 | var fired = false;
|
2840 |
|
2841 | function g() {
|
2842 | this.removeListener(type, g);
|
2843 |
|
2844 | if (!fired) {
|
2845 | fired = true;
|
2846 | listener.apply(this, arguments);
|
2847 | }
|
2848 | }
|
2849 |
|
2850 | g.listener = listener;
|
2851 | this.on(type, g);
|
2852 |
|
2853 | return this;
|
2854 | };
|
2855 |
|
2856 |
|
2857 | EventEmitter.prototype.removeListener = function(type, listener) {
|
2858 | var list, position, length, i;
|
2859 |
|
2860 | if (!isFunction(listener))
|
2861 | throw TypeError('listener must be a function');
|
2862 |
|
2863 | if (!this._events || !this._events[type])
|
2864 | return this;
|
2865 |
|
2866 | list = this._events[type];
|
2867 | length = list.length;
|
2868 | position = -1;
|
2869 |
|
2870 | if (list === listener ||
|
2871 | (isFunction(list.listener) && list.listener === listener)) {
|
2872 | delete this._events[type];
|
2873 | if (this._events.removeListener)
|
2874 | this.emit('removeListener', type, listener);
|
2875 |
|
2876 | } else if (isObject(list)) {
|
2877 | for (i = length; i-- > 0;) {
|
2878 | if (list[i] === listener ||
|
2879 | (list[i].listener && list[i].listener === listener)) {
|
2880 | position = i;
|
2881 | break;
|
2882 | }
|
2883 | }
|
2884 |
|
2885 | if (position < 0)
|
2886 | return this;
|
2887 |
|
2888 | if (list.length === 1) {
|
2889 | list.length = 0;
|
2890 | delete this._events[type];
|
2891 | } else {
|
2892 | list.splice(position, 1);
|
2893 | }
|
2894 |
|
2895 | if (this._events.removeListener)
|
2896 | this.emit('removeListener', type, listener);
|
2897 | }
|
2898 |
|
2899 | return this;
|
2900 | };
|
2901 |
|
2902 | EventEmitter.prototype.removeAllListeners = function(type) {
|
2903 | var key, listeners;
|
2904 |
|
2905 | if (!this._events)
|
2906 | return this;
|
2907 |
|
2908 |
|
2909 | if (!this._events.removeListener) {
|
2910 | if (arguments.length === 0)
|
2911 | this._events = {};
|
2912 | else if (this._events[type])
|
2913 | delete this._events[type];
|
2914 | return this;
|
2915 | }
|
2916 |
|
2917 |
|
2918 | if (arguments.length === 0) {
|
2919 | for (key in this._events) {
|
2920 | if (key === 'removeListener') continue;
|
2921 | this.removeAllListeners(key);
|
2922 | }
|
2923 | this.removeAllListeners('removeListener');
|
2924 | this._events = {};
|
2925 | return this;
|
2926 | }
|
2927 |
|
2928 | listeners = this._events[type];
|
2929 |
|
2930 | if (isFunction(listeners)) {
|
2931 | this.removeListener(type, listeners);
|
2932 | } else {
|
2933 |
|
2934 | while (listeners.length)
|
2935 | this.removeListener(type, listeners[listeners.length - 1]);
|
2936 | }
|
2937 | delete this._events[type];
|
2938 |
|
2939 | return this;
|
2940 | };
|
2941 |
|
2942 | EventEmitter.prototype.listeners = function(type) {
|
2943 | var ret;
|
2944 | if (!this._events || !this._events[type])
|
2945 | ret = [];
|
2946 | else if (isFunction(this._events[type]))
|
2947 | ret = [this._events[type]];
|
2948 | else
|
2949 | ret = this._events[type].slice();
|
2950 | return ret;
|
2951 | };
|
2952 |
|
2953 | EventEmitter.listenerCount = function(emitter, type) {
|
2954 | var ret;
|
2955 | if (!emitter._events || !emitter._events[type])
|
2956 | ret = 0;
|
2957 | else if (isFunction(emitter._events[type]))
|
2958 | ret = 1;
|
2959 | else
|
2960 | ret = emitter._events[type].length;
|
2961 | return ret;
|
2962 | };
|
2963 |
|
2964 | function isFunction(arg) {
|
2965 | return typeof arg === 'function';
|
2966 | }
|
2967 |
|
2968 | function isNumber(arg) {
|
2969 | return typeof arg === 'number';
|
2970 | }
|
2971 |
|
2972 | function isObject(arg) {
|
2973 | return typeof arg === 'object' && arg !== null;
|
2974 | }
|
2975 |
|
2976 | function isUndefined(arg) {
|
2977 | return arg === void 0;
|
2978 | }
|
2979 |
|
2980 | },{}],23:[function(require,module,exports){
|
2981 | var http = module.exports;
|
2982 | var EventEmitter = require('events').EventEmitter;
|
2983 | var Request = require('./lib/request');
|
2984 | var url = require('url')
|
2985 |
|
2986 | http.request = function (params, cb) {
|
2987 | if (typeof params === 'string') {
|
2988 | params = url.parse(params)
|
2989 | }
|
2990 | if (!params) params = {};
|
2991 | if (!params.host && !params.port) {
|
2992 | params.port = parseInt(window.location.port, 10);
|
2993 | }
|
2994 | if (!params.host && params.hostname) {
|
2995 | params.host = params.hostname;
|
2996 | }
|
2997 |
|
2998 | if (!params.protocol) {
|
2999 | if (params.scheme) {
|
3000 | params.protocol = params.scheme + ':';
|
3001 | } else {
|
3002 | params.protocol = window.location.protocol;
|
3003 | }
|
3004 | }
|
3005 |
|
3006 | if (!params.host) {
|
3007 | params.host = window.location.hostname || window.location.host;
|
3008 | }
|
3009 | if (/:/.test(params.host)) {
|
3010 | if (!params.port) {
|
3011 | params.port = params.host.split(':')[1];
|
3012 | }
|
3013 | params.host = params.host.split(':')[0];
|
3014 | }
|
3015 | if (!params.port) params.port = params.protocol == 'https:' ? 443 : 80;
|
3016 |
|
3017 | var req = new Request(new xhrHttp, params);
|
3018 | if (cb) req.on('response', cb);
|
3019 | return req;
|
3020 | };
|
3021 |
|
3022 | http.get = function (params, cb) {
|
3023 | params.method = 'GET';
|
3024 | var req = http.request(params, cb);
|
3025 | req.end();
|
3026 | return req;
|
3027 | };
|
3028 |
|
3029 | http.Agent = function () {};
|
3030 | http.Agent.defaultMaxSockets = 4;
|
3031 |
|
3032 | var xhrHttp = (function () {
|
3033 | if (typeof window === 'undefined') {
|
3034 | throw new Error('no window object present');
|
3035 | }
|
3036 | else if (window.XMLHttpRequest) {
|
3037 | return window.XMLHttpRequest;
|
3038 | }
|
3039 | else if (window.ActiveXObject) {
|
3040 | var axs = [
|
3041 | 'Msxml2.XMLHTTP.6.0',
|
3042 | 'Msxml2.XMLHTTP.3.0',
|
3043 | 'Microsoft.XMLHTTP'
|
3044 | ];
|
3045 | for (var i = 0; i < axs.length; i++) {
|
3046 | try {
|
3047 | var ax = new(window.ActiveXObject)(axs[i]);
|
3048 | return function () {
|
3049 | if (ax) {
|
3050 | var ax_ = ax;
|
3051 | ax = null;
|
3052 | return ax_;
|
3053 | }
|
3054 | else {
|
3055 | return new(window.ActiveXObject)(axs[i]);
|
3056 | }
|
3057 | };
|
3058 | }
|
3059 | catch (e) {}
|
3060 | }
|
3061 | throw new Error('ajax not supported in this browser')
|
3062 | }
|
3063 | else {
|
3064 | throw new Error('ajax not supported in this browser');
|
3065 | }
|
3066 | })();
|
3067 |
|
3068 | http.STATUS_CODES = {
|
3069 | 100 : 'Continue',
|
3070 | 101 : 'Switching Protocols',
|
3071 | 102 : 'Processing',
|
3072 | 200 : 'OK',
|
3073 | 201 : 'Created',
|
3074 | 202 : 'Accepted',
|
3075 | 203 : 'Non-Authoritative Information',
|
3076 | 204 : 'No Content',
|
3077 | 205 : 'Reset Content',
|
3078 | 206 : 'Partial Content',
|
3079 | 207 : 'Multi-Status',
|
3080 | 300 : 'Multiple Choices',
|
3081 | 301 : 'Moved Permanently',
|
3082 | 302 : 'Moved Temporarily',
|
3083 | 303 : 'See Other',
|
3084 | 304 : 'Not Modified',
|
3085 | 305 : 'Use Proxy',
|
3086 | 307 : 'Temporary Redirect',
|
3087 | 400 : 'Bad Request',
|
3088 | 401 : 'Unauthorized',
|
3089 | 402 : 'Payment Required',
|
3090 | 403 : 'Forbidden',
|
3091 | 404 : 'Not Found',
|
3092 | 405 : 'Method Not Allowed',
|
3093 | 406 : 'Not Acceptable',
|
3094 | 407 : 'Proxy Authentication Required',
|
3095 | 408 : 'Request Time-out',
|
3096 | 409 : 'Conflict',
|
3097 | 410 : 'Gone',
|
3098 | 411 : 'Length Required',
|
3099 | 412 : 'Precondition Failed',
|
3100 | 413 : 'Request Entity Too Large',
|
3101 | 414 : 'Request-URI Too Large',
|
3102 | 415 : 'Unsupported Media Type',
|
3103 | 416 : 'Requested Range Not Satisfiable',
|
3104 | 417 : 'Expectation Failed',
|
3105 | 418 : 'I\'m a teapot',
|
3106 | 422 : 'Unprocessable Entity',
|
3107 | 423 : 'Locked',
|
3108 | 424 : 'Failed Dependency',
|
3109 | 425 : 'Unordered Collection',
|
3110 | 426 : 'Upgrade Required',
|
3111 | 428 : 'Precondition Required',
|
3112 | 429 : 'Too Many Requests',
|
3113 | 431 : 'Request Header Fields Too Large',
|
3114 | 500 : 'Internal Server Error',
|
3115 | 501 : 'Not Implemented',
|
3116 | 502 : 'Bad Gateway',
|
3117 | 503 : 'Service Unavailable',
|
3118 | 504 : 'Gateway Time-out',
|
3119 | 505 : 'HTTP Version Not Supported',
|
3120 | 506 : 'Variant Also Negotiates',
|
3121 | 507 : 'Insufficient Storage',
|
3122 | 509 : 'Bandwidth Limit Exceeded',
|
3123 | 510 : 'Not Extended',
|
3124 | 511 : 'Network Authentication Required'
|
3125 | };
|
3126 | },{"./lib/request":24,"events":22,"url":49}],24:[function(require,module,exports){
|
3127 | var Stream = require('stream');
|
3128 | var Response = require('./response');
|
3129 | var Base64 = require('Base64');
|
3130 | var inherits = require('inherits');
|
3131 |
|
3132 | var Request = module.exports = function (xhr, params) {
|
3133 | var self = this;
|
3134 | self.writable = true;
|
3135 | self.xhr = xhr;
|
3136 | self.body = [];
|
3137 |
|
3138 | self.uri = (params.protocol || 'http:') + '//'
|
3139 | + params.host
|
3140 | + (params.port ? ':' + params.port : '')
|
3141 | + (params.path || '/')
|
3142 | ;
|
3143 |
|
3144 | if (typeof params.withCredentials === 'undefined') {
|
3145 | params.withCredentials = true;
|
3146 | }
|
3147 |
|
3148 | try { xhr.withCredentials = params.withCredentials }
|
3149 | catch (e) {}
|
3150 |
|
3151 | if (params.responseType) try { xhr.responseType = params.responseType }
|
3152 | catch (e) {}
|
3153 |
|
3154 | xhr.open(
|
3155 | params.method || 'GET',
|
3156 | self.uri,
|
3157 | true
|
3158 | );
|
3159 |
|
3160 | xhr.onerror = function(event) {
|
3161 | self.emit('error', new Error('Network error'));
|
3162 | };
|
3163 |
|
3164 | self._headers = {};
|
3165 |
|
3166 | if (params.headers) {
|
3167 | var keys = objectKeys(params.headers);
|
3168 | for (var i = 0; i < keys.length; i++) {
|
3169 | var key = keys[i];
|
3170 | if (!self.isSafeRequestHeader(key)) continue;
|
3171 | var value = params.headers[key];
|
3172 | self.setHeader(key, value);
|
3173 | }
|
3174 | }
|
3175 |
|
3176 | if (params.auth) {
|
3177 |
|
3178 | this.setHeader('Authorization', 'Basic ' + Base64.btoa(params.auth));
|
3179 | }
|
3180 |
|
3181 | var res = new Response;
|
3182 | res.on('close', function () {
|
3183 | self.emit('close');
|
3184 | });
|
3185 |
|
3186 | res.on('ready', function () {
|
3187 | self.emit('response', res);
|
3188 | });
|
3189 |
|
3190 | res.on('error', function (err) {
|
3191 | self.emit('error', err);
|
3192 | });
|
3193 |
|
3194 | xhr.onreadystatechange = function () {
|
3195 |
|
3196 |
|
3197 |
|
3198 | if (xhr.__aborted) return;
|
3199 | res.handle(xhr);
|
3200 | };
|
3201 | };
|
3202 |
|
3203 | inherits(Request, Stream);
|
3204 |
|
3205 | Request.prototype.setHeader = function (key, value) {
|
3206 | this._headers[key.toLowerCase()] = value
|
3207 | };
|
3208 |
|
3209 | Request.prototype.getHeader = function (key) {
|
3210 | return this._headers[key.toLowerCase()]
|
3211 | };
|
3212 |
|
3213 | Request.prototype.removeHeader = function (key) {
|
3214 | delete this._headers[key.toLowerCase()]
|
3215 | };
|
3216 |
|
3217 | Request.prototype.write = function (s) {
|
3218 | this.body.push(s);
|
3219 | };
|
3220 |
|
3221 | Request.prototype.destroy = function (s) {
|
3222 | this.xhr.__aborted = true;
|
3223 | this.xhr.abort();
|
3224 | this.emit('close');
|
3225 | };
|
3226 |
|
3227 | Request.prototype.end = function (s) {
|
3228 | if (s !== undefined) this.body.push(s);
|
3229 |
|
3230 | var keys = objectKeys(this._headers);
|
3231 | for (var i = 0; i < keys.length; i++) {
|
3232 | var key = keys[i];
|
3233 | var value = this._headers[key];
|
3234 | if (isArray(value)) {
|
3235 | for (var j = 0; j < value.length; j++) {
|
3236 | this.xhr.setRequestHeader(key, value[j]);
|
3237 | }
|
3238 | }
|
3239 | else this.xhr.setRequestHeader(key, value)
|
3240 | }
|
3241 |
|
3242 | if (this.body.length === 0) {
|
3243 | this.xhr.send('');
|
3244 | }
|
3245 | else if (typeof this.body[0] === 'string') {
|
3246 | this.xhr.send(this.body.join(''));
|
3247 | }
|
3248 | else if (isArray(this.body[0])) {
|
3249 | var body = [];
|
3250 | for (var i = 0; i < this.body.length; i++) {
|
3251 | body.push.apply(body, this.body[i]);
|
3252 | }
|
3253 | this.xhr.send(body);
|
3254 | }
|
3255 | else if (/Array/.test(Object.prototype.toString.call(this.body[0]))) {
|
3256 | var len = 0;
|
3257 | for (var i = 0; i < this.body.length; i++) {
|
3258 | len += this.body[i].length;
|
3259 | }
|
3260 | var body = new(this.body[0].constructor)(len);
|
3261 | var k = 0;
|
3262 |
|
3263 | for (var i = 0; i < this.body.length; i++) {
|
3264 | var b = this.body[i];
|
3265 | for (var j = 0; j < b.length; j++) {
|
3266 | body[k++] = b[j];
|
3267 | }
|
3268 | }
|
3269 | this.xhr.send(body);
|
3270 | }
|
3271 | else if (isXHR2Compatible(this.body[0])) {
|
3272 | this.xhr.send(this.body[0]);
|
3273 | }
|
3274 | else {
|
3275 | var body = '';
|
3276 | for (var i = 0; i < this.body.length; i++) {
|
3277 | body += this.body[i].toString();
|
3278 | }
|
3279 | this.xhr.send(body);
|
3280 | }
|
3281 | };
|
3282 |
|
3283 |
|
3284 | Request.unsafeHeaders = [
|
3285 | "accept-charset",
|
3286 | "accept-encoding",
|
3287 | "access-control-request-headers",
|
3288 | "access-control-request-method",
|
3289 | "connection",
|
3290 | "content-length",
|
3291 | "cookie",
|
3292 | "cookie2",
|
3293 | "content-transfer-encoding",
|
3294 | "date",
|
3295 | "expect",
|
3296 | "host",
|
3297 | "keep-alive",
|
3298 | "origin",
|
3299 | "referer",
|
3300 | "te",
|
3301 | "trailer",
|
3302 | "transfer-encoding",
|
3303 | "upgrade",
|
3304 | "user-agent",
|
3305 | "via"
|
3306 | ];
|
3307 |
|
3308 | Request.prototype.isSafeRequestHeader = function (headerName) {
|
3309 | if (!headerName) return false;
|
3310 | return indexOf(Request.unsafeHeaders, headerName.toLowerCase()) === -1;
|
3311 | };
|
3312 |
|
3313 | var objectKeys = Object.keys || function (obj) {
|
3314 | var keys = [];
|
3315 | for (var key in obj) keys.push(key);
|
3316 | return keys;
|
3317 | };
|
3318 |
|
3319 | var isArray = Array.isArray || function (xs) {
|
3320 | return Object.prototype.toString.call(xs) === '[object Array]';
|
3321 | };
|
3322 |
|
3323 | var indexOf = function (xs, x) {
|
3324 | if (xs.indexOf) return xs.indexOf(x);
|
3325 | for (var i = 0; i < xs.length; i++) {
|
3326 | if (xs[i] === x) return i;
|
3327 | }
|
3328 | return -1;
|
3329 | };
|
3330 |
|
3331 | var isXHR2Compatible = function (obj) {
|
3332 | if (typeof Blob !== 'undefined' && obj instanceof Blob) return true;
|
3333 | if (typeof ArrayBuffer !== 'undefined' && obj instanceof ArrayBuffer) return true;
|
3334 | if (typeof FormData !== 'undefined' && obj instanceof FormData) return true;
|
3335 | };
|
3336 |
|
3337 | },{"./response":25,"Base64":26,"inherits":28,"stream":48}],25:[function(require,module,exports){
|
3338 | var Stream = require('stream');
|
3339 | var util = require('util');
|
3340 |
|
3341 | var Response = module.exports = function (res) {
|
3342 | this.offset = 0;
|
3343 | this.readable = true;
|
3344 | };
|
3345 |
|
3346 | util.inherits(Response, Stream);
|
3347 |
|
3348 | var capable = {
|
3349 | streaming : true,
|
3350 | status2 : true
|
3351 | };
|
3352 |
|
3353 | function parseHeaders (res) {
|
3354 | var lines = res.getAllResponseHeaders().split(/\r?\n/);
|
3355 | var headers = {};
|
3356 | for (var i = 0; i < lines.length; i++) {
|
3357 | var line = lines[i];
|
3358 | if (line === '') continue;
|
3359 |
|
3360 | var m = line.match(/^([^:]+):\s*(.*)/);
|
3361 | if (m) {
|
3362 | var key = m[1].toLowerCase(), value = m[2];
|
3363 |
|
3364 | if (headers[key] !== undefined) {
|
3365 |
|
3366 | if (isArray(headers[key])) {
|
3367 | headers[key].push(value);
|
3368 | }
|
3369 | else {
|
3370 | headers[key] = [ headers[key], value ];
|
3371 | }
|
3372 | }
|
3373 | else {
|
3374 | headers[key] = value;
|
3375 | }
|
3376 | }
|
3377 | else {
|
3378 | headers[line] = true;
|
3379 | }
|
3380 | }
|
3381 | return headers;
|
3382 | }
|
3383 |
|
3384 | Response.prototype.getResponse = function (xhr) {
|
3385 | var respType = String(xhr.responseType).toLowerCase();
|
3386 | if (respType === 'blob') return xhr.responseBlob || xhr.response;
|
3387 | if (respType === 'arraybuffer') return xhr.response;
|
3388 | return xhr.responseText;
|
3389 | }
|
3390 |
|
3391 | Response.prototype.getHeader = function (key) {
|
3392 | return this.headers[key.toLowerCase()];
|
3393 | };
|
3394 |
|
3395 | Response.prototype.handle = function (res) {
|
3396 | if (res.readyState === 2 && capable.status2) {
|
3397 | try {
|
3398 | this.statusCode = res.status;
|
3399 | this.headers = parseHeaders(res);
|
3400 | }
|
3401 | catch (err) {
|
3402 | capable.status2 = false;
|
3403 | }
|
3404 |
|
3405 | if (capable.status2) {
|
3406 | this.emit('ready');
|
3407 | }
|
3408 | }
|
3409 | else if (capable.streaming && res.readyState === 3) {
|
3410 | try {
|
3411 | if (!this.statusCode) {
|
3412 | this.statusCode = res.status;
|
3413 | this.headers = parseHeaders(res);
|
3414 | this.emit('ready');
|
3415 | }
|
3416 | }
|
3417 | catch (err) {}
|
3418 |
|
3419 | try {
|
3420 | this._emitData(res);
|
3421 | }
|
3422 | catch (err) {
|
3423 | capable.streaming = false;
|
3424 | }
|
3425 | }
|
3426 | else if (res.readyState === 4) {
|
3427 | if (!this.statusCode) {
|
3428 | this.statusCode = res.status;
|
3429 | this.emit('ready');
|
3430 | }
|
3431 | this._emitData(res);
|
3432 |
|
3433 | if (res.error) {
|
3434 | this.emit('error', this.getResponse(res));
|
3435 | }
|
3436 | else this.emit('end');
|
3437 |
|
3438 | this.emit('close');
|
3439 | }
|
3440 | };
|
3441 |
|
3442 | Response.prototype._emitData = function (res) {
|
3443 | var respBody = this.getResponse(res);
|
3444 | if (respBody.toString().match(/ArrayBuffer/)) {
|
3445 | this.emit('data', new Uint8Array(respBody, this.offset));
|
3446 | this.offset = respBody.byteLength;
|
3447 | return;
|
3448 | }
|
3449 | if (respBody.length > this.offset) {
|
3450 | this.emit('data', respBody.slice(this.offset));
|
3451 | this.offset = respBody.length;
|
3452 | }
|
3453 | };
|
3454 |
|
3455 | var isArray = Array.isArray || function (xs) {
|
3456 | return Object.prototype.toString.call(xs) === '[object Array]';
|
3457 | };
|
3458 |
|
3459 | },{"stream":48,"util":51}],26:[function(require,module,exports){
|
3460 | ;(function () {
|
3461 |
|
3462 | var object = typeof exports != 'undefined' ? exports : this;
|
3463 | var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
3464 |
|
3465 | function InvalidCharacterError(message) {
|
3466 | this.message = message;
|
3467 | }
|
3468 | InvalidCharacterError.prototype = new Error;
|
3469 | InvalidCharacterError.prototype.name = 'InvalidCharacterError';
|
3470 |
|
3471 |
|
3472 |
|
3473 | object.btoa || (
|
3474 | object.btoa = function (input) {
|
3475 | for (
|
3476 |
|
3477 | var block, charCode, idx = 0, map = chars, output = '';
|
3478 |
|
3479 |
|
3480 |
|
3481 | input.charAt(idx | 0) || (map = '=', idx % 1);
|
3482 |
|
3483 | output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
3484 | ) {
|
3485 | charCode = input.charCodeAt(idx += 3/4);
|
3486 | if (charCode > 0xFF) {
|
3487 | throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
|
3488 | }
|
3489 | block = block << 8 | charCode;
|
3490 | }
|
3491 | return output;
|
3492 | });
|
3493 |
|
3494 |
|
3495 |
|
3496 | object.atob || (
|
3497 | object.atob = function (input) {
|
3498 | input = input.replace(/=+$/, '');
|
3499 | if (input.length % 4 == 1) {
|
3500 | throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
|
3501 | }
|
3502 | for (
|
3503 |
|
3504 | var bc = 0, bs, buffer, idx = 0, output = '';
|
3505 |
|
3506 | buffer = input.charAt(idx++);
|
3507 |
|
3508 | ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
|
3509 |
|
3510 |
|
3511 | bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
|
3512 | ) {
|
3513 |
|
3514 | buffer = chars.indexOf(buffer);
|
3515 | }
|
3516 | return output;
|
3517 | });
|
3518 |
|
3519 | }());
|
3520 |
|
3521 | },{}],27:[function(require,module,exports){
|
3522 | var http = require('http');
|
3523 |
|
3524 | var https = module.exports;
|
3525 |
|
3526 | for (var key in http) {
|
3527 | if (http.hasOwnProperty(key)) https[key] = http[key];
|
3528 | };
|
3529 |
|
3530 | https.request = function (params, cb) {
|
3531 | if (!params) params = {};
|
3532 | params.scheme = 'https';
|
3533 | return http.request.call(this, params, cb);
|
3534 | }
|
3535 |
|
3536 | },{"http":23}],28:[function(require,module,exports){
|
3537 | if (typeof Object.create === 'function') {
|
3538 |
|
3539 | module.exports = function inherits(ctor, superCtor) {
|
3540 | ctor.super_ = superCtor
|
3541 | ctor.prototype = Object.create(superCtor.prototype, {
|
3542 | constructor: {
|
3543 | value: ctor,
|
3544 | enumerable: false,
|
3545 | writable: true,
|
3546 | configurable: true
|
3547 | }
|
3548 | });
|
3549 | };
|
3550 | } else {
|
3551 |
|
3552 | module.exports = function inherits(ctor, superCtor) {
|
3553 | ctor.super_ = superCtor
|
3554 | var TempCtor = function () {}
|
3555 | TempCtor.prototype = superCtor.prototype
|
3556 | ctor.prototype = new TempCtor()
|
3557 | ctor.prototype.constructor = ctor
|
3558 | }
|
3559 | }
|
3560 |
|
3561 | },{}],29:[function(require,module,exports){
|
3562 | module.exports = Array.isArray || function (arr) {
|
3563 | return Object.prototype.toString.call(arr) == '[object Array]';
|
3564 | };
|
3565 |
|
3566 | },{}],30:[function(require,module,exports){
|
3567 | (function (process){
|
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 | function normalizeArray(parts, allowAboveRoot) {
|
3594 |
|
3595 | var up = 0;
|
3596 | for (var i = parts.length - 1; i >= 0; i--) {
|
3597 | var last = parts[i];
|
3598 | if (last === '.') {
|
3599 | parts.splice(i, 1);
|
3600 | } else if (last === '..') {
|
3601 | parts.splice(i, 1);
|
3602 | up++;
|
3603 | } else if (up) {
|
3604 | parts.splice(i, 1);
|
3605 | up--;
|
3606 | }
|
3607 | }
|
3608 |
|
3609 |
|
3610 | if (allowAboveRoot) {
|
3611 | for (; up--; up) {
|
3612 | parts.unshift('..');
|
3613 | }
|
3614 | }
|
3615 |
|
3616 | return parts;
|
3617 | }
|
3618 |
|
3619 |
|
3620 |
|
3621 | var splitPathRe =
|
3622 | /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
3623 | var splitPath = function(filename) {
|
3624 | return splitPathRe.exec(filename).slice(1);
|
3625 | };
|
3626 |
|
3627 |
|
3628 |
|
3629 | exports.resolve = function() {
|
3630 | var resolvedPath = '',
|
3631 | resolvedAbsolute = false;
|
3632 |
|
3633 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
3634 | var path = (i >= 0) ? arguments[i] : process.cwd();
|
3635 |
|
3636 |
|
3637 | if (typeof path !== 'string') {
|
3638 | throw new TypeError('Arguments to path.resolve must be strings');
|
3639 | } else if (!path) {
|
3640 | continue;
|
3641 | }
|
3642 |
|
3643 | resolvedPath = path + '/' + resolvedPath;
|
3644 | resolvedAbsolute = path.charAt(0) === '/';
|
3645 | }
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
3652 | return !!p;
|
3653 | }), !resolvedAbsolute).join('/');
|
3654 |
|
3655 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
3656 | };
|
3657 |
|
3658 |
|
3659 |
|
3660 | exports.normalize = function(path) {
|
3661 | var isAbsolute = exports.isAbsolute(path),
|
3662 | trailingSlash = substr(path, -1) === '/';
|
3663 |
|
3664 |
|
3665 | path = normalizeArray(filter(path.split('/'), function(p) {
|
3666 | return !!p;
|
3667 | }), !isAbsolute).join('/');
|
3668 |
|
3669 | if (!path && !isAbsolute) {
|
3670 | path = '.';
|
3671 | }
|
3672 | if (path && trailingSlash) {
|
3673 | path += '/';
|
3674 | }
|
3675 |
|
3676 | return (isAbsolute ? '/' : '') + path;
|
3677 | };
|
3678 |
|
3679 |
|
3680 | exports.isAbsolute = function(path) {
|
3681 | return path.charAt(0) === '/';
|
3682 | };
|
3683 |
|
3684 |
|
3685 | exports.join = function() {
|
3686 | var paths = Array.prototype.slice.call(arguments, 0);
|
3687 | return exports.normalize(filter(paths, function(p, index) {
|
3688 | if (typeof p !== 'string') {
|
3689 | throw new TypeError('Arguments to path.join must be strings');
|
3690 | }
|
3691 | return p;
|
3692 | }).join('/'));
|
3693 | };
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 | exports.relative = function(from, to) {
|
3699 | from = exports.resolve(from).substr(1);
|
3700 | to = exports.resolve(to).substr(1);
|
3701 |
|
3702 | function trim(arr) {
|
3703 | var start = 0;
|
3704 | for (; start < arr.length; start++) {
|
3705 | if (arr[start] !== '') break;
|
3706 | }
|
3707 |
|
3708 | var end = arr.length - 1;
|
3709 | for (; end >= 0; end--) {
|
3710 | if (arr[end] !== '') break;
|
3711 | }
|
3712 |
|
3713 | if (start > end) return [];
|
3714 | return arr.slice(start, end - start + 1);
|
3715 | }
|
3716 |
|
3717 | var fromParts = trim(from.split('/'));
|
3718 | var toParts = trim(to.split('/'));
|
3719 |
|
3720 | var length = Math.min(fromParts.length, toParts.length);
|
3721 | var samePartsLength = length;
|
3722 | for (var i = 0; i < length; i++) {
|
3723 | if (fromParts[i] !== toParts[i]) {
|
3724 | samePartsLength = i;
|
3725 | break;
|
3726 | }
|
3727 | }
|
3728 |
|
3729 | var outputParts = [];
|
3730 | for (var i = samePartsLength; i < fromParts.length; i++) {
|
3731 | outputParts.push('..');
|
3732 | }
|
3733 |
|
3734 | outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
3735 |
|
3736 | return outputParts.join('/');
|
3737 | };
|
3738 |
|
3739 | exports.sep = '/';
|
3740 | exports.delimiter = ':';
|
3741 |
|
3742 | exports.dirname = function(path) {
|
3743 | var result = splitPath(path),
|
3744 | root = result[0],
|
3745 | dir = result[1];
|
3746 |
|
3747 | if (!root && !dir) {
|
3748 |
|
3749 | return '.';
|
3750 | }
|
3751 |
|
3752 | if (dir) {
|
3753 |
|
3754 | dir = dir.substr(0, dir.length - 1);
|
3755 | }
|
3756 |
|
3757 | return root + dir;
|
3758 | };
|
3759 |
|
3760 |
|
3761 | exports.basename = function(path, ext) {
|
3762 | var f = splitPath(path)[2];
|
3763 |
|
3764 | if (ext && f.substr(-1 * ext.length) === ext) {
|
3765 | f = f.substr(0, f.length - ext.length);
|
3766 | }
|
3767 | return f;
|
3768 | };
|
3769 |
|
3770 |
|
3771 | exports.extname = function(path) {
|
3772 | return splitPath(path)[3];
|
3773 | };
|
3774 |
|
3775 | function filter (xs, f) {
|
3776 | if (xs.filter) return xs.filter(f);
|
3777 | var res = [];
|
3778 | for (var i = 0; i < xs.length; i++) {
|
3779 | if (f(xs[i], i, xs)) res.push(xs[i]);
|
3780 | }
|
3781 | return res;
|
3782 | }
|
3783 |
|
3784 |
|
3785 | var substr = 'ab'.substr(-1) === 'b'
|
3786 | ? function (str, start, len) { return str.substr(start, len) }
|
3787 | : function (str, start, len) {
|
3788 | if (start < 0) start = str.length + start;
|
3789 | return str.substr(start, len);
|
3790 | }
|
3791 | ;
|
3792 |
|
3793 | }).call(this,require('_process'))
|
3794 | },{"_process":31}],31:[function(require,module,exports){
|
3795 |
|
3796 |
|
3797 | var process = module.exports = {};
|
3798 |
|
3799 | process.nextTick = (function () {
|
3800 | var canSetImmediate = typeof window !== 'undefined'
|
3801 | && window.setImmediate;
|
3802 | var canPost = typeof window !== 'undefined'
|
3803 | && window.postMessage && window.addEventListener
|
3804 | ;
|
3805 |
|
3806 | if (canSetImmediate) {
|
3807 | return function (f) { return window.setImmediate(f) };
|
3808 | }
|
3809 |
|
3810 | if (canPost) {
|
3811 | var queue = [];
|
3812 | window.addEventListener('message', function (ev) {
|
3813 | var source = ev.source;
|
3814 | if ((source === window || source === null) && ev.data === 'process-tick') {
|
3815 | ev.stopPropagation();
|
3816 | if (queue.length > 0) {
|
3817 | var fn = queue.shift();
|
3818 | fn();
|
3819 | }
|
3820 | }
|
3821 | }, true);
|
3822 |
|
3823 | return function nextTick(fn) {
|
3824 | queue.push(fn);
|
3825 | window.postMessage('process-tick', '*');
|
3826 | };
|
3827 | }
|
3828 |
|
3829 | return function nextTick(fn) {
|
3830 | setTimeout(fn, 0);
|
3831 | };
|
3832 | })();
|
3833 |
|
3834 | process.title = 'browser';
|
3835 | process.browser = true;
|
3836 | process.env = {};
|
3837 | process.argv = [];
|
3838 |
|
3839 | function noop() {}
|
3840 |
|
3841 | process.on = noop;
|
3842 | process.addListener = noop;
|
3843 | process.once = noop;
|
3844 | process.off = noop;
|
3845 | process.removeListener = noop;
|
3846 | process.removeAllListeners = noop;
|
3847 | process.emit = noop;
|
3848 |
|
3849 | process.binding = function (name) {
|
3850 | throw new Error('process.binding is not supported');
|
3851 | }
|
3852 |
|
3853 |
|
3854 | process.cwd = function () { return '/' };
|
3855 | process.chdir = function (dir) {
|
3856 | throw new Error('process.chdir is not supported');
|
3857 | };
|
3858 |
|
3859 | },{}],32:[function(require,module,exports){
|
3860 | (function (global){
|
3861 |
|
3862 | ;(function(root) {
|
3863 |
|
3864 |
|
3865 | var freeExports = typeof exports == 'object' && exports;
|
3866 | var freeModule = typeof module == 'object' && module &&
|
3867 | module.exports == freeExports && module;
|
3868 | var freeGlobal = typeof global == 'object' && global;
|
3869 | if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
3870 | root = freeGlobal;
|
3871 | }
|
3872 |
|
3873 | |
3874 |
|
3875 |
|
3876 |
|
3877 |
|
3878 | var punycode,
|
3879 |
|
3880 |
|
3881 | maxInt = 2147483647,
|
3882 |
|
3883 |
|
3884 | base = 36,
|
3885 | tMin = 1,
|
3886 | tMax = 26,
|
3887 | skew = 38,
|
3888 | damp = 700,
|
3889 | initialBias = 72,
|
3890 | initialN = 128,
|
3891 | delimiter = '-',
|
3892 |
|
3893 |
|
3894 | regexPunycode = /^xn--/,
|
3895 | regexNonASCII = /[^ -~]/,
|
3896 | regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g,
|
3897 |
|
3898 |
|
3899 | errors = {
|
3900 | 'overflow': 'Overflow: input needs wider integers to process',
|
3901 | 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
|
3902 | 'invalid-input': 'Invalid input'
|
3903 | },
|
3904 |
|
3905 |
|
3906 | baseMinusTMin = base - tMin,
|
3907 | floor = Math.floor,
|
3908 | stringFromCharCode = String.fromCharCode,
|
3909 |
|
3910 |
|
3911 | key;
|
3912 |
|
3913 |
|
3914 |
|
3915 | |
3916 |
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 | function error(type) {
|
3922 | throw RangeError(errors[type]);
|
3923 | }
|
3924 |
|
3925 | |
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 | function map(array, fn) {
|
3934 | var length = array.length;
|
3935 | while (length--) {
|
3936 | array[length] = fn(array[length]);
|
3937 | }
|
3938 | return array;
|
3939 | }
|
3940 |
|
3941 | |
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 | function mapDomain(string, fn) {
|
3951 | return map(string.split(regexSeparators), fn).join('.');
|
3952 | }
|
3953 |
|
3954 | |
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 | function ucs2decode(string) {
|
3968 | var output = [],
|
3969 | counter = 0,
|
3970 | length = string.length,
|
3971 | value,
|
3972 | extra;
|
3973 | while (counter < length) {
|
3974 | value = string.charCodeAt(counter++);
|
3975 | if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
|
3976 |
|
3977 | extra = string.charCodeAt(counter++);
|
3978 | if ((extra & 0xFC00) == 0xDC00) {
|
3979 | output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
|
3980 | } else {
|
3981 |
|
3982 |
|
3983 | output.push(value);
|
3984 | counter--;
|
3985 | }
|
3986 | } else {
|
3987 | output.push(value);
|
3988 | }
|
3989 | }
|
3990 | return output;
|
3991 | }
|
3992 |
|
3993 | |
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 | function ucs2encode(array) {
|
4002 | return map(array, function(value) {
|
4003 | var output = '';
|
4004 | if (value > 0xFFFF) {
|
4005 | value -= 0x10000;
|
4006 | output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
|
4007 | value = 0xDC00 | value & 0x3FF;
|
4008 | }
|
4009 | output += stringFromCharCode(value);
|
4010 | return output;
|
4011 | }).join('');
|
4012 | }
|
4013 |
|
4014 | |
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 | function basicToDigit(codePoint) {
|
4024 | if (codePoint - 48 < 10) {
|
4025 | return codePoint - 22;
|
4026 | }
|
4027 | if (codePoint - 65 < 26) {
|
4028 | return codePoint - 65;
|
4029 | }
|
4030 | if (codePoint - 97 < 26) {
|
4031 | return codePoint - 97;
|
4032 | }
|
4033 | return base;
|
4034 | }
|
4035 |
|
4036 | |
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 | function digitToBasic(digit, flag) {
|
4048 |
|
4049 |
|
4050 | return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
4051 | }
|
4052 |
|
4053 | |
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 | function adapt(delta, numPoints, firstTime) {
|
4059 | var k = 0;
|
4060 | delta = firstTime ? floor(delta / damp) : delta >> 1;
|
4061 | delta += floor(delta / numPoints);
|
4062 | for (; delta > baseMinusTMin * tMax >> 1; k += base) {
|
4063 | delta = floor(delta / baseMinusTMin);
|
4064 | }
|
4065 | return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
|
4066 | }
|
4067 |
|
4068 | |
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 | function decode(input) {
|
4076 |
|
4077 | var output = [],
|
4078 | inputLength = input.length,
|
4079 | out,
|
4080 | i = 0,
|
4081 | n = initialN,
|
4082 | bias = initialBias,
|
4083 | basic,
|
4084 | j,
|
4085 | index,
|
4086 | oldi,
|
4087 | w,
|
4088 | k,
|
4089 | digit,
|
4090 | t,
|
4091 |
|
4092 | baseMinusT;
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 | basic = input.lastIndexOf(delimiter);
|
4099 | if (basic < 0) {
|
4100 | basic = 0;
|
4101 | }
|
4102 |
|
4103 | for (j = 0; j < basic; ++j) {
|
4104 |
|
4105 | if (input.charCodeAt(j) >= 0x80) {
|
4106 | error('not-basic');
|
4107 | }
|
4108 | output.push(input.charCodeAt(j));
|
4109 | }
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 | for (index = basic > 0 ? basic + 1 : 0; index < inputLength; ) {
|
4115 |
|
4116 |
|
4117 |
|
4118 |
|
4119 |
|
4120 |
|
4121 | for (oldi = i, w = 1, k = base; ; k += base) {
|
4122 |
|
4123 | if (index >= inputLength) {
|
4124 | error('invalid-input');
|
4125 | }
|
4126 |
|
4127 | digit = basicToDigit(input.charCodeAt(index++));
|
4128 |
|
4129 | if (digit >= base || digit > floor((maxInt - i) / w)) {
|
4130 | error('overflow');
|
4131 | }
|
4132 |
|
4133 | i += digit * w;
|
4134 | t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
4135 |
|
4136 | if (digit < t) {
|
4137 | break;
|
4138 | }
|
4139 |
|
4140 | baseMinusT = base - t;
|
4141 | if (w > floor(maxInt / baseMinusT)) {
|
4142 | error('overflow');
|
4143 | }
|
4144 |
|
4145 | w *= baseMinusT;
|
4146 |
|
4147 | }
|
4148 |
|
4149 | out = output.length + 1;
|
4150 | bias = adapt(i - oldi, out, oldi == 0);
|
4151 |
|
4152 |
|
4153 |
|
4154 | if (floor(i / out) > maxInt - n) {
|
4155 | error('overflow');
|
4156 | }
|
4157 |
|
4158 | n += floor(i / out);
|
4159 | i %= out;
|
4160 |
|
4161 |
|
4162 | output.splice(i++, 0, n);
|
4163 |
|
4164 | }
|
4165 |
|
4166 | return ucs2encode(output);
|
4167 | }
|
4168 |
|
4169 | |
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 | function encode(input) {
|
4177 | var n,
|
4178 | delta,
|
4179 | handledCPCount,
|
4180 | basicLength,
|
4181 | bias,
|
4182 | j,
|
4183 | m,
|
4184 | q,
|
4185 | k,
|
4186 | t,
|
4187 | currentValue,
|
4188 | output = [],
|
4189 |
|
4190 | inputLength,
|
4191 |
|
4192 | handledCPCountPlusOne,
|
4193 | baseMinusT,
|
4194 | qMinusT;
|
4195 |
|
4196 |
|
4197 | input = ucs2decode(input);
|
4198 |
|
4199 |
|
4200 | inputLength = input.length;
|
4201 |
|
4202 |
|
4203 | n = initialN;
|
4204 | delta = 0;
|
4205 | bias = initialBias;
|
4206 |
|
4207 |
|
4208 | for (j = 0; j < inputLength; ++j) {
|
4209 | currentValue = input[j];
|
4210 | if (currentValue < 0x80) {
|
4211 | output.push(stringFromCharCode(currentValue));
|
4212 | }
|
4213 | }
|
4214 |
|
4215 | handledCPCount = basicLength = output.length;
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 | if (basicLength) {
|
4222 | output.push(delimiter);
|
4223 | }
|
4224 |
|
4225 |
|
4226 | while (handledCPCount < inputLength) {
|
4227 |
|
4228 |
|
4229 |
|
4230 | for (m = maxInt, j = 0; j < inputLength; ++j) {
|
4231 | currentValue = input[j];
|
4232 | if (currentValue >= n && currentValue < m) {
|
4233 | m = currentValue;
|
4234 | }
|
4235 | }
|
4236 |
|
4237 |
|
4238 |
|
4239 | handledCPCountPlusOne = handledCPCount + 1;
|
4240 | if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
|
4241 | error('overflow');
|
4242 | }
|
4243 |
|
4244 | delta += (m - n) * handledCPCountPlusOne;
|
4245 | n = m;
|
4246 |
|
4247 | for (j = 0; j < inputLength; ++j) {
|
4248 | currentValue = input[j];
|
4249 |
|
4250 | if (currentValue < n && ++delta > maxInt) {
|
4251 | error('overflow');
|
4252 | }
|
4253 |
|
4254 | if (currentValue == n) {
|
4255 |
|
4256 | for (q = delta, k = base; ; k += base) {
|
4257 | t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
|
4258 | if (q < t) {
|
4259 | break;
|
4260 | }
|
4261 | qMinusT = q - t;
|
4262 | baseMinusT = base - t;
|
4263 | output.push(
|
4264 | stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
|
4265 | );
|
4266 | q = floor(qMinusT / baseMinusT);
|
4267 | }
|
4268 |
|
4269 | output.push(stringFromCharCode(digitToBasic(q, 0)));
|
4270 | bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
|
4271 | delta = 0;
|
4272 | ++handledCPCount;
|
4273 | }
|
4274 | }
|
4275 |
|
4276 | ++delta;
|
4277 | ++n;
|
4278 |
|
4279 | }
|
4280 | return output.join('');
|
4281 | }
|
4282 |
|
4283 | |
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 |
|
4289 |
|
4290 |
|
4291 |
|
4292 |
|
4293 | function toUnicode(domain) {
|
4294 | return mapDomain(domain, function(string) {
|
4295 | return regexPunycode.test(string)
|
4296 | ? decode(string.slice(4).toLowerCase())
|
4297 | : string;
|
4298 | });
|
4299 | }
|
4300 |
|
4301 | |
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 | function toASCII(domain) {
|
4310 | return mapDomain(domain, function(string) {
|
4311 | return regexNonASCII.test(string)
|
4312 | ? 'xn--' + encode(string)
|
4313 | : string;
|
4314 | });
|
4315 | }
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 | punycode = {
|
4321 | |
4322 |
|
4323 |
|
4324 |
|
4325 |
|
4326 | 'version': '1.2.4',
|
4327 | |
4328 |
|
4329 |
|
4330 |
|
4331 |
|
4332 |
|
4333 |
|
4334 | 'ucs2': {
|
4335 | 'decode': ucs2decode,
|
4336 | 'encode': ucs2encode
|
4337 | },
|
4338 | 'decode': decode,
|
4339 | 'encode': encode,
|
4340 | 'toASCII': toASCII,
|
4341 | 'toUnicode': toUnicode
|
4342 | };
|
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 | if (
|
4348 | typeof define == 'function' &&
|
4349 | typeof define.amd == 'object' &&
|
4350 | define.amd
|
4351 | ) {
|
4352 | define('punycode', function() {
|
4353 | return punycode;
|
4354 | });
|
4355 | } else if (freeExports && !freeExports.nodeType) {
|
4356 | if (freeModule) {
|
4357 | freeModule.exports = punycode;
|
4358 | } else {
|
4359 | for (key in punycode) {
|
4360 | punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
|
4361 | }
|
4362 | }
|
4363 | } else {
|
4364 | root.punycode = punycode;
|
4365 | }
|
4366 |
|
4367 | }(this));
|
4368 |
|
4369 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4370 | },{}],33:[function(require,module,exports){
|
4371 |
|
4372 |
|
4373 |
|
4374 |
|
4375 |
|
4376 |
|
4377 |
|
4378 |
|
4379 |
|
4380 |
|
4381 |
|
4382 |
|
4383 |
|
4384 |
|
4385 |
|
4386 |
|
4387 |
|
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 | 'use strict';
|
4393 |
|
4394 |
|
4395 |
|
4396 |
|
4397 | function hasOwnProperty(obj, prop) {
|
4398 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
4399 | }
|
4400 |
|
4401 | module.exports = function(qs, sep, eq, options) {
|
4402 | sep = sep || '&';
|
4403 | eq = eq || '=';
|
4404 | var obj = {};
|
4405 |
|
4406 | if (typeof qs !== 'string' || qs.length === 0) {
|
4407 | return obj;
|
4408 | }
|
4409 |
|
4410 | var regexp = /\+/g;
|
4411 | qs = qs.split(sep);
|
4412 |
|
4413 | var maxKeys = 1000;
|
4414 | if (options && typeof options.maxKeys === 'number') {
|
4415 | maxKeys = options.maxKeys;
|
4416 | }
|
4417 |
|
4418 | var len = qs.length;
|
4419 |
|
4420 | if (maxKeys > 0 && len > maxKeys) {
|
4421 | len = maxKeys;
|
4422 | }
|
4423 |
|
4424 | for (var i = 0; i < len; ++i) {
|
4425 | var x = qs[i].replace(regexp, '%20'),
|
4426 | idx = x.indexOf(eq),
|
4427 | kstr, vstr, k, v;
|
4428 |
|
4429 | if (idx >= 0) {
|
4430 | kstr = x.substr(0, idx);
|
4431 | vstr = x.substr(idx + 1);
|
4432 | } else {
|
4433 | kstr = x;
|
4434 | vstr = '';
|
4435 | }
|
4436 |
|
4437 | k = decodeURIComponent(kstr);
|
4438 | v = decodeURIComponent(vstr);
|
4439 |
|
4440 | if (!hasOwnProperty(obj, k)) {
|
4441 | obj[k] = v;
|
4442 | } else if (isArray(obj[k])) {
|
4443 | obj[k].push(v);
|
4444 | } else {
|
4445 | obj[k] = [obj[k], v];
|
4446 | }
|
4447 | }
|
4448 |
|
4449 | return obj;
|
4450 | };
|
4451 |
|
4452 | var isArray = Array.isArray || function (xs) {
|
4453 | return Object.prototype.toString.call(xs) === '[object Array]';
|
4454 | };
|
4455 |
|
4456 | },{}],34:[function(require,module,exports){
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 | 'use strict';
|
4479 |
|
4480 | var stringifyPrimitive = function(v) {
|
4481 | switch (typeof v) {
|
4482 | case 'string':
|
4483 | return v;
|
4484 |
|
4485 | case 'boolean':
|
4486 | return v ? 'true' : 'false';
|
4487 |
|
4488 | case 'number':
|
4489 | return isFinite(v) ? v : '';
|
4490 |
|
4491 | default:
|
4492 | return '';
|
4493 | }
|
4494 | };
|
4495 |
|
4496 | module.exports = function(obj, sep, eq, name) {
|
4497 | sep = sep || '&';
|
4498 | eq = eq || '=';
|
4499 | if (obj === null) {
|
4500 | obj = undefined;
|
4501 | }
|
4502 |
|
4503 | if (typeof obj === 'object') {
|
4504 | return map(objectKeys(obj), function(k) {
|
4505 | var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
4506 | if (isArray(obj[k])) {
|
4507 | return map(obj[k], function(v) {
|
4508 | return ks + encodeURIComponent(stringifyPrimitive(v));
|
4509 | }).join(sep);
|
4510 | } else {
|
4511 | return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
4512 | }
|
4513 | }).join(sep);
|
4514 |
|
4515 | }
|
4516 |
|
4517 | if (!name) return '';
|
4518 | return encodeURIComponent(stringifyPrimitive(name)) + eq +
|
4519 | encodeURIComponent(stringifyPrimitive(obj));
|
4520 | };
|
4521 |
|
4522 | var isArray = Array.isArray || function (xs) {
|
4523 | return Object.prototype.toString.call(xs) === '[object Array]';
|
4524 | };
|
4525 |
|
4526 | function map (xs, f) {
|
4527 | if (xs.map) return xs.map(f);
|
4528 | var res = [];
|
4529 | for (var i = 0; i < xs.length; i++) {
|
4530 | res.push(f(xs[i], i));
|
4531 | }
|
4532 | return res;
|
4533 | }
|
4534 |
|
4535 | var objectKeys = Object.keys || function (obj) {
|
4536 | var res = [];
|
4537 | for (var key in obj) {
|
4538 | if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
|
4539 | }
|
4540 | return res;
|
4541 | };
|
4542 |
|
4543 | },{}],35:[function(require,module,exports){
|
4544 | 'use strict';
|
4545 |
|
4546 | exports.decode = exports.parse = require('./decode');
|
4547 | exports.encode = exports.stringify = require('./encode');
|
4548 |
|
4549 | },{"./decode":33,"./encode":34}],36:[function(require,module,exports){
|
4550 | module.exports = require("./lib/_stream_duplex.js")
|
4551 |
|
4552 | },{"./lib/_stream_duplex.js":37}],37:[function(require,module,exports){
|
4553 | (function (process){
|
4554 |
|
4555 |
|
4556 |
|
4557 |
|
4558 |
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 |
|
4572 |
|
4573 |
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 | module.exports = Duplex;
|
4581 |
|
4582 |
|
4583 | var objectKeys = Object.keys || function (obj) {
|
4584 | var keys = [];
|
4585 | for (var key in obj) keys.push(key);
|
4586 | return keys;
|
4587 | }
|
4588 |
|
4589 |
|
4590 |
|
4591 |
|
4592 | var util = require('core-util-is');
|
4593 | util.inherits = require('inherits');
|
4594 |
|
4595 |
|
4596 | var Readable = require('./_stream_readable');
|
4597 | var Writable = require('./_stream_writable');
|
4598 |
|
4599 | util.inherits(Duplex, Readable);
|
4600 |
|
4601 | forEach(objectKeys(Writable.prototype), function(method) {
|
4602 | if (!Duplex.prototype[method])
|
4603 | Duplex.prototype[method] = Writable.prototype[method];
|
4604 | });
|
4605 |
|
4606 | function Duplex(options) {
|
4607 | if (!(this instanceof Duplex))
|
4608 | return new Duplex(options);
|
4609 |
|
4610 | Readable.call(this, options);
|
4611 | Writable.call(this, options);
|
4612 |
|
4613 | if (options && options.readable === false)
|
4614 | this.readable = false;
|
4615 |
|
4616 | if (options && options.writable === false)
|
4617 | this.writable = false;
|
4618 |
|
4619 | this.allowHalfOpen = true;
|
4620 | if (options && options.allowHalfOpen === false)
|
4621 | this.allowHalfOpen = false;
|
4622 |
|
4623 | this.once('end', onend);
|
4624 | }
|
4625 |
|
4626 |
|
4627 | function onend() {
|
4628 |
|
4629 |
|
4630 | if (this.allowHalfOpen || this._writableState.ended)
|
4631 | return;
|
4632 |
|
4633 |
|
4634 |
|
4635 | process.nextTick(this.end.bind(this));
|
4636 | }
|
4637 |
|
4638 | function forEach (xs, f) {
|
4639 | for (var i = 0, l = xs.length; i < l; i++) {
|
4640 | f(xs[i], i);
|
4641 | }
|
4642 | }
|
4643 |
|
4644 | }).call(this,require('_process'))
|
4645 | },{"./_stream_readable":39,"./_stream_writable":41,"_process":31,"core-util-is":42,"inherits":28}],38:[function(require,module,exports){
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 | module.exports = PassThrough;
|
4672 |
|
4673 | var Transform = require('./_stream_transform');
|
4674 |
|
4675 |
|
4676 | var util = require('core-util-is');
|
4677 | util.inherits = require('inherits');
|
4678 |
|
4679 |
|
4680 | util.inherits(PassThrough, Transform);
|
4681 |
|
4682 | function PassThrough(options) {
|
4683 | if (!(this instanceof PassThrough))
|
4684 | return new PassThrough(options);
|
4685 |
|
4686 | Transform.call(this, options);
|
4687 | }
|
4688 |
|
4689 | PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
4690 | cb(null, chunk);
|
4691 | };
|
4692 |
|
4693 | },{"./_stream_transform":40,"core-util-is":42,"inherits":28}],39:[function(require,module,exports){
|
4694 | (function (process){
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 | module.exports = Readable;
|
4717 |
|
4718 |
|
4719 | var isArray = require('isarray');
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 | var Buffer = require('buffer').Buffer;
|
4725 |
|
4726 |
|
4727 | Readable.ReadableState = ReadableState;
|
4728 |
|
4729 | var EE = require('events').EventEmitter;
|
4730 |
|
4731 |
|
4732 | if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
4733 | return emitter.listeners(type).length;
|
4734 | };
|
4735 |
|
4736 |
|
4737 | var Stream = require('stream');
|
4738 |
|
4739 |
|
4740 | var util = require('core-util-is');
|
4741 | util.inherits = require('inherits');
|
4742 |
|
4743 |
|
4744 | var StringDecoder;
|
4745 |
|
4746 | util.inherits(Readable, Stream);
|
4747 |
|
4748 | function ReadableState(options, stream) {
|
4749 | options = options || {};
|
4750 |
|
4751 |
|
4752 |
|
4753 | var hwm = options.highWaterMark;
|
4754 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
4755 |
|
4756 |
|
4757 | this.highWaterMark = ~~this.highWaterMark;
|
4758 |
|
4759 | this.buffer = [];
|
4760 | this.length = 0;
|
4761 | this.pipes = null;
|
4762 | this.pipesCount = 0;
|
4763 | this.flowing = false;
|
4764 | this.ended = false;
|
4765 | this.endEmitted = false;
|
4766 | this.reading = false;
|
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 | this.calledRead = false;
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 | this.sync = true;
|
4779 |
|
4780 |
|
4781 |
|
4782 | this.needReadable = false;
|
4783 | this.emittedReadable = false;
|
4784 | this.readableListening = false;
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 | this.objectMode = !!options.objectMode;
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
4795 |
|
4796 |
|
4797 |
|
4798 | this.ranOut = false;
|
4799 |
|
4800 |
|
4801 | this.awaitDrain = 0;
|
4802 |
|
4803 |
|
4804 | this.readingMore = false;
|
4805 |
|
4806 | this.decoder = null;
|
4807 | this.encoding = null;
|
4808 | if (options.encoding) {
|
4809 | if (!StringDecoder)
|
4810 | StringDecoder = require('string_decoder/').StringDecoder;
|
4811 | this.decoder = new StringDecoder(options.encoding);
|
4812 | this.encoding = options.encoding;
|
4813 | }
|
4814 | }
|
4815 |
|
4816 | function Readable(options) {
|
4817 | if (!(this instanceof Readable))
|
4818 | return new Readable(options);
|
4819 |
|
4820 | this._readableState = new ReadableState(options, this);
|
4821 |
|
4822 |
|
4823 | this.readable = true;
|
4824 |
|
4825 | Stream.call(this);
|
4826 | }
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 | Readable.prototype.push = function(chunk, encoding) {
|
4833 | var state = this._readableState;
|
4834 |
|
4835 | if (typeof chunk === 'string' && !state.objectMode) {
|
4836 | encoding = encoding || state.defaultEncoding;
|
4837 | if (encoding !== state.encoding) {
|
4838 | chunk = new Buffer(chunk, encoding);
|
4839 | encoding = '';
|
4840 | }
|
4841 | }
|
4842 |
|
4843 | return readableAddChunk(this, state, chunk, encoding, false);
|
4844 | };
|
4845 |
|
4846 |
|
4847 | Readable.prototype.unshift = function(chunk) {
|
4848 | var state = this._readableState;
|
4849 | return readableAddChunk(this, state, chunk, '', true);
|
4850 | };
|
4851 |
|
4852 | function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
4853 | var er = chunkInvalid(state, chunk);
|
4854 | if (er) {
|
4855 | stream.emit('error', er);
|
4856 | } else if (chunk === null || chunk === undefined) {
|
4857 | state.reading = false;
|
4858 | if (!state.ended)
|
4859 | onEofChunk(stream, state);
|
4860 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
4861 | if (state.ended && !addToFront) {
|
4862 | var e = new Error('stream.push() after EOF');
|
4863 | stream.emit('error', e);
|
4864 | } else if (state.endEmitted && addToFront) {
|
4865 | var e = new Error('stream.unshift() after end event');
|
4866 | stream.emit('error', e);
|
4867 | } else {
|
4868 | if (state.decoder && !addToFront && !encoding)
|
4869 | chunk = state.decoder.write(chunk);
|
4870 |
|
4871 |
|
4872 | state.length += state.objectMode ? 1 : chunk.length;
|
4873 | if (addToFront) {
|
4874 | state.buffer.unshift(chunk);
|
4875 | } else {
|
4876 | state.reading = false;
|
4877 | state.buffer.push(chunk);
|
4878 | }
|
4879 |
|
4880 | if (state.needReadable)
|
4881 | emitReadable(stream);
|
4882 |
|
4883 | maybeReadMore(stream, state);
|
4884 | }
|
4885 | } else if (!addToFront) {
|
4886 | state.reading = false;
|
4887 | }
|
4888 |
|
4889 | return needMoreData(state);
|
4890 | }
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 | function needMoreData(state) {
|
4902 | return !state.ended &&
|
4903 | (state.needReadable ||
|
4904 | state.length < state.highWaterMark ||
|
4905 | state.length === 0);
|
4906 | }
|
4907 |
|
4908 |
|
4909 | Readable.prototype.setEncoding = function(enc) {
|
4910 | if (!StringDecoder)
|
4911 | StringDecoder = require('string_decoder/').StringDecoder;
|
4912 | this._readableState.decoder = new StringDecoder(enc);
|
4913 | this._readableState.encoding = enc;
|
4914 | };
|
4915 |
|
4916 |
|
4917 | var MAX_HWM = 0x800000;
|
4918 | function roundUpToNextPowerOf2(n) {
|
4919 | if (n >= MAX_HWM) {
|
4920 | n = MAX_HWM;
|
4921 | } else {
|
4922 |
|
4923 | n--;
|
4924 | for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
4925 | n++;
|
4926 | }
|
4927 | return n;
|
4928 | }
|
4929 |
|
4930 | function howMuchToRead(n, state) {
|
4931 | if (state.length === 0 && state.ended)
|
4932 | return 0;
|
4933 |
|
4934 | if (state.objectMode)
|
4935 | return n === 0 ? 0 : 1;
|
4936 |
|
4937 | if (n === null || isNaN(n)) {
|
4938 |
|
4939 | if (state.flowing && state.buffer.length)
|
4940 | return state.buffer[0].length;
|
4941 | else
|
4942 | return state.length;
|
4943 | }
|
4944 |
|
4945 | if (n <= 0)
|
4946 | return 0;
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 | if (n > state.highWaterMark)
|
4953 | state.highWaterMark = roundUpToNextPowerOf2(n);
|
4954 |
|
4955 |
|
4956 | if (n > state.length) {
|
4957 | if (!state.ended) {
|
4958 | state.needReadable = true;
|
4959 | return 0;
|
4960 | } else
|
4961 | return state.length;
|
4962 | }
|
4963 |
|
4964 | return n;
|
4965 | }
|
4966 |
|
4967 |
|
4968 | Readable.prototype.read = function(n) {
|
4969 | var state = this._readableState;
|
4970 | state.calledRead = true;
|
4971 | var nOrig = n;
|
4972 | var ret;
|
4973 |
|
4974 | if (typeof n !== 'number' || n > 0)
|
4975 | state.emittedReadable = false;
|
4976 |
|
4977 |
|
4978 |
|
4979 |
|
4980 | if (n === 0 &&
|
4981 | state.needReadable &&
|
4982 | (state.length >= state.highWaterMark || state.ended)) {
|
4983 | emitReadable(this);
|
4984 | return null;
|
4985 | }
|
4986 |
|
4987 | n = howMuchToRead(n, state);
|
4988 |
|
4989 |
|
4990 | if (n === 0 && state.ended) {
|
4991 | ret = null;
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 | if (state.length > 0 && state.decoder) {
|
5005 | ret = fromList(n, state);
|
5006 | state.length -= ret.length;
|
5007 | }
|
5008 |
|
5009 | if (state.length === 0)
|
5010 | endReadable(this);
|
5011 |
|
5012 | return ret;
|
5013 | }
|
5014 |
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 | var doRead = state.needReadable;
|
5039 |
|
5040 |
|
5041 | if (state.length - n <= state.highWaterMark)
|
5042 | doRead = true;
|
5043 |
|
5044 |
|
5045 |
|
5046 | if (state.ended || state.reading)
|
5047 | doRead = false;
|
5048 |
|
5049 | if (doRead) {
|
5050 | state.reading = true;
|
5051 | state.sync = true;
|
5052 |
|
5053 | if (state.length === 0)
|
5054 | state.needReadable = true;
|
5055 |
|
5056 | this._read(state.highWaterMark);
|
5057 | state.sync = false;
|
5058 | }
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 | if (doRead && !state.reading)
|
5064 | n = howMuchToRead(nOrig, state);
|
5065 |
|
5066 | if (n > 0)
|
5067 | ret = fromList(n, state);
|
5068 | else
|
5069 | ret = null;
|
5070 |
|
5071 | if (ret === null) {
|
5072 | state.needReadable = true;
|
5073 | n = 0;
|
5074 | }
|
5075 |
|
5076 | state.length -= n;
|
5077 |
|
5078 |
|
5079 |
|
5080 | if (state.length === 0 && !state.ended)
|
5081 | state.needReadable = true;
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 | if (state.ended && !state.endEmitted && state.length === 0)
|
5087 | endReadable(this);
|
5088 |
|
5089 | return ret;
|
5090 | };
|
5091 |
|
5092 | function chunkInvalid(state, chunk) {
|
5093 | var er = null;
|
5094 | if (!Buffer.isBuffer(chunk) &&
|
5095 | 'string' !== typeof chunk &&
|
5096 | chunk !== null &&
|
5097 | chunk !== undefined &&
|
5098 | !state.objectMode) {
|
5099 | er = new TypeError('Invalid non-string/buffer chunk');
|
5100 | }
|
5101 | return er;
|
5102 | }
|
5103 |
|
5104 |
|
5105 | function onEofChunk(stream, state) {
|
5106 | if (state.decoder && !state.ended) {
|
5107 | var chunk = state.decoder.end();
|
5108 | if (chunk && chunk.length) {
|
5109 | state.buffer.push(chunk);
|
5110 | state.length += state.objectMode ? 1 : chunk.length;
|
5111 | }
|
5112 | }
|
5113 | state.ended = true;
|
5114 |
|
5115 |
|
5116 |
|
5117 | if (state.length > 0)
|
5118 | emitReadable(stream);
|
5119 | else
|
5120 | endReadable(stream);
|
5121 | }
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 | function emitReadable(stream) {
|
5127 | var state = stream._readableState;
|
5128 | state.needReadable = false;
|
5129 | if (state.emittedReadable)
|
5130 | return;
|
5131 |
|
5132 | state.emittedReadable = true;
|
5133 | if (state.sync)
|
5134 | process.nextTick(function() {
|
5135 | emitReadable_(stream);
|
5136 | });
|
5137 | else
|
5138 | emitReadable_(stream);
|
5139 | }
|
5140 |
|
5141 | function emitReadable_(stream) {
|
5142 | stream.emit('readable');
|
5143 | }
|
5144 |
|
5145 |
|
5146 |
|
5147 |
|
5148 |
|
5149 |
|
5150 |
|
5151 |
|
5152 | function maybeReadMore(stream, state) {
|
5153 | if (!state.readingMore) {
|
5154 | state.readingMore = true;
|
5155 | process.nextTick(function() {
|
5156 | maybeReadMore_(stream, state);
|
5157 | });
|
5158 | }
|
5159 | }
|
5160 |
|
5161 | function maybeReadMore_(stream, state) {
|
5162 | var len = state.length;
|
5163 | while (!state.reading && !state.flowing && !state.ended &&
|
5164 | state.length < state.highWaterMark) {
|
5165 | stream.read(0);
|
5166 | if (len === state.length)
|
5167 |
|
5168 | break;
|
5169 | else
|
5170 | len = state.length;
|
5171 | }
|
5172 | state.readingMore = false;
|
5173 | }
|
5174 |
|
5175 |
|
5176 |
|
5177 |
|
5178 |
|
5179 | Readable.prototype._read = function(n) {
|
5180 | this.emit('error', new Error('not implemented'));
|
5181 | };
|
5182 |
|
5183 | Readable.prototype.pipe = function(dest, pipeOpts) {
|
5184 | var src = this;
|
5185 | var state = this._readableState;
|
5186 |
|
5187 | switch (state.pipesCount) {
|
5188 | case 0:
|
5189 | state.pipes = dest;
|
5190 | break;
|
5191 | case 1:
|
5192 | state.pipes = [state.pipes, dest];
|
5193 | break;
|
5194 | default:
|
5195 | state.pipes.push(dest);
|
5196 | break;
|
5197 | }
|
5198 | state.pipesCount += 1;
|
5199 |
|
5200 | var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
5201 | dest !== process.stdout &&
|
5202 | dest !== process.stderr;
|
5203 |
|
5204 | var endFn = doEnd ? onend : cleanup;
|
5205 | if (state.endEmitted)
|
5206 | process.nextTick(endFn);
|
5207 | else
|
5208 | src.once('end', endFn);
|
5209 |
|
5210 | dest.on('unpipe', onunpipe);
|
5211 | function onunpipe(readable) {
|
5212 | if (readable !== src) return;
|
5213 | cleanup();
|
5214 | }
|
5215 |
|
5216 | function onend() {
|
5217 | dest.end();
|
5218 | }
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 |
|
5224 | var ondrain = pipeOnDrain(src);
|
5225 | dest.on('drain', ondrain);
|
5226 |
|
5227 | function cleanup() {
|
5228 |
|
5229 | dest.removeListener('close', onclose);
|
5230 | dest.removeListener('finish', onfinish);
|
5231 | dest.removeListener('drain', ondrain);
|
5232 | dest.removeListener('error', onerror);
|
5233 | dest.removeListener('unpipe', onunpipe);
|
5234 | src.removeListener('end', onend);
|
5235 | src.removeListener('end', cleanup);
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 | if (!dest._writableState || dest._writableState.needDrain)
|
5243 | ondrain();
|
5244 | }
|
5245 |
|
5246 |
|
5247 |
|
5248 | function onerror(er) {
|
5249 | unpipe();
|
5250 | dest.removeListener('error', onerror);
|
5251 | if (EE.listenerCount(dest, 'error') === 0)
|
5252 | dest.emit('error', er);
|
5253 | }
|
5254 |
|
5255 |
|
5256 | if (!dest._events || !dest._events.error)
|
5257 | dest.on('error', onerror);
|
5258 | else if (isArray(dest._events.error))
|
5259 | dest._events.error.unshift(onerror);
|
5260 | else
|
5261 | dest._events.error = [onerror, dest._events.error];
|
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 | function onclose() {
|
5267 | dest.removeListener('finish', onfinish);
|
5268 | unpipe();
|
5269 | }
|
5270 | dest.once('close', onclose);
|
5271 | function onfinish() {
|
5272 | dest.removeListener('close', onclose);
|
5273 | unpipe();
|
5274 | }
|
5275 | dest.once('finish', onfinish);
|
5276 |
|
5277 | function unpipe() {
|
5278 | src.unpipe(dest);
|
5279 | }
|
5280 |
|
5281 |
|
5282 | dest.emit('pipe', src);
|
5283 |
|
5284 |
|
5285 | if (!state.flowing) {
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 | this.on('readable', pipeOnReadable);
|
5291 |
|
5292 | state.flowing = true;
|
5293 | process.nextTick(function() {
|
5294 | flow(src);
|
5295 | });
|
5296 | }
|
5297 |
|
5298 | return dest;
|
5299 | };
|
5300 |
|
5301 | function pipeOnDrain(src) {
|
5302 | return function() {
|
5303 | var dest = this;
|
5304 | var state = src._readableState;
|
5305 | state.awaitDrain--;
|
5306 | if (state.awaitDrain === 0)
|
5307 | flow(src);
|
5308 | };
|
5309 | }
|
5310 |
|
5311 | function flow(src) {
|
5312 | var state = src._readableState;
|
5313 | var chunk;
|
5314 | state.awaitDrain = 0;
|
5315 |
|
5316 | function write(dest, i, list) {
|
5317 | var written = dest.write(chunk);
|
5318 | if (false === written) {
|
5319 | state.awaitDrain++;
|
5320 | }
|
5321 | }
|
5322 |
|
5323 | while (state.pipesCount && null !== (chunk = src.read())) {
|
5324 |
|
5325 | if (state.pipesCount === 1)
|
5326 | write(state.pipes, 0, null);
|
5327 | else
|
5328 | forEach(state.pipes, write);
|
5329 |
|
5330 | src.emit('data', chunk);
|
5331 |
|
5332 |
|
5333 | if (state.awaitDrain > 0)
|
5334 | return;
|
5335 | }
|
5336 |
|
5337 |
|
5338 |
|
5339 |
|
5340 |
|
5341 | if (state.pipesCount === 0) {
|
5342 | state.flowing = false;
|
5343 |
|
5344 |
|
5345 | if (EE.listenerCount(src, 'data') > 0)
|
5346 | emitDataEvents(src);
|
5347 | return;
|
5348 | }
|
5349 |
|
5350 |
|
5351 |
|
5352 | state.ranOut = true;
|
5353 | }
|
5354 |
|
5355 | function pipeOnReadable() {
|
5356 | if (this._readableState.ranOut) {
|
5357 | this._readableState.ranOut = false;
|
5358 | flow(this);
|
5359 | }
|
5360 | }
|
5361 |
|
5362 |
|
5363 | Readable.prototype.unpipe = function(dest) {
|
5364 | var state = this._readableState;
|
5365 |
|
5366 |
|
5367 | if (state.pipesCount === 0)
|
5368 | return this;
|
5369 |
|
5370 |
|
5371 | if (state.pipesCount === 1) {
|
5372 |
|
5373 | if (dest && dest !== state.pipes)
|
5374 | return this;
|
5375 |
|
5376 | if (!dest)
|
5377 | dest = state.pipes;
|
5378 |
|
5379 |
|
5380 | state.pipes = null;
|
5381 | state.pipesCount = 0;
|
5382 | this.removeListener('readable', pipeOnReadable);
|
5383 | state.flowing = false;
|
5384 | if (dest)
|
5385 | dest.emit('unpipe', this);
|
5386 | return this;
|
5387 | }
|
5388 |
|
5389 |
|
5390 |
|
5391 | if (!dest) {
|
5392 |
|
5393 | var dests = state.pipes;
|
5394 | var len = state.pipesCount;
|
5395 | state.pipes = null;
|
5396 | state.pipesCount = 0;
|
5397 | this.removeListener('readable', pipeOnReadable);
|
5398 | state.flowing = false;
|
5399 |
|
5400 | for (var i = 0; i < len; i++)
|
5401 | dests[i].emit('unpipe', this);
|
5402 | return this;
|
5403 | }
|
5404 |
|
5405 |
|
5406 | var i = indexOf(state.pipes, dest);
|
5407 | if (i === -1)
|
5408 | return this;
|
5409 |
|
5410 | state.pipes.splice(i, 1);
|
5411 | state.pipesCount -= 1;
|
5412 | if (state.pipesCount === 1)
|
5413 | state.pipes = state.pipes[0];
|
5414 |
|
5415 | dest.emit('unpipe', this);
|
5416 |
|
5417 | return this;
|
5418 | };
|
5419 |
|
5420 |
|
5421 |
|
5422 | Readable.prototype.on = function(ev, fn) {
|
5423 | var res = Stream.prototype.on.call(this, ev, fn);
|
5424 |
|
5425 | if (ev === 'data' && !this._readableState.flowing)
|
5426 | emitDataEvents(this);
|
5427 |
|
5428 | if (ev === 'readable' && this.readable) {
|
5429 | var state = this._readableState;
|
5430 | if (!state.readableListening) {
|
5431 | state.readableListening = true;
|
5432 | state.emittedReadable = false;
|
5433 | state.needReadable = true;
|
5434 | if (!state.reading) {
|
5435 | this.read(0);
|
5436 | } else if (state.length) {
|
5437 | emitReadable(this, state);
|
5438 | }
|
5439 | }
|
5440 | }
|
5441 |
|
5442 | return res;
|
5443 | };
|
5444 | Readable.prototype.addListener = Readable.prototype.on;
|
5445 |
|
5446 |
|
5447 |
|
5448 | Readable.prototype.resume = function() {
|
5449 | emitDataEvents(this);
|
5450 | this.read(0);
|
5451 | this.emit('resume');
|
5452 | };
|
5453 |
|
5454 | Readable.prototype.pause = function() {
|
5455 | emitDataEvents(this, true);
|
5456 | this.emit('pause');
|
5457 | };
|
5458 |
|
5459 | function emitDataEvents(stream, startPaused) {
|
5460 | var state = stream._readableState;
|
5461 |
|
5462 | if (state.flowing) {
|
5463 |
|
5464 | throw new Error('Cannot switch to old mode now.');
|
5465 | }
|
5466 |
|
5467 | var paused = startPaused || false;
|
5468 | var readable = false;
|
5469 |
|
5470 |
|
5471 | stream.readable = true;
|
5472 | stream.pipe = Stream.prototype.pipe;
|
5473 | stream.on = stream.addListener = Stream.prototype.on;
|
5474 |
|
5475 | stream.on('readable', function() {
|
5476 | readable = true;
|
5477 |
|
5478 | var c;
|
5479 | while (!paused && (null !== (c = stream.read())))
|
5480 | stream.emit('data', c);
|
5481 |
|
5482 | if (c === null) {
|
5483 | readable = false;
|
5484 | stream._readableState.needReadable = true;
|
5485 | }
|
5486 | });
|
5487 |
|
5488 | stream.pause = function() {
|
5489 | paused = true;
|
5490 | this.emit('pause');
|
5491 | };
|
5492 |
|
5493 | stream.resume = function() {
|
5494 | paused = false;
|
5495 | if (readable)
|
5496 | process.nextTick(function() {
|
5497 | stream.emit('readable');
|
5498 | });
|
5499 | else
|
5500 | this.read(0);
|
5501 | this.emit('resume');
|
5502 | };
|
5503 |
|
5504 |
|
5505 | stream.emit('readable');
|
5506 | }
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 | Readable.prototype.wrap = function(stream) {
|
5512 | var state = this._readableState;
|
5513 | var paused = false;
|
5514 |
|
5515 | var self = this;
|
5516 | stream.on('end', function() {
|
5517 | if (state.decoder && !state.ended) {
|
5518 | var chunk = state.decoder.end();
|
5519 | if (chunk && chunk.length)
|
5520 | self.push(chunk);
|
5521 | }
|
5522 |
|
5523 | self.push(null);
|
5524 | });
|
5525 |
|
5526 | stream.on('data', function(chunk) {
|
5527 | if (state.decoder)
|
5528 | chunk = state.decoder.write(chunk);
|
5529 |
|
5530 |
|
5531 |
|
5532 | if (state.objectMode && (chunk === null || chunk === undefined))
|
5533 | return;
|
5534 | else if (!state.objectMode && (!chunk || !chunk.length))
|
5535 | return;
|
5536 |
|
5537 | var ret = self.push(chunk);
|
5538 | if (!ret) {
|
5539 | paused = true;
|
5540 | stream.pause();
|
5541 | }
|
5542 | });
|
5543 |
|
5544 |
|
5545 |
|
5546 | for (var i in stream) {
|
5547 | if (typeof stream[i] === 'function' &&
|
5548 | typeof this[i] === 'undefined') {
|
5549 | this[i] = function(method) { return function() {
|
5550 | return stream[method].apply(stream, arguments);
|
5551 | }}(i);
|
5552 | }
|
5553 | }
|
5554 |
|
5555 |
|
5556 | var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
5557 | forEach(events, function(ev) {
|
5558 | stream.on(ev, self.emit.bind(self, ev));
|
5559 | });
|
5560 |
|
5561 |
|
5562 |
|
5563 | self._read = function(n) {
|
5564 | if (paused) {
|
5565 | paused = false;
|
5566 | stream.resume();
|
5567 | }
|
5568 | };
|
5569 |
|
5570 | return self;
|
5571 | };
|
5572 |
|
5573 |
|
5574 |
|
5575 |
|
5576 | Readable._fromList = fromList;
|
5577 |
|
5578 |
|
5579 |
|
5580 | function fromList(n, state) {
|
5581 | var list = state.buffer;
|
5582 | var length = state.length;
|
5583 | var stringMode = !!state.decoder;
|
5584 | var objectMode = !!state.objectMode;
|
5585 | var ret;
|
5586 |
|
5587 |
|
5588 | if (list.length === 0)
|
5589 | return null;
|
5590 |
|
5591 | if (length === 0)
|
5592 | ret = null;
|
5593 | else if (objectMode)
|
5594 | ret = list.shift();
|
5595 | else if (!n || n >= length) {
|
5596 |
|
5597 | if (stringMode)
|
5598 | ret = list.join('');
|
5599 | else
|
5600 | ret = Buffer.concat(list, length);
|
5601 | list.length = 0;
|
5602 | } else {
|
5603 |
|
5604 | if (n < list[0].length) {
|
5605 |
|
5606 |
|
5607 | var buf = list[0];
|
5608 | ret = buf.slice(0, n);
|
5609 | list[0] = buf.slice(n);
|
5610 | } else if (n === list[0].length) {
|
5611 |
|
5612 | ret = list.shift();
|
5613 | } else {
|
5614 |
|
5615 |
|
5616 | if (stringMode)
|
5617 | ret = '';
|
5618 | else
|
5619 | ret = new Buffer(n);
|
5620 |
|
5621 | var c = 0;
|
5622 | for (var i = 0, l = list.length; i < l && c < n; i++) {
|
5623 | var buf = list[0];
|
5624 | var cpy = Math.min(n - c, buf.length);
|
5625 |
|
5626 | if (stringMode)
|
5627 | ret += buf.slice(0, cpy);
|
5628 | else
|
5629 | buf.copy(ret, c, 0, cpy);
|
5630 |
|
5631 | if (cpy < buf.length)
|
5632 | list[0] = buf.slice(cpy);
|
5633 | else
|
5634 | list.shift();
|
5635 |
|
5636 | c += cpy;
|
5637 | }
|
5638 | }
|
5639 | }
|
5640 |
|
5641 | return ret;
|
5642 | }
|
5643 |
|
5644 | function endReadable(stream) {
|
5645 | var state = stream._readableState;
|
5646 |
|
5647 |
|
5648 |
|
5649 | if (state.length > 0)
|
5650 | throw new Error('endReadable called on non-empty stream');
|
5651 |
|
5652 | if (!state.endEmitted && state.calledRead) {
|
5653 | state.ended = true;
|
5654 | process.nextTick(function() {
|
5655 |
|
5656 | if (!state.endEmitted && state.length === 0) {
|
5657 | state.endEmitted = true;
|
5658 | stream.readable = false;
|
5659 | stream.emit('end');
|
5660 | }
|
5661 | });
|
5662 | }
|
5663 | }
|
5664 |
|
5665 | function forEach (xs, f) {
|
5666 | for (var i = 0, l = xs.length; i < l; i++) {
|
5667 | f(xs[i], i);
|
5668 | }
|
5669 | }
|
5670 |
|
5671 | function indexOf (xs, x) {
|
5672 | for (var i = 0, l = xs.length; i < l; i++) {
|
5673 | if (xs[i] === x) return i;
|
5674 | }
|
5675 | return -1;
|
5676 | }
|
5677 |
|
5678 | }).call(this,require('_process'))
|
5679 | },{"_process":31,"buffer":3,"core-util-is":42,"events":22,"inherits":28,"isarray":29,"stream":48,"string_decoder/":43}],40:[function(require,module,exports){
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 |
|
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 |
|
5744 | module.exports = Transform;
|
5745 |
|
5746 | var Duplex = require('./_stream_duplex');
|
5747 |
|
5748 |
|
5749 | var util = require('core-util-is');
|
5750 | util.inherits = require('inherits');
|
5751 |
|
5752 |
|
5753 | util.inherits(Transform, Duplex);
|
5754 |
|
5755 |
|
5756 | function TransformState(options, stream) {
|
5757 | this.afterTransform = function(er, data) {
|
5758 | return afterTransform(stream, er, data);
|
5759 | };
|
5760 |
|
5761 | this.needTransform = false;
|
5762 | this.transforming = false;
|
5763 | this.writecb = null;
|
5764 | this.writechunk = null;
|
5765 | }
|
5766 |
|
5767 | function afterTransform(stream, er, data) {
|
5768 | var ts = stream._transformState;
|
5769 | ts.transforming = false;
|
5770 |
|
5771 | var cb = ts.writecb;
|
5772 |
|
5773 | if (!cb)
|
5774 | return stream.emit('error', new Error('no writecb in Transform class'));
|
5775 |
|
5776 | ts.writechunk = null;
|
5777 | ts.writecb = null;
|
5778 |
|
5779 | if (data !== null && data !== undefined)
|
5780 | stream.push(data);
|
5781 |
|
5782 | if (cb)
|
5783 | cb(er);
|
5784 |
|
5785 | var rs = stream._readableState;
|
5786 | rs.reading = false;
|
5787 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
5788 | stream._read(rs.highWaterMark);
|
5789 | }
|
5790 | }
|
5791 |
|
5792 |
|
5793 | function Transform(options) {
|
5794 | if (!(this instanceof Transform))
|
5795 | return new Transform(options);
|
5796 |
|
5797 | Duplex.call(this, options);
|
5798 |
|
5799 | var ts = this._transformState = new TransformState(options, this);
|
5800 |
|
5801 |
|
5802 | var stream = this;
|
5803 |
|
5804 |
|
5805 | this._readableState.needReadable = true;
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 | this._readableState.sync = false;
|
5811 |
|
5812 | this.once('finish', function() {
|
5813 | if ('function' === typeof this._flush)
|
5814 | this._flush(function(er) {
|
5815 | done(stream, er);
|
5816 | });
|
5817 | else
|
5818 | done(stream);
|
5819 | });
|
5820 | }
|
5821 |
|
5822 | Transform.prototype.push = function(chunk, encoding) {
|
5823 | this._transformState.needTransform = false;
|
5824 | return Duplex.prototype.push.call(this, chunk, encoding);
|
5825 | };
|
5826 |
|
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 | Transform.prototype._transform = function(chunk, encoding, cb) {
|
5838 | throw new Error('not implemented');
|
5839 | };
|
5840 |
|
5841 | Transform.prototype._write = function(chunk, encoding, cb) {
|
5842 | var ts = this._transformState;
|
5843 | ts.writecb = cb;
|
5844 | ts.writechunk = chunk;
|
5845 | ts.writeencoding = encoding;
|
5846 | if (!ts.transforming) {
|
5847 | var rs = this._readableState;
|
5848 | if (ts.needTransform ||
|
5849 | rs.needReadable ||
|
5850 | rs.length < rs.highWaterMark)
|
5851 | this._read(rs.highWaterMark);
|
5852 | }
|
5853 | };
|
5854 |
|
5855 |
|
5856 |
|
5857 |
|
5858 | Transform.prototype._read = function(n) {
|
5859 | var ts = this._transformState;
|
5860 |
|
5861 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
5862 | ts.transforming = true;
|
5863 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
5864 | } else {
|
5865 |
|
5866 |
|
5867 | ts.needTransform = true;
|
5868 | }
|
5869 | };
|
5870 |
|
5871 |
|
5872 | function done(stream, er) {
|
5873 | if (er)
|
5874 | return stream.emit('error', er);
|
5875 |
|
5876 |
|
5877 |
|
5878 | var ws = stream._writableState;
|
5879 | var rs = stream._readableState;
|
5880 | var ts = stream._transformState;
|
5881 |
|
5882 | if (ws.length)
|
5883 | throw new Error('calling transform done when ws.length != 0');
|
5884 |
|
5885 | if (ts.transforming)
|
5886 | throw new Error('calling transform done when still transforming');
|
5887 |
|
5888 | return stream.push(null);
|
5889 | }
|
5890 |
|
5891 | },{"./_stream_duplex":37,"core-util-is":42,"inherits":28}],41:[function(require,module,exports){
|
5892 | (function (process){
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 | module.exports = Writable;
|
5919 |
|
5920 |
|
5921 | var Buffer = require('buffer').Buffer;
|
5922 |
|
5923 |
|
5924 | Writable.WritableState = WritableState;
|
5925 |
|
5926 |
|
5927 |
|
5928 | var util = require('core-util-is');
|
5929 | util.inherits = require('inherits');
|
5930 |
|
5931 |
|
5932 | var Stream = require('stream');
|
5933 |
|
5934 | util.inherits(Writable, Stream);
|
5935 |
|
5936 | function WriteReq(chunk, encoding, cb) {
|
5937 | this.chunk = chunk;
|
5938 | this.encoding = encoding;
|
5939 | this.callback = cb;
|
5940 | }
|
5941 |
|
5942 | function WritableState(options, stream) {
|
5943 | options = options || {};
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 | var hwm = options.highWaterMark;
|
5949 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
5950 |
|
5951 |
|
5952 |
|
5953 | this.objectMode = !!options.objectMode;
|
5954 |
|
5955 |
|
5956 | this.highWaterMark = ~~this.highWaterMark;
|
5957 |
|
5958 | this.needDrain = false;
|
5959 |
|
5960 | this.ending = false;
|
5961 |
|
5962 | this.ended = false;
|
5963 |
|
5964 | this.finished = false;
|
5965 |
|
5966 |
|
5967 |
|
5968 |
|
5969 | var noDecode = options.decodeStrings === false;
|
5970 | this.decodeStrings = !noDecode;
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
5976 |
|
5977 |
|
5978 |
|
5979 |
|
5980 | this.length = 0;
|
5981 |
|
5982 |
|
5983 | this.writing = false;
|
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 |
|
5989 | this.sync = true;
|
5990 |
|
5991 |
|
5992 |
|
5993 |
|
5994 | this.bufferProcessing = false;
|
5995 |
|
5996 |
|
5997 | this.onwrite = function(er) {
|
5998 | onwrite(stream, er);
|
5999 | };
|
6000 |
|
6001 |
|
6002 | this.writecb = null;
|
6003 |
|
6004 |
|
6005 | this.writelen = 0;
|
6006 |
|
6007 | this.buffer = [];
|
6008 |
|
6009 |
|
6010 | this.errorEmitted = false;
|
6011 | }
|
6012 |
|
6013 | function Writable(options) {
|
6014 | var Duplex = require('./_stream_duplex');
|
6015 |
|
6016 |
|
6017 |
|
6018 | if (!(this instanceof Writable) && !(this instanceof Duplex))
|
6019 | return new Writable(options);
|
6020 |
|
6021 | this._writableState = new WritableState(options, this);
|
6022 |
|
6023 |
|
6024 | this.writable = true;
|
6025 |
|
6026 | Stream.call(this);
|
6027 | }
|
6028 |
|
6029 |
|
6030 | Writable.prototype.pipe = function() {
|
6031 | this.emit('error', new Error('Cannot pipe. Not readable.'));
|
6032 | };
|
6033 |
|
6034 |
|
6035 | function writeAfterEnd(stream, state, cb) {
|
6036 | var er = new Error('write after end');
|
6037 |
|
6038 | stream.emit('error', er);
|
6039 | process.nextTick(function() {
|
6040 | cb(er);
|
6041 | });
|
6042 | }
|
6043 |
|
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 | function validChunk(stream, state, chunk, cb) {
|
6050 | var valid = true;
|
6051 | if (!Buffer.isBuffer(chunk) &&
|
6052 | 'string' !== typeof chunk &&
|
6053 | chunk !== null &&
|
6054 | chunk !== undefined &&
|
6055 | !state.objectMode) {
|
6056 | var er = new TypeError('Invalid non-string/buffer chunk');
|
6057 | stream.emit('error', er);
|
6058 | process.nextTick(function() {
|
6059 | cb(er);
|
6060 | });
|
6061 | valid = false;
|
6062 | }
|
6063 | return valid;
|
6064 | }
|
6065 |
|
6066 | Writable.prototype.write = function(chunk, encoding, cb) {
|
6067 | var state = this._writableState;
|
6068 | var ret = false;
|
6069 |
|
6070 | if (typeof encoding === 'function') {
|
6071 | cb = encoding;
|
6072 | encoding = null;
|
6073 | }
|
6074 |
|
6075 | if (Buffer.isBuffer(chunk))
|
6076 | encoding = 'buffer';
|
6077 | else if (!encoding)
|
6078 | encoding = state.defaultEncoding;
|
6079 |
|
6080 | if (typeof cb !== 'function')
|
6081 | cb = function() {};
|
6082 |
|
6083 | if (state.ended)
|
6084 | writeAfterEnd(this, state, cb);
|
6085 | else if (validChunk(this, state, chunk, cb))
|
6086 | ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
6087 |
|
6088 | return ret;
|
6089 | };
|
6090 |
|
6091 | function decodeChunk(state, chunk, encoding) {
|
6092 | if (!state.objectMode &&
|
6093 | state.decodeStrings !== false &&
|
6094 | typeof chunk === 'string') {
|
6095 | chunk = new Buffer(chunk, encoding);
|
6096 | }
|
6097 | return chunk;
|
6098 | }
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 | function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
6104 | chunk = decodeChunk(state, chunk, encoding);
|
6105 | if (Buffer.isBuffer(chunk))
|
6106 | encoding = 'buffer';
|
6107 | var len = state.objectMode ? 1 : chunk.length;
|
6108 |
|
6109 | state.length += len;
|
6110 |
|
6111 | var ret = state.length < state.highWaterMark;
|
6112 |
|
6113 | if (!ret)
|
6114 | state.needDrain = true;
|
6115 |
|
6116 | if (state.writing)
|
6117 | state.buffer.push(new WriteReq(chunk, encoding, cb));
|
6118 | else
|
6119 | doWrite(stream, state, len, chunk, encoding, cb);
|
6120 |
|
6121 | return ret;
|
6122 | }
|
6123 |
|
6124 | function doWrite(stream, state, len, chunk, encoding, cb) {
|
6125 | state.writelen = len;
|
6126 | state.writecb = cb;
|
6127 | state.writing = true;
|
6128 | state.sync = true;
|
6129 | stream._write(chunk, encoding, state.onwrite);
|
6130 | state.sync = false;
|
6131 | }
|
6132 |
|
6133 | function onwriteError(stream, state, sync, er, cb) {
|
6134 | if (sync)
|
6135 | process.nextTick(function() {
|
6136 | cb(er);
|
6137 | });
|
6138 | else
|
6139 | cb(er);
|
6140 |
|
6141 | stream._writableState.errorEmitted = true;
|
6142 | stream.emit('error', er);
|
6143 | }
|
6144 |
|
6145 | function onwriteStateUpdate(state) {
|
6146 | state.writing = false;
|
6147 | state.writecb = null;
|
6148 | state.length -= state.writelen;
|
6149 | state.writelen = 0;
|
6150 | }
|
6151 |
|
6152 | function onwrite(stream, er) {
|
6153 | var state = stream._writableState;
|
6154 | var sync = state.sync;
|
6155 | var cb = state.writecb;
|
6156 |
|
6157 | onwriteStateUpdate(state);
|
6158 |
|
6159 | if (er)
|
6160 | onwriteError(stream, state, sync, er, cb);
|
6161 | else {
|
6162 |
|
6163 | var finished = needFinish(stream, state);
|
6164 |
|
6165 | if (!finished && !state.bufferProcessing && state.buffer.length)
|
6166 | clearBuffer(stream, state);
|
6167 |
|
6168 | if (sync) {
|
6169 | process.nextTick(function() {
|
6170 | afterWrite(stream, state, finished, cb);
|
6171 | });
|
6172 | } else {
|
6173 | afterWrite(stream, state, finished, cb);
|
6174 | }
|
6175 | }
|
6176 | }
|
6177 |
|
6178 | function afterWrite(stream, state, finished, cb) {
|
6179 | if (!finished)
|
6180 | onwriteDrain(stream, state);
|
6181 | cb();
|
6182 | if (finished)
|
6183 | finishMaybe(stream, state);
|
6184 | }
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 | function onwriteDrain(stream, state) {
|
6190 | if (state.length === 0 && state.needDrain) {
|
6191 | state.needDrain = false;
|
6192 | stream.emit('drain');
|
6193 | }
|
6194 | }
|
6195 |
|
6196 |
|
6197 |
|
6198 | function clearBuffer(stream, state) {
|
6199 | state.bufferProcessing = true;
|
6200 |
|
6201 | for (var c = 0; c < state.buffer.length; c++) {
|
6202 | var entry = state.buffer[c];
|
6203 | var chunk = entry.chunk;
|
6204 | var encoding = entry.encoding;
|
6205 | var cb = entry.callback;
|
6206 | var len = state.objectMode ? 1 : chunk.length;
|
6207 |
|
6208 | doWrite(stream, state, len, chunk, encoding, cb);
|
6209 |
|
6210 |
|
6211 |
|
6212 |
|
6213 |
|
6214 | if (state.writing) {
|
6215 | c++;
|
6216 | break;
|
6217 | }
|
6218 | }
|
6219 |
|
6220 | state.bufferProcessing = false;
|
6221 | if (c < state.buffer.length)
|
6222 | state.buffer = state.buffer.slice(c);
|
6223 | else
|
6224 | state.buffer.length = 0;
|
6225 | }
|
6226 |
|
6227 | Writable.prototype._write = function(chunk, encoding, cb) {
|
6228 | cb(new Error('not implemented'));
|
6229 | };
|
6230 |
|
6231 | Writable.prototype.end = function(chunk, encoding, cb) {
|
6232 | var state = this._writableState;
|
6233 |
|
6234 | if (typeof chunk === 'function') {
|
6235 | cb = chunk;
|
6236 | chunk = null;
|
6237 | encoding = null;
|
6238 | } else if (typeof encoding === 'function') {
|
6239 | cb = encoding;
|
6240 | encoding = null;
|
6241 | }
|
6242 |
|
6243 | if (typeof chunk !== 'undefined' && chunk !== null)
|
6244 | this.write(chunk, encoding);
|
6245 |
|
6246 |
|
6247 | if (!state.ending && !state.finished)
|
6248 | endWritable(this, state, cb);
|
6249 | };
|
6250 |
|
6251 |
|
6252 | function needFinish(stream, state) {
|
6253 | return (state.ending &&
|
6254 | state.length === 0 &&
|
6255 | !state.finished &&
|
6256 | !state.writing);
|
6257 | }
|
6258 |
|
6259 | function finishMaybe(stream, state) {
|
6260 | var need = needFinish(stream, state);
|
6261 | if (need) {
|
6262 | state.finished = true;
|
6263 | stream.emit('finish');
|
6264 | }
|
6265 | return need;
|
6266 | }
|
6267 |
|
6268 | function endWritable(stream, state, cb) {
|
6269 | state.ending = true;
|
6270 | finishMaybe(stream, state);
|
6271 | if (cb) {
|
6272 | if (state.finished)
|
6273 | process.nextTick(cb);
|
6274 | else
|
6275 | stream.once('finish', cb);
|
6276 | }
|
6277 | state.ended = true;
|
6278 | }
|
6279 |
|
6280 | }).call(this,require('_process'))
|
6281 | },{"./_stream_duplex":37,"_process":31,"buffer":3,"core-util-is":42,"inherits":28,"stream":48}],42:[function(require,module,exports){
|
6282 | (function (Buffer){
|
6283 |
|
6284 |
|
6285 |
|
6286 |
|
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 |
|
6295 |
|
6296 |
|
6297 |
|
6298 |
|
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 |
|
6305 |
|
6306 | function isArray(ar) {
|
6307 | return Array.isArray(ar);
|
6308 | }
|
6309 | exports.isArray = isArray;
|
6310 |
|
6311 | function isBoolean(arg) {
|
6312 | return typeof arg === 'boolean';
|
6313 | }
|
6314 | exports.isBoolean = isBoolean;
|
6315 |
|
6316 | function isNull(arg) {
|
6317 | return arg === null;
|
6318 | }
|
6319 | exports.isNull = isNull;
|
6320 |
|
6321 | function isNullOrUndefined(arg) {
|
6322 | return arg == null;
|
6323 | }
|
6324 | exports.isNullOrUndefined = isNullOrUndefined;
|
6325 |
|
6326 | function isNumber(arg) {
|
6327 | return typeof arg === 'number';
|
6328 | }
|
6329 | exports.isNumber = isNumber;
|
6330 |
|
6331 | function isString(arg) {
|
6332 | return typeof arg === 'string';
|
6333 | }
|
6334 | exports.isString = isString;
|
6335 |
|
6336 | function isSymbol(arg) {
|
6337 | return typeof arg === 'symbol';
|
6338 | }
|
6339 | exports.isSymbol = isSymbol;
|
6340 |
|
6341 | function isUndefined(arg) {
|
6342 | return arg === void 0;
|
6343 | }
|
6344 | exports.isUndefined = isUndefined;
|
6345 |
|
6346 | function isRegExp(re) {
|
6347 | return isObject(re) && objectToString(re) === '[object RegExp]';
|
6348 | }
|
6349 | exports.isRegExp = isRegExp;
|
6350 |
|
6351 | function isObject(arg) {
|
6352 | return typeof arg === 'object' && arg !== null;
|
6353 | }
|
6354 | exports.isObject = isObject;
|
6355 |
|
6356 | function isDate(d) {
|
6357 | return isObject(d) && objectToString(d) === '[object Date]';
|
6358 | }
|
6359 | exports.isDate = isDate;
|
6360 |
|
6361 | function isError(e) {
|
6362 | return isObject(e) &&
|
6363 | (objectToString(e) === '[object Error]' || e instanceof Error);
|
6364 | }
|
6365 | exports.isError = isError;
|
6366 |
|
6367 | function isFunction(arg) {
|
6368 | return typeof arg === 'function';
|
6369 | }
|
6370 | exports.isFunction = isFunction;
|
6371 |
|
6372 | function isPrimitive(arg) {
|
6373 | return arg === null ||
|
6374 | typeof arg === 'boolean' ||
|
6375 | typeof arg === 'number' ||
|
6376 | typeof arg === 'string' ||
|
6377 | typeof arg === 'symbol' ||
|
6378 | typeof arg === 'undefined';
|
6379 | }
|
6380 | exports.isPrimitive = isPrimitive;
|
6381 |
|
6382 | function isBuffer(arg) {
|
6383 | return Buffer.isBuffer(arg);
|
6384 | }
|
6385 | exports.isBuffer = isBuffer;
|
6386 |
|
6387 | function objectToString(o) {
|
6388 | return Object.prototype.toString.call(o);
|
6389 | }
|
6390 | }).call(this,require("buffer").Buffer)
|
6391 | },{"buffer":3}],43:[function(require,module,exports){
|
6392 |
|
6393 |
|
6394 |
|
6395 |
|
6396 |
|
6397 |
|
6398 |
|
6399 |
|
6400 |
|
6401 |
|
6402 |
|
6403 |
|
6404 |
|
6405 |
|
6406 |
|
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 | var Buffer = require('buffer').Buffer;
|
6414 |
|
6415 | var isBufferEncoding = Buffer.isEncoding
|
6416 | || function(encoding) {
|
6417 | switch (encoding && encoding.toLowerCase()) {
|
6418 | case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
|
6419 | default: return false;
|
6420 | }
|
6421 | }
|
6422 |
|
6423 |
|
6424 | function assertEncoding(encoding) {
|
6425 | if (encoding && !isBufferEncoding(encoding)) {
|
6426 | throw new Error('Unknown encoding: ' + encoding);
|
6427 | }
|
6428 | }
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 | var StringDecoder = exports.StringDecoder = function(encoding) {
|
6439 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
6440 | assertEncoding(encoding);
|
6441 | switch (this.encoding) {
|
6442 | case 'utf8':
|
6443 |
|
6444 | this.surrogateSize = 3;
|
6445 | break;
|
6446 | case 'ucs2':
|
6447 | case 'utf16le':
|
6448 |
|
6449 | this.surrogateSize = 2;
|
6450 | this.detectIncompleteChar = utf16DetectIncompleteChar;
|
6451 | break;
|
6452 | case 'base64':
|
6453 |
|
6454 | this.surrogateSize = 3;
|
6455 | this.detectIncompleteChar = base64DetectIncompleteChar;
|
6456 | break;
|
6457 | default:
|
6458 | this.write = passThroughWrite;
|
6459 | return;
|
6460 | }
|
6461 |
|
6462 |
|
6463 |
|
6464 | this.charBuffer = new Buffer(6);
|
6465 |
|
6466 | this.charReceived = 0;
|
6467 |
|
6468 | this.charLength = 0;
|
6469 | };
|
6470 |
|
6471 |
|
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 |
|
6479 |
|
6480 |
|
6481 | StringDecoder.prototype.write = function(buffer) {
|
6482 | var charStr = '';
|
6483 |
|
6484 | while (this.charLength) {
|
6485 |
|
6486 | var available = (buffer.length >= this.charLength - this.charReceived) ?
|
6487 | this.charLength - this.charReceived :
|
6488 | buffer.length;
|
6489 |
|
6490 |
|
6491 | buffer.copy(this.charBuffer, this.charReceived, 0, available);
|
6492 | this.charReceived += available;
|
6493 |
|
6494 | if (this.charReceived < this.charLength) {
|
6495 |
|
6496 | return '';
|
6497 | }
|
6498 |
|
6499 |
|
6500 | buffer = buffer.slice(available, buffer.length);
|
6501 |
|
6502 |
|
6503 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
6504 |
|
6505 |
|
6506 | var charCode = charStr.charCodeAt(charStr.length - 1);
|
6507 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
6508 | this.charLength += this.surrogateSize;
|
6509 | charStr = '';
|
6510 | continue;
|
6511 | }
|
6512 | this.charReceived = this.charLength = 0;
|
6513 |
|
6514 |
|
6515 | if (buffer.length === 0) {
|
6516 | return charStr;
|
6517 | }
|
6518 | break;
|
6519 | }
|
6520 |
|
6521 |
|
6522 | this.detectIncompleteChar(buffer);
|
6523 |
|
6524 | var end = buffer.length;
|
6525 | if (this.charLength) {
|
6526 |
|
6527 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
|
6528 | end -= this.charReceived;
|
6529 | }
|
6530 |
|
6531 | charStr += buffer.toString(this.encoding, 0, end);
|
6532 |
|
6533 | var end = charStr.length - 1;
|
6534 | var charCode = charStr.charCodeAt(end);
|
6535 |
|
6536 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
6537 | var size = this.surrogateSize;
|
6538 | this.charLength += size;
|
6539 | this.charReceived += size;
|
6540 | this.charBuffer.copy(this.charBuffer, size, 0, size);
|
6541 | buffer.copy(this.charBuffer, 0, 0, size);
|
6542 | return charStr.substring(0, end);
|
6543 | }
|
6544 |
|
6545 |
|
6546 | return charStr;
|
6547 | };
|
6548 |
|
6549 |
|
6550 |
|
6551 |
|
6552 |
|
6553 | StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
6554 |
|
6555 | var i = (buffer.length >= 3) ? 3 : buffer.length;
|
6556 |
|
6557 |
|
6558 |
|
6559 | for (; i > 0; i--) {
|
6560 | var c = buffer[buffer.length - i];
|
6561 |
|
6562 |
|
6563 |
|
6564 |
|
6565 | if (i == 1 && c >> 5 == 0x06) {
|
6566 | this.charLength = 2;
|
6567 | break;
|
6568 | }
|
6569 |
|
6570 |
|
6571 | if (i <= 2 && c >> 4 == 0x0E) {
|
6572 | this.charLength = 3;
|
6573 | break;
|
6574 | }
|
6575 |
|
6576 |
|
6577 | if (i <= 3 && c >> 3 == 0x1E) {
|
6578 | this.charLength = 4;
|
6579 | break;
|
6580 | }
|
6581 | }
|
6582 | this.charReceived = i;
|
6583 | };
|
6584 |
|
6585 | StringDecoder.prototype.end = function(buffer) {
|
6586 | var res = '';
|
6587 | if (buffer && buffer.length)
|
6588 | res = this.write(buffer);
|
6589 |
|
6590 | if (this.charReceived) {
|
6591 | var cr = this.charReceived;
|
6592 | var buf = this.charBuffer;
|
6593 | var enc = this.encoding;
|
6594 | res += buf.slice(0, cr).toString(enc);
|
6595 | }
|
6596 |
|
6597 | return res;
|
6598 | };
|
6599 |
|
6600 | function passThroughWrite(buffer) {
|
6601 | return buffer.toString(this.encoding);
|
6602 | }
|
6603 |
|
6604 | function utf16DetectIncompleteChar(buffer) {
|
6605 | this.charReceived = buffer.length % 2;
|
6606 | this.charLength = this.charReceived ? 2 : 0;
|
6607 | }
|
6608 |
|
6609 | function base64DetectIncompleteChar(buffer) {
|
6610 | this.charReceived = buffer.length % 3;
|
6611 | this.charLength = this.charReceived ? 3 : 0;
|
6612 | }
|
6613 |
|
6614 | },{"buffer":3}],44:[function(require,module,exports){
|
6615 | module.exports = require("./lib/_stream_passthrough.js")
|
6616 |
|
6617 | },{"./lib/_stream_passthrough.js":38}],45:[function(require,module,exports){
|
6618 | exports = module.exports = require('./lib/_stream_readable.js');
|
6619 | exports.Readable = exports;
|
6620 | exports.Writable = require('./lib/_stream_writable.js');
|
6621 | exports.Duplex = require('./lib/_stream_duplex.js');
|
6622 | exports.Transform = require('./lib/_stream_transform.js');
|
6623 | exports.PassThrough = require('./lib/_stream_passthrough.js');
|
6624 |
|
6625 | },{"./lib/_stream_duplex.js":37,"./lib/_stream_passthrough.js":38,"./lib/_stream_readable.js":39,"./lib/_stream_transform.js":40,"./lib/_stream_writable.js":41}],46:[function(require,module,exports){
|
6626 | module.exports = require("./lib/_stream_transform.js")
|
6627 |
|
6628 | },{"./lib/_stream_transform.js":40}],47:[function(require,module,exports){
|
6629 | module.exports = require("./lib/_stream_writable.js")
|
6630 |
|
6631 | },{"./lib/_stream_writable.js":41}],48:[function(require,module,exports){
|
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 |
|
6638 |
|
6639 |
|
6640 |
|
6641 |
|
6642 |
|
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 | module.exports = Stream;
|
6654 |
|
6655 | var EE = require('events').EventEmitter;
|
6656 | var inherits = require('inherits');
|
6657 |
|
6658 | inherits(Stream, EE);
|
6659 | Stream.Readable = require('readable-stream/readable.js');
|
6660 | Stream.Writable = require('readable-stream/writable.js');
|
6661 | Stream.Duplex = require('readable-stream/duplex.js');
|
6662 | Stream.Transform = require('readable-stream/transform.js');
|
6663 | Stream.PassThrough = require('readable-stream/passthrough.js');
|
6664 |
|
6665 |
|
6666 | Stream.Stream = Stream;
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 | function Stream() {
|
6674 | EE.call(this);
|
6675 | }
|
6676 |
|
6677 | Stream.prototype.pipe = function(dest, options) {
|
6678 | var source = this;
|
6679 |
|
6680 | function ondata(chunk) {
|
6681 | if (dest.writable) {
|
6682 | if (false === dest.write(chunk) && source.pause) {
|
6683 | source.pause();
|
6684 | }
|
6685 | }
|
6686 | }
|
6687 |
|
6688 | source.on('data', ondata);
|
6689 |
|
6690 | function ondrain() {
|
6691 | if (source.readable && source.resume) {
|
6692 | source.resume();
|
6693 | }
|
6694 | }
|
6695 |
|
6696 | dest.on('drain', ondrain);
|
6697 |
|
6698 |
|
6699 |
|
6700 | if (!dest._isStdio && (!options || options.end !== false)) {
|
6701 | source.on('end', onend);
|
6702 | source.on('close', onclose);
|
6703 | }
|
6704 |
|
6705 | var didOnEnd = false;
|
6706 | function onend() {
|
6707 | if (didOnEnd) return;
|
6708 | didOnEnd = true;
|
6709 |
|
6710 | dest.end();
|
6711 | }
|
6712 |
|
6713 |
|
6714 | function onclose() {
|
6715 | if (didOnEnd) return;
|
6716 | didOnEnd = true;
|
6717 |
|
6718 | if (typeof dest.destroy === 'function') dest.destroy();
|
6719 | }
|
6720 |
|
6721 |
|
6722 | function onerror(er) {
|
6723 | cleanup();
|
6724 | if (EE.listenerCount(this, 'error') === 0) {
|
6725 | throw er;
|
6726 | }
|
6727 | }
|
6728 |
|
6729 | source.on('error', onerror);
|
6730 | dest.on('error', onerror);
|
6731 |
|
6732 |
|
6733 | function cleanup() {
|
6734 | source.removeListener('data', ondata);
|
6735 | dest.removeListener('drain', ondrain);
|
6736 |
|
6737 | source.removeListener('end', onend);
|
6738 | source.removeListener('close', onclose);
|
6739 |
|
6740 | source.removeListener('error', onerror);
|
6741 | dest.removeListener('error', onerror);
|
6742 |
|
6743 | source.removeListener('end', cleanup);
|
6744 | source.removeListener('close', cleanup);
|
6745 |
|
6746 | dest.removeListener('close', cleanup);
|
6747 | }
|
6748 |
|
6749 | source.on('end', cleanup);
|
6750 | source.on('close', cleanup);
|
6751 |
|
6752 | dest.on('close', cleanup);
|
6753 |
|
6754 | dest.emit('pipe', source);
|
6755 |
|
6756 |
|
6757 | return dest;
|
6758 | };
|
6759 |
|
6760 | },{"events":22,"inherits":28,"readable-stream/duplex.js":36,"readable-stream/passthrough.js":44,"readable-stream/readable.js":45,"readable-stream/transform.js":46,"readable-stream/writable.js":47}],49:[function(require,module,exports){
|
6761 |
|
6762 |
|
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 | var punycode = require('punycode');
|
6783 |
|
6784 | exports.parse = urlParse;
|
6785 | exports.resolve = urlResolve;
|
6786 | exports.resolveObject = urlResolveObject;
|
6787 | exports.format = urlFormat;
|
6788 |
|
6789 | exports.Url = Url;
|
6790 |
|
6791 | function Url() {
|
6792 | this.protocol = null;
|
6793 | this.slashes = null;
|
6794 | this.auth = null;
|
6795 | this.host = null;
|
6796 | this.port = null;
|
6797 | this.hostname = null;
|
6798 | this.hash = null;
|
6799 | this.search = null;
|
6800 | this.query = null;
|
6801 | this.pathname = null;
|
6802 | this.path = null;
|
6803 | this.href = null;
|
6804 | }
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 | var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
6811 | portPattern = /:[0-9]*$/,
|
6812 |
|
6813 |
|
6814 |
|
6815 | delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
|
6816 |
|
6817 |
|
6818 | unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
|
6819 |
|
6820 |
|
6821 | autoEscape = ['\''].concat(unwise),
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 | nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
|
6827 | hostEndingChars = ['/', '?', '#'],
|
6828 | hostnameMaxLen = 255,
|
6829 | hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/,
|
6830 | hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/,
|
6831 |
|
6832 | unsafeProtocol = {
|
6833 | 'javascript': true,
|
6834 | 'javascript:': true
|
6835 | },
|
6836 |
|
6837 | hostlessProtocol = {
|
6838 | 'javascript': true,
|
6839 | 'javascript:': true
|
6840 | },
|
6841 |
|
6842 | slashedProtocol = {
|
6843 | 'http': true,
|
6844 | 'https': true,
|
6845 | 'ftp': true,
|
6846 | 'gopher': true,
|
6847 | 'file': true,
|
6848 | 'http:': true,
|
6849 | 'https:': true,
|
6850 | 'ftp:': true,
|
6851 | 'gopher:': true,
|
6852 | 'file:': true
|
6853 | },
|
6854 | querystring = require('querystring');
|
6855 |
|
6856 | function urlParse(url, parseQueryString, slashesDenoteHost) {
|
6857 | if (url && isObject(url) && url instanceof Url) return url;
|
6858 |
|
6859 | var u = new Url;
|
6860 | u.parse(url, parseQueryString, slashesDenoteHost);
|
6861 | return u;
|
6862 | }
|
6863 |
|
6864 | Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
6865 | if (!isString(url)) {
|
6866 | throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
6867 | }
|
6868 |
|
6869 | var rest = url;
|
6870 |
|
6871 |
|
6872 |
|
6873 | rest = rest.trim();
|
6874 |
|
6875 | var proto = protocolPattern.exec(rest);
|
6876 | if (proto) {
|
6877 | proto = proto[0];
|
6878 | var lowerProto = proto.toLowerCase();
|
6879 | this.protocol = lowerProto;
|
6880 | rest = rest.substr(proto.length);
|
6881 | }
|
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 | if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
|
6888 | var slashes = rest.substr(0, 2) === '//';
|
6889 | if (slashes && !(proto && hostlessProtocol[proto])) {
|
6890 | rest = rest.substr(2);
|
6891 | this.slashes = true;
|
6892 | }
|
6893 | }
|
6894 |
|
6895 | if (!hostlessProtocol[proto] &&
|
6896 | (slashes || (proto && !slashedProtocol[proto]))) {
|
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 |
|
6907 |
|
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 |
|
6914 | var hostEnd = -1;
|
6915 | for (var i = 0; i < hostEndingChars.length; i++) {
|
6916 | var hec = rest.indexOf(hostEndingChars[i]);
|
6917 | if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
6918 | hostEnd = hec;
|
6919 | }
|
6920 |
|
6921 |
|
6922 |
|
6923 | var auth, atSign;
|
6924 | if (hostEnd === -1) {
|
6925 |
|
6926 | atSign = rest.lastIndexOf('@');
|
6927 | } else {
|
6928 |
|
6929 |
|
6930 | atSign = rest.lastIndexOf('@', hostEnd);
|
6931 | }
|
6932 |
|
6933 |
|
6934 |
|
6935 | if (atSign !== -1) {
|
6936 | auth = rest.slice(0, atSign);
|
6937 | rest = rest.slice(atSign + 1);
|
6938 | this.auth = decodeURIComponent(auth);
|
6939 | }
|
6940 |
|
6941 |
|
6942 | hostEnd = -1;
|
6943 | for (var i = 0; i < nonHostChars.length; i++) {
|
6944 | var hec = rest.indexOf(nonHostChars[i]);
|
6945 | if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
|
6946 | hostEnd = hec;
|
6947 | }
|
6948 |
|
6949 | if (hostEnd === -1)
|
6950 | hostEnd = rest.length;
|
6951 |
|
6952 | this.host = rest.slice(0, hostEnd);
|
6953 | rest = rest.slice(hostEnd);
|
6954 |
|
6955 |
|
6956 | this.parseHost();
|
6957 |
|
6958 |
|
6959 |
|
6960 | this.hostname = this.hostname || '';
|
6961 |
|
6962 |
|
6963 |
|
6964 | var ipv6Hostname = this.hostname[0] === '[' &&
|
6965 | this.hostname[this.hostname.length - 1] === ']';
|
6966 |
|
6967 |
|
6968 | if (!ipv6Hostname) {
|
6969 | var hostparts = this.hostname.split(/\./);
|
6970 | for (var i = 0, l = hostparts.length; i < l; i++) {
|
6971 | var part = hostparts[i];
|
6972 | if (!part) continue;
|
6973 | if (!part.match(hostnamePartPattern)) {
|
6974 | var newpart = '';
|
6975 | for (var j = 0, k = part.length; j < k; j++) {
|
6976 | if (part.charCodeAt(j) > 127) {
|
6977 |
|
6978 |
|
6979 |
|
6980 | newpart += 'x';
|
6981 | } else {
|
6982 | newpart += part[j];
|
6983 | }
|
6984 | }
|
6985 |
|
6986 | if (!newpart.match(hostnamePartPattern)) {
|
6987 | var validParts = hostparts.slice(0, i);
|
6988 | var notHost = hostparts.slice(i + 1);
|
6989 | var bit = part.match(hostnamePartStart);
|
6990 | if (bit) {
|
6991 | validParts.push(bit[1]);
|
6992 | notHost.unshift(bit[2]);
|
6993 | }
|
6994 | if (notHost.length) {
|
6995 | rest = '/' + notHost.join('.') + rest;
|
6996 | }
|
6997 | this.hostname = validParts.join('.');
|
6998 | break;
|
6999 | }
|
7000 | }
|
7001 | }
|
7002 | }
|
7003 |
|
7004 | if (this.hostname.length > hostnameMaxLen) {
|
7005 | this.hostname = '';
|
7006 | } else {
|
7007 |
|
7008 | this.hostname = this.hostname.toLowerCase();
|
7009 | }
|
7010 |
|
7011 | if (!ipv6Hostname) {
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 | var domainArray = this.hostname.split('.');
|
7017 | var newOut = [];
|
7018 | for (var i = 0; i < domainArray.length; ++i) {
|
7019 | var s = domainArray[i];
|
7020 | newOut.push(s.match(/[^A-Za-z0-9_-]/) ?
|
7021 | 'xn--' + punycode.encode(s) : s);
|
7022 | }
|
7023 | this.hostname = newOut.join('.');
|
7024 | }
|
7025 |
|
7026 | var p = this.port ? ':' + this.port : '';
|
7027 | var h = this.hostname || '';
|
7028 | this.host = h + p;
|
7029 | this.href += this.host;
|
7030 |
|
7031 |
|
7032 |
|
7033 | if (ipv6Hostname) {
|
7034 | this.hostname = this.hostname.substr(1, this.hostname.length - 2);
|
7035 | if (rest[0] !== '/') {
|
7036 | rest = '/' + rest;
|
7037 | }
|
7038 | }
|
7039 | }
|
7040 |
|
7041 |
|
7042 |
|
7043 | if (!unsafeProtocol[lowerProto]) {
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 | for (var i = 0, l = autoEscape.length; i < l; i++) {
|
7049 | var ae = autoEscape[i];
|
7050 | var esc = encodeURIComponent(ae);
|
7051 | if (esc === ae) {
|
7052 | esc = escape(ae);
|
7053 | }
|
7054 | rest = rest.split(ae).join(esc);
|
7055 | }
|
7056 | }
|
7057 |
|
7058 |
|
7059 |
|
7060 | var hash = rest.indexOf('#');
|
7061 | if (hash !== -1) {
|
7062 |
|
7063 | this.hash = rest.substr(hash);
|
7064 | rest = rest.slice(0, hash);
|
7065 | }
|
7066 | var qm = rest.indexOf('?');
|
7067 | if (qm !== -1) {
|
7068 | this.search = rest.substr(qm);
|
7069 | this.query = rest.substr(qm + 1);
|
7070 | if (parseQueryString) {
|
7071 | this.query = querystring.parse(this.query);
|
7072 | }
|
7073 | rest = rest.slice(0, qm);
|
7074 | } else if (parseQueryString) {
|
7075 |
|
7076 | this.search = '';
|
7077 | this.query = {};
|
7078 | }
|
7079 | if (rest) this.pathname = rest;
|
7080 | if (slashedProtocol[lowerProto] &&
|
7081 | this.hostname && !this.pathname) {
|
7082 | this.pathname = '/';
|
7083 | }
|
7084 |
|
7085 |
|
7086 | if (this.pathname || this.search) {
|
7087 | var p = this.pathname || '';
|
7088 | var s = this.search || '';
|
7089 | this.path = p + s;
|
7090 | }
|
7091 |
|
7092 |
|
7093 | this.href = this.format();
|
7094 | return this;
|
7095 | };
|
7096 |
|
7097 |
|
7098 | function urlFormat(obj) {
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 | if (isString(obj)) obj = urlParse(obj);
|
7104 | if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
|
7105 | return obj.format();
|
7106 | }
|
7107 |
|
7108 | Url.prototype.format = function() {
|
7109 | var auth = this.auth || '';
|
7110 | if (auth) {
|
7111 | auth = encodeURIComponent(auth);
|
7112 | auth = auth.replace(/%3A/i, ':');
|
7113 | auth += '@';
|
7114 | }
|
7115 |
|
7116 | var protocol = this.protocol || '',
|
7117 | pathname = this.pathname || '',
|
7118 | hash = this.hash || '',
|
7119 | host = false,
|
7120 | query = '';
|
7121 |
|
7122 | if (this.host) {
|
7123 | host = auth + this.host;
|
7124 | } else if (this.hostname) {
|
7125 | host = auth + (this.hostname.indexOf(':') === -1 ?
|
7126 | this.hostname :
|
7127 | '[' + this.hostname + ']');
|
7128 | if (this.port) {
|
7129 | host += ':' + this.port;
|
7130 | }
|
7131 | }
|
7132 |
|
7133 | if (this.query &&
|
7134 | isObject(this.query) &&
|
7135 | Object.keys(this.query).length) {
|
7136 | query = querystring.stringify(this.query);
|
7137 | }
|
7138 |
|
7139 | var search = this.search || (query && ('?' + query)) || '';
|
7140 |
|
7141 | if (protocol && protocol.substr(-1) !== ':') protocol += ':';
|
7142 |
|
7143 |
|
7144 |
|
7145 | if (this.slashes ||
|
7146 | (!protocol || slashedProtocol[protocol]) && host !== false) {
|
7147 | host = '//' + (host || '');
|
7148 | if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
|
7149 | } else if (!host) {
|
7150 | host = '';
|
7151 | }
|
7152 |
|
7153 | if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
|
7154 | if (search && search.charAt(0) !== '?') search = '?' + search;
|
7155 |
|
7156 | pathname = pathname.replace(/[?#]/g, function(match) {
|
7157 | return encodeURIComponent(match);
|
7158 | });
|
7159 | search = search.replace('#', '%23');
|
7160 |
|
7161 | return protocol + host + pathname + search + hash;
|
7162 | };
|
7163 |
|
7164 | function urlResolve(source, relative) {
|
7165 | return urlParse(source, false, true).resolve(relative);
|
7166 | }
|
7167 |
|
7168 | Url.prototype.resolve = function(relative) {
|
7169 | return this.resolveObject(urlParse(relative, false, true)).format();
|
7170 | };
|
7171 |
|
7172 | function urlResolveObject(source, relative) {
|
7173 | if (!source) return relative;
|
7174 | return urlParse(source, false, true).resolveObject(relative);
|
7175 | }
|
7176 |
|
7177 | Url.prototype.resolveObject = function(relative) {
|
7178 | if (isString(relative)) {
|
7179 | var rel = new Url();
|
7180 | rel.parse(relative, false, true);
|
7181 | relative = rel;
|
7182 | }
|
7183 |
|
7184 | var result = new Url();
|
7185 | Object.keys(this).forEach(function(k) {
|
7186 | result[k] = this[k];
|
7187 | }, this);
|
7188 |
|
7189 |
|
7190 |
|
7191 | result.hash = relative.hash;
|
7192 |
|
7193 |
|
7194 | if (relative.href === '') {
|
7195 | result.href = result.format();
|
7196 | return result;
|
7197 | }
|
7198 |
|
7199 |
|
7200 | if (relative.slashes && !relative.protocol) {
|
7201 |
|
7202 | Object.keys(relative).forEach(function(k) {
|
7203 | if (k !== 'protocol')
|
7204 | result[k] = relative[k];
|
7205 | });
|
7206 |
|
7207 |
|
7208 | if (slashedProtocol[result.protocol] &&
|
7209 | result.hostname && !result.pathname) {
|
7210 | result.path = result.pathname = '/';
|
7211 | }
|
7212 |
|
7213 | result.href = result.format();
|
7214 | return result;
|
7215 | }
|
7216 |
|
7217 | if (relative.protocol && relative.protocol !== result.protocol) {
|
7218 |
|
7219 |
|
7220 |
|
7221 |
|
7222 |
|
7223 |
|
7224 |
|
7225 |
|
7226 | if (!slashedProtocol[relative.protocol]) {
|
7227 | Object.keys(relative).forEach(function(k) {
|
7228 | result[k] = relative[k];
|
7229 | });
|
7230 | result.href = result.format();
|
7231 | return result;
|
7232 | }
|
7233 |
|
7234 | result.protocol = relative.protocol;
|
7235 | if (!relative.host && !hostlessProtocol[relative.protocol]) {
|
7236 | var relPath = (relative.pathname || '').split('/');
|
7237 | while (relPath.length && !(relative.host = relPath.shift()));
|
7238 | if (!relative.host) relative.host = '';
|
7239 | if (!relative.hostname) relative.hostname = '';
|
7240 | if (relPath[0] !== '') relPath.unshift('');
|
7241 | if (relPath.length < 2) relPath.unshift('');
|
7242 | result.pathname = relPath.join('/');
|
7243 | } else {
|
7244 | result.pathname = relative.pathname;
|
7245 | }
|
7246 | result.search = relative.search;
|
7247 | result.query = relative.query;
|
7248 | result.host = relative.host || '';
|
7249 | result.auth = relative.auth;
|
7250 | result.hostname = relative.hostname || relative.host;
|
7251 | result.port = relative.port;
|
7252 |
|
7253 | if (result.pathname || result.search) {
|
7254 | var p = result.pathname || '';
|
7255 | var s = result.search || '';
|
7256 | result.path = p + s;
|
7257 | }
|
7258 | result.slashes = result.slashes || relative.slashes;
|
7259 | result.href = result.format();
|
7260 | return result;
|
7261 | }
|
7262 |
|
7263 | var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
|
7264 | isRelAbs = (
|
7265 | relative.host ||
|
7266 | relative.pathname && relative.pathname.charAt(0) === '/'
|
7267 | ),
|
7268 | mustEndAbs = (isRelAbs || isSourceAbs ||
|
7269 | (result.host && relative.pathname)),
|
7270 | removeAllDots = mustEndAbs,
|
7271 | srcPath = result.pathname && result.pathname.split('/') || [],
|
7272 | relPath = relative.pathname && relative.pathname.split('/') || [],
|
7273 | psychotic = result.protocol && !slashedProtocol[result.protocol];
|
7274 |
|
7275 |
|
7276 |
|
7277 |
|
7278 |
|
7279 |
|
7280 | if (psychotic) {
|
7281 | result.hostname = '';
|
7282 | result.port = null;
|
7283 | if (result.host) {
|
7284 | if (srcPath[0] === '') srcPath[0] = result.host;
|
7285 | else srcPath.unshift(result.host);
|
7286 | }
|
7287 | result.host = '';
|
7288 | if (relative.protocol) {
|
7289 | relative.hostname = null;
|
7290 | relative.port = null;
|
7291 | if (relative.host) {
|
7292 | if (relPath[0] === '') relPath[0] = relative.host;
|
7293 | else relPath.unshift(relative.host);
|
7294 | }
|
7295 | relative.host = null;
|
7296 | }
|
7297 | mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
|
7298 | }
|
7299 |
|
7300 | if (isRelAbs) {
|
7301 |
|
7302 | result.host = (relative.host || relative.host === '') ?
|
7303 | relative.host : result.host;
|
7304 | result.hostname = (relative.hostname || relative.hostname === '') ?
|
7305 | relative.hostname : result.hostname;
|
7306 | result.search = relative.search;
|
7307 | result.query = relative.query;
|
7308 | srcPath = relPath;
|
7309 |
|
7310 | } else if (relPath.length) {
|
7311 |
|
7312 |
|
7313 | if (!srcPath) srcPath = [];
|
7314 | srcPath.pop();
|
7315 | srcPath = srcPath.concat(relPath);
|
7316 | result.search = relative.search;
|
7317 | result.query = relative.query;
|
7318 | } else if (!isNullOrUndefined(relative.search)) {
|
7319 |
|
7320 |
|
7321 |
|
7322 | if (psychotic) {
|
7323 | result.hostname = result.host = srcPath.shift();
|
7324 |
|
7325 |
|
7326 |
|
7327 | var authInHost = result.host && result.host.indexOf('@') > 0 ?
|
7328 | result.host.split('@') : false;
|
7329 | if (authInHost) {
|
7330 | result.auth = authInHost.shift();
|
7331 | result.host = result.hostname = authInHost.shift();
|
7332 | }
|
7333 | }
|
7334 | result.search = relative.search;
|
7335 | result.query = relative.query;
|
7336 |
|
7337 | if (!isNull(result.pathname) || !isNull(result.search)) {
|
7338 | result.path = (result.pathname ? result.pathname : '') +
|
7339 | (result.search ? result.search : '');
|
7340 | }
|
7341 | result.href = result.format();
|
7342 | return result;
|
7343 | }
|
7344 |
|
7345 | if (!srcPath.length) {
|
7346 |
|
7347 |
|
7348 | result.pathname = null;
|
7349 |
|
7350 | if (result.search) {
|
7351 | result.path = '/' + result.search;
|
7352 | } else {
|
7353 | result.path = null;
|
7354 | }
|
7355 | result.href = result.format();
|
7356 | return result;
|
7357 | }
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 | var last = srcPath.slice(-1)[0];
|
7363 | var hasTrailingSlash = (
|
7364 | (result.host || relative.host) && (last === '.' || last === '..') ||
|
7365 | last === '');
|
7366 |
|
7367 |
|
7368 |
|
7369 | var up = 0;
|
7370 | for (var i = srcPath.length; i >= 0; i--) {
|
7371 | last = srcPath[i];
|
7372 | if (last == '.') {
|
7373 | srcPath.splice(i, 1);
|
7374 | } else if (last === '..') {
|
7375 | srcPath.splice(i, 1);
|
7376 | up++;
|
7377 | } else if (up) {
|
7378 | srcPath.splice(i, 1);
|
7379 | up--;
|
7380 | }
|
7381 | }
|
7382 |
|
7383 |
|
7384 | if (!mustEndAbs && !removeAllDots) {
|
7385 | for (; up--; up) {
|
7386 | srcPath.unshift('..');
|
7387 | }
|
7388 | }
|
7389 |
|
7390 | if (mustEndAbs && srcPath[0] !== '' &&
|
7391 | (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
|
7392 | srcPath.unshift('');
|
7393 | }
|
7394 |
|
7395 | if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
|
7396 | srcPath.push('');
|
7397 | }
|
7398 |
|
7399 | var isAbsolute = srcPath[0] === '' ||
|
7400 | (srcPath[0] && srcPath[0].charAt(0) === '/');
|
7401 |
|
7402 |
|
7403 | if (psychotic) {
|
7404 | result.hostname = result.host = isAbsolute ? '' :
|
7405 | srcPath.length ? srcPath.shift() : '';
|
7406 |
|
7407 |
|
7408 |
|
7409 | var authInHost = result.host && result.host.indexOf('@') > 0 ?
|
7410 | result.host.split('@') : false;
|
7411 | if (authInHost) {
|
7412 | result.auth = authInHost.shift();
|
7413 | result.host = result.hostname = authInHost.shift();
|
7414 | }
|
7415 | }
|
7416 |
|
7417 | mustEndAbs = mustEndAbs || (result.host && srcPath.length);
|
7418 |
|
7419 | if (mustEndAbs && !isAbsolute) {
|
7420 | srcPath.unshift('');
|
7421 | }
|
7422 |
|
7423 | if (!srcPath.length) {
|
7424 | result.pathname = null;
|
7425 | result.path = null;
|
7426 | } else {
|
7427 | result.pathname = srcPath.join('/');
|
7428 | }
|
7429 |
|
7430 |
|
7431 | if (!isNull(result.pathname) || !isNull(result.search)) {
|
7432 | result.path = (result.pathname ? result.pathname : '') +
|
7433 | (result.search ? result.search : '');
|
7434 | }
|
7435 | result.auth = relative.auth || result.auth;
|
7436 | result.slashes = result.slashes || relative.slashes;
|
7437 | result.href = result.format();
|
7438 | return result;
|
7439 | };
|
7440 |
|
7441 | Url.prototype.parseHost = function() {
|
7442 | var host = this.host;
|
7443 | var port = portPattern.exec(host);
|
7444 | if (port) {
|
7445 | port = port[0];
|
7446 | if (port !== ':') {
|
7447 | this.port = port.substr(1);
|
7448 | }
|
7449 | host = host.substr(0, host.length - port.length);
|
7450 | }
|
7451 | if (host) this.hostname = host;
|
7452 | };
|
7453 |
|
7454 | function isString(arg) {
|
7455 | return typeof arg === "string";
|
7456 | }
|
7457 |
|
7458 | function isObject(arg) {
|
7459 | return typeof arg === 'object' && arg !== null;
|
7460 | }
|
7461 |
|
7462 | function isNull(arg) {
|
7463 | return arg === null;
|
7464 | }
|
7465 | function isNullOrUndefined(arg) {
|
7466 | return arg == null;
|
7467 | }
|
7468 |
|
7469 | },{"punycode":32,"querystring":35}],50:[function(require,module,exports){
|
7470 | module.exports = function isBuffer(arg) {
|
7471 | return arg && typeof arg === 'object'
|
7472 | && typeof arg.copy === 'function'
|
7473 | && typeof arg.fill === 'function'
|
7474 | && typeof arg.readUInt8 === 'function';
|
7475 | }
|
7476 | },{}],51:[function(require,module,exports){
|
7477 | (function (process,global){
|
7478 |
|
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 |
|
7485 |
|
7486 |
|
7487 |
|
7488 |
|
7489 |
|
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 |
|
7498 |
|
7499 | var formatRegExp = /%[sdj%]/g;
|
7500 | exports.format = function(f) {
|
7501 | if (!isString(f)) {
|
7502 | var objects = [];
|
7503 | for (var i = 0; i < arguments.length; i++) {
|
7504 | objects.push(inspect(arguments[i]));
|
7505 | }
|
7506 | return objects.join(' ');
|
7507 | }
|
7508 |
|
7509 | var i = 1;
|
7510 | var args = arguments;
|
7511 | var len = args.length;
|
7512 | var str = String(f).replace(formatRegExp, function(x) {
|
7513 | if (x === '%%') return '%';
|
7514 | if (i >= len) return x;
|
7515 | switch (x) {
|
7516 | case '%s': return String(args[i++]);
|
7517 | case '%d': return Number(args[i++]);
|
7518 | case '%j':
|
7519 | try {
|
7520 | return JSON.stringify(args[i++]);
|
7521 | } catch (_) {
|
7522 | return '[Circular]';
|
7523 | }
|
7524 | default:
|
7525 | return x;
|
7526 | }
|
7527 | });
|
7528 | for (var x = args[i]; i < len; x = args[++i]) {
|
7529 | if (isNull(x) || !isObject(x)) {
|
7530 | str += ' ' + x;
|
7531 | } else {
|
7532 | str += ' ' + inspect(x);
|
7533 | }
|
7534 | }
|
7535 | return str;
|
7536 | };
|
7537 |
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 | exports.deprecate = function(fn, msg) {
|
7543 |
|
7544 | if (isUndefined(global.process)) {
|
7545 | return function() {
|
7546 | return exports.deprecate(fn, msg).apply(this, arguments);
|
7547 | };
|
7548 | }
|
7549 |
|
7550 | if (process.noDeprecation === true) {
|
7551 | return fn;
|
7552 | }
|
7553 |
|
7554 | var warned = false;
|
7555 | function deprecated() {
|
7556 | if (!warned) {
|
7557 | if (process.throwDeprecation) {
|
7558 | throw new Error(msg);
|
7559 | } else if (process.traceDeprecation) {
|
7560 | console.trace(msg);
|
7561 | } else {
|
7562 | console.error(msg);
|
7563 | }
|
7564 | warned = true;
|
7565 | }
|
7566 | return fn.apply(this, arguments);
|
7567 | }
|
7568 |
|
7569 | return deprecated;
|
7570 | };
|
7571 |
|
7572 |
|
7573 | var debugs = {};
|
7574 | var debugEnviron;
|
7575 | exports.debuglog = function(set) {
|
7576 | if (isUndefined(debugEnviron))
|
7577 | debugEnviron = process.env.NODE_DEBUG || '';
|
7578 | set = set.toUpperCase();
|
7579 | if (!debugs[set]) {
|
7580 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
7581 | var pid = process.pid;
|
7582 | debugs[set] = function() {
|
7583 | var msg = exports.format.apply(exports, arguments);
|
7584 | console.error('%s %d: %s', set, pid, msg);
|
7585 | };
|
7586 | } else {
|
7587 | debugs[set] = function() {};
|
7588 | }
|
7589 | }
|
7590 | return debugs[set];
|
7591 | };
|
7592 |
|
7593 |
|
7594 | /**
|
7595 | * Echos the value of a value. Trys to print the value out
|
7596 | * in the best way possible given the different types.
|
7597 | *
|
7598 | * @param {Object} obj The object to print out.
|
7599 | * @param {Object} opts Optional options object that alters the output.
|
7600 | */
|
7601 |
|
7602 | function inspect(obj, opts) {
|
7603 |
|
7604 | var ctx = {
|
7605 | seen: [],
|
7606 | stylize: stylizeNoColor
|
7607 | };
|
7608 |
|
7609 | if (arguments.length >= 3) ctx.depth = arguments[2];
|
7610 | if (arguments.length >= 4) ctx.colors = arguments[3];
|
7611 | if (isBoolean(opts)) {
|
7612 |
|
7613 | ctx.showHidden = opts;
|
7614 | } else if (opts) {
|
7615 |
|
7616 | exports._extend(ctx, opts);
|
7617 | }
|
7618 |
|
7619 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
7620 | if (isUndefined(ctx.depth)) ctx.depth = 2;
|
7621 | if (isUndefined(ctx.colors)) ctx.colors = false;
|
7622 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
7623 | if (ctx.colors) ctx.stylize = stylizeWithColor;
|
7624 | return formatValue(ctx, obj, ctx.depth);
|
7625 | }
|
7626 | exports.inspect = inspect;
|
7627 |
|
7628 |
|
7629 |
|
7630 | inspect.colors = {
|
7631 | 'bold' : [1, 22],
|
7632 | 'italic' : [3, 23],
|
7633 | 'underline' : [4, 24],
|
7634 | 'inverse' : [7, 27],
|
7635 | 'white' : [37, 39],
|
7636 | 'grey' : [90, 39],
|
7637 | 'black' : [30, 39],
|
7638 | 'blue' : [34, 39],
|
7639 | 'cyan' : [36, 39],
|
7640 | 'green' : [32, 39],
|
7641 | 'magenta' : [35, 39],
|
7642 | 'red' : [31, 39],
|
7643 | 'yellow' : [33, 39]
|
7644 | };
|
7645 |
|
7646 |
|
7647 | inspect.styles = {
|
7648 | 'special': 'cyan',
|
7649 | 'number': 'yellow',
|
7650 | 'boolean': 'yellow',
|
7651 | 'undefined': 'grey',
|
7652 | 'null': 'bold',
|
7653 | 'string': 'green',
|
7654 | 'date': 'magenta',
|
7655 |
|
7656 | 'regexp': 'red'
|
7657 | };
|
7658 |
|
7659 |
|
7660 | function stylizeWithColor(str, styleType) {
|
7661 | var style = inspect.styles[styleType];
|
7662 |
|
7663 | if (style) {
|
7664 | return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
7665 | '\u001b[' + inspect.colors[style][1] + 'm';
|
7666 | } else {
|
7667 | return str;
|
7668 | }
|
7669 | }
|
7670 |
|
7671 |
|
7672 | function stylizeNoColor(str, styleType) {
|
7673 | return str;
|
7674 | }
|
7675 |
|
7676 |
|
7677 | function arrayToHash(array) {
|
7678 | var hash = {};
|
7679 |
|
7680 | array.forEach(function(val, idx) {
|
7681 | hash[val] = true;
|
7682 | });
|
7683 |
|
7684 | return hash;
|
7685 | }
|
7686 |
|
7687 |
|
7688 | function formatValue(ctx, value, recurseTimes) {
|
7689 |
|
7690 |
|
7691 | if (ctx.customInspect &&
|
7692 | value &&
|
7693 | isFunction(value.inspect) &&
|
7694 |
|
7695 | value.inspect !== exports.inspect &&
|
7696 |
|
7697 | !(value.constructor && value.constructor.prototype === value)) {
|
7698 | var ret = value.inspect(recurseTimes, ctx);
|
7699 | if (!isString(ret)) {
|
7700 | ret = formatValue(ctx, ret, recurseTimes);
|
7701 | }
|
7702 | return ret;
|
7703 | }
|
7704 |
|
7705 |
|
7706 | var primitive = formatPrimitive(ctx, value);
|
7707 | if (primitive) {
|
7708 | return primitive;
|
7709 | }
|
7710 |
|
7711 |
|
7712 | var keys = Object.keys(value);
|
7713 | var visibleKeys = arrayToHash(keys);
|
7714 |
|
7715 | if (ctx.showHidden) {
|
7716 | keys = Object.getOwnPropertyNames(value);
|
7717 | }
|
7718 |
|
7719 |
|
7720 |
|
7721 | if (isError(value)
|
7722 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
7723 | return formatError(value);
|
7724 | }
|
7725 |
|
7726 |
|
7727 | if (keys.length === 0) {
|
7728 | if (isFunction(value)) {
|
7729 | var name = value.name ? ': ' + value.name : '';
|
7730 | return ctx.stylize('[Function' + name + ']', 'special');
|
7731 | }
|
7732 | if (isRegExp(value)) {
|
7733 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
7734 | }
|
7735 | if (isDate(value)) {
|
7736 | return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
7737 | }
|
7738 | if (isError(value)) {
|
7739 | return formatError(value);
|
7740 | }
|
7741 | }
|
7742 |
|
7743 | var base = '', array = false, braces = ['{', '}'];
|
7744 |
|
7745 |
|
7746 | if (isArray(value)) {
|
7747 | array = true;
|
7748 | braces = ['[', ']'];
|
7749 | }
|
7750 |
|
7751 |
|
7752 | if (isFunction(value)) {
|
7753 | var n = value.name ? ': ' + value.name : '';
|
7754 | base = ' [Function' + n + ']';
|
7755 | }
|
7756 |
|
7757 |
|
7758 | if (isRegExp(value)) {
|
7759 | base = ' ' + RegExp.prototype.toString.call(value);
|
7760 | }
|
7761 |
|
7762 |
|
7763 | if (isDate(value)) {
|
7764 | base = ' ' + Date.prototype.toUTCString.call(value);
|
7765 | }
|
7766 |
|
7767 |
|
7768 | if (isError(value)) {
|
7769 | base = ' ' + formatError(value);
|
7770 | }
|
7771 |
|
7772 | if (keys.length === 0 && (!array || value.length == 0)) {
|
7773 | return braces[0] + base + braces[1];
|
7774 | }
|
7775 |
|
7776 | if (recurseTimes < 0) {
|
7777 | if (isRegExp(value)) {
|
7778 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
7779 | } else {
|
7780 | return ctx.stylize('[Object]', 'special');
|
7781 | }
|
7782 | }
|
7783 |
|
7784 | ctx.seen.push(value);
|
7785 |
|
7786 | var output;
|
7787 | if (array) {
|
7788 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
7789 | } else {
|
7790 | output = keys.map(function(key) {
|
7791 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
7792 | });
|
7793 | }
|
7794 |
|
7795 | ctx.seen.pop();
|
7796 |
|
7797 | return reduceToSingleString(output, base, braces);
|
7798 | }
|
7799 |
|
7800 |
|
7801 | function formatPrimitive(ctx, value) {
|
7802 | if (isUndefined(value))
|
7803 | return ctx.stylize('undefined', 'undefined');
|
7804 | if (isString(value)) {
|
7805 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
7806 | .replace(/'/g, "\\'")
|
7807 | .replace(/\\"/g, '"') + '\'';
|
7808 | return ctx.stylize(simple, 'string');
|
7809 | }
|
7810 | if (isNumber(value))
|
7811 | return ctx.stylize('' + value, 'number');
|
7812 | if (isBoolean(value))
|
7813 | return ctx.stylize('' + value, 'boolean');
|
7814 |
|
7815 | if (isNull(value))
|
7816 | return ctx.stylize('null', 'null');
|
7817 | }
|
7818 |
|
7819 |
|
7820 | function formatError(value) {
|
7821 | return '[' + Error.prototype.toString.call(value) + ']';
|
7822 | }
|
7823 |
|
7824 |
|
7825 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
7826 | var output = [];
|
7827 | for (var i = 0, l = value.length; i < l; ++i) {
|
7828 | if (hasOwnProperty(value, String(i))) {
|
7829 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
7830 | String(i), true));
|
7831 | } else {
|
7832 | output.push('');
|
7833 | }
|
7834 | }
|
7835 | keys.forEach(function(key) {
|
7836 | if (!key.match(/^\d+$/)) {
|
7837 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
7838 | key, true));
|
7839 | }
|
7840 | });
|
7841 | return output;
|
7842 | }
|
7843 |
|
7844 |
|
7845 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
7846 | var name, str, desc;
|
7847 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
7848 | if (desc.get) {
|
7849 | if (desc.set) {
|
7850 | str = ctx.stylize('[Getter/Setter]', 'special');
|
7851 | } else {
|
7852 | str = ctx.stylize('[Getter]', 'special');
|
7853 | }
|
7854 | } else {
|
7855 | if (desc.set) {
|
7856 | str = ctx.stylize('[Setter]', 'special');
|
7857 | }
|
7858 | }
|
7859 | if (!hasOwnProperty(visibleKeys, key)) {
|
7860 | name = '[' + key + ']';
|
7861 | }
|
7862 | if (!str) {
|
7863 | if (ctx.seen.indexOf(desc.value) < 0) {
|
7864 | if (isNull(recurseTimes)) {
|
7865 | str = formatValue(ctx, desc.value, null);
|
7866 | } else {
|
7867 | str = formatValue(ctx, desc.value, recurseTimes - 1);
|
7868 | }
|
7869 | if (str.indexOf('\n') > -1) {
|
7870 | if (array) {
|
7871 | str = str.split('\n').map(function(line) {
|
7872 | return ' ' + line;
|
7873 | }).join('\n').substr(2);
|
7874 | } else {
|
7875 | str = '\n' + str.split('\n').map(function(line) {
|
7876 | return ' ' + line;
|
7877 | }).join('\n');
|
7878 | }
|
7879 | }
|
7880 | } else {
|
7881 | str = ctx.stylize('[Circular]', 'special');
|
7882 | }
|
7883 | }
|
7884 | if (isUndefined(name)) {
|
7885 | if (array && key.match(/^\d+$/)) {
|
7886 | return str;
|
7887 | }
|
7888 | name = JSON.stringify('' + key);
|
7889 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
7890 | name = name.substr(1, name.length - 2);
|
7891 | name = ctx.stylize(name, 'name');
|
7892 | } else {
|
7893 | name = name.replace(/'/g, "\\'")
|
7894 | .replace(/\\"/g, '"')
|
7895 | .replace(/(^"|"$)/g, "'");
|
7896 | name = ctx.stylize(name, 'string');
|
7897 | }
|
7898 | }
|
7899 |
|
7900 | return name + ': ' + str;
|
7901 | }
|
7902 |
|
7903 |
|
7904 | function reduceToSingleString(output, base, braces) {
|
7905 | var numLinesEst = 0;
|
7906 | var length = output.reduce(function(prev, cur) {
|
7907 | numLinesEst++;
|
7908 | if (cur.indexOf('\n') >= 0) numLinesEst++;
|
7909 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
7910 | }, 0);
|
7911 |
|
7912 | if (length > 60) {
|
7913 | return braces[0] +
|
7914 | (base === '' ? '' : base + '\n ') +
|
7915 | ' ' +
|
7916 | output.join(',\n ') +
|
7917 | ' ' +
|
7918 | braces[1];
|
7919 | }
|
7920 |
|
7921 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
7922 | }
|
7923 |
|
7924 |
|
7925 |
|
7926 |
|
7927 | function isArray(ar) {
|
7928 | return Array.isArray(ar);
|
7929 | }
|
7930 | exports.isArray = isArray;
|
7931 |
|
7932 | function isBoolean(arg) {
|
7933 | return typeof arg === 'boolean';
|
7934 | }
|
7935 | exports.isBoolean = isBoolean;
|
7936 |
|
7937 | function isNull(arg) {
|
7938 | return arg === null;
|
7939 | }
|
7940 | exports.isNull = isNull;
|
7941 |
|
7942 | function isNullOrUndefined(arg) {
|
7943 | return arg == null;
|
7944 | }
|
7945 | exports.isNullOrUndefined = isNullOrUndefined;
|
7946 |
|
7947 | function isNumber(arg) {
|
7948 | return typeof arg === 'number';
|
7949 | }
|
7950 | exports.isNumber = isNumber;
|
7951 |
|
7952 | function isString(arg) {
|
7953 | return typeof arg === 'string';
|
7954 | }
|
7955 | exports.isString = isString;
|
7956 |
|
7957 | function isSymbol(arg) {
|
7958 | return typeof arg === 'symbol';
|
7959 | }
|
7960 | exports.isSymbol = isSymbol;
|
7961 |
|
7962 | function isUndefined(arg) {
|
7963 | return arg === void 0;
|
7964 | }
|
7965 | exports.isUndefined = isUndefined;
|
7966 |
|
7967 | function isRegExp(re) {
|
7968 | return isObject(re) && objectToString(re) === '[object RegExp]';
|
7969 | }
|
7970 | exports.isRegExp = isRegExp;
|
7971 |
|
7972 | function isObject(arg) {
|
7973 | return typeof arg === 'object' && arg !== null;
|
7974 | }
|
7975 | exports.isObject = isObject;
|
7976 |
|
7977 | function isDate(d) {
|
7978 | return isObject(d) && objectToString(d) === '[object Date]';
|
7979 | }
|
7980 | exports.isDate = isDate;
|
7981 |
|
7982 | function isError(e) {
|
7983 | return isObject(e) &&
|
7984 | (objectToString(e) === '[object Error]' || e instanceof Error);
|
7985 | }
|
7986 | exports.isError = isError;
|
7987 |
|
7988 | function isFunction(arg) {
|
7989 | return typeof arg === 'function';
|
7990 | }
|
7991 | exports.isFunction = isFunction;
|
7992 |
|
7993 | function isPrimitive(arg) {
|
7994 | return arg === null ||
|
7995 | typeof arg === 'boolean' ||
|
7996 | typeof arg === 'number' ||
|
7997 | typeof arg === 'string' ||
|
7998 | typeof arg === 'symbol' ||
|
7999 | typeof arg === 'undefined';
|
8000 | }
|
8001 | exports.isPrimitive = isPrimitive;
|
8002 |
|
8003 | exports.isBuffer = require('./support/isBuffer');
|
8004 |
|
8005 | function objectToString(o) {
|
8006 | return Object.prototype.toString.call(o);
|
8007 | }
|
8008 |
|
8009 |
|
8010 | function pad(n) {
|
8011 | return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
8012 | }
|
8013 |
|
8014 |
|
8015 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
8016 | 'Oct', 'Nov', 'Dec'];
|
8017 |
|
8018 |
|
8019 | function timestamp() {
|
8020 | var d = new Date();
|
8021 | var time = [pad(d.getHours()),
|
8022 | pad(d.getMinutes()),
|
8023 | pad(d.getSeconds())].join(':');
|
8024 | return [d.getDate(), months[d.getMonth()], time].join(' ');
|
8025 | }
|
8026 |
|
8027 |
|
8028 |
|
8029 | exports.log = function() {
|
8030 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
8031 | };
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 |
|
8038 |
|
8039 |
|
8040 |
|
8041 |
|
8042 |
|
8043 |
|
8044 |
|
8045 |
|
8046 |
|
8047 | exports.inherits = require('inherits');
|
8048 |
|
8049 | exports._extend = function(origin, add) {
|
8050 |
|
8051 | if (!add || !isObject(add)) return origin;
|
8052 |
|
8053 | var keys = Object.keys(add);
|
8054 | var i = keys.length;
|
8055 | while (i--) {
|
8056 | origin[keys[i]] = add[keys[i]];
|
8057 | }
|
8058 | return origin;
|
8059 | };
|
8060 |
|
8061 | function hasOwnProperty(obj, prop) {
|
8062 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
8063 | }
|
8064 |
|
8065 | }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
8066 | },{"./support/isBuffer":50,"_process":31,"inherits":28}],52:[function(require,module,exports){
|
8067 | module.exports = require('./lib/jjv.js');
|
8068 |
|
8069 | },{"./lib/jjv.js":53}],53:[function(require,module,exports){
|
8070 |
|
8071 |
|
8072 |
|
8073 |
|
8074 |
|
8075 |
|
8076 |
|
8077 |
|
8078 |
|
8079 |
|
8080 | (function () {
|
8081 | var clone = function (obj) {
|
8082 |
|
8083 | if (obj === null || typeof obj !== 'object') return obj;
|
8084 | var copy;
|
8085 |
|
8086 |
|
8087 | if (obj instanceof Date) {
|
8088 | copy = new Date();
|
8089 | copy.setTime(obj.getTime());
|
8090 | return copy;
|
8091 | }
|
8092 |
|
8093 |
|
8094 | if (obj instanceof RegExp) {
|
8095 | copy = new RegExp(obj);
|
8096 | return copy;
|
8097 | }
|
8098 |
|
8099 |
|
8100 | if (obj instanceof Array) {
|
8101 | copy = [];
|
8102 | for (var i = 0, len = obj.length; i < len; i++)
|
8103 | copy[i] = clone(obj[i]);
|
8104 | return copy;
|
8105 | }
|
8106 |
|
8107 |
|
8108 | if (obj instanceof Object) {
|
8109 | copy = {};
|
8110 |
|
8111 | for (var attr in obj) {
|
8112 | if (obj.hasOwnProperty(attr))
|
8113 | copy[attr] = clone(obj[attr]);
|
8114 | }
|
8115 | return copy;
|
8116 | }
|
8117 |
|
8118 | throw new Error("Unable to clone object!");
|
8119 | };
|
8120 |
|
8121 | var clone_stack = function (stack) {
|
8122 | var new_stack = [ clone(stack[0]) ], key = new_stack[0].key, obj = new_stack[0].object;
|
8123 | for (var i = 1, len = stack.length; i< len; i++) {
|
8124 | obj = obj[key];
|
8125 | key = stack[i].key;
|
8126 | new_stack.push({ object: obj, key: key });
|
8127 | }
|
8128 | return new_stack;
|
8129 | };
|
8130 |
|
8131 | var copy_stack = function (new_stack, old_stack) {
|
8132 | var stack_last = new_stack.length-1, key = new_stack[stack_last].key;
|
8133 | old_stack[stack_last].object[key] = new_stack[stack_last].object[key];
|
8134 | };
|
8135 |
|
8136 | var handled = {
|
8137 | 'type': true,
|
8138 | 'not': true,
|
8139 | 'anyOf': true,
|
8140 | 'allOf': true,
|
8141 | 'oneOf': true,
|
8142 | '$ref': true,
|
8143 | '$schema': true,
|
8144 | 'id': true,
|
8145 | 'exclusiveMaximum': true,
|
8146 | 'exclusiveMininum': true,
|
8147 | 'properties': true,
|
8148 | 'patternProperties': true,
|
8149 | 'additionalProperties': true,
|
8150 | 'items': true,
|
8151 | 'additionalItems': true,
|
8152 | 'required': true,
|
8153 | 'default': true,
|
8154 | 'title': true,
|
8155 | 'description': true,
|
8156 | 'definitions': true,
|
8157 | 'dependencies': true
|
8158 | };
|
8159 |
|
8160 | var fieldType = {
|
8161 | 'null': function (x) {
|
8162 | return x === null;
|
8163 | },
|
8164 | 'string': function (x) {
|
8165 | return typeof x === 'string';
|
8166 | },
|
8167 | 'boolean': function (x) {
|
8168 | return typeof x === 'boolean';
|
8169 | },
|
8170 | 'number': function (x) {
|
8171 |
|
8172 | return typeof x === 'number' && x === x;
|
8173 | },
|
8174 | 'integer': function (x) {
|
8175 | return typeof x === 'number' && x%1 === 0;
|
8176 | },
|
8177 | 'object': function (x) {
|
8178 | return x && typeof x === 'object' && !Array.isArray(x);
|
8179 | },
|
8180 | 'array': function (x) {
|
8181 | return Array.isArray(x);
|
8182 | },
|
8183 | 'date': function (x) {
|
8184 | return x instanceof Date;
|
8185 | }
|
8186 | };
|
8187 |
|
8188 |
|
8189 | var fieldFormat = {
|
8190 | 'alpha': function (v) {
|
8191 | return (/^[a-zA-Z]+$/).test(v);
|
8192 | },
|
8193 | 'alphanumeric': function (v) {
|
8194 | return (/^[a-zA-Z0-9]+$/).test(v);
|
8195 | },
|
8196 | 'identifier': function (v) {
|
8197 | return (/^[-_a-zA-Z0-9]+$/).test(v);
|
8198 | },
|
8199 | 'hexadecimal': function (v) {
|
8200 | return (/^[a-fA-F0-9]+$/).test(v);
|
8201 | },
|
8202 | 'numeric': function (v) {
|
8203 | return (/^[0-9]+$/).test(v);
|
8204 | },
|
8205 | 'date-time': function (v) {
|
8206 | return !isNaN(Date.parse(v)) && v.indexOf('/') === -1;
|
8207 | },
|
8208 | 'uppercase': function (v) {
|
8209 | return v === v.toUpperCase();
|
8210 | },
|
8211 | 'lowercase': function (v) {
|
8212 | return v === v.toLowerCase();
|
8213 | },
|
8214 | 'hostname': function (v) {
|
8215 | return v.length < 256 && (/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/).test(v);
|
8216 | },
|
8217 | 'uri': function (v) {
|
8218 | return (/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/).test(v);
|
8219 | },
|
8220 | 'email': function (v) {
|
8221 | return (/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/).test(v);
|
8222 | },
|
8223 | 'ipv4': function (v) {
|
8224 | if ((/^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$/).test(v)) {
|
8225 | var parts = v.split('.').sort();
|
8226 | if (parts[3] <= 255)
|
8227 | return true;
|
8228 | }
|
8229 | return false;
|
8230 | },
|
8231 | 'ipv6': function(v) {
|
8232 | return (/^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/).test(v);
|
8233 |
|
8234 | }
|
8235 | };
|
8236 |
|
8237 | var fieldValidate = {
|
8238 | 'readOnly': function (v, p) {
|
8239 | return false;
|
8240 | },
|
8241 |
|
8242 | 'minimum': function (v, p, schema) {
|
8243 | return !(v < p || schema.exclusiveMinimum && v <= p);
|
8244 | },
|
8245 | 'maximum': function (v, p, schema) {
|
8246 | return !(v > p || schema.exclusiveMaximum && v >= p);
|
8247 | },
|
8248 | 'multipleOf': function (v, p) {
|
8249 | return (v/p)%1 === 0 || typeof v !== 'number';
|
8250 | },
|
8251 |
|
8252 | 'pattern': function (v, p) {
|
8253 | if (typeof v !== 'string')
|
8254 | return true;
|
8255 | var pattern, modifiers;
|
8256 | if (typeof p === 'string')
|
8257 | pattern=p;
|
8258 | else {
|
8259 | pattern=p[0];
|
8260 | modifiers=p[1];
|
8261 | }
|
8262 | var regex = new RegExp(pattern, modifiers);
|
8263 | return regex.test(v);
|
8264 | },
|
8265 | 'minLength': function (v, p) {
|
8266 | return v.length >= p || typeof v !== 'string';
|
8267 | },
|
8268 | 'maxLength': function (v, p) {
|
8269 | return v.length <= p || typeof v !== 'string';
|
8270 | },
|
8271 |
|
8272 | 'minItems': function (v, p) {
|
8273 | return v.length >= p || !Array.isArray(v);
|
8274 | },
|
8275 | 'maxItems': function (v, p) {
|
8276 | return v.length <= p || !Array.isArray(v);
|
8277 | },
|
8278 | 'uniqueItems': function (v, p) {
|
8279 | var hash = {}, key;
|
8280 | for (var i = 0, len = v.length; i < len; i++) {
|
8281 | key = JSON.stringify(v[i]);
|
8282 | if (hash.hasOwnProperty(key))
|
8283 | return false;
|
8284 | else
|
8285 | hash[key] = true;
|
8286 | }
|
8287 | return true;
|
8288 | },
|
8289 |
|
8290 | 'minProperties': function (v, p) {
|
8291 | if (typeof v !== 'object')
|
8292 | return true;
|
8293 | var count = 0;
|
8294 | for (var attr in v) if (v.hasOwnProperty(attr)) count = count + 1;
|
8295 | return count >= p;
|
8296 | },
|
8297 | 'maxProperties': function (v, p) {
|
8298 | if (typeof v !== 'object')
|
8299 | return true;
|
8300 | var count = 0;
|
8301 | for (var attr in v) if (v.hasOwnProperty(attr)) count = count + 1;
|
8302 | return count <= p;
|
8303 | },
|
8304 |
|
8305 | 'constant': function (v, p) {
|
8306 | return JSON.stringify(v) == JSON.stringify(p);
|
8307 | },
|
8308 | 'enum': function (v, p) {
|
8309 | var i, len, vs;
|
8310 | if (typeof v === 'object') {
|
8311 | vs = JSON.stringify(v);
|
8312 | for (i = 0, len = p.length; i < len; i++)
|
8313 | if (vs === JSON.stringify(p[i]))
|
8314 | return true;
|
8315 | } else {
|
8316 | for (i = 0, len = p.length; i < len; i++)
|
8317 | if (v === p[i])
|
8318 | return true;
|
8319 | }
|
8320 | return false;
|
8321 | }
|
8322 | };
|
8323 |
|
8324 | var normalizeID = function (id) {
|
8325 | return id.indexOf("://") === -1 ? id : id.split("#")[0];
|
8326 | };
|
8327 |
|
8328 | var resolveURI = function (env, schema_stack, uri) {
|
8329 | var curschema, components, hash_idx, name;
|
8330 |
|
8331 | hash_idx = uri.indexOf('#');
|
8332 |
|
8333 | if (hash_idx === -1) {
|
8334 | if (!env.schema.hasOwnProperty(uri))
|
8335 | return null;
|
8336 | return [env.schema[uri]];
|
8337 | }
|
8338 |
|
8339 | if (hash_idx > 0) {
|
8340 | name = uri.substr(0, hash_idx);
|
8341 | uri = uri.substr(hash_idx+1);
|
8342 | if (!env.schema.hasOwnProperty(name)) {
|
8343 | if (schema_stack && schema_stack[0].id === name)
|
8344 | schema_stack = [schema_stack[0]];
|
8345 | else
|
8346 | return null;
|
8347 | } else
|
8348 | schema_stack = [env.schema[name]];
|
8349 | } else {
|
8350 | if (!schema_stack)
|
8351 | return null;
|
8352 | uri = uri.substr(1);
|
8353 | }
|
8354 |
|
8355 | if (uri === '')
|
8356 | return [schema_stack[0]];
|
8357 |
|
8358 | if (uri.charAt(0) === '/') {
|
8359 | uri = uri.substr(1);
|
8360 | curschema = schema_stack[0];
|
8361 | components = uri.split('/');
|
8362 | while (components.length > 0) {
|
8363 | if (!curschema.hasOwnProperty(components[0]))
|
8364 | return null;
|
8365 | curschema = curschema[components[0]];
|
8366 | schema_stack.push(curschema);
|
8367 | components.shift();
|
8368 | }
|
8369 | return schema_stack;
|
8370 | } else
|
8371 | return null;
|
8372 | };
|
8373 |
|
8374 | var resolveObjectRef = function (object_stack, uri) {
|
8375 | var components, object, last_frame = object_stack.length-1, skip_frames, frame, m = /^(\d+)/.exec(uri);
|
8376 |
|
8377 | if (m) {
|
8378 | uri = uri.substr(m[0].length);
|
8379 | skip_frames = parseInt(m[1], 10);
|
8380 | if (skip_frames < 0 || skip_frames > last_frame)
|
8381 | return;
|
8382 | frame = object_stack[last_frame-skip_frames];
|
8383 | if (uri === '#')
|
8384 | return frame.key;
|
8385 | } else
|
8386 | frame = object_stack[0];
|
8387 |
|
8388 | object = frame.object[frame.key];
|
8389 |
|
8390 | if (uri === '')
|
8391 | return object;
|
8392 |
|
8393 | if (uri.charAt(0) === '/') {
|
8394 | uri = uri.substr(1);
|
8395 | components = uri.split('/');
|
8396 | while (components.length > 0) {
|
8397 | components[0] = components[0].replace(/~1/g, '/').replace(/~0/g, '~');
|
8398 | if (!object.hasOwnProperty(components[0]))
|
8399 | return;
|
8400 | object = object[components[0]];
|
8401 | components.shift();
|
8402 | }
|
8403 | return object;
|
8404 | } else
|
8405 | return;
|
8406 | };
|
8407 |
|
8408 | var checkValidity = function (env, schema_stack, object_stack, options) {
|
8409 | var i, len, count, hasProp, hasPattern;
|
8410 | var p, v, malformed = false, objerrs = {}, objerr, props, matched;
|
8411 | var sl = schema_stack.length-1, schema = schema_stack[sl], new_stack;
|
8412 | var ol = object_stack.length-1, object = object_stack[ol].object, name = object_stack[ol].key, prop = object[name];
|
8413 | var errCount, minErrCount;
|
8414 |
|
8415 | if (schema.hasOwnProperty('$ref')) {
|
8416 | schema_stack= resolveURI(env, schema_stack, schema.$ref);
|
8417 | if (!schema_stack)
|
8418 | return {'$ref': schema.$ref};
|
8419 | else
|
8420 | return checkValidity(env, schema_stack, object_stack, options);
|
8421 | }
|
8422 |
|
8423 | if (schema.hasOwnProperty('type')) {
|
8424 | if (typeof schema.type === 'string') {
|
8425 | if (options.useCoerce && env.coerceType.hasOwnProperty(schema.type))
|
8426 | prop = object[name] = env.coerceType[schema.type](prop);
|
8427 | if (!env.fieldType[schema.type](prop))
|
8428 | return {'type': schema.type};
|
8429 | } else {
|
8430 | malformed = true;
|
8431 | for (i = 0, len = schema.type.length; i < len && malformed; i++)
|
8432 | if (env.fieldType[schema.type[i]](prop))
|
8433 | malformed = false;
|
8434 | if (malformed)
|
8435 | return {'type': schema.type};
|
8436 | }
|
8437 | }
|
8438 |
|
8439 | if (schema.hasOwnProperty('allOf')) {
|
8440 | for (i = 0, len = schema.allOf.length; i < len; i++) {
|
8441 | objerr = checkValidity(env, schema_stack.concat(schema.allOf[i]), object_stack, options);
|
8442 | if (objerr)
|
8443 | return objerr;
|
8444 | }
|
8445 | }
|
8446 |
|
8447 | if (!options.useCoerce && !options.useDefault && !options.removeAdditional) {
|
8448 | if (schema.hasOwnProperty('oneOf')) {
|
8449 | minErrCount = Infinity;
|
8450 | for (i = 0, len = schema.oneOf.length, count = 0; i < len; i++) {
|
8451 | objerr = checkValidity(env, schema_stack.concat(schema.oneOf[i]), object_stack, options);
|
8452 | if (!objerr) {
|
8453 | count = count + 1;
|
8454 | if (count > 1)
|
8455 | break;
|
8456 | } else {
|
8457 | errCount = objerr.schema ? Object.keys(objerr.schema).length : 1;
|
8458 | if (errCount < minErrCount) {
|
8459 | minErrCount = errCount;
|
8460 | objerrs = objerr;
|
8461 | }
|
8462 | }
|
8463 | }
|
8464 | if (count > 1)
|
8465 | return {'oneOf': true};
|
8466 | else if (count < 1)
|
8467 | return objerrs;
|
8468 | objerrs = {};
|
8469 | }
|
8470 |
|
8471 | if (schema.hasOwnProperty('anyOf')) {
|
8472 | objerrs = null;
|
8473 | minErrCount = Infinity;
|
8474 | for (i = 0, len = schema.anyOf.length; i < len; i++) {
|
8475 | objerr = checkValidity(env, schema_stack.concat(schema.anyOf[i]), object_stack, options);
|
8476 | if (!objerr) {
|
8477 | objerrs = null;
|
8478 | break;
|
8479 | }
|
8480 | else {
|
8481 | errCount = objerr.schema ? Object.keys(objerr.schema).length : 1;
|
8482 | if (errCount < minErrCount) {
|
8483 | minErrCount = errCount;
|
8484 | objerrs = objerr;
|
8485 | }
|
8486 | }
|
8487 | }
|
8488 | if (objerrs)
|
8489 | return objerrs;
|
8490 | }
|
8491 |
|
8492 | if (schema.hasOwnProperty('not')) {
|
8493 | objerr = checkValidity(env, schema_stack.concat(schema.not), object_stack, options);
|
8494 | if (!objerr)
|
8495 | return {'not': true};
|
8496 | }
|
8497 | } else {
|
8498 | if (schema.hasOwnProperty('oneOf')) {
|
8499 | minErrCount = Infinity;
|
8500 | for (i = 0, len = schema.oneOf.length, count = 0; i < len; i++) {
|
8501 | new_stack = clone_stack(object_stack);
|
8502 | objerr = checkValidity(env, schema_stack.concat(schema.oneOf[i]), new_stack, options);
|
8503 | if (!objerr) {
|
8504 | count = count + 1;
|
8505 | if (count > 1)
|
8506 | break;
|
8507 | else
|
8508 | copy_stack(new_stack, object_stack);
|
8509 | } else {
|
8510 | errCount = objerr.schema ? Object.keys(objerr.schema).length : 1;
|
8511 | if (errCount < minErrCount) {
|
8512 | minErrCount = errCount;
|
8513 | objerrs = objerr;
|
8514 | }
|
8515 | }
|
8516 | }
|
8517 | if (count > 1)
|
8518 | return {'oneOf': true};
|
8519 | else if (count < 1)
|
8520 | return objerrs;
|
8521 | objerrs = {};
|
8522 | }
|
8523 |
|
8524 | if (schema.hasOwnProperty('anyOf')) {
|
8525 | objerrs = null;
|
8526 | minErrCount = Infinity;
|
8527 | for (i = 0, len = schema.anyOf.length; i < len; i++) {
|
8528 | new_stack = clone_stack(object_stack);
|
8529 | objerr = checkValidity(env, schema_stack.concat(schema.anyOf[i]), new_stack, options);
|
8530 | if (!objerr) {
|
8531 | copy_stack(new_stack, object_stack);
|
8532 | objerrs = null;
|
8533 | break;
|
8534 | }
|
8535 | else {
|
8536 | errCount = objerr.schema ? Object.keys(objerr.schema).length : 1;
|
8537 | if (errCount < minErrCount) {
|
8538 | minErrCount = errCount;
|
8539 | objerrs = objerr;
|
8540 | }
|
8541 | }
|
8542 | }
|
8543 | if (objerrs)
|
8544 | return objerrs;
|
8545 | }
|
8546 |
|
8547 | if (schema.hasOwnProperty('not')) {
|
8548 | new_stack = clone_stack(object_stack);
|
8549 | objerr = checkValidity(env, schema_stack.concat(schema.not), new_stack, options);
|
8550 | if (!objerr)
|
8551 | return {'not': true};
|
8552 | }
|
8553 | }
|
8554 |
|
8555 | if (schema.hasOwnProperty('dependencies')) {
|
8556 | for (p in schema.dependencies)
|
8557 | if (schema.dependencies.hasOwnProperty(p) && prop.hasOwnProperty(p)) {
|
8558 | if (Array.isArray(schema.dependencies[p])) {
|
8559 | for (i = 0, len = schema.dependencies[p].length; i < len; i++)
|
8560 | if (!prop.hasOwnProperty(schema.dependencies[p][i])) {
|
8561 | return {'dependencies': true};
|
8562 | }
|
8563 | } else {
|
8564 | objerr = checkValidity(env, schema_stack.concat(schema.dependencies[p]), object_stack, options);
|
8565 | if (objerr)
|
8566 | return objerr;
|
8567 | }
|
8568 | }
|
8569 | }
|
8570 |
|
8571 | if (!Array.isArray(prop)) {
|
8572 | props = [];
|
8573 | objerrs = {};
|
8574 | for (p in prop)
|
8575 | if (prop.hasOwnProperty(p))
|
8576 | props.push(p);
|
8577 |
|
8578 | if (options.checkRequired && schema.required) {
|
8579 | for (i = 0, len = schema.required.length; i < len; i++)
|
8580 | if (!prop.hasOwnProperty(schema.required[i])) {
|
8581 | objerrs[schema.required[i]] = {'required': true};
|
8582 | malformed = true;
|
8583 | }
|
8584 | }
|
8585 |
|
8586 | hasProp = schema.hasOwnProperty('properties');
|
8587 | hasPattern = schema.hasOwnProperty('patternProperties');
|
8588 | if (hasProp || hasPattern) {
|
8589 | i = props.length;
|
8590 | while (i--) {
|
8591 | matched = false;
|
8592 | if (hasProp && schema.properties.hasOwnProperty(props[i])) {
|
8593 | matched = true;
|
8594 | objerr = checkValidity(env, schema_stack.concat(schema.properties[props[i]]), object_stack.concat({object: prop, key: props[i]}), options);
|
8595 | if (objerr !== null) {
|
8596 | objerrs[props[i]] = objerr;
|
8597 | malformed = true;
|
8598 | }
|
8599 | }
|
8600 | if (hasPattern) {
|
8601 | for (p in schema.patternProperties)
|
8602 | if (schema.patternProperties.hasOwnProperty(p) && props[i].match(p)) {
|
8603 | matched = true;
|
8604 | objerr = checkValidity(env, schema_stack.concat(schema.patternProperties[p]), object_stack.concat({object: prop, key: props[i]}), options);
|
8605 | if (objerr !== null) {
|
8606 | objerrs[props[i]] = objerr;
|
8607 | malformed = true;
|
8608 | }
|
8609 | }
|
8610 | }
|
8611 | if (matched)
|
8612 | props.splice(i, 1);
|
8613 | }
|
8614 | }
|
8615 |
|
8616 | if (options.useDefault && hasProp && !malformed) {
|
8617 | for (p in schema.properties)
|
8618 | if (schema.properties.hasOwnProperty(p) && !prop.hasOwnProperty(p) && schema.properties[p].hasOwnProperty('default'))
|
8619 | prop[p] = schema.properties[p]['default'];
|
8620 | }
|
8621 |
|
8622 | if (options.removeAdditional && hasProp && schema.additionalProperties !== true && typeof schema.additionalProperties !== 'object') {
|
8623 | for (i = 0, len = props.length; i < len; i++)
|
8624 | delete prop[props[i]];
|
8625 | } else {
|
8626 | if (schema.hasOwnProperty('additionalProperties')) {
|
8627 | if (typeof schema.additionalProperties === 'boolean') {
|
8628 | if (!schema.additionalProperties) {
|
8629 | for (i = 0, len = props.length; i < len; i++) {
|
8630 | objerrs[props[i]] = {'additional': true};
|
8631 | malformed = true;
|
8632 | }
|
8633 | }
|
8634 | } else {
|
8635 | for (i = 0, len = props.length; i < len; i++) {
|
8636 | objerr = checkValidity(env, schema_stack.concat(schema.additionalProperties), object_stack.concat({object: prop, key: props[i]}), options);
|
8637 | if (objerr !== null) {
|
8638 | objerrs[props[i]] = objerr;
|
8639 | malformed = true;
|
8640 | }
|
8641 | }
|
8642 | }
|
8643 | }
|
8644 | }
|
8645 | if (malformed)
|
8646 | return {'schema': objerrs};
|
8647 | } else {
|
8648 | if (schema.hasOwnProperty('items')) {
|
8649 | if (Array.isArray(schema.items)) {
|
8650 | for (i = 0, len = schema.items.length; i < len; i++) {
|
8651 | objerr = checkValidity(env, schema_stack.concat(schema.items[i]), object_stack.concat({object: prop, key: i}), options);
|
8652 | if (objerr !== null) {
|
8653 | objerrs[i] = objerr;
|
8654 | malformed = true;
|
8655 | }
|
8656 | }
|
8657 | if (prop.length > len && schema.hasOwnProperty('additionalItems')) {
|
8658 | if (typeof schema.additionalItems === 'boolean') {
|
8659 | if (!schema.additionalItems)
|
8660 | return {'additionalItems': true};
|
8661 | } else {
|
8662 | for (i = len, len = prop.length; i < len; i++) {
|
8663 | objerr = checkValidity(env, schema_stack.concat(schema.additionalItems), object_stack.concat({object: prop, key: i}), options);
|
8664 | if (objerr !== null) {
|
8665 | objerrs[i] = objerr;
|
8666 | malformed = true;
|
8667 | }
|
8668 | }
|
8669 | }
|
8670 | }
|
8671 | } else {
|
8672 | for (i = 0, len = prop.length; i < len; i++) {
|
8673 | objerr = checkValidity(env, schema_stack.concat(schema.items), object_stack.concat({object: prop, key: i}), options);
|
8674 | if (objerr !== null) {
|
8675 | objerrs[i] = objerr;
|
8676 | malformed = true;
|
8677 | }
|
8678 | }
|
8679 | }
|
8680 | } else if (schema.hasOwnProperty('additionalItems')) {
|
8681 | if (typeof schema.additionalItems !== 'boolean') {
|
8682 | for (i = 0, len = prop.length; i < len; i++) {
|
8683 | objerr = checkValidity(env, schema_stack.concat(schema.additionalItems), object_stack.concat({object: prop, key: i}), options);
|
8684 | if (objerr !== null) {
|
8685 | objerrs[i] = objerr;
|
8686 | malformed = true;
|
8687 | }
|
8688 | }
|
8689 | }
|
8690 | }
|
8691 | if (malformed)
|
8692 | return {'schema': objerrs};
|
8693 | }
|
8694 |
|
8695 | for (v in schema) {
|
8696 | if (schema.hasOwnProperty(v) && !handled.hasOwnProperty(v)) {
|
8697 | if (v === 'format') {
|
8698 | if (env.fieldFormat.hasOwnProperty(schema[v]) && !env.fieldFormat[schema[v]](prop, schema, object_stack, options)) {
|
8699 | objerrs[v] = true;
|
8700 | malformed = true;
|
8701 | }
|
8702 | } else {
|
8703 | if (env.fieldValidate.hasOwnProperty(v) && !env.fieldValidate[v](prop, schema[v].hasOwnProperty('$data') ? resolveObjectRef(object_stack, schema[v].$data) : schema[v], schema, object_stack, options)) {
|
8704 | objerrs[v] = true;
|
8705 | malformed = true;
|
8706 | }
|
8707 | }
|
8708 | }
|
8709 | }
|
8710 |
|
8711 | if (malformed)
|
8712 | return objerrs;
|
8713 | else
|
8714 | return null;
|
8715 | };
|
8716 |
|
8717 | var defaultOptions = {
|
8718 | useDefault: false,
|
8719 | useCoerce: false,
|
8720 | checkRequired: true,
|
8721 | removeAdditional: false
|
8722 | };
|
8723 |
|
8724 | function Environment() {
|
8725 | if (!(this instanceof Environment))
|
8726 | return new Environment();
|
8727 |
|
8728 | this.coerceType = {};
|
8729 | this.fieldType = clone(fieldType);
|
8730 | this.fieldValidate = clone(fieldValidate);
|
8731 | this.fieldFormat = clone(fieldFormat);
|
8732 | this.defaultOptions = clone(defaultOptions);
|
8733 | this.schema = {};
|
8734 | }
|
8735 |
|
8736 | Environment.prototype = {
|
8737 | validate: function (name, object, options) {
|
8738 | var schema_stack = [name], errors = null, object_stack = [{object: {'__root__': object}, key: '__root__'}];
|
8739 |
|
8740 | if (typeof name === 'string') {
|
8741 | schema_stack = resolveURI(this, null, name);
|
8742 | if (!schema_stack)
|
8743 | throw new Error('jjv: could not find schema \'' + name + '\'.');
|
8744 | }
|
8745 |
|
8746 | if (!options) {
|
8747 | options = this.defaultOptions;
|
8748 | } else {
|
8749 | for (var p in this.defaultOptions)
|
8750 | if (this.defaultOptions.hasOwnProperty(p) && !options.hasOwnProperty(p))
|
8751 | options[p] = this.defaultOptions[p];
|
8752 | }
|
8753 |
|
8754 | errors = checkValidity(this, schema_stack, object_stack, options);
|
8755 |
|
8756 | if (errors)
|
8757 | return {validation: errors.hasOwnProperty('schema') ? errors.schema : errors};
|
8758 | else
|
8759 | return null;
|
8760 | },
|
8761 |
|
8762 | resolveRef: function (schema_stack, $ref) {
|
8763 | return resolveURI(this, schema_stack, $ref);
|
8764 | },
|
8765 |
|
8766 | addType: function (name, func) {
|
8767 | this.fieldType[name] = func;
|
8768 | },
|
8769 |
|
8770 | addTypeCoercion: function (type, func) {
|
8771 | this.coerceType[type] = func;
|
8772 | },
|
8773 |
|
8774 | addCheck: function (name, func) {
|
8775 | this.fieldValidate[name] = func;
|
8776 | },
|
8777 |
|
8778 | addFormat: function (name, func) {
|
8779 | this.fieldFormat[name] = func;
|
8780 | },
|
8781 |
|
8782 | addSchema: function (name, schema) {
|
8783 | if (!schema && name) {
|
8784 | schema = name;
|
8785 | name = undefined;
|
8786 | }
|
8787 | if (schema.hasOwnProperty('id') && typeof schema.id === 'string' && schema.id !== name) {
|
8788 | if (schema.id.charAt(0) === '/')
|
8789 | throw new Error('jjv: schema id\'s starting with / are invalid.');
|
8790 | this.schema[normalizeID(schema.id)] = schema;
|
8791 | } else if (!name) {
|
8792 | throw new Error('jjv: schema needs either a name or id attribute.');
|
8793 | }
|
8794 | if (name)
|
8795 | this.schema[normalizeID(name)] = schema;
|
8796 | }
|
8797 | };
|
8798 |
|
8799 |
|
8800 | if (typeof module !== 'undefined' && typeof module.exports !== 'undefined')
|
8801 | module.exports = Environment;
|
8802 | else if (typeof define === 'function' && define.amd)
|
8803 | define(function () {return Environment;});
|
8804 | else
|
8805 | this.jjv = Environment;
|
8806 | }).call(this);
|
8807 |
|
8808 | },{}],54:[function(require,module,exports){
|
8809 | (function (global){
|
8810 |
|
8811 |
|
8812 |
|
8813 |
|
8814 |
|
8815 |
|
8816 |
|
8817 |
|
8818 |
|
8819 | ;(function() {
|
8820 |
|
8821 |
|
8822 | var undefined;
|
8823 |
|
8824 |
|
8825 | var arrayPool = [],
|
8826 | objectPool = [];
|
8827 |
|
8828 |
|
8829 | var idCounter = 0;
|
8830 |
|
8831 |
|
8832 | var keyPrefix = +new Date + '';
|
8833 |
|
8834 |
|
8835 | var largeArraySize = 75;
|
8836 |
|
8837 |
|
8838 | var maxPoolSize = 40;
|
8839 |
|
8840 |
|
8841 | var whitespace = (
|
8842 |
|
8843 | ' \t\x0B\f\xA0\ufeff' +
|
8844 |
|
8845 |
|
8846 | '\n\r\u2028\u2029' +
|
8847 |
|
8848 |
|
8849 | '\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
|
8850 | );
|
8851 |
|
8852 |
|
8853 | var reEmptyStringLeading = /\b__p \+= '';/g,
|
8854 | reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
8855 | reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
8856 |
|
8857 | |
8858 |
|
8859 |
|
8860 |
|
8861 | var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
|
8862 |
|
8863 |
|
8864 | var reFlags = /\w*$/;
|
8865 |
|
8866 |
|
8867 | var reFuncName = /^\s*function[ \n\r\t]+\w/;
|
8868 |
|
8869 |
|
8870 | var reInterpolate = /<%=([\s\S]+?)%>/g;
|
8871 |
|
8872 |
|
8873 | var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
|
8874 |
|
8875 |
|
8876 | var reNoMatch = /($^)/;
|
8877 |
|
8878 |
|
8879 | var reThis = /\bthis\b/;
|
8880 |
|
8881 |
|
8882 | var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
|
8883 |
|
8884 |
|
8885 | var contextProps = [
|
8886 | 'Array', 'Boolean', 'Date', 'Function', 'Math', 'Number', 'Object',
|
8887 | 'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
|
8888 | 'parseInt', 'setTimeout'
|
8889 | ];
|
8890 |
|
8891 |
|
8892 | var templateCounter = 0;
|
8893 |
|
8894 |
|
8895 | var argsClass = '[object Arguments]',
|
8896 | arrayClass = '[object Array]',
|
8897 | boolClass = '[object Boolean]',
|
8898 | dateClass = '[object Date]',
|
8899 | funcClass = '[object Function]',
|
8900 | numberClass = '[object Number]',
|
8901 | objectClass = '[object Object]',
|
8902 | regexpClass = '[object RegExp]',
|
8903 | stringClass = '[object String]';
|
8904 |
|
8905 |
|
8906 | var cloneableClasses = {};
|
8907 | cloneableClasses[funcClass] = false;
|
8908 | cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
|
8909 | cloneableClasses[boolClass] = cloneableClasses[dateClass] =
|
8910 | cloneableClasses[numberClass] = cloneableClasses[objectClass] =
|
8911 | cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
|
8912 |
|
8913 |
|
8914 | var debounceOptions = {
|
8915 | 'leading': false,
|
8916 | 'maxWait': 0,
|
8917 | 'trailing': false
|
8918 | };
|
8919 |
|
8920 |
|
8921 | var descriptor = {
|
8922 | 'configurable': false,
|
8923 | 'enumerable': false,
|
8924 | 'value': null,
|
8925 | 'writable': false
|
8926 | };
|
8927 |
|
8928 |
|
8929 | var objectTypes = {
|
8930 | 'boolean': false,
|
8931 | 'function': true,
|
8932 | 'object': true,
|
8933 | 'number': false,
|
8934 | 'string': false,
|
8935 | 'undefined': false
|
8936 | };
|
8937 |
|
8938 |
|
8939 | var stringEscapes = {
|
8940 | '\\': '\\',
|
8941 | "'": "'",
|
8942 | '\n': 'n',
|
8943 | '\r': 'r',
|
8944 | '\t': 't',
|
8945 | '\u2028': 'u2028',
|
8946 | '\u2029': 'u2029'
|
8947 | };
|
8948 |
|
8949 |
|
8950 | var root = (objectTypes[typeof window] && window) || this;
|
8951 |
|
8952 |
|
8953 | var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
8954 |
|
8955 |
|
8956 | var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
|
8957 |
|
8958 |
|
8959 | var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
|
8960 |
|
8961 |
|
8962 | var freeGlobal = objectTypes[typeof global] && global;
|
8963 | if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
|
8964 | root = freeGlobal;
|
8965 | }
|
8966 |
|
8967 |
|
8968 |
|
8969 | |
8970 |
|
8971 |
|
8972 |
|
8973 |
|
8974 |
|
8975 |
|
8976 |
|
8977 |
|
8978 |
|
8979 | function baseIndexOf(array, value, fromIndex) {
|
8980 | var index = (fromIndex || 0) - 1,
|
8981 | length = array ? array.length : 0;
|
8982 |
|
8983 | while (++index < length) {
|
8984 | if (array[index] === value) {
|
8985 | return index;
|
8986 | }
|
8987 | }
|
8988 | return -1;
|
8989 | }
|
8990 |
|
8991 | |
8992 |
|
8993 |
|
8994 |
|
8995 |
|
8996 |
|
8997 |
|
8998 |
|
8999 |
|
9000 | function cacheIndexOf(cache, value) {
|
9001 | var type = typeof value;
|
9002 | cache = cache.cache;
|
9003 |
|
9004 | if (type == 'boolean' || value == null) {
|
9005 | return cache[value] ? 0 : -1;
|
9006 | }
|
9007 | if (type != 'number' && type != 'string') {
|
9008 | type = 'object';
|
9009 | }
|
9010 | var key = type == 'number' ? value : keyPrefix + value;
|
9011 | cache = (cache = cache[type]) && cache[key];
|
9012 |
|
9013 | return type == 'object'
|
9014 | ? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
|
9015 | : (cache ? 0 : -1);
|
9016 | }
|
9017 |
|
9018 | |
9019 |
|
9020 |
|
9021 |
|
9022 |
|
9023 |
|
9024 | function cachePush(value) {
|
9025 | var cache = this.cache,
|
9026 | type = typeof value;
|
9027 |
|
9028 | if (type == 'boolean' || value == null) {
|
9029 | cache[value] = true;
|
9030 | } else {
|
9031 | if (type != 'number' && type != 'string') {
|
9032 | type = 'object';
|
9033 | }
|
9034 | var key = type == 'number' ? value : keyPrefix + value,
|
9035 | typeCache = cache[type] || (cache[type] = {});
|
9036 |
|
9037 | if (type == 'object') {
|
9038 | (typeCache[key] || (typeCache[key] = [])).push(value);
|
9039 | } else {
|
9040 | typeCache[key] = true;
|
9041 | }
|
9042 | }
|
9043 | }
|
9044 |
|
9045 | |
9046 |
|
9047 |
|
9048 |
|
9049 |
|
9050 |
|
9051 |
|
9052 |
|
9053 | function charAtCallback(value) {
|
9054 | return value.charCodeAt(0);
|
9055 | }
|
9056 |
|
9057 | |
9058 |
|
9059 |
|
9060 |
|
9061 |
|
9062 |
|
9063 |
|
9064 |
|
9065 |
|
9066 | function compareAscending(a, b) {
|
9067 | var ac = a.criteria,
|
9068 | bc = b.criteria,
|
9069 | index = -1,
|
9070 | length = ac.length;
|
9071 |
|
9072 | while (++index < length) {
|
9073 | var value = ac[index],
|
9074 | other = bc[index];
|
9075 |
|
9076 | if (value !== other) {
|
9077 | if (value > other || typeof value == 'undefined') {
|
9078 | return 1;
|
9079 | }
|
9080 | if (value < other || typeof other == 'undefined') {
|
9081 | return -1;
|
9082 | }
|
9083 | }
|
9084 | }
|
9085 |
|
9086 |
|
9087 |
|
9088 |
|
9089 |
|
9090 |
|
9091 | return a.index - b.index;
|
9092 | }
|
9093 |
|
9094 | |
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 |
|
9100 |
|
9101 | function createCache(array) {
|
9102 | var index = -1,
|
9103 | length = array.length,
|
9104 | first = array[0],
|
9105 | mid = array[(length / 2) | 0],
|
9106 | last = array[length - 1];
|
9107 |
|
9108 | if (first && typeof first == 'object' &&
|
9109 | mid && typeof mid == 'object' && last && typeof last == 'object') {
|
9110 | return false;
|
9111 | }
|
9112 | var cache = getObject();
|
9113 | cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
|
9114 |
|
9115 | var result = getObject();
|
9116 | result.array = array;
|
9117 | result.cache = cache;
|
9118 | result.push = cachePush;
|
9119 |
|
9120 | while (++index < length) {
|
9121 | result.push(array[index]);
|
9122 | }
|
9123 | return result;
|
9124 | }
|
9125 |
|
9126 | |
9127 |
|
9128 |
|
9129 |
|
9130 |
|
9131 |
|
9132 |
|
9133 |
|
9134 | function escapeStringChar(match) {
|
9135 | return '\\' + stringEscapes[match];
|
9136 | }
|
9137 |
|
9138 | |
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 |
|
9144 | function getArray() {
|
9145 | return arrayPool.pop() || [];
|
9146 | }
|
9147 |
|
9148 | |
9149 |
|
9150 |
|
9151 |
|
9152 |
|
9153 |
|
9154 | function getObject() {
|
9155 | return objectPool.pop() || {
|
9156 | 'array': null,
|
9157 | 'cache': null,
|
9158 | 'criteria': null,
|
9159 | 'false': false,
|
9160 | 'index': 0,
|
9161 | 'null': false,
|
9162 | 'number': null,
|
9163 | 'object': null,
|
9164 | 'push': null,
|
9165 | 'string': null,
|
9166 | 'true': false,
|
9167 | 'undefined': false,
|
9168 | 'value': null
|
9169 | };
|
9170 | }
|
9171 |
|
9172 | |
9173 |
|
9174 |
|
9175 |
|
9176 |
|
9177 |
|
9178 | function releaseArray(array) {
|
9179 | array.length = 0;
|
9180 | if (arrayPool.length < maxPoolSize) {
|
9181 | arrayPool.push(array);
|
9182 | }
|
9183 | }
|
9184 |
|
9185 | |
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 | function releaseObject(object) {
|
9192 | var cache = object.cache;
|
9193 | if (cache) {
|
9194 | releaseObject(cache);
|
9195 | }
|
9196 | object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
|
9197 | if (objectPool.length < maxPoolSize) {
|
9198 | objectPool.push(object);
|
9199 | }
|
9200 | }
|
9201 |
|
9202 | |
9203 |
|
9204 |
|
9205 |
|
9206 |
|
9207 |
|
9208 |
|
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 | function slice(array, start, end) {
|
9216 | start || (start = 0);
|
9217 | if (typeof end == 'undefined') {
|
9218 | end = array ? array.length : 0;
|
9219 | }
|
9220 | var index = -1,
|
9221 | length = end - start || 0,
|
9222 | result = Array(length < 0 ? 0 : length);
|
9223 |
|
9224 | while (++index < length) {
|
9225 | result[index] = array[start + index];
|
9226 | }
|
9227 | return result;
|
9228 | }
|
9229 |
|
9230 |
|
9231 |
|
9232 | |
9233 |
|
9234 |
|
9235 |
|
9236 |
|
9237 |
|
9238 |
|
9239 |
|
9240 |
|
9241 | function runInContext(context) {
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 | context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
|
9247 |
|
9248 |
|
9249 | var Array = context.Array,
|
9250 | Boolean = context.Boolean,
|
9251 | Date = context.Date,
|
9252 | Function = context.Function,
|
9253 | Math = context.Math,
|
9254 | Number = context.Number,
|
9255 | Object = context.Object,
|
9256 | RegExp = context.RegExp,
|
9257 | String = context.String,
|
9258 | TypeError = context.TypeError;
|
9259 |
|
9260 | |
9261 |
|
9262 |
|
9263 |
|
9264 |
|
9265 |
|
9266 | var arrayRef = [];
|
9267 |
|
9268 |
|
9269 | var objectProto = Object.prototype;
|
9270 |
|
9271 |
|
9272 | var oldDash = context._;
|
9273 |
|
9274 |
|
9275 | var toString = objectProto.toString;
|
9276 |
|
9277 |
|
9278 | var reNative = RegExp('^' +
|
9279 | String(toString)
|
9280 | .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
9281 | .replace(/toString| for [^\]]+/g, '.*?') + '$'
|
9282 | );
|
9283 |
|
9284 |
|
9285 | var ceil = Math.ceil,
|
9286 | clearTimeout = context.clearTimeout,
|
9287 | floor = Math.floor,
|
9288 | fnToString = Function.prototype.toString,
|
9289 | getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
|
9290 | hasOwnProperty = objectProto.hasOwnProperty,
|
9291 | push = arrayRef.push,
|
9292 | setTimeout = context.setTimeout,
|
9293 | splice = arrayRef.splice,
|
9294 | unshift = arrayRef.unshift;
|
9295 |
|
9296 |
|
9297 | var defineProperty = (function() {
|
9298 |
|
9299 | try {
|
9300 | var o = {},
|
9301 | func = isNative(func = Object.defineProperty) && func,
|
9302 | result = func(o, o, o) && func;
|
9303 | } catch(e) { }
|
9304 | return result;
|
9305 | }());
|
9306 |
|
9307 |
|
9308 | var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
|
9309 | nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
|
9310 | nativeIsFinite = context.isFinite,
|
9311 | nativeIsNaN = context.isNaN,
|
9312 | nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
|
9313 | nativeMax = Math.max,
|
9314 | nativeMin = Math.min,
|
9315 | nativeParseInt = context.parseInt,
|
9316 | nativeRandom = Math.random;
|
9317 |
|
9318 |
|
9319 | var ctorByClass = {};
|
9320 | ctorByClass[arrayClass] = Array;
|
9321 | ctorByClass[boolClass] = Boolean;
|
9322 | ctorByClass[dateClass] = Date;
|
9323 | ctorByClass[funcClass] = Function;
|
9324 | ctorByClass[objectClass] = Object;
|
9325 | ctorByClass[numberClass] = Number;
|
9326 | ctorByClass[regexpClass] = RegExp;
|
9327 | ctorByClass[stringClass] = String;
|
9328 |
|
9329 |
|
9330 |
|
9331 | |
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 |
|
9344 |
|
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 |
|
9350 |
|
9351 |
|
9352 |
|
9353 |
|
9354 |
|
9355 |
|
9356 |
|
9357 |
|
9358 |
|
9359 |
|
9360 |
|
9361 |
|
9362 |
|
9363 |
|
9364 |
|
9365 |
|
9366 |
|
9367 |
|
9368 |
|
9369 |
|
9370 |
|
9371 |
|
9372 |
|
9373 |
|
9374 |
|
9375 |
|
9376 |
|
9377 |
|
9378 |
|
9379 |
|
9380 |
|
9381 |
|
9382 |
|
9383 |
|
9384 |
|
9385 |
|
9386 |
|
9387 |
|
9388 |
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 | function lodash(value) {
|
9397 |
|
9398 | return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
|
9399 | ? value
|
9400 | : new lodashWrapper(value);
|
9401 | }
|
9402 |
|
9403 | |
9404 |
|
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 |
|
9410 |
|
9411 | function lodashWrapper(value, chainAll) {
|
9412 | this.__chain__ = !!chainAll;
|
9413 | this.__wrapped__ = value;
|
9414 | }
|
9415 |
|
9416 | lodashWrapper.prototype = lodash.prototype;
|
9417 |
|
9418 | |
9419 |
|
9420 |
|
9421 |
|
9422 |
|
9423 |
|
9424 |
|
9425 | var support = lodash.support = {};
|
9426 |
|
9427 | |
9428 |
|
9429 |
|
9430 |
|
9431 |
|
9432 |
|
9433 |
|
9434 | support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
|
9435 |
|
9436 | |
9437 |
|
9438 |
|
9439 |
|
9440 |
|
9441 |
|
9442 | support.funcNames = typeof Function.name == 'string';
|
9443 |
|
9444 | |
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 | lodash.templateSettings = {
|
9454 |
|
9455 | |
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 |
|
9461 | 'escape': /<%-([\s\S]+?)%>/g,
|
9462 |
|
9463 | |
9464 |
|
9465 |
|
9466 |
|
9467 |
|
9468 |
|
9469 | 'evaluate': /<%([\s\S]+?)%>/g,
|
9470 |
|
9471 | |
9472 |
|
9473 |
|
9474 |
|
9475 |
|
9476 |
|
9477 | 'interpolate': reInterpolate,
|
9478 |
|
9479 | |
9480 |
|
9481 |
|
9482 |
|
9483 |
|
9484 |
|
9485 | 'variable': '',
|
9486 |
|
9487 | |
9488 |
|
9489 |
|
9490 |
|
9491 |
|
9492 |
|
9493 | 'imports': {
|
9494 |
|
9495 | |
9496 |
|
9497 |
|
9498 |
|
9499 |
|
9500 |
|
9501 | '_': lodash
|
9502 | }
|
9503 | };
|
9504 |
|
9505 |
|
9506 |
|
9507 | |
9508 |
|
9509 |
|
9510 |
|
9511 |
|
9512 |
|
9513 |
|
9514 |
|
9515 | function baseBind(bindData) {
|
9516 | var func = bindData[0],
|
9517 | partialArgs = bindData[2],
|
9518 | thisArg = bindData[4];
|
9519 |
|
9520 | function bound() {
|
9521 |
|
9522 |
|
9523 | if (partialArgs) {
|
9524 |
|
9525 |
|
9526 |
|
9527 | var args = slice(partialArgs);
|
9528 | push.apply(args, arguments);
|
9529 | }
|
9530 |
|
9531 |
|
9532 | if (this instanceof bound) {
|
9533 |
|
9534 | var thisBinding = baseCreate(func.prototype),
|
9535 | result = func.apply(thisBinding, args || arguments);
|
9536 | return isObject(result) ? result : thisBinding;
|
9537 | }
|
9538 | return func.apply(thisArg, args || arguments);
|
9539 | }
|
9540 | setBindData(bound, bindData);
|
9541 | return bound;
|
9542 | }
|
9543 |
|
9544 | |
9545 |
|
9546 |
|
9547 |
|
9548 |
|
9549 |
|
9550 |
|
9551 |
|
9552 |
|
9553 |
|
9554 |
|
9555 |
|
9556 | function baseClone(value, isDeep, callback, stackA, stackB) {
|
9557 | if (callback) {
|
9558 | var result = callback(value);
|
9559 | if (typeof result != 'undefined') {
|
9560 | return result;
|
9561 | }
|
9562 | }
|
9563 |
|
9564 | var isObj = isObject(value);
|
9565 | if (isObj) {
|
9566 | var className = toString.call(value);
|
9567 | if (!cloneableClasses[className]) {
|
9568 | return value;
|
9569 | }
|
9570 | var ctor = ctorByClass[className];
|
9571 | switch (className) {
|
9572 | case boolClass:
|
9573 | case dateClass:
|
9574 | return new ctor(+value);
|
9575 |
|
9576 | case numberClass:
|
9577 | case stringClass:
|
9578 | return new ctor(value);
|
9579 |
|
9580 | case regexpClass:
|
9581 | result = ctor(value.source, reFlags.exec(value));
|
9582 | result.lastIndex = value.lastIndex;
|
9583 | return result;
|
9584 | }
|
9585 | } else {
|
9586 | return value;
|
9587 | }
|
9588 | var isArr = isArray(value);
|
9589 | if (isDeep) {
|
9590 |
|
9591 | var initedStack = !stackA;
|
9592 | stackA || (stackA = getArray());
|
9593 | stackB || (stackB = getArray());
|
9594 |
|
9595 | var length = stackA.length;
|
9596 | while (length--) {
|
9597 | if (stackA[length] == value) {
|
9598 | return stackB[length];
|
9599 | }
|
9600 | }
|
9601 | result = isArr ? ctor(value.length) : {};
|
9602 | }
|
9603 | else {
|
9604 | result = isArr ? slice(value) : assign({}, value);
|
9605 | }
|
9606 |
|
9607 | if (isArr) {
|
9608 | if (hasOwnProperty.call(value, 'index')) {
|
9609 | result.index = value.index;
|
9610 | }
|
9611 | if (hasOwnProperty.call(value, 'input')) {
|
9612 | result.input = value.input;
|
9613 | }
|
9614 | }
|
9615 |
|
9616 | if (!isDeep) {
|
9617 | return result;
|
9618 | }
|
9619 |
|
9620 |
|
9621 | stackA.push(value);
|
9622 | stackB.push(result);
|
9623 |
|
9624 |
|
9625 | (isArr ? forEach : forOwn)(value, function(objValue, key) {
|
9626 | result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
|
9627 | });
|
9628 |
|
9629 | if (initedStack) {
|
9630 | releaseArray(stackA);
|
9631 | releaseArray(stackB);
|
9632 | }
|
9633 | return result;
|
9634 | }
|
9635 |
|
9636 | |
9637 |
|
9638 |
|
9639 |
|
9640 |
|
9641 |
|
9642 |
|
9643 |
|
9644 | function baseCreate(prototype, properties) {
|
9645 | return isObject(prototype) ? nativeCreate(prototype) : {};
|
9646 | }
|
9647 |
|
9648 | if (!nativeCreate) {
|
9649 | baseCreate = (function() {
|
9650 | function Object() {}
|
9651 | return function(prototype) {
|
9652 | if (isObject(prototype)) {
|
9653 | Object.prototype = prototype;
|
9654 | var result = new Object;
|
9655 | Object.prototype = null;
|
9656 | }
|
9657 | return result || context.Object();
|
9658 | };
|
9659 | }());
|
9660 | }
|
9661 |
|
9662 | |
9663 |
|
9664 |
|
9665 |
|
9666 |
|
9667 |
|
9668 |
|
9669 |
|
9670 |
|
9671 |
|
9672 | function baseCreateCallback(func, thisArg, argCount) {
|
9673 | if (typeof func != 'function') {
|
9674 | return identity;
|
9675 | }
|
9676 |
|
9677 | if (typeof thisArg == 'undefined' || !('prototype' in func)) {
|
9678 | return func;
|
9679 | }
|
9680 | var bindData = func.__bindData__;
|
9681 | if (typeof bindData == 'undefined') {
|
9682 | if (support.funcNames) {
|
9683 | bindData = !func.name;
|
9684 | }
|
9685 | bindData = bindData || !support.funcDecomp;
|
9686 | if (!bindData) {
|
9687 | var source = fnToString.call(func);
|
9688 | if (!support.funcNames) {
|
9689 | bindData = !reFuncName.test(source);
|
9690 | }
|
9691 | if (!bindData) {
|
9692 |
|
9693 | bindData = reThis.test(source);
|
9694 | setBindData(func, bindData);
|
9695 | }
|
9696 | }
|
9697 | }
|
9698 |
|
9699 | if (bindData === false || (bindData !== true && bindData[1] & 1)) {
|
9700 | return func;
|
9701 | }
|
9702 | switch (argCount) {
|
9703 | case 1: return function(value) {
|
9704 | return func.call(thisArg, value);
|
9705 | };
|
9706 | case 2: return function(a, b) {
|
9707 | return func.call(thisArg, a, b);
|
9708 | };
|
9709 | case 3: return function(value, index, collection) {
|
9710 | return func.call(thisArg, value, index, collection);
|
9711 | };
|
9712 | case 4: return function(accumulator, value, index, collection) {
|
9713 | return func.call(thisArg, accumulator, value, index, collection);
|
9714 | };
|
9715 | }
|
9716 | return bind(func, thisArg);
|
9717 | }
|
9718 |
|
9719 | |
9720 |
|
9721 |
|
9722 |
|
9723 |
|
9724 |
|
9725 |
|
9726 |
|
9727 | function baseCreateWrapper(bindData) {
|
9728 | var func = bindData[0],
|
9729 | bitmask = bindData[1],
|
9730 | partialArgs = bindData[2],
|
9731 | partialRightArgs = bindData[3],
|
9732 | thisArg = bindData[4],
|
9733 | arity = bindData[5];
|
9734 |
|
9735 | var isBind = bitmask & 1,
|
9736 | isBindKey = bitmask & 2,
|
9737 | isCurry = bitmask & 4,
|
9738 | isCurryBound = bitmask & 8,
|
9739 | key = func;
|
9740 |
|
9741 | function bound() {
|
9742 | var thisBinding = isBind ? thisArg : this;
|
9743 | if (partialArgs) {
|
9744 | var args = slice(partialArgs);
|
9745 | push.apply(args, arguments);
|
9746 | }
|
9747 | if (partialRightArgs || isCurry) {
|
9748 | args || (args = slice(arguments));
|
9749 | if (partialRightArgs) {
|
9750 | push.apply(args, partialRightArgs);
|
9751 | }
|
9752 | if (isCurry && args.length < arity) {
|
9753 | bitmask |= 16 & ~32;
|
9754 | return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
|
9755 | }
|
9756 | }
|
9757 | args || (args = arguments);
|
9758 | if (isBindKey) {
|
9759 | func = thisBinding[key];
|
9760 | }
|
9761 | if (this instanceof bound) {
|
9762 | thisBinding = baseCreate(func.prototype);
|
9763 | var result = func.apply(thisBinding, args);
|
9764 | return isObject(result) ? result : thisBinding;
|
9765 | }
|
9766 | return func.apply(thisBinding, args);
|
9767 | }
|
9768 | setBindData(bound, bindData);
|
9769 | return bound;
|
9770 | }
|
9771 |
|
9772 | |
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 | function baseDifference(array, values) {
|
9782 | var index = -1,
|
9783 | indexOf = getIndexOf(),
|
9784 | length = array ? array.length : 0,
|
9785 | isLarge = length >= largeArraySize && indexOf === baseIndexOf,
|
9786 | result = [];
|
9787 |
|
9788 | if (isLarge) {
|
9789 | var cache = createCache(values);
|
9790 | if (cache) {
|
9791 | indexOf = cacheIndexOf;
|
9792 | values = cache;
|
9793 | } else {
|
9794 | isLarge = false;
|
9795 | }
|
9796 | }
|
9797 | while (++index < length) {
|
9798 | var value = array[index];
|
9799 | if (indexOf(values, value) < 0) {
|
9800 | result.push(value);
|
9801 | }
|
9802 | }
|
9803 | if (isLarge) {
|
9804 | releaseObject(values);
|
9805 | }
|
9806 | return result;
|
9807 | }
|
9808 |
|
9809 | |
9810 |
|
9811 |
|
9812 |
|
9813 |
|
9814 |
|
9815 |
|
9816 |
|
9817 |
|
9818 |
|
9819 |
|
9820 | function baseFlatten(array, isShallow, isStrict, fromIndex) {
|
9821 | var index = (fromIndex || 0) - 1,
|
9822 | length = array ? array.length : 0,
|
9823 | result = [];
|
9824 |
|
9825 | while (++index < length) {
|
9826 | var value = array[index];
|
9827 |
|
9828 | if (value && typeof value == 'object' && typeof value.length == 'number'
|
9829 | && (isArray(value) || isArguments(value))) {
|
9830 |
|
9831 | if (!isShallow) {
|
9832 | value = baseFlatten(value, isShallow, isStrict);
|
9833 | }
|
9834 | var valIndex = -1,
|
9835 | valLength = value.length,
|
9836 | resIndex = result.length;
|
9837 |
|
9838 | result.length += valLength;
|
9839 | while (++valIndex < valLength) {
|
9840 | result[resIndex++] = value[valIndex];
|
9841 | }
|
9842 | } else if (!isStrict) {
|
9843 | result.push(value);
|
9844 | }
|
9845 | }
|
9846 | return result;
|
9847 | }
|
9848 |
|
9849 | |
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 | function baseIsEqual(a, b, callback, isWhere, stackA, stackB) {
|
9863 |
|
9864 | if (callback) {
|
9865 | var result = callback(a, b);
|
9866 | if (typeof result != 'undefined') {
|
9867 | return !!result;
|
9868 | }
|
9869 | }
|
9870 |
|
9871 | if (a === b) {
|
9872 |
|
9873 | return a !== 0 || (1 / a == 1 / b);
|
9874 | }
|
9875 | var type = typeof a,
|
9876 | otherType = typeof b;
|
9877 |
|
9878 |
|
9879 | if (a === a &&
|
9880 | !(a && objectTypes[type]) &&
|
9881 | !(b && objectTypes[otherType])) {
|
9882 | return false;
|
9883 | }
|
9884 |
|
9885 |
|
9886 | if (a == null || b == null) {
|
9887 | return a === b;
|
9888 | }
|
9889 |
|
9890 | var className = toString.call(a),
|
9891 | otherClass = toString.call(b);
|
9892 |
|
9893 | if (className == argsClass) {
|
9894 | className = objectClass;
|
9895 | }
|
9896 | if (otherClass == argsClass) {
|
9897 | otherClass = objectClass;
|
9898 | }
|
9899 | if (className != otherClass) {
|
9900 | return false;
|
9901 | }
|
9902 | switch (className) {
|
9903 | case boolClass:
|
9904 | case dateClass:
|
9905 |
|
9906 |
|
9907 | return +a == +b;
|
9908 |
|
9909 | case numberClass:
|
9910 |
|
9911 | return (a != +a)
|
9912 | ? b != +b
|
9913 |
|
9914 | : (a == 0 ? (1 / a == 1 / b) : a == +b);
|
9915 |
|
9916 | case regexpClass:
|
9917 | case stringClass:
|
9918 |
|
9919 |
|
9920 | return a == String(b);
|
9921 | }
|
9922 | var isArr = className == arrayClass;
|
9923 | if (!isArr) {
|
9924 |
|
9925 | var aWrapped = hasOwnProperty.call(a, '__wrapped__'),
|
9926 | bWrapped = hasOwnProperty.call(b, '__wrapped__');
|
9927 |
|
9928 | if (aWrapped || bWrapped) {
|
9929 | return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB);
|
9930 | }
|
9931 |
|
9932 | if (className != objectClass) {
|
9933 | return false;
|
9934 | }
|
9935 |
|
9936 | var ctorA = a.constructor,
|
9937 | ctorB = b.constructor;
|
9938 |
|
9939 |
|
9940 | if (ctorA != ctorB &&
|
9941 | !(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
|
9942 | ('constructor' in a && 'constructor' in b)
|
9943 | ) {
|
9944 | return false;
|
9945 | }
|
9946 | }
|
9947 |
|
9948 |
|
9949 |
|
9950 | var initedStack = !stackA;
|
9951 | stackA || (stackA = getArray());
|
9952 | stackB || (stackB = getArray());
|
9953 |
|
9954 | var length = stackA.length;
|
9955 | while (length--) {
|
9956 | if (stackA[length] == a) {
|
9957 | return stackB[length] == b;
|
9958 | }
|
9959 | }
|
9960 | var size = 0;
|
9961 | result = true;
|
9962 |
|
9963 |
|
9964 | stackA.push(a);
|
9965 | stackB.push(b);
|
9966 |
|
9967 |
|
9968 | if (isArr) {
|
9969 |
|
9970 | length = a.length;
|
9971 | size = b.length;
|
9972 | result = size == length;
|
9973 |
|
9974 | if (result || isWhere) {
|
9975 |
|
9976 | while (size--) {
|
9977 | var index = length,
|
9978 | value = b[size];
|
9979 |
|
9980 | if (isWhere) {
|
9981 | while (index--) {
|
9982 | if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
|
9983 | break;
|
9984 | }
|
9985 | }
|
9986 | } else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
|
9987 | break;
|
9988 | }
|
9989 | }
|
9990 | }
|
9991 | }
|
9992 | else {
|
9993 |
|
9994 |
|
9995 | forIn(b, function(value, key, b) {
|
9996 | if (hasOwnProperty.call(b, key)) {
|
9997 |
|
9998 | size++;
|
9999 |
|
10000 | return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
|
10001 | }
|
10002 | });
|
10003 |
|
10004 | if (result && !isWhere) {
|
10005 |
|
10006 | forIn(a, function(value, key, a) {
|
10007 | if (hasOwnProperty.call(a, key)) {
|
10008 |
|
10009 | return (result = --size > -1);
|
10010 | }
|
10011 | });
|
10012 | }
|
10013 | }
|
10014 | stackA.pop();
|
10015 | stackB.pop();
|
10016 |
|
10017 | if (initedStack) {
|
10018 | releaseArray(stackA);
|
10019 | releaseArray(stackB);
|
10020 | }
|
10021 | return result;
|
10022 | }
|
10023 |
|
10024 | |
10025 |
|
10026 |
|
10027 |
|
10028 |
|
10029 |
|
10030 |
|
10031 |
|
10032 |
|
10033 |
|
10034 |
|
10035 | function baseMerge(object, source, callback, stackA, stackB) {
|
10036 | (isArray(source) ? forEach : forOwn)(source, function(source, key) {
|
10037 | var found,
|
10038 | isArr,
|
10039 | result = source,
|
10040 | value = object[key];
|
10041 |
|
10042 | if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
|
10043 |
|
10044 | var stackLength = stackA.length;
|
10045 | while (stackLength--) {
|
10046 | if ((found = stackA[stackLength] == source)) {
|
10047 | value = stackB[stackLength];
|
10048 | break;
|
10049 | }
|
10050 | }
|
10051 | if (!found) {
|
10052 | var isShallow;
|
10053 | if (callback) {
|
10054 | result = callback(value, source);
|
10055 | if ((isShallow = typeof result != 'undefined')) {
|
10056 | value = result;
|
10057 | }
|
10058 | }
|
10059 | if (!isShallow) {
|
10060 | value = isArr
|
10061 | ? (isArray(value) ? value : [])
|
10062 | : (isPlainObject(value) ? value : {});
|
10063 | }
|
10064 |
|
10065 | stackA.push(source);
|
10066 | stackB.push(value);
|
10067 |
|
10068 |
|
10069 | if (!isShallow) {
|
10070 | baseMerge(value, source, callback, stackA, stackB);
|
10071 | }
|
10072 | }
|
10073 | }
|
10074 | else {
|
10075 | if (callback) {
|
10076 | result = callback(value, source);
|
10077 | if (typeof result == 'undefined') {
|
10078 | result = source;
|
10079 | }
|
10080 | }
|
10081 | if (typeof result != 'undefined') {
|
10082 | value = result;
|
10083 | }
|
10084 | }
|
10085 | object[key] = value;
|
10086 | });
|
10087 | }
|
10088 |
|
10089 | |
10090 |
|
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 |
|
10096 |
|
10097 |
|
10098 | function baseRandom(min, max) {
|
10099 | return min + floor(nativeRandom() * (max - min + 1));
|
10100 | }
|
10101 |
|
10102 | |
10103 |
|
10104 |
|
10105 |
|
10106 |
|
10107 |
|
10108 |
|
10109 |
|
10110 |
|
10111 |
|
10112 | function baseUniq(array, isSorted, callback) {
|
10113 | var index = -1,
|
10114 | indexOf = getIndexOf(),
|
10115 | length = array ? array.length : 0,
|
10116 | result = [];
|
10117 |
|
10118 | var isLarge = !isSorted && length >= largeArraySize && indexOf === baseIndexOf,
|
10119 | seen = (callback || isLarge) ? getArray() : result;
|
10120 |
|
10121 | if (isLarge) {
|
10122 | var cache = createCache(seen);
|
10123 | indexOf = cacheIndexOf;
|
10124 | seen = cache;
|
10125 | }
|
10126 | while (++index < length) {
|
10127 | var value = array[index],
|
10128 | computed = callback ? callback(value, index, array) : value;
|
10129 |
|
10130 | if (isSorted
|
10131 | ? !index || seen[seen.length - 1] !== computed
|
10132 | : indexOf(seen, computed) < 0
|
10133 | ) {
|
10134 | if (callback || isLarge) {
|
10135 | seen.push(computed);
|
10136 | }
|
10137 | result.push(value);
|
10138 | }
|
10139 | }
|
10140 | if (isLarge) {
|
10141 | releaseArray(seen.array);
|
10142 | releaseObject(seen);
|
10143 | } else if (callback) {
|
10144 | releaseArray(seen);
|
10145 | }
|
10146 | return result;
|
10147 | }
|
10148 |
|
10149 | |
10150 |
|
10151 |
|
10152 |
|
10153 |
|
10154 |
|
10155 |
|
10156 |
|
10157 |
|
10158 |
|
10159 | function createAggregator(setter) {
|
10160 | return function(collection, callback, thisArg) {
|
10161 | var result = {};
|
10162 | callback = lodash.createCallback(callback, thisArg, 3);
|
10163 |
|
10164 | var index = -1,
|
10165 | length = collection ? collection.length : 0;
|
10166 |
|
10167 | if (typeof length == 'number') {
|
10168 | while (++index < length) {
|
10169 | var value = collection[index];
|
10170 | setter(result, value, callback(value, index, collection), collection);
|
10171 | }
|
10172 | } else {
|
10173 | forOwn(collection, function(value, key, collection) {
|
10174 | setter(result, value, callback(value, key, collection), collection);
|
10175 | });
|
10176 | }
|
10177 | return result;
|
10178 | };
|
10179 | }
|
10180 |
|
10181 | |
10182 |
|
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 |
|
10189 |
|
10190 |
|
10191 |
|
10192 |
|
10193 |
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 |
|
10201 |
|
10202 |
|
10203 | function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) {
|
10204 | var isBind = bitmask & 1,
|
10205 | isBindKey = bitmask & 2,
|
10206 | isCurry = bitmask & 4,
|
10207 | isCurryBound = bitmask & 8,
|
10208 | isPartial = bitmask & 16,
|
10209 | isPartialRight = bitmask & 32;
|
10210 |
|
10211 | if (!isBindKey && !isFunction(func)) {
|
10212 | throw new TypeError;
|
10213 | }
|
10214 | if (isPartial && !partialArgs.length) {
|
10215 | bitmask &= ~16;
|
10216 | isPartial = partialArgs = false;
|
10217 | }
|
10218 | if (isPartialRight && !partialRightArgs.length) {
|
10219 | bitmask &= ~32;
|
10220 | isPartialRight = partialRightArgs = false;
|
10221 | }
|
10222 | var bindData = func && func.__bindData__;
|
10223 | if (bindData && bindData !== true) {
|
10224 |
|
10225 | bindData = slice(bindData);
|
10226 | if (bindData[2]) {
|
10227 | bindData[2] = slice(bindData[2]);
|
10228 | }
|
10229 | if (bindData[3]) {
|
10230 | bindData[3] = slice(bindData[3]);
|
10231 | }
|
10232 |
|
10233 | if (isBind && !(bindData[1] & 1)) {
|
10234 | bindData[4] = thisArg;
|
10235 | }
|
10236 |
|
10237 | if (!isBind && bindData[1] & 1) {
|
10238 | bitmask |= 8;
|
10239 | }
|
10240 |
|
10241 | if (isCurry && !(bindData[1] & 4)) {
|
10242 | bindData[5] = arity;
|
10243 | }
|
10244 |
|
10245 | if (isPartial) {
|
10246 | push.apply(bindData[2] || (bindData[2] = []), partialArgs);
|
10247 | }
|
10248 |
|
10249 | if (isPartialRight) {
|
10250 | unshift.apply(bindData[3] || (bindData[3] = []), partialRightArgs);
|
10251 | }
|
10252 |
|
10253 | bindData[1] |= bitmask;
|
10254 | return createWrapper.apply(null, bindData);
|
10255 | }
|
10256 |
|
10257 | var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper;
|
10258 | return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]);
|
10259 | }
|
10260 |
|
10261 | |
10262 |
|
10263 |
|
10264 |
|
10265 |
|
10266 |
|
10267 |
|
10268 | function escapeHtmlChar(match) {
|
10269 | return htmlEscapes[match];
|
10270 | }
|
10271 |
|
10272 | |
10273 |
|
10274 |
|
10275 |
|
10276 |
|
10277 |
|
10278 |
|
10279 |
|
10280 | function getIndexOf() {
|
10281 | var result = (result = lodash.indexOf) === indexOf ? baseIndexOf : result;
|
10282 | return result;
|
10283 | }
|
10284 |
|
10285 | |
10286 |
|
10287 |
|
10288 |
|
10289 |
|
10290 |
|
10291 |
|
10292 | function isNative(value) {
|
10293 | return typeof value == 'function' && reNative.test(value);
|
10294 | }
|
10295 |
|
10296 | |
10297 |
|
10298 |
|
10299 |
|
10300 |
|
10301 |
|
10302 |
|
10303 | var setBindData = !defineProperty ? noop : function(func, value) {
|
10304 | descriptor.value = value;
|
10305 | defineProperty(func, '__bindData__', descriptor);
|
10306 | };
|
10307 |
|
10308 | |
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 | function shimIsPlainObject(value) {
|
10319 | var ctor,
|
10320 | result;
|
10321 |
|
10322 |
|
10323 | if (!(value && toString.call(value) == objectClass) ||
|
10324 | (ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor))) {
|
10325 | return false;
|
10326 | }
|
10327 |
|
10328 |
|
10329 |
|
10330 | forIn(value, function(value, key) {
|
10331 | result = key;
|
10332 | });
|
10333 | return typeof result == 'undefined' || hasOwnProperty.call(value, result);
|
10334 | }
|
10335 |
|
10336 | |
10337 |
|
10338 |
|
10339 |
|
10340 |
|
10341 |
|
10342 |
|
10343 | function unescapeHtmlChar(match) {
|
10344 | return htmlUnescapes[match];
|
10345 | }
|
10346 |
|
10347 |
|
10348 |
|
10349 | |
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 |
|
10357 |
|
10358 |
|
10359 |
|
10360 |
|
10361 |
|
10362 |
|
10363 |
|
10364 |
|
10365 | function isArguments(value) {
|
10366 | return value && typeof value == 'object' && typeof value.length == 'number' &&
|
10367 | toString.call(value) == argsClass || false;
|
10368 | }
|
10369 |
|
10370 | |
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 |
|
10376 |
|
10377 |
|
10378 |
|
10379 |
|
10380 |
|
10381 |
|
10382 |
|
10383 |
|
10384 |
|
10385 |
|
10386 |
|
10387 | var isArray = nativeIsArray || function(value) {
|
10388 | return value && typeof value == 'object' && typeof value.length == 'number' &&
|
10389 | toString.call(value) == arrayClass || false;
|
10390 | };
|
10391 |
|
10392 | |
10393 |
|
10394 |
|
10395 |
|
10396 |
|
10397 |
|
10398 |
|
10399 |
|
10400 |
|
10401 | var shimKeys = function(object) {
|
10402 | var index, iterable = object, result = [];
|
10403 | if (!iterable) return result;
|
10404 | if (!(objectTypes[typeof object])) return result;
|
10405 | for (index in iterable) {
|
10406 | if (hasOwnProperty.call(iterable, index)) {
|
10407 | result.push(index);
|
10408 | }
|
10409 | }
|
10410 | return result
|
10411 | };
|
10412 |
|
10413 | |
10414 |
|
10415 |
|
10416 |
|
10417 |
|
10418 |
|
10419 |
|
10420 |
|
10421 |
|
10422 |
|
10423 |
|
10424 |
|
10425 |
|
10426 | var keys = !nativeKeys ? shimKeys : function(object) {
|
10427 | if (!isObject(object)) {
|
10428 | return [];
|
10429 | }
|
10430 | return nativeKeys(object);
|
10431 | };
|
10432 |
|
10433 | |
10434 |
|
10435 |
|
10436 |
|
10437 |
|
10438 |
|
10439 |
|
10440 |
|
10441 | var htmlEscapes = {
|
10442 | '&': '&',
|
10443 | '<': '<',
|
10444 | '>': '>',
|
10445 | '"': '"',
|
10446 | "'": '''
|
10447 | };
|
10448 |
|
10449 |
|
10450 | var htmlUnescapes = invert(htmlEscapes);
|
10451 |
|
10452 |
|
10453 | var reEscapedHtml = RegExp('(' + keys(htmlUnescapes).join('|') + ')', 'g'),
|
10454 | reUnescapedHtml = RegExp('[' + keys(htmlEscapes).join('') + ']', 'g');
|
10455 |
|
10456 |
|
10457 |
|
10458 | |
10459 |
|
10460 |
|
10461 |
|
10462 |
|
10463 |
|
10464 |
|
10465 |
|
10466 |
|
10467 |
|
10468 |
|
10469 |
|
10470 |
|
10471 |
|
10472 |
|
10473 |
|
10474 |
|
10475 |
|
10476 |
|
10477 |
|
10478 |
|
10479 |
|
10480 |
|
10481 |
|
10482 |
|
10483 |
|
10484 |
|
10485 |
|
10486 |
|
10487 |
|
10488 | var assign = function(object, source, guard) {
|
10489 | var index, iterable = object, result = iterable;
|
10490 | if (!iterable) return result;
|
10491 | var args = arguments,
|
10492 | argsIndex = 0,
|
10493 | argsLength = typeof guard == 'number' ? 2 : args.length;
|
10494 | if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {
|
10495 | var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);
|
10496 | } else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {
|
10497 | callback = args[--argsLength];
|
10498 | }
|
10499 | while (++argsIndex < argsLength) {
|
10500 | iterable = args[argsIndex];
|
10501 | if (iterable && objectTypes[typeof iterable]) {
|
10502 | var ownIndex = -1,
|
10503 | ownProps = objectTypes[typeof iterable] && keys(iterable),
|
10504 | length = ownProps ? ownProps.length : 0;
|
10505 |
|
10506 | while (++ownIndex < length) {
|
10507 | index = ownProps[ownIndex];
|
10508 | result[index] = callback ? callback(result[index], iterable[index]) : iterable[index];
|
10509 | }
|
10510 | }
|
10511 | }
|
10512 | return result
|
10513 | };
|
10514 |
|
10515 | |
10516 |
|
10517 |
|
10518 |
|
10519 |
|
10520 |
|
10521 |
|
10522 |
|
10523 |
|
10524 |
|
10525 |
|
10526 |
|
10527 |
|
10528 |
|
10529 |
|
10530 |
|
10531 |
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 |
|
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 |
|
10542 |
|
10543 |
|
10544 |
|
10545 |
|
10546 |
|
10547 |
|
10548 |
|
10549 |
|
10550 |
|
10551 |
|
10552 |
|
10553 |
|
10554 |
|
10555 | function clone(value, isDeep, callback, thisArg) {
|
10556 |
|
10557 |
|
10558 | if (typeof isDeep != 'boolean' && isDeep != null) {
|
10559 | thisArg = callback;
|
10560 | callback = isDeep;
|
10561 | isDeep = false;
|
10562 | }
|
10563 | return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
|
10564 | }
|
10565 |
|
10566 | |
10567 |
|
10568 |
|
10569 |
|
10570 |
|
10571 |
|
10572 |
|
10573 |
|
10574 |
|
10575 |
|
10576 |
|
10577 |
|
10578 |
|
10579 |
|
10580 |
|
10581 |
|
10582 |
|
10583 |
|
10584 |
|
10585 |
|
10586 |
|
10587 |
|
10588 |
|
10589 |
|
10590 |
|
10591 |
|
10592 |
|
10593 |
|
10594 |
|
10595 |
|
10596 |
|
10597 |
|
10598 |
|
10599 |
|
10600 |
|
10601 |
|
10602 |
|
10603 |
|
10604 |
|
10605 |
|
10606 |
|
10607 | function cloneDeep(value, callback, thisArg) {
|
10608 | return baseClone(value, true, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
|
10609 | }
|
10610 |
|
10611 | |
10612 |
|
10613 |
|
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 |
|
10622 |
|
10623 |
|
10624 |
|
10625 |
|
10626 |
|
10627 |
|
10628 |
|
10629 |
|
10630 |
|
10631 |
|
10632 |
|
10633 |
|
10634 |
|
10635 |
|
10636 |
|
10637 |
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 | function create(prototype, properties) {
|
10643 | var result = baseCreate(prototype);
|
10644 | return properties ? assign(result, properties) : result;
|
10645 | }
|
10646 |
|
10647 | |
10648 |
|
10649 |
|
10650 |
|
10651 |
|
10652 |
|
10653 |
|
10654 |
|
10655 |
|
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 | var defaults = function(object, source, guard) {
|
10668 | var index, iterable = object, result = iterable;
|
10669 | if (!iterable) return result;
|
10670 | var args = arguments,
|
10671 | argsIndex = 0,
|
10672 | argsLength = typeof guard == 'number' ? 2 : args.length;
|
10673 | while (++argsIndex < argsLength) {
|
10674 | iterable = args[argsIndex];
|
10675 | if (iterable && objectTypes[typeof iterable]) {
|
10676 | var ownIndex = -1,
|
10677 | ownProps = objectTypes[typeof iterable] && keys(iterable),
|
10678 | length = ownProps ? ownProps.length : 0;
|
10679 |
|
10680 | while (++ownIndex < length) {
|
10681 | index = ownProps[ownIndex];
|
10682 | if (typeof result[index] == 'undefined') result[index] = iterable[index];
|
10683 | }
|
10684 | }
|
10685 | }
|
10686 | return result
|
10687 | };
|
10688 |
|
10689 | |
10690 |
|
10691 |
|
10692 |
|
10693 |
|
10694 |
|
10695 |
|
10696 |
|
10697 |
|
10698 |
|
10699 |
|
10700 |
|
10701 |
|
10702 |
|
10703 |
|
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 |
|
10709 |
|
10710 |
|
10711 |
|
10712 |
|
10713 |
|
10714 |
|
10715 |
|
10716 |
|
10717 |
|
10718 |
|
10719 |
|
10720 |
|
10721 |
|
10722 |
|
10723 |
|
10724 |
|
10725 |
|
10726 |
|
10727 |
|
10728 |
|
10729 |
|
10730 | function findKey(object, callback, thisArg) {
|
10731 | var result;
|
10732 | callback = lodash.createCallback(callback, thisArg, 3);
|
10733 | forOwn(object, function(value, key, object) {
|
10734 | if (callback(value, key, object)) {
|
10735 | result = key;
|
10736 | return false;
|
10737 | }
|
10738 | });
|
10739 | return result;
|
10740 | }
|
10741 |
|
10742 | |
10743 |
|
10744 |
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 |
|
10751 |
|
10752 |
|
10753 |
|
10754 |
|
10755 |
|
10756 |
|
10757 |
|
10758 |
|
10759 |
|
10760 |
|
10761 |
|
10762 |
|
10763 |
|
10764 |
|
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 |
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 |
|
10781 |
|
10782 |
|
10783 | function findLastKey(object, callback, thisArg) {
|
10784 | var result;
|
10785 | callback = lodash.createCallback(callback, thisArg, 3);
|
10786 | forOwnRight(object, function(value, key, object) {
|
10787 | if (callback(value, key, object)) {
|
10788 | result = key;
|
10789 | return false;
|
10790 | }
|
10791 | });
|
10792 | return result;
|
10793 | }
|
10794 |
|
10795 | |
10796 |
|
10797 |
|
10798 |
|
10799 |
|
10800 |
|
10801 |
|
10802 |
|
10803 |
|
10804 |
|
10805 |
|
10806 |
|
10807 |
|
10808 |
|
10809 |
|
10810 |
|
10811 |
|
10812 |
|
10813 |
|
10814 |
|
10815 |
|
10816 |
|
10817 |
|
10818 |
|
10819 |
|
10820 |
|
10821 |
|
10822 |
|
10823 |
|
10824 |
|
10825 |
|
10826 | var forIn = function(collection, callback, thisArg) {
|
10827 | var index, iterable = collection, result = iterable;
|
10828 | if (!iterable) return result;
|
10829 | if (!objectTypes[typeof iterable]) return result;
|
10830 | callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
|
10831 | for (index in iterable) {
|
10832 | if (callback(iterable[index], index, collection) === false) return result;
|
10833 | }
|
10834 | return result
|
10835 | };
|
10836 |
|
10837 | |
10838 |
|
10839 |
|
10840 |
|
10841 |
|
10842 |
|
10843 |
|
10844 |
|
10845 |
|
10846 |
|
10847 |
|
10848 |
|
10849 |
|
10850 |
|
10851 |
|
10852 |
|
10853 |
|
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 |
|
10862 |
|
10863 |
|
10864 |
|
10865 | function forInRight(object, callback, thisArg) {
|
10866 | var pairs = [];
|
10867 |
|
10868 | forIn(object, function(value, key) {
|
10869 | pairs.push(key, value);
|
10870 | });
|
10871 |
|
10872 | var length = pairs.length;
|
10873 | callback = baseCreateCallback(callback, thisArg, 3);
|
10874 | while (length--) {
|
10875 | if (callback(pairs[length--], pairs[length], object) === false) {
|
10876 | break;
|
10877 | }
|
10878 | }
|
10879 | return object;
|
10880 | }
|
10881 |
|
10882 | |
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 |
|
10896 |
|
10897 |
|
10898 |
|
10899 |
|
10900 |
|
10901 |
|
10902 |
|
10903 | var forOwn = function(collection, callback, thisArg) {
|
10904 | var index, iterable = collection, result = iterable;
|
10905 | if (!iterable) return result;
|
10906 | if (!objectTypes[typeof iterable]) return result;
|
10907 | callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
|
10908 | var ownIndex = -1,
|
10909 | ownProps = objectTypes[typeof iterable] && keys(iterable),
|
10910 | length = ownProps ? ownProps.length : 0;
|
10911 |
|
10912 | while (++ownIndex < length) {
|
10913 | index = ownProps[ownIndex];
|
10914 | if (callback(iterable[index], index, collection) === false) return result;
|
10915 | }
|
10916 | return result
|
10917 | };
|
10918 |
|
10919 | |
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 |
|
10928 |
|
10929 |
|
10930 |
|
10931 |
|
10932 |
|
10933 |
|
10934 |
|
10935 |
|
10936 |
|
10937 | function forOwnRight(object, callback, thisArg) {
|
10938 | var props = keys(object),
|
10939 | length = props.length;
|
10940 |
|
10941 | callback = baseCreateCallback(callback, thisArg, 3);
|
10942 | while (length--) {
|
10943 | var key = props[length];
|
10944 | if (callback(object[key], key, object) === false) {
|
10945 | break;
|
10946 | }
|
10947 | }
|
10948 | return object;
|
10949 | }
|
10950 |
|
10951 | |
10952 |
|
10953 |
|
10954 |
|
10955 |
|
10956 |
|
10957 |
|
10958 |
|
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 |
|
10966 | function functions(object) {
|
10967 | var result = [];
|
10968 | forIn(object, function(value, key) {
|
10969 | if (isFunction(value)) {
|
10970 | result.push(key);
|
10971 | }
|
10972 | });
|
10973 | return result.sort();
|
10974 | }
|
10975 |
|
10976 | |
10977 |
|
10978 |
|
10979 |
|
10980 |
|
10981 |
|
10982 |
|
10983 |
|
10984 |
|
10985 |
|
10986 |
|
10987 |
|
10988 |
|
10989 |
|
10990 |
|
10991 | function has(object, key) {
|
10992 | return object ? hasOwnProperty.call(object, key) : false;
|
10993 | }
|
10994 |
|
10995 | |
10996 |
|
10997 |
|
10998 |
|
10999 |
|
11000 |
|
11001 |
|
11002 |
|
11003 |
|
11004 |
|
11005 |
|
11006 |
|
11007 |
|
11008 | function invert(object) {
|
11009 | var index = -1,
|
11010 | props = keys(object),
|
11011 | length = props.length,
|
11012 | result = {};
|
11013 |
|
11014 | while (++index < length) {
|
11015 | var key = props[index];
|
11016 | result[object[key]] = key;
|
11017 | }
|
11018 | return result;
|
11019 | }
|
11020 |
|
11021 | |
11022 |
|
11023 |
|
11024 |
|
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 | function isBoolean(value) {
|
11035 | return value === true || value === false ||
|
11036 | value && typeof value == 'object' && toString.call(value) == boolClass || false;
|
11037 | }
|
11038 |
|
11039 | |
11040 |
|
11041 |
|
11042 |
|
11043 |
|
11044 |
|
11045 |
|
11046 |
|
11047 |
|
11048 |
|
11049 |
|
11050 |
|
11051 |
|
11052 | function isDate(value) {
|
11053 | return value && typeof value == 'object' && toString.call(value) == dateClass || false;
|
11054 | }
|
11055 |
|
11056 | |
11057 |
|
11058 |
|
11059 |
|
11060 |
|
11061 |
|
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 | function isElement(value) {
|
11070 | return value && value.nodeType === 1 || false;
|
11071 | }
|
11072 |
|
11073 | |
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 |
|
11082 |
|
11083 |
|
11084 |
|
11085 |
|
11086 |
|
11087 |
|
11088 |
|
11089 |
|
11090 |
|
11091 |
|
11092 |
|
11093 |
|
11094 | function isEmpty(value) {
|
11095 | var result = true;
|
11096 | if (!value) {
|
11097 | return result;
|
11098 | }
|
11099 | var className = toString.call(value),
|
11100 | length = value.length;
|
11101 |
|
11102 | if ((className == arrayClass || className == stringClass || className == argsClass ) ||
|
11103 | (className == objectClass && typeof length == 'number' && isFunction(value.splice))) {
|
11104 | return !length;
|
11105 | }
|
11106 | forOwn(value, function() {
|
11107 | return (result = false);
|
11108 | });
|
11109 | return result;
|
11110 | }
|
11111 |
|
11112 | |
11113 |
|
11114 |
|
11115 |
|
11116 |
|
11117 |
|
11118 |
|
11119 |
|
11120 |
|
11121 |
|
11122 |
|
11123 |
|
11124 |
|
11125 |
|
11126 |
|
11127 |
|
11128 |
|
11129 |
|
11130 |
|
11131 |
|
11132 |
|
11133 |
|
11134 |
|
11135 |
|
11136 |
|
11137 |
|
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 |
|
11150 | function isEqual(a, b, callback, thisArg) {
|
11151 | return baseIsEqual(a, b, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 2));
|
11152 | }
|
11153 |
|
11154 | |
11155 |
|
11156 |
|
11157 |
|
11158 |
|
11159 |
|
11160 |
|
11161 |
|
11162 |
|
11163 |
|
11164 |
|
11165 |
|
11166 |
|
11167 |
|
11168 |
|
11169 |
|
11170 |
|
11171 |
|
11172 |
|
11173 |
|
11174 |
|
11175 |
|
11176 |
|
11177 |
|
11178 |
|
11179 |
|
11180 |
|
11181 |
|
11182 | function isFinite(value) {
|
11183 | return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value));
|
11184 | }
|
11185 |
|
11186 | |
11187 |
|
11188 |
|
11189 |
|
11190 |
|
11191 |
|
11192 |
|
11193 |
|
11194 |
|
11195 |
|
11196 |
|
11197 |
|
11198 |
|
11199 | function isFunction(value) {
|
11200 | return typeof value == 'function';
|
11201 | }
|
11202 |
|
11203 | |
11204 |
|
11205 |
|
11206 |
|
11207 |
|
11208 |
|
11209 |
|
11210 |
|
11211 |
|
11212 |
|
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 |
|
11220 |
|
11221 |
|
11222 |
|
11223 | function isObject(value) {
|
11224 |
|
11225 |
|
11226 |
|
11227 |
|
11228 | return !!(value && objectTypes[typeof value]);
|
11229 | }
|
11230 |
|
11231 | |
11232 |
|
11233 |
|
11234 |
|
11235 |
|
11236 |
|
11237 |
|
11238 |
|
11239 |
|
11240 |
|
11241 |
|
11242 |
|
11243 |
|
11244 |
|
11245 |
|
11246 |
|
11247 |
|
11248 |
|
11249 |
|
11250 |
|
11251 |
|
11252 |
|
11253 |
|
11254 |
|
11255 |
|
11256 | function isNaN(value) {
|
11257 |
|
11258 |
|
11259 | return isNumber(value) && value != +value;
|
11260 | }
|
11261 |
|
11262 | |
11263 |
|
11264 |
|
11265 |
|
11266 |
|
11267 |
|
11268 |
|
11269 |
|
11270 |
|
11271 |
|
11272 |
|
11273 |
|
11274 |
|
11275 |
|
11276 |
|
11277 |
|
11278 | function isNull(value) {
|
11279 | return value === null;
|
11280 | }
|
11281 |
|
11282 | |
11283 |
|
11284 |
|
11285 |
|
11286 |
|
11287 |
|
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 |
|
11297 | function isNumber(value) {
|
11298 | return typeof value == 'number' ||
|
11299 | value && typeof value == 'object' && toString.call(value) == numberClass || false;
|
11300 | }
|
11301 |
|
11302 | |
11303 |
|
11304 |
|
11305 |
|
11306 |
|
11307 |
|
11308 |
|
11309 |
|
11310 |
|
11311 |
|
11312 |
|
11313 |
|
11314 |
|
11315 |
|
11316 |
|
11317 |
|
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 |
|
11325 |
|
11326 | var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
11327 | if (!(value && toString.call(value) == objectClass)) {
|
11328 | return false;
|
11329 | }
|
11330 | var valueOf = value.valueOf,
|
11331 | objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
11332 |
|
11333 | return objProto
|
11334 | ? (value == objProto || getPrototypeOf(value) == objProto)
|
11335 | : shimIsPlainObject(value);
|
11336 | };
|
11337 |
|
11338 | |
11339 |
|
11340 |
|
11341 |
|
11342 |
|
11343 |
|
11344 |
|
11345 |
|
11346 |
|
11347 |
|
11348 |
|
11349 |
|
11350 |
|
11351 | function isRegExp(value) {
|
11352 | return value && typeof value == 'object' && toString.call(value) == regexpClass || false;
|
11353 | }
|
11354 |
|
11355 | |
11356 |
|
11357 |
|
11358 |
|
11359 |
|
11360 |
|
11361 |
|
11362 |
|
11363 |
|
11364 |
|
11365 |
|
11366 |
|
11367 |
|
11368 | function isString(value) {
|
11369 | return typeof value == 'string' ||
|
11370 | value && typeof value == 'object' && toString.call(value) == stringClass || false;
|
11371 | }
|
11372 |
|
11373 | |
11374 |
|
11375 |
|
11376 |
|
11377 |
|
11378 |
|
11379 |
|
11380 |
|
11381 |
|
11382 |
|
11383 |
|
11384 |
|
11385 |
|
11386 | function isUndefined(value) {
|
11387 | return typeof value == 'undefined';
|
11388 | }
|
11389 |
|
11390 | |
11391 |
|
11392 |
|
11393 |
|
11394 |
|
11395 |
|
11396 |
|
11397 |
|
11398 |
|
11399 |
|
11400 |
|
11401 |
|
11402 |
|
11403 |
|
11404 |
|
11405 |
|
11406 |
|
11407 |
|
11408 |
|
11409 |
|
11410 |
|
11411 |
|
11412 |
|
11413 |
|
11414 |
|
11415 |
|
11416 |
|
11417 |
|
11418 |
|
11419 |
|
11420 |
|
11421 |
|
11422 |
|
11423 |
|
11424 |
|
11425 |
|
11426 | function mapValues(object, callback, thisArg) {
|
11427 | var result = {};
|
11428 | callback = lodash.createCallback(callback, thisArg, 3);
|
11429 |
|
11430 | forOwn(object, function(value, key, object) {
|
11431 | result[key] = callback(value, key, object);
|
11432 | });
|
11433 | return result;
|
11434 | }
|
11435 |
|
11436 | |
11437 |
|
11438 |
|
11439 |
|
11440 |
|
11441 |
|
11442 |
|
11443 |
|
11444 |
|
11445 |
|
11446 |
|
11447 |
|
11448 |
|
11449 |
|
11450 |
|
11451 |
|
11452 |
|
11453 |
|
11454 |
|
11455 |
|
11456 |
|
11457 |
|
11458 |
|
11459 |
|
11460 |
|
11461 |
|
11462 |
|
11463 |
|
11464 |
|
11465 |
|
11466 |
|
11467 |
|
11468 |
|
11469 |
|
11470 |
|
11471 |
|
11472 |
|
11473 |
|
11474 |
|
11475 |
|
11476 |
|
11477 |
|
11478 |
|
11479 |
|
11480 |
|
11481 |
|
11482 |
|
11483 |
|
11484 |
|
11485 |
|
11486 |
|
11487 | function merge(object) {
|
11488 | var args = arguments,
|
11489 | length = 2;
|
11490 |
|
11491 | if (!isObject(object)) {
|
11492 | return object;
|
11493 | }
|
11494 |
|
11495 |
|
11496 | if (typeof args[2] != 'number') {
|
11497 | length = args.length;
|
11498 | }
|
11499 | if (length > 3 && typeof args[length - 2] == 'function') {
|
11500 | var callback = baseCreateCallback(args[--length - 1], args[length--], 2);
|
11501 | } else if (length > 2 && typeof args[length - 1] == 'function') {
|
11502 | callback = args[--length];
|
11503 | }
|
11504 | var sources = slice(arguments, 1, length),
|
11505 | index = -1,
|
11506 | stackA = getArray(),
|
11507 | stackB = getArray();
|
11508 |
|
11509 | while (++index < length) {
|
11510 | baseMerge(object, sources[index], callback, stackA, stackB);
|
11511 | }
|
11512 | releaseArray(stackA);
|
11513 | releaseArray(stackB);
|
11514 | return object;
|
11515 | }
|
11516 |
|
11517 | |
11518 |
|
11519 |
|
11520 |
|
11521 |
|
11522 |
|
11523 |
|
11524 |
|
11525 |
|
11526 |
|
11527 |
|
11528 |
|
11529 |
|
11530 |
|
11531 |
|
11532 |
|
11533 |
|
11534 |
|
11535 |
|
11536 |
|
11537 |
|
11538 |
|
11539 |
|
11540 |
|
11541 |
|
11542 |
|
11543 | function omit(object, callback, thisArg) {
|
11544 | var result = {};
|
11545 | if (typeof callback != 'function') {
|
11546 | var props = [];
|
11547 | forIn(object, function(value, key) {
|
11548 | props.push(key);
|
11549 | });
|
11550 | props = baseDifference(props, baseFlatten(arguments, true, false, 1));
|
11551 |
|
11552 | var index = -1,
|
11553 | length = props.length;
|
11554 |
|
11555 | while (++index < length) {
|
11556 | var key = props[index];
|
11557 | result[key] = object[key];
|
11558 | }
|
11559 | } else {
|
11560 | callback = lodash.createCallback(callback, thisArg, 3);
|
11561 | forIn(object, function(value, key, object) {
|
11562 | if (!callback(value, key, object)) {
|
11563 | result[key] = value;
|
11564 | }
|
11565 | });
|
11566 | }
|
11567 | return result;
|
11568 | }
|
11569 |
|
11570 | |
11571 |
|
11572 |
|
11573 |
|
11574 |
|
11575 |
|
11576 |
|
11577 |
|
11578 |
|
11579 |
|
11580 |
|
11581 |
|
11582 |
|
11583 |
|
11584 | function pairs(object) {
|
11585 | var index = -1,
|
11586 | props = keys(object),
|
11587 | length = props.length,
|
11588 | result = Array(length);
|
11589 |
|
11590 | while (++index < length) {
|
11591 | var key = props[index];
|
11592 | result[index] = [key, object[key]];
|
11593 | }
|
11594 | return result;
|
11595 | }
|
11596 |
|
11597 | |
11598 |
|
11599 |
|
11600 |
|
11601 |
|
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 |
|
11607 |
|
11608 |
|
11609 |
|
11610 |
|
11611 |
|
11612 |
|
11613 |
|
11614 |
|
11615 |
|
11616 |
|
11617 |
|
11618 |
|
11619 |
|
11620 |
|
11621 |
|
11622 |
|
11623 |
|
11624 | function pick(object, callback, thisArg) {
|
11625 | var result = {};
|
11626 | if (typeof callback != 'function') {
|
11627 | var index = -1,
|
11628 | props = baseFlatten(arguments, true, false, 1),
|
11629 | length = isObject(object) ? props.length : 0;
|
11630 |
|
11631 | while (++index < length) {
|
11632 | var key = props[index];
|
11633 | if (key in object) {
|
11634 | result[key] = object[key];
|
11635 | }
|
11636 | }
|
11637 | } else {
|
11638 | callback = lodash.createCallback(callback, thisArg, 3);
|
11639 | forIn(object, function(value, key, object) {
|
11640 | if (callback(value, key, object)) {
|
11641 | result[key] = value;
|
11642 | }
|
11643 | });
|
11644 | }
|
11645 | return result;
|
11646 | }
|
11647 |
|
11648 | |
11649 |
|
11650 |
|
11651 |
|
11652 |
|
11653 |
|
11654 |
|
11655 |
|
11656 |
|
11657 |
|
11658 |
|
11659 |
|
11660 |
|
11661 |
|
11662 |
|
11663 |
|
11664 |
|
11665 |
|
11666 |
|
11667 |
|
11668 |
|
11669 |
|
11670 |
|
11671 |
|
11672 |
|
11673 |
|
11674 |
|
11675 |
|
11676 |
|
11677 |
|
11678 |
|
11679 | function transform(object, callback, accumulator, thisArg) {
|
11680 | var isArr = isArray(object);
|
11681 | if (accumulator == null) {
|
11682 | if (isArr) {
|
11683 | accumulator = [];
|
11684 | } else {
|
11685 | var ctor = object && object.constructor,
|
11686 | proto = ctor && ctor.prototype;
|
11687 |
|
11688 | accumulator = baseCreate(proto);
|
11689 | }
|
11690 | }
|
11691 | if (callback) {
|
11692 | callback = lodash.createCallback(callback, thisArg, 4);
|
11693 | (isArr ? forEach : forOwn)(object, function(value, index, object) {
|
11694 | return callback(accumulator, value, index, object);
|
11695 | });
|
11696 | }
|
11697 | return accumulator;
|
11698 | }
|
11699 |
|
11700 | |
11701 |
|
11702 |
|
11703 |
|
11704 |
|
11705 |
|
11706 |
|
11707 |
|
11708 |
|
11709 |
|
11710 |
|
11711 |
|
11712 |
|
11713 | function values(object) {
|
11714 | var index = -1,
|
11715 | props = keys(object),
|
11716 | length = props.length,
|
11717 | result = Array(length);
|
11718 |
|
11719 | while (++index < length) {
|
11720 | result[index] = object[props[index]];
|
11721 | }
|
11722 | return result;
|
11723 | }
|
11724 |
|
11725 |
|
11726 |
|
11727 | |
11728 |
|
11729 |
|
11730 |
|
11731 |
|
11732 |
|
11733 |
|
11734 |
|
11735 |
|
11736 |
|
11737 |
|
11738 |
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 |
|
11747 |
|
11748 | function at(collection) {
|
11749 | var args = arguments,
|
11750 | index = -1,
|
11751 | props = baseFlatten(args, true, false, 1),
|
11752 | length = (args[2] && args[2][args[1]] === collection) ? 1 : props.length,
|
11753 | result = Array(length);
|
11754 |
|
11755 | while(++index < length) {
|
11756 | result[index] = collection[props[index]];
|
11757 | }
|
11758 | return result;
|
11759 | }
|
11760 |
|
11761 | |
11762 |
|
11763 |
|
11764 |
|
11765 |
|
11766 |
|
11767 |
|
11768 |
|
11769 |
|
11770 |
|
11771 |
|
11772 |
|
11773 |
|
11774 |
|
11775 |
|
11776 |
|
11777 |
|
11778 |
|
11779 |
|
11780 |
|
11781 |
|
11782 |
|
11783 |
|
11784 |
|
11785 |
|
11786 |
|
11787 |
|
11788 | function contains(collection, target, fromIndex) {
|
11789 | var index = -1,
|
11790 | indexOf = getIndexOf(),
|
11791 | length = collection ? collection.length : 0,
|
11792 | result = false;
|
11793 |
|
11794 | fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0;
|
11795 | if (isArray(collection)) {
|
11796 | result = indexOf(collection, target, fromIndex) > -1;
|
11797 | } else if (typeof length == 'number') {
|
11798 | result = (isString(collection) ? collection.indexOf(target, fromIndex) : indexOf(collection, target, fromIndex)) > -1;
|
11799 | } else {
|
11800 | forOwn(collection, function(value) {
|
11801 | if (++index >= fromIndex) {
|
11802 | return !(result = value === target);
|
11803 | }
|
11804 | });
|
11805 | }
|
11806 | return result;
|
11807 | }
|
11808 |
|
11809 | |
11810 |
|
11811 |
|
11812 |
|
11813 |
|
11814 |
|
11815 |
|
11816 |
|
11817 |
|
11818 |
|
11819 |
|
11820 |
|
11821 |
|
11822 |
|
11823 |
|
11824 |
|
11825 |
|
11826 |
|
11827 |
|
11828 |
|
11829 |
|
11830 |
|
11831 |
|
11832 |
|
11833 |
|
11834 |
|
11835 |
|
11836 |
|
11837 |
|
11838 |
|
11839 |
|
11840 |
|
11841 |
|
11842 |
|
11843 | var countBy = createAggregator(function(result, value, key) {
|
11844 | (hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1);
|
11845 | });
|
11846 |
|
11847 | |
11848 |
|
11849 |
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 |
|
11856 |
|
11857 |
|
11858 |
|
11859 |
|
11860 |
|
11861 |
|
11862 |
|
11863 |
|
11864 |
|
11865 |
|
11866 |
|
11867 |
|
11868 |
|
11869 |
|
11870 |
|
11871 |
|
11872 |
|
11873 |
|
11874 |
|
11875 |
|
11876 |
|
11877 |
|
11878 |
|
11879 |
|
11880 |
|
11881 |
|
11882 |
|
11883 |
|
11884 |
|
11885 |
|
11886 |
|
11887 |
|
11888 | function every(collection, callback, thisArg) {
|
11889 | var result = true;
|
11890 | callback = lodash.createCallback(callback, thisArg, 3);
|
11891 |
|
11892 | var index = -1,
|
11893 | length = collection ? collection.length : 0;
|
11894 |
|
11895 | if (typeof length == 'number') {
|
11896 | while (++index < length) {
|
11897 | if (!(result = !!callback(collection[index], index, collection))) {
|
11898 | break;
|
11899 | }
|
11900 | }
|
11901 | } else {
|
11902 | forOwn(collection, function(value, index, collection) {
|
11903 | return (result = !!callback(value, index, collection));
|
11904 | });
|
11905 | }
|
11906 | return result;
|
11907 | }
|
11908 |
|
11909 | |
11910 |
|
11911 |
|
11912 |
|
11913 |
|
11914 |
|
11915 |
|
11916 |
|
11917 |
|
11918 |
|
11919 |
|
11920 |
|
11921 |
|
11922 |
|
11923 |
|
11924 |
|
11925 |
|
11926 |
|
11927 |
|
11928 |
|
11929 |
|
11930 |
|
11931 |
|
11932 |
|
11933 |
|
11934 |
|
11935 |
|
11936 |
|
11937 |
|
11938 |
|
11939 |
|
11940 |
|
11941 |
|
11942 |
|
11943 |
|
11944 |
|
11945 |
|
11946 |
|
11947 |
|
11948 |
|
11949 | function filter(collection, callback, thisArg) {
|
11950 | var result = [];
|
11951 | callback = lodash.createCallback(callback, thisArg, 3);
|
11952 |
|
11953 | var index = -1,
|
11954 | length = collection ? collection.length : 0;
|
11955 |
|
11956 | if (typeof length == 'number') {
|
11957 | while (++index < length) {
|
11958 | var value = collection[index];
|
11959 | if (callback(value, index, collection)) {
|
11960 | result.push(value);
|
11961 | }
|
11962 | }
|
11963 | } else {
|
11964 | forOwn(collection, function(value, index, collection) {
|
11965 | if (callback(value, index, collection)) {
|
11966 | result.push(value);
|
11967 | }
|
11968 | });
|
11969 | }
|
11970 | return result;
|
11971 | }
|
11972 |
|
11973 | |
11974 |
|
11975 |
|
11976 |
|
11977 |
|
11978 |
|
11979 |
|
11980 |
|
11981 |
|
11982 |
|
11983 |
|
11984 |
|
11985 |
|
11986 |
|
11987 |
|
11988 |
|
11989 |
|
11990 |
|
11991 |
|
11992 |
|
11993 |
|
11994 |
|
11995 |
|
11996 |
|
11997 |
|
11998 |
|
11999 |
|
12000 |
|
12001 |
|
12002 |
|
12003 |
|
12004 |
|
12005 |
|
12006 |
|
12007 |
|
12008 |
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 |
|
12014 |
|
12015 |
|
12016 | function find(collection, callback, thisArg) {
|
12017 | callback = lodash.createCallback(callback, thisArg, 3);
|
12018 |
|
12019 | var index = -1,
|
12020 | length = collection ? collection.length : 0;
|
12021 |
|
12022 | if (typeof length == 'number') {
|
12023 | while (++index < length) {
|
12024 | var value = collection[index];
|
12025 | if (callback(value, index, collection)) {
|
12026 | return value;
|
12027 | }
|
12028 | }
|
12029 | } else {
|
12030 | var result;
|
12031 | forOwn(collection, function(value, index, collection) {
|
12032 | if (callback(value, index, collection)) {
|
12033 | result = value;
|
12034 | return false;
|
12035 | }
|
12036 | });
|
12037 | return result;
|
12038 | }
|
12039 | }
|
12040 |
|
12041 | |
12042 |
|
12043 |
|
12044 |
|
12045 |
|
12046 |
|
12047 |
|
12048 |
|
12049 |
|
12050 |
|
12051 |
|
12052 |
|
12053 |
|
12054 |
|
12055 |
|
12056 |
|
12057 |
|
12058 |
|
12059 |
|
12060 |
|
12061 | function findLast(collection, callback, thisArg) {
|
12062 | var result;
|
12063 | callback = lodash.createCallback(callback, thisArg, 3);
|
12064 | forEachRight(collection, function(value, index, collection) {
|
12065 | if (callback(value, index, collection)) {
|
12066 | result = value;
|
12067 | return false;
|
12068 | }
|
12069 | });
|
12070 | return result;
|
12071 | }
|
12072 |
|
12073 | |
12074 |
|
12075 |
|
12076 |
|
12077 |
|
12078 |
|
12079 |
|
12080 |
|
12081 |
|
12082 |
|
12083 |
|
12084 |
|
12085 |
|
12086 |
|
12087 |
|
12088 |
|
12089 |
|
12090 |
|
12091 |
|
12092 |
|
12093 |
|
12094 |
|
12095 |
|
12096 |
|
12097 |
|
12098 |
|
12099 | function forEach(collection, callback, thisArg) {
|
12100 | var index = -1,
|
12101 | length = collection ? collection.length : 0;
|
12102 |
|
12103 | callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
|
12104 | if (typeof length == 'number') {
|
12105 | while (++index < length) {
|
12106 | if (callback(collection[index], index, collection) === false) {
|
12107 | break;
|
12108 | }
|
12109 | }
|
12110 | } else {
|
12111 | forOwn(collection, callback);
|
12112 | }
|
12113 | return collection;
|
12114 | }
|
12115 |
|
12116 | |
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 |
|
12123 |
|
12124 |
|
12125 |
|
12126 |
|
12127 |
|
12128 |
|
12129 |
|
12130 |
|
12131 |
|
12132 |
|
12133 | function forEachRight(collection, callback, thisArg) {
|
12134 | var length = collection ? collection.length : 0;
|
12135 | callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
|
12136 | if (typeof length == 'number') {
|
12137 | while (length--) {
|
12138 | if (callback(collection[length], length, collection) === false) {
|
12139 | break;
|
12140 | }
|
12141 | }
|
12142 | } else {
|
12143 | var props = keys(collection);
|
12144 | length = props.length;
|
12145 | forOwn(collection, function(value, key, collection) {
|
12146 | key = props ? props[--length] : --length;
|
12147 | return callback(collection[key], key, collection);
|
12148 | });
|
12149 | }
|
12150 | return collection;
|
12151 | }
|
12152 |
|
12153 | |
12154 |
|
12155 |
|
12156 |
|
12157 |
|
12158 |
|
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 |
|
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 |
|
12175 |
|
12176 |
|
12177 |
|
12178 |
|
12179 |
|
12180 |
|
12181 |
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 |
|
12187 |
|
12188 | var groupBy = createAggregator(function(result, value, key) {
|
12189 | (hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value);
|
12190 | });
|
12191 |
|
12192 | |
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 |
|
12198 |
|
12199 |
|
12200 |
|
12201 |
|
12202 |
|
12203 |
|
12204 |
|
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 |
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 |
|
12219 |
|
12220 |
|
12221 |
|
12222 |
|
12223 |
|
12224 |
|
12225 |
|
12226 |
|
12227 |
|
12228 |
|
12229 |
|
12230 |
|
12231 | var indexBy = createAggregator(function(result, value, key) {
|
12232 | result[key] = value;
|
12233 | });
|
12234 |
|
12235 | |
12236 |
|
12237 |
|
12238 |
|
12239 |
|
12240 |
|
12241 |
|
12242 |
|
12243 |
|
12244 |
|
12245 |
|
12246 |
|
12247 |
|
12248 |
|
12249 |
|
12250 |
|
12251 |
|
12252 |
|
12253 |
|
12254 |
|
12255 |
|
12256 |
|
12257 | function invoke(collection, methodName) {
|
12258 | var args = slice(arguments, 2),
|
12259 | index = -1,
|
12260 | isFunc = typeof methodName == 'function',
|
12261 | length = collection ? collection.length : 0,
|
12262 | result = Array(typeof length == 'number' ? length : 0);
|
12263 |
|
12264 | forEach(collection, function(value) {
|
12265 | result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
|
12266 | });
|
12267 | return result;
|
12268 | }
|
12269 |
|
12270 | |
12271 |
|
12272 |
|
12273 |
|
12274 |
|
12275 |
|
12276 |
|
12277 |
|
12278 |
|
12279 |
|
12280 |
|
12281 |
|
12282 |
|
12283 |
|
12284 |
|
12285 |
|
12286 |
|
12287 |
|
12288 |
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 |
|
12294 |
|
12295 |
|
12296 |
|
12297 |
|
12298 |
|
12299 |
|
12300 |
|
12301 |
|
12302 |
|
12303 |
|
12304 |
|
12305 |
|
12306 |
|
12307 |
|
12308 |
|
12309 | function map(collection, callback, thisArg) {
|
12310 | var index = -1,
|
12311 | length = collection ? collection.length : 0;
|
12312 |
|
12313 | callback = lodash.createCallback(callback, thisArg, 3);
|
12314 | if (typeof length == 'number') {
|
12315 | var result = Array(length);
|
12316 | while (++index < length) {
|
12317 | result[index] = callback(collection[index], index, collection);
|
12318 | }
|
12319 | } else {
|
12320 | result = [];
|
12321 | forOwn(collection, function(value, key, collection) {
|
12322 | result[++index] = callback(value, key, collection);
|
12323 | });
|
12324 | }
|
12325 | return result;
|
12326 | }
|
12327 |
|
12328 | |
12329 |
|
12330 |
|
12331 |
|
12332 |
|
12333 |
|
12334 |
|
12335 |
|
12336 |
|
12337 |
|
12338 |
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 |
|
12347 |
|
12348 |
|
12349 |
|
12350 |
|
12351 |
|
12352 |
|
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 |
|
12363 |
|
12364 |
|
12365 |
|
12366 |
|
12367 |
|
12368 | function max(collection, callback, thisArg) {
|
12369 | var computed = -Infinity,
|
12370 | result = computed;
|
12371 |
|
12372 |
|
12373 |
|
12374 | if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
|
12375 | callback = null;
|
12376 | }
|
12377 | if (callback == null && isArray(collection)) {
|
12378 | var index = -1,
|
12379 | length = collection.length;
|
12380 |
|
12381 | while (++index < length) {
|
12382 | var value = collection[index];
|
12383 | if (value > result) {
|
12384 | result = value;
|
12385 | }
|
12386 | }
|
12387 | } else {
|
12388 | callback = (callback == null && isString(collection))
|
12389 | ? charAtCallback
|
12390 | : lodash.createCallback(callback, thisArg, 3);
|
12391 |
|
12392 | forEach(collection, function(value, index, collection) {
|
12393 | var current = callback(value, index, collection);
|
12394 | if (current > computed) {
|
12395 | computed = current;
|
12396 | result = value;
|
12397 | }
|
12398 | });
|
12399 | }
|
12400 | return result;
|
12401 | }
|
12402 |
|
12403 | |
12404 |
|
12405 |
|
12406 |
|
12407 |
|
12408 |
|
12409 |
|
12410 |
|
12411 |
|
12412 |
|
12413 |
|
12414 |
|
12415 |
|
12416 |
|
12417 |
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 |
|
12425 |
|
12426 |
|
12427 |
|
12428 |
|
12429 |
|
12430 |
|
12431 |
|
12432 |
|
12433 |
|
12434 |
|
12435 |
|
12436 |
|
12437 |
|
12438 |
|
12439 |
|
12440 |
|
12441 |
|
12442 |
|
12443 | function min(collection, callback, thisArg) {
|
12444 | var computed = Infinity,
|
12445 | result = computed;
|
12446 |
|
12447 |
|
12448 |
|
12449 | if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
|
12450 | callback = null;
|
12451 | }
|
12452 | if (callback == null && isArray(collection)) {
|
12453 | var index = -1,
|
12454 | length = collection.length;
|
12455 |
|
12456 | while (++index < length) {
|
12457 | var value = collection[index];
|
12458 | if (value < result) {
|
12459 | result = value;
|
12460 | }
|
12461 | }
|
12462 | } else {
|
12463 | callback = (callback == null && isString(collection))
|
12464 | ? charAtCallback
|
12465 | : lodash.createCallback(callback, thisArg, 3);
|
12466 |
|
12467 | forEach(collection, function(value, index, collection) {
|
12468 | var current = callback(value, index, collection);
|
12469 | if (current < computed) {
|
12470 | computed = current;
|
12471 | result = value;
|
12472 | }
|
12473 | });
|
12474 | }
|
12475 | return result;
|
12476 | }
|
12477 |
|
12478 | |
12479 |
|
12480 |
|
12481 |
|
12482 |
|
12483 |
|
12484 |
|
12485 |
|
12486 |
|
12487 |
|
12488 |
|
12489 |
|
12490 |
|
12491 |
|
12492 |
|
12493 |
|
12494 |
|
12495 |
|
12496 |
|
12497 |
|
12498 | var pluck = map;
|
12499 |
|
12500 | |
12501 |
|
12502 |
|
12503 |
|
12504 |
|
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 |
|
12514 |
|
12515 |
|
12516 |
|
12517 |
|
12518 |
|
12519 |
|
12520 |
|
12521 |
|
12522 |
|
12523 |
|
12524 |
|
12525 |
|
12526 |
|
12527 |
|
12528 |
|
12529 |
|
12530 | function reduce(collection, callback, accumulator, thisArg) {
|
12531 | if (!collection) return accumulator;
|
12532 | var noaccum = arguments.length < 3;
|
12533 | callback = lodash.createCallback(callback, thisArg, 4);
|
12534 |
|
12535 | var index = -1,
|
12536 | length = collection.length;
|
12537 |
|
12538 | if (typeof length == 'number') {
|
12539 | if (noaccum) {
|
12540 | accumulator = collection[++index];
|
12541 | }
|
12542 | while (++index < length) {
|
12543 | accumulator = callback(accumulator, collection[index], index, collection);
|
12544 | }
|
12545 | } else {
|
12546 | forOwn(collection, function(value, index, collection) {
|
12547 | accumulator = noaccum
|
12548 | ? (noaccum = false, value)
|
12549 | : callback(accumulator, value, index, collection)
|
12550 | });
|
12551 | }
|
12552 | return accumulator;
|
12553 | }
|
12554 |
|
12555 | |
12556 |
|
12557 |
|
12558 |
|
12559 |
|
12560 |
|
12561 |
|
12562 |
|
12563 |
|
12564 |
|
12565 |
|
12566 |
|
12567 |
|
12568 |
|
12569 |
|
12570 |
|
12571 |
|
12572 |
|
12573 |
|
12574 | function reduceRight(collection, callback, accumulator, thisArg) {
|
12575 | var noaccum = arguments.length < 3;
|
12576 | callback = lodash.createCallback(callback, thisArg, 4);
|
12577 | forEachRight(collection, function(value, index, collection) {
|
12578 | accumulator = noaccum
|
12579 | ? (noaccum = false, value)
|
12580 | : callback(accumulator, value, index, collection);
|
12581 | });
|
12582 | return accumulator;
|
12583 | }
|
12584 |
|
12585 | |
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 |
|
12595 |
|
12596 |
|
12597 |
|
12598 |
|
12599 |
|
12600 |
|
12601 |
|
12602 |
|
12603 |
|
12604 |
|
12605 |
|
12606 |
|
12607 |
|
12608 |
|
12609 |
|
12610 |
|
12611 |
|
12612 |
|
12613 |
|
12614 |
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 |
|
12620 |
|
12621 |
|
12622 |
|
12623 | function reject(collection, callback, thisArg) {
|
12624 | callback = lodash.createCallback(callback, thisArg, 3);
|
12625 | return filter(collection, function(value, index, collection) {
|
12626 | return !callback(value, index, collection);
|
12627 | });
|
12628 | }
|
12629 |
|
12630 | |
12631 |
|
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 |
|
12640 |
|
12641 |
|
12642 |
|
12643 |
|
12644 |
|
12645 |
|
12646 |
|
12647 |
|
12648 |
|
12649 | function sample(collection, n, guard) {
|
12650 | if (collection && typeof collection.length != 'number') {
|
12651 | collection = values(collection);
|
12652 | }
|
12653 | if (n == null || guard) {
|
12654 | return collection ? collection[baseRandom(0, collection.length - 1)] : undefined;
|
12655 | }
|
12656 | var result = shuffle(collection);
|
12657 | result.length = nativeMin(nativeMax(0, n), result.length);
|
12658 | return result;
|
12659 | }
|
12660 |
|
12661 | |
12662 |
|
12663 |
|
12664 |
|
12665 |
|
12666 |
|
12667 |
|
12668 |
|
12669 |
|
12670 |
|
12671 |
|
12672 |
|
12673 |
|
12674 |
|
12675 | function shuffle(collection) {
|
12676 | var index = -1,
|
12677 | length = collection ? collection.length : 0,
|
12678 | result = Array(typeof length == 'number' ? length : 0);
|
12679 |
|
12680 | forEach(collection, function(value) {
|
12681 | var rand = baseRandom(0, ++index);
|
12682 | result[index] = result[rand];
|
12683 | result[rand] = value;
|
12684 | });
|
12685 | return result;
|
12686 | }
|
12687 |
|
12688 | |
12689 |
|
12690 |
|
12691 |
|
12692 |
|
12693 |
|
12694 |
|
12695 |
|
12696 |
|
12697 |
|
12698 |
|
12699 |
|
12700 |
|
12701 |
|
12702 |
|
12703 |
|
12704 |
|
12705 |
|
12706 |
|
12707 |
|
12708 | function size(collection) {
|
12709 | var length = collection ? collection.length : 0;
|
12710 | return typeof length == 'number' ? length : keys(collection).length;
|
12711 | }
|
12712 |
|
12713 | |
12714 |
|
12715 |
|
12716 |
|
12717 |
|
12718 |
|
12719 |
|
12720 |
|
12721 |
|
12722 |
|
12723 |
|
12724 |
|
12725 |
|
12726 |
|
12727 |
|
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 |
|
12734 |
|
12735 |
|
12736 |
|
12737 |
|
12738 |
|
12739 |
|
12740 |
|
12741 |
|
12742 |
|
12743 |
|
12744 |
|
12745 |
|
12746 |
|
12747 |
|
12748 |
|
12749 |
|
12750 |
|
12751 |
|
12752 |
|
12753 |
|
12754 |
|
12755 | function some(collection, callback, thisArg) {
|
12756 | var result;
|
12757 | callback = lodash.createCallback(callback, thisArg, 3);
|
12758 |
|
12759 | var index = -1,
|
12760 | length = collection ? collection.length : 0;
|
12761 |
|
12762 | if (typeof length == 'number') {
|
12763 | while (++index < length) {
|
12764 | if ((result = callback(collection[index], index, collection))) {
|
12765 | break;
|
12766 | }
|
12767 | }
|
12768 | } else {
|
12769 | forOwn(collection, function(value, index, collection) {
|
12770 | return !(result = callback(value, index, collection));
|
12771 | });
|
12772 | }
|
12773 | return !!result;
|
12774 | }
|
12775 |
|
12776 | |
12777 |
|
12778 |
|
12779 |
|
12780 |
|
12781 |
|
12782 |
|
12783 |
|
12784 |
|
12785 |
|
12786 |
|
12787 |
|
12788 |
|
12789 |
|
12790 |
|
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 |
|
12796 |
|
12797 |
|
12798 |
|
12799 |
|
12800 |
|
12801 |
|
12802 |
|
12803 |
|
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 |
|
12824 |
|
12825 | function sortBy(collection, callback, thisArg) {
|
12826 | var index = -1,
|
12827 | isArr = isArray(callback),
|
12828 | length = collection ? collection.length : 0,
|
12829 | result = Array(typeof length == 'number' ? length : 0);
|
12830 |
|
12831 | if (!isArr) {
|
12832 | callback = lodash.createCallback(callback, thisArg, 3);
|
12833 | }
|
12834 | forEach(collection, function(value, key, collection) {
|
12835 | var object = result[++index] = getObject();
|
12836 | if (isArr) {
|
12837 | object.criteria = map(callback, function(key) { return value[key]; });
|
12838 | } else {
|
12839 | (object.criteria = getArray())[0] = callback(value, key, collection);
|
12840 | }
|
12841 | object.index = index;
|
12842 | object.value = value;
|
12843 | });
|
12844 |
|
12845 | length = result.length;
|
12846 | result.sort(compareAscending);
|
12847 | while (length--) {
|
12848 | var object = result[length];
|
12849 | result[length] = object.value;
|
12850 | if (!isArr) {
|
12851 | releaseArray(object.criteria);
|
12852 | }
|
12853 | releaseObject(object);
|
12854 | }
|
12855 | return result;
|
12856 | }
|
12857 |
|
12858 | |
12859 |
|
12860 |
|
12861 |
|
12862 |
|
12863 |
|
12864 |
|
12865 |
|
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 |
|
12871 | function toArray(collection) {
|
12872 | if (collection && typeof collection.length == 'number') {
|
12873 | return slice(collection);
|
12874 | }
|
12875 | return values(collection);
|
12876 | }
|
12877 |
|
12878 | |
12879 |
|
12880 |
|
12881 |
|
12882 |
|
12883 |
|
12884 |
|
12885 |
|
12886 |
|
12887 |
|
12888 |
|
12889 |
|
12890 |
|
12891 |
|
12892 |
|
12893 |
|
12894 |
|
12895 |
|
12896 |
|
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 | var where = filter;
|
12904 |
|
12905 |
|
12906 |
|
12907 | |
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 |
|
12921 | function compact(array) {
|
12922 | var index = -1,
|
12923 | length = array ? array.length : 0,
|
12924 | result = [];
|
12925 |
|
12926 | while (++index < length) {
|
12927 | var value = array[index];
|
12928 | if (value) {
|
12929 | result.push(value);
|
12930 | }
|
12931 | }
|
12932 | return result;
|
12933 | }
|
12934 |
|
12935 | |
12936 |
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 |
|
12946 |
|
12947 |
|
12948 |
|
12949 |
|
12950 | function difference(array) {
|
12951 | return baseDifference(array, baseFlatten(arguments, true, true, 1));
|
12952 | }
|
12953 |
|
12954 | |
12955 |
|
12956 |
|
12957 |
|
12958 |
|
12959 |
|
12960 |
|
12961 |
|
12962 |
|
12963 |
|
12964 |
|
12965 |
|
12966 |
|
12967 |
|
12968 |
|
12969 |
|
12970 |
|
12971 |
|
12972 |
|
12973 |
|
12974 |
|
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 |
|
12983 |
|
12984 |
|
12985 |
|
12986 |
|
12987 |
|
12988 |
|
12989 |
|
12990 |
|
12991 |
|
12992 |
|
12993 |
|
12994 |
|
12995 | function findIndex(array, callback, thisArg) {
|
12996 | var index = -1,
|
12997 | length = array ? array.length : 0;
|
12998 |
|
12999 | callback = lodash.createCallback(callback, thisArg, 3);
|
13000 | while (++index < length) {
|
13001 | if (callback(array[index], index, array)) {
|
13002 | return index;
|
13003 | }
|
13004 | }
|
13005 | return -1;
|
13006 | }
|
13007 |
|
13008 | |
13009 |
|
13010 |
|
13011 |
|
13012 |
|
13013 |
|
13014 |
|
13015 |
|
13016 |
|
13017 |
|
13018 |
|
13019 |
|
13020 |
|
13021 |
|
13022 |
|
13023 |
|
13024 |
|
13025 |
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 |
|
13032 |
|
13033 |
|
13034 |
|
13035 |
|
13036 |
|
13037 |
|
13038 |
|
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 |
|
13048 |
|
13049 | function findLastIndex(array, callback, thisArg) {
|
13050 | var length = array ? array.length : 0;
|
13051 | callback = lodash.createCallback(callback, thisArg, 3);
|
13052 | while (length--) {
|
13053 | if (callback(array[length], length, array)) {
|
13054 | return length;
|
13055 | }
|
13056 | }
|
13057 | return -1;
|
13058 | }
|
13059 |
|
13060 | |
13061 |
|
13062 |
|
13063 |
|
13064 |
|
13065 |
|
13066 |
|
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 |
|
13078 |
|
13079 |
|
13080 |
|
13081 |
|
13082 |
|
13083 |
|
13084 |
|
13085 |
|
13086 |
|
13087 |
|
13088 |
|
13089 |
|
13090 |
|
13091 |
|
13092 |
|
13093 |
|
13094 |
|
13095 |
|
13096 |
|
13097 |
|
13098 |
|
13099 |
|
13100 |
|
13101 |
|
13102 |
|
13103 |
|
13104 |
|
13105 |
|
13106 |
|
13107 |
|
13108 |
|
13109 |
|
13110 |
|
13111 | function first(array, callback, thisArg) {
|
13112 | var n = 0,
|
13113 | length = array ? array.length : 0;
|
13114 |
|
13115 | if (typeof callback != 'number' && callback != null) {
|
13116 | var index = -1;
|
13117 | callback = lodash.createCallback(callback, thisArg, 3);
|
13118 | while (++index < length && callback(array[index], index, array)) {
|
13119 | n++;
|
13120 | }
|
13121 | } else {
|
13122 | n = callback;
|
13123 | if (n == null || thisArg) {
|
13124 | return array ? array[0] : undefined;
|
13125 | }
|
13126 | }
|
13127 | return slice(array, 0, nativeMin(nativeMax(0, n), length));
|
13128 | }
|
13129 |
|
13130 | |
13131 |
|
13132 |
|
13133 |
|
13134 |
|
13135 |
|
13136 |
|
13137 |
|
13138 |
|
13139 |
|
13140 |
|
13141 |
|
13142 |
|
13143 |
|
13144 |
|
13145 |
|
13146 |
|
13147 |
|
13148 |
|
13149 |
|
13150 |
|
13151 |
|
13152 |
|
13153 |
|
13154 |
|
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 |
|
13160 |
|
13161 |
|
13162 |
|
13163 |
|
13164 |
|
13165 |
|
13166 |
|
13167 |
|
13168 |
|
13169 |
|
13170 |
|
13171 | function flatten(array, isShallow, callback, thisArg) {
|
13172 |
|
13173 | if (typeof isShallow != 'boolean' && isShallow != null) {
|
13174 | thisArg = callback;
|
13175 | callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow;
|
13176 | isShallow = false;
|
13177 | }
|
13178 | if (callback != null) {
|
13179 | array = map(array, callback, thisArg);
|
13180 | }
|
13181 | return baseFlatten(array, isShallow);
|
13182 | }
|
13183 |
|
13184 | |
13185 |
|
13186 |
|
13187 |
|
13188 |
|
13189 |
|
13190 |
|
13191 |
|
13192 |
|
13193 |
|
13194 |
|
13195 |
|
13196 |
|
13197 |
|
13198 |
|
13199 |
|
13200 |
|
13201 |
|
13202 |
|
13203 |
|
13204 |
|
13205 |
|
13206 |
|
13207 |
|
13208 | function indexOf(array, value, fromIndex) {
|
13209 | if (typeof fromIndex == 'number') {
|
13210 | var length = array ? array.length : 0;
|
13211 | fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex || 0);
|
13212 | } else if (fromIndex) {
|
13213 | var index = sortedIndex(array, value);
|
13214 | return array[index] === value ? index : -1;
|
13215 | }
|
13216 | return baseIndexOf(array, value, fromIndex);
|
13217 | }
|
13218 |
|
13219 | |
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 |
|
13227 |
|
13228 |
|
13229 |
|
13230 |
|
13231 |
|
13232 |
|
13233 |
|
13234 |
|
13235 |
|
13236 |
|
13237 |
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 |
|
13243 |
|
13244 |
|
13245 |
|
13246 |
|
13247 |
|
13248 |
|
13249 |
|
13250 |
|
13251 |
|
13252 |
|
13253 |
|
13254 |
|
13255 |
|
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 |
|
13264 |
|
13265 |
|
13266 |
|
13267 |
|
13268 |
|
13269 | function initial(array, callback, thisArg) {
|
13270 | var n = 0,
|
13271 | length = array ? array.length : 0;
|
13272 |
|
13273 | if (typeof callback != 'number' && callback != null) {
|
13274 | var index = length;
|
13275 | callback = lodash.createCallback(callback, thisArg, 3);
|
13276 | while (index-- && callback(array[index], index, array)) {
|
13277 | n++;
|
13278 | }
|
13279 | } else {
|
13280 | n = (callback == null || thisArg) ? 1 : callback || n;
|
13281 | }
|
13282 | return slice(array, 0, nativeMin(nativeMax(0, length - n), length));
|
13283 | }
|
13284 |
|
13285 | |
13286 |
|
13287 |
|
13288 |
|
13289 |
|
13290 |
|
13291 |
|
13292 |
|
13293 |
|
13294 |
|
13295 |
|
13296 |
|
13297 |
|
13298 |
|
13299 | function intersection() {
|
13300 | var args = [],
|
13301 | argsIndex = -1,
|
13302 | argsLength = arguments.length,
|
13303 | caches = getArray(),
|
13304 | indexOf = getIndexOf(),
|
13305 | trustIndexOf = indexOf === baseIndexOf,
|
13306 | seen = getArray();
|
13307 |
|
13308 | while (++argsIndex < argsLength) {
|
13309 | var value = arguments[argsIndex];
|
13310 | if (isArray(value) || isArguments(value)) {
|
13311 | args.push(value);
|
13312 | caches.push(trustIndexOf && value.length >= largeArraySize &&
|
13313 | createCache(argsIndex ? args[argsIndex] : seen));
|
13314 | }
|
13315 | }
|
13316 | var array = args[0],
|
13317 | index = -1,
|
13318 | length = array ? array.length : 0,
|
13319 | result = [];
|
13320 |
|
13321 | outer:
|
13322 | while (++index < length) {
|
13323 | var cache = caches[0];
|
13324 | value = array[index];
|
13325 |
|
13326 | if ((cache ? cacheIndexOf(cache, value) : indexOf(seen, value)) < 0) {
|
13327 | argsIndex = argsLength;
|
13328 | (cache || seen).push(value);
|
13329 | while (--argsIndex) {
|
13330 | cache = caches[argsIndex];
|
13331 | if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
|
13332 | continue outer;
|
13333 | }
|
13334 | }
|
13335 | result.push(value);
|
13336 | }
|
13337 | }
|
13338 | while (argsLength--) {
|
13339 | cache = caches[argsLength];
|
13340 | if (cache) {
|
13341 | releaseObject(cache);
|
13342 | }
|
13343 | }
|
13344 | releaseArray(caches);
|
13345 | releaseArray(seen);
|
13346 | return result;
|
13347 | }
|
13348 |
|
13349 | |
13350 |
|
13351 |
|
13352 |
|
13353 |
|
13354 |
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 |
|
13360 |
|
13361 |
|
13362 |
|
13363 |
|
13364 |
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 |
|
13383 |
|
13384 |
|
13385 |
|
13386 |
|
13387 |
|
13388 |
|
13389 |
|
13390 |
|
13391 |
|
13392 |
|
13393 |
|
13394 |
|
13395 |
|
13396 |
|
13397 |
|
13398 |
|
13399 | function last(array, callback, thisArg) {
|
13400 | var n = 0,
|
13401 | length = array ? array.length : 0;
|
13402 |
|
13403 | if (typeof callback != 'number' && callback != null) {
|
13404 | var index = length;
|
13405 | callback = lodash.createCallback(callback, thisArg, 3);
|
13406 | while (index-- && callback(array[index], index, array)) {
|
13407 | n++;
|
13408 | }
|
13409 | } else {
|
13410 | n = callback;
|
13411 | if (n == null || thisArg) {
|
13412 | return array ? array[length - 1] : undefined;
|
13413 | }
|
13414 | }
|
13415 | return slice(array, nativeMax(0, length - n));
|
13416 | }
|
13417 |
|
13418 | |
13419 |
|
13420 |
|
13421 |
|
13422 |
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 |
|
13428 |
|
13429 |
|
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 |
|
13435 |
|
13436 |
|
13437 |
|
13438 |
|
13439 |
|
13440 |
|
13441 |
|
13442 |
|
13443 |
|
13444 |
|
13445 | function lastIndexOf(array, value, fromIndex) {
|
13446 | var index = array ? array.length : 0;
|
13447 | if (typeof fromIndex == 'number') {
|
13448 | index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1;
|
13449 | }
|
13450 | while (index--) {
|
13451 | if (array[index] === value) {
|
13452 | return index;
|
13453 | }
|
13454 | }
|
13455 | return -1;
|
13456 | }
|
13457 |
|
13458 | |
13459 |
|
13460 |
|
13461 |
|
13462 |
|
13463 |
|
13464 |
|
13465 |
|
13466 |
|
13467 |
|
13468 |
|
13469 |
|
13470 |
|
13471 |
|
13472 |
|
13473 |
|
13474 |
|
13475 | function pull(array) {
|
13476 | var args = arguments,
|
13477 | argsIndex = 0,
|
13478 | argsLength = args.length,
|
13479 | length = array ? array.length : 0;
|
13480 |
|
13481 | while (++argsIndex < argsLength) {
|
13482 | var index = -1,
|
13483 | value = args[argsIndex];
|
13484 | while (++index < length) {
|
13485 | if (array[index] === value) {
|
13486 | splice.call(array, index--, 1);
|
13487 | length--;
|
13488 | }
|
13489 | }
|
13490 | }
|
13491 | return array;
|
13492 | }
|
13493 |
|
13494 | |
13495 |
|
13496 |
|
13497 |
|
13498 |
|
13499 |
|
13500 |
|
13501 |
|
13502 |
|
13503 |
|
13504 |
|
13505 |
|
13506 |
|
13507 |
|
13508 |
|
13509 |
|
13510 |
|
13511 |
|
13512 |
|
13513 |
|
13514 |
|
13515 |
|
13516 |
|
13517 |
|
13518 |
|
13519 |
|
13520 |
|
13521 |
|
13522 |
|
13523 |
|
13524 |
|
13525 |
|
13526 | function range(start, end, step) {
|
13527 | start = +start || 0;
|
13528 | step = typeof step == 'number' ? step : (+step || 1);
|
13529 |
|
13530 | if (end == null) {
|
13531 | end = start;
|
13532 | start = 0;
|
13533 | }
|
13534 |
|
13535 |
|
13536 | var index = -1,
|
13537 | length = nativeMax(0, ceil((end - start) / (step || 1))),
|
13538 | result = Array(length);
|
13539 |
|
13540 | while (++index < length) {
|
13541 | result[index] = start;
|
13542 | start += step;
|
13543 | }
|
13544 | return result;
|
13545 | }
|
13546 |
|
13547 | |
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 |
|
13553 |
|
13554 |
|
13555 |
|
13556 |
|
13557 |
|
13558 |
|
13559 |
|
13560 |
|
13561 |
|
13562 |
|
13563 |
|
13564 |
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 |
|
13573 |
|
13574 |
|
13575 |
|
13576 |
|
13577 |
|
13578 |
|
13579 | function remove(array, callback, thisArg) {
|
13580 | var index = -1,
|
13581 | length = array ? array.length : 0,
|
13582 | result = [];
|
13583 |
|
13584 | callback = lodash.createCallback(callback, thisArg, 3);
|
13585 | while (++index < length) {
|
13586 | var value = array[index];
|
13587 | if (callback(value, index, array)) {
|
13588 | result.push(value);
|
13589 | splice.call(array, index--, 1);
|
13590 | length--;
|
13591 | }
|
13592 | }
|
13593 | return result;
|
13594 | }
|
13595 |
|
13596 | |
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 |
|
13606 |
|
13607 |
|
13608 |
|
13609 |
|
13610 |
|
13611 |
|
13612 |
|
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 |
|
13622 |
|
13623 |
|
13624 |
|
13625 |
|
13626 |
|
13627 |
|
13628 |
|
13629 |
|
13630 |
|
13631 |
|
13632 |
|
13633 |
|
13634 |
|
13635 |
|
13636 |
|
13637 |
|
13638 |
|
13639 |
|
13640 |
|
13641 |
|
13642 |
|
13643 |
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 | function rest(array, callback, thisArg) {
|
13649 | if (typeof callback != 'number' && callback != null) {
|
13650 | var n = 0,
|
13651 | index = -1,
|
13652 | length = array ? array.length : 0;
|
13653 |
|
13654 | callback = lodash.createCallback(callback, thisArg, 3);
|
13655 | while (++index < length && callback(array[index], index, array)) {
|
13656 | n++;
|
13657 | }
|
13658 | } else {
|
13659 | n = (callback == null || thisArg) ? 1 : nativeMax(0, callback);
|
13660 | }
|
13661 | return slice(array, n);
|
13662 | }
|
13663 |
|
13664 | |
13665 |
|
13666 |
|
13667 |
|
13668 |
|
13669 |
|
13670 |
|
13671 |
|
13672 |
|
13673 |
|
13674 |
|
13675 |
|
13676 |
|
13677 |
|
13678 |
|
13679 |
|
13680 |
|
13681 |
|
13682 |
|
13683 |
|
13684 |
|
13685 |
|
13686 |
|
13687 |
|
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 |
|
13703 |
|
13704 |
|
13705 |
|
13706 |
|
13707 |
|
13708 |
|
13709 |
|
13710 |
|
13711 |
|
13712 | function sortedIndex(array, value, callback, thisArg) {
|
13713 | var low = 0,
|
13714 | high = array ? array.length : low;
|
13715 |
|
13716 |
|
13717 | callback = callback ? lodash.createCallback(callback, thisArg, 1) : identity;
|
13718 | value = callback(value);
|
13719 |
|
13720 | while (low < high) {
|
13721 | var mid = (low + high) >>> 1;
|
13722 | (callback(array[mid]) < value)
|
13723 | ? low = mid + 1
|
13724 | : high = mid;
|
13725 | }
|
13726 | return low;
|
13727 | }
|
13728 |
|
13729 | |
13730 |
|
13731 |
|
13732 |
|
13733 |
|
13734 |
|
13735 |
|
13736 |
|
13737 |
|
13738 |
|
13739 |
|
13740 |
|
13741 |
|
13742 |
|
13743 | function union() {
|
13744 | return baseUniq(baseFlatten(arguments, true, true));
|
13745 | }
|
13746 |
|
13747 | |
13748 |
|
13749 |
|
13750 |
|
13751 |
|
13752 |
|
13753 |
|
13754 |
|
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 |
|
13766 |
|
13767 |
|
13768 |
|
13769 |
|
13770 |
|
13771 |
|
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 |
|
13780 |
|
13781 |
|
13782 |
|
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 |
|
13790 |
|
13791 | function uniq(array, isSorted, callback, thisArg) {
|
13792 |
|
13793 | if (typeof isSorted != 'boolean' && isSorted != null) {
|
13794 | thisArg = callback;
|
13795 | callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted;
|
13796 | isSorted = false;
|
13797 | }
|
13798 | if (callback != null) {
|
13799 | callback = lodash.createCallback(callback, thisArg, 3);
|
13800 | }
|
13801 | return baseUniq(array, isSorted, callback);
|
13802 | }
|
13803 |
|
13804 | |
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 |
|
13819 | function without(array) {
|
13820 | return baseDifference(array, slice(arguments, 1));
|
13821 | }
|
13822 |
|
13823 | |
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 |
|
13832 |
|
13833 |
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 |
|
13839 |
|
13840 | function xor() {
|
13841 | var index = -1,
|
13842 | length = arguments.length;
|
13843 |
|
13844 | while (++index < length) {
|
13845 | var array = arguments[index];
|
13846 | if (isArray(array) || isArguments(array)) {
|
13847 | var result = result
|
13848 | ? baseUniq(baseDifference(result, array).concat(baseDifference(array, result)))
|
13849 | : array;
|
13850 | }
|
13851 | }
|
13852 | return result || [];
|
13853 | }
|
13854 |
|
13855 | |
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 | function zip() {
|
13872 | var array = arguments.length > 1 ? arguments : arguments[0],
|
13873 | index = -1,
|
13874 | length = array ? max(pluck(array, 'length')) : 0,
|
13875 | result = Array(length < 0 ? 0 : length);
|
13876 |
|
13877 | while (++index < length) {
|
13878 | result[index] = pluck(array, index);
|
13879 | }
|
13880 | return result;
|
13881 | }
|
13882 |
|
13883 | |
13884 |
|
13885 |
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 |
|
13894 |
|
13895 |
|
13896 |
|
13897 |
|
13898 |
|
13899 |
|
13900 |
|
13901 | function zipObject(keys, values) {
|
13902 | var index = -1,
|
13903 | length = keys ? keys.length : 0,
|
13904 | result = {};
|
13905 |
|
13906 | if (!values && length && !isArray(keys[0])) {
|
13907 | values = [];
|
13908 | }
|
13909 | while (++index < length) {
|
13910 | var key = keys[index];
|
13911 | if (values) {
|
13912 | result[key] = values[index];
|
13913 | } else if (key) {
|
13914 | result[key[0]] = key[1];
|
13915 | }
|
13916 | }
|
13917 | return result;
|
13918 | }
|
13919 |
|
13920 |
|
13921 |
|
13922 | |
13923 |
|
13924 |
|
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 |
|
13934 |
|
13935 |
|
13936 |
|
13937 |
|
13938 |
|
13939 |
|
13940 |
|
13941 |
|
13942 |
|
13943 |
|
13944 |
|
13945 |
|
13946 | function after(n, func) {
|
13947 | if (!isFunction(func)) {
|
13948 | throw new TypeError;
|
13949 | }
|
13950 | return function() {
|
13951 | if (--n < 1) {
|
13952 | return func.apply(this, arguments);
|
13953 | }
|
13954 | };
|
13955 | }
|
13956 |
|
13957 | |
13958 |
|
13959 |
|
13960 |
|
13961 |
|
13962 |
|
13963 |
|
13964 |
|
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 |
|
13971 |
|
13972 |
|
13973 |
|
13974 |
|
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 | function bind(func, thisArg) {
|
13980 | return arguments.length > 2
|
13981 | ? createWrapper(func, 17, slice(arguments, 2), null, thisArg)
|
13982 | : createWrapper(func, 1, null, null, thisArg);
|
13983 | }
|
13984 |
|
13985 | |
13986 |
|
13987 |
|
13988 |
|
13989 |
|
13990 |
|
13991 |
|
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 |
|
13998 |
|
13999 |
|
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 | function bindAll(object) {
|
14010 | var funcs = arguments.length > 1 ? baseFlatten(arguments, true, false, 1) : functions(object),
|
14011 | index = -1,
|
14012 | length = funcs.length;
|
14013 |
|
14014 | while (++index < length) {
|
14015 | var key = funcs[index];
|
14016 | object[key] = createWrapper(object[key], 1, null, null, object);
|
14017 | }
|
14018 | return object;
|
14019 | }
|
14020 |
|
14021 | |
14022 |
|
14023 |
|
14024 |
|
14025 |
|
14026 |
|
14027 |
|
14028 |
|
14029 |
|
14030 |
|
14031 |
|
14032 |
|
14033 |
|
14034 |
|
14035 |
|
14036 |
|
14037 |
|
14038 |
|
14039 |
|
14040 |
|
14041 |
|
14042 |
|
14043 |
|
14044 |
|
14045 |
|
14046 |
|
14047 |
|
14048 |
|
14049 |
|
14050 |
|
14051 |
|
14052 |
|
14053 |
|
14054 |
|
14055 | function bindKey(object, key) {
|
14056 | return arguments.length > 2
|
14057 | ? createWrapper(key, 19, slice(arguments, 2), null, object)
|
14058 | : createWrapper(key, 3, null, null, object);
|
14059 | }
|
14060 |
|
14061 | |
14062 |
|
14063 |
|
14064 |
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 |
|
14072 |
|
14073 |
|
14074 |
|
14075 |
|
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 |
|
14087 |
|
14088 |
|
14089 |
|
14090 |
|
14091 | function compose() {
|
14092 | var funcs = arguments,
|
14093 | length = funcs.length;
|
14094 |
|
14095 | while (length--) {
|
14096 | if (!isFunction(funcs[length])) {
|
14097 | throw new TypeError;
|
14098 | }
|
14099 | }
|
14100 | return function() {
|
14101 | var args = arguments,
|
14102 | length = funcs.length;
|
14103 |
|
14104 | while (length--) {
|
14105 | args = [funcs[length].apply(this, args)];
|
14106 | }
|
14107 | return args[0];
|
14108 | };
|
14109 | }
|
14110 |
|
14111 | |
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 |
|
14121 |
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 |
|
14127 |
|
14128 |
|
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 |
|
14138 |
|
14139 | function curry(func, arity) {
|
14140 | arity = typeof arity == 'number' ? arity : (+arity || func.length);
|
14141 | return createWrapper(func, 4, null, null, null, arity);
|
14142 | }
|
14143 |
|
14144 | |
14145 |
|
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 |
|
14152 |
|
14153 |
|
14154 |
|
14155 |
|
14156 |
|
14157 |
|
14158 |
|
14159 |
|
14160 |
|
14161 |
|
14162 |
|
14163 |
|
14164 |
|
14165 |
|
14166 |
|
14167 |
|
14168 |
|
14169 |
|
14170 |
|
14171 |
|
14172 |
|
14173 |
|
14174 |
|
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 |
|
14180 |
|
14181 |
|
14182 |
|
14183 | function debounce(func, wait, options) {
|
14184 | var args,
|
14185 | maxTimeoutId,
|
14186 | result,
|
14187 | stamp,
|
14188 | thisArg,
|
14189 | timeoutId,
|
14190 | trailingCall,
|
14191 | lastCalled = 0,
|
14192 | maxWait = false,
|
14193 | trailing = true;
|
14194 |
|
14195 | if (!isFunction(func)) {
|
14196 | throw new TypeError;
|
14197 | }
|
14198 | wait = nativeMax(0, wait) || 0;
|
14199 | if (options === true) {
|
14200 | var leading = true;
|
14201 | trailing = false;
|
14202 | } else if (isObject(options)) {
|
14203 | leading = options.leading;
|
14204 | maxWait = 'maxWait' in options && (nativeMax(wait, options.maxWait) || 0);
|
14205 | trailing = 'trailing' in options ? options.trailing : trailing;
|
14206 | }
|
14207 | var delayed = function() {
|
14208 | var remaining = wait - (now() - stamp);
|
14209 | if (remaining <= 0) {
|
14210 | if (maxTimeoutId) {
|
14211 | clearTimeout(maxTimeoutId);
|
14212 | }
|
14213 | var isCalled = trailingCall;
|
14214 | maxTimeoutId = timeoutId = trailingCall = undefined;
|
14215 | if (isCalled) {
|
14216 | lastCalled = now();
|
14217 | result = func.apply(thisArg, args);
|
14218 | if (!timeoutId && !maxTimeoutId) {
|
14219 | args = thisArg = null;
|
14220 | }
|
14221 | }
|
14222 | } else {
|
14223 | timeoutId = setTimeout(delayed, remaining);
|
14224 | }
|
14225 | };
|
14226 |
|
14227 | var maxDelayed = function() {
|
14228 | if (timeoutId) {
|
14229 | clearTimeout(timeoutId);
|
14230 | }
|
14231 | maxTimeoutId = timeoutId = trailingCall = undefined;
|
14232 | if (trailing || (maxWait !== wait)) {
|
14233 | lastCalled = now();
|
14234 | result = func.apply(thisArg, args);
|
14235 | if (!timeoutId && !maxTimeoutId) {
|
14236 | args = thisArg = null;
|
14237 | }
|
14238 | }
|
14239 | };
|
14240 |
|
14241 | return function() {
|
14242 | args = arguments;
|
14243 | stamp = now();
|
14244 | thisArg = this;
|
14245 | trailingCall = trailing && (timeoutId || !leading);
|
14246 |
|
14247 | if (maxWait === false) {
|
14248 | var leadingCall = leading && !timeoutId;
|
14249 | } else {
|
14250 | if (!maxTimeoutId && !leading) {
|
14251 | lastCalled = stamp;
|
14252 | }
|
14253 | var remaining = maxWait - (stamp - lastCalled),
|
14254 | isCalled = remaining <= 0;
|
14255 |
|
14256 | if (isCalled) {
|
14257 | if (maxTimeoutId) {
|
14258 | maxTimeoutId = clearTimeout(maxTimeoutId);
|
14259 | }
|
14260 | lastCalled = stamp;
|
14261 | result = func.apply(thisArg, args);
|
14262 | }
|
14263 | else if (!maxTimeoutId) {
|
14264 | maxTimeoutId = setTimeout(maxDelayed, remaining);
|
14265 | }
|
14266 | }
|
14267 | if (isCalled && timeoutId) {
|
14268 | timeoutId = clearTimeout(timeoutId);
|
14269 | }
|
14270 | else if (!timeoutId && wait !== maxWait) {
|
14271 | timeoutId = setTimeout(delayed, wait);
|
14272 | }
|
14273 | if (leadingCall) {
|
14274 | isCalled = true;
|
14275 | result = func.apply(thisArg, args);
|
14276 | }
|
14277 | if (isCalled && !timeoutId && !maxTimeoutId) {
|
14278 | args = thisArg = null;
|
14279 | }
|
14280 | return result;
|
14281 | };
|
14282 | }
|
14283 |
|
14284 | |
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 |
|
14291 |
|
14292 |
|
14293 |
|
14294 |
|
14295 |
|
14296 |
|
14297 |
|
14298 |
|
14299 | function defer(func) {
|
14300 | if (!isFunction(func)) {
|
14301 | throw new TypeError;
|
14302 | }
|
14303 | var args = slice(arguments, 1);
|
14304 | return setTimeout(function() { func.apply(undefined, args); }, 1);
|
14305 | }
|
14306 |
|
14307 | |
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 |
|
14316 |
|
14317 |
|
14318 |
|
14319 |
|
14320 |
|
14321 |
|
14322 |
|
14323 | function delay(func, wait) {
|
14324 | if (!isFunction(func)) {
|
14325 | throw new TypeError;
|
14326 | }
|
14327 | var args = slice(arguments, 2);
|
14328 | return setTimeout(function() { func.apply(undefined, args); }, wait);
|
14329 | }
|
14330 |
|
14331 | |
14332 |
|
14333 |
|
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 |
|
14349 |
|
14350 |
|
14351 |
|
14352 |
|
14353 |
|
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 |
|
14359 |
|
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 |
|
14365 |
|
14366 |
|
14367 |
|
14368 | function memoize(func, resolver) {
|
14369 | if (!isFunction(func)) {
|
14370 | throw new TypeError;
|
14371 | }
|
14372 | var memoized = function() {
|
14373 | var cache = memoized.cache,
|
14374 | key = resolver ? resolver.apply(this, arguments) : keyPrefix + arguments[0];
|
14375 |
|
14376 | return hasOwnProperty.call(cache, key)
|
14377 | ? cache[key]
|
14378 | : (cache[key] = func.apply(this, arguments));
|
14379 | }
|
14380 | memoized.cache = {};
|
14381 | return memoized;
|
14382 | }
|
14383 |
|
14384 | |
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 |
|
14396 |
|
14397 |
|
14398 |
|
14399 |
|
14400 |
|
14401 | function once(func) {
|
14402 | var ran,
|
14403 | result;
|
14404 |
|
14405 | if (!isFunction(func)) {
|
14406 | throw new TypeError;
|
14407 | }
|
14408 | return function() {
|
14409 | if (ran) {
|
14410 | return result;
|
14411 | }
|
14412 | ran = true;
|
14413 | result = func.apply(this, arguments);
|
14414 |
|
14415 |
|
14416 | func = null;
|
14417 | return result;
|
14418 | };
|
14419 | }
|
14420 |
|
14421 | |
14422 |
|
14423 |
|
14424 |
|
14425 |
|
14426 |
|
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 |
|
14439 | function partial(func) {
|
14440 | return createWrapper(func, 16, slice(arguments, 1));
|
14441 | }
|
14442 |
|
14443 | |
14444 |
|
14445 |
|
14446 |
|
14447 |
|
14448 |
|
14449 |
|
14450 |
|
14451 |
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 |
|
14463 |
|
14464 |
|
14465 |
|
14466 |
|
14467 |
|
14468 |
|
14469 |
|
14470 | function partialRight(func) {
|
14471 | return createWrapper(func, 32, null, slice(arguments, 1));
|
14472 | }
|
14473 |
|
14474 | |
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 |
|
14480 |
|
14481 |
|
14482 |
|
14483 |
|
14484 |
|
14485 |
|
14486 |
|
14487 |
|
14488 |
|
14489 |
|
14490 |
|
14491 |
|
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 | function throttle(func, wait, options) {
|
14506 | var leading = true,
|
14507 | trailing = true;
|
14508 |
|
14509 | if (!isFunction(func)) {
|
14510 | throw new TypeError;
|
14511 | }
|
14512 | if (options === false) {
|
14513 | leading = false;
|
14514 | } else if (isObject(options)) {
|
14515 | leading = 'leading' in options ? options.leading : leading;
|
14516 | trailing = 'trailing' in options ? options.trailing : trailing;
|
14517 | }
|
14518 | debounceOptions.leading = leading;
|
14519 | debounceOptions.maxWait = wait;
|
14520 | debounceOptions.trailing = trailing;
|
14521 |
|
14522 | return debounce(func, wait, debounceOptions);
|
14523 | }
|
14524 |
|
14525 | |
14526 |
|
14527 |
|
14528 |
|
14529 |
|
14530 |
|
14531 |
|
14532 |
|
14533 |
|
14534 |
|
14535 |
|
14536 |
|
14537 |
|
14538 |
|
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 |
|
14544 |
|
14545 |
|
14546 | function wrap(value, wrapper) {
|
14547 | return createWrapper(wrapper, 16, [value]);
|
14548 | }
|
14549 |
|
14550 |
|
14551 |
|
14552 | |
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 |
|
14558 |
|
14559 |
|
14560 |
|
14561 |
|
14562 |
|
14563 |
|
14564 |
|
14565 |
|
14566 |
|
14567 | function constant(value) {
|
14568 | return function() {
|
14569 | return value;
|
14570 | };
|
14571 | }
|
14572 |
|
14573 | |
14574 |
|
14575 |
|
14576 |
|
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 |
|
14585 |
|
14586 |
|
14587 |
|
14588 |
|
14589 |
|
14590 |
|
14591 |
|
14592 |
|
14593 |
|
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 |
|
14599 |
|
14600 |
|
14601 |
|
14602 |
|
14603 |
|
14604 | function createCallback(func, thisArg, argCount) {
|
14605 | var type = typeof func;
|
14606 | if (func == null || type == 'function') {
|
14607 | return baseCreateCallback(func, thisArg, argCount);
|
14608 | }
|
14609 |
|
14610 | if (type != 'object') {
|
14611 | return property(func);
|
14612 | }
|
14613 | var props = keys(func),
|
14614 | key = props[0],
|
14615 | a = func[key];
|
14616 |
|
14617 |
|
14618 | if (props.length == 1 && a === a && !isObject(a)) {
|
14619 |
|
14620 |
|
14621 | return function(object) {
|
14622 | var b = object[key];
|
14623 | return a === b && (a !== 0 || (1 / a == 1 / b));
|
14624 | };
|
14625 | }
|
14626 | return function(object) {
|
14627 | var length = props.length,
|
14628 | result = false;
|
14629 |
|
14630 | while (length--) {
|
14631 | if (!(result = baseIsEqual(object[props[length]], func[props[length]], null, true))) {
|
14632 | break;
|
14633 | }
|
14634 | }
|
14635 | return result;
|
14636 | };
|
14637 | }
|
14638 |
|
14639 | |
14640 |
|
14641 |
|
14642 |
|
14643 |
|
14644 |
|
14645 |
|
14646 |
|
14647 |
|
14648 |
|
14649 |
|
14650 |
|
14651 |
|
14652 |
|
14653 | function escape(string) {
|
14654 | return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar);
|
14655 | }
|
14656 |
|
14657 | |
14658 |
|
14659 |
|
14660 |
|
14661 |
|
14662 |
|
14663 |
|
14664 |
|
14665 |
|
14666 |
|
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 | function identity(value) {
|
14672 | return value;
|
14673 | }
|
14674 |
|
14675 | |
14676 |
|
14677 |
|
14678 |
|
14679 |
|
14680 |
|
14681 |
|
14682 |
|
14683 |
|
14684 |
|
14685 |
|
14686 |
|
14687 |
|
14688 |
|
14689 |
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 |
|
14695 |
|
14696 |
|
14697 |
|
14698 |
|
14699 |
|
14700 |
|
14701 |
|
14702 |
|
14703 | function mixin(object, source, options) {
|
14704 | var chain = true,
|
14705 | methodNames = source && functions(source);
|
14706 |
|
14707 | if (!source || (!options && !methodNames.length)) {
|
14708 | if (options == null) {
|
14709 | options = source;
|
14710 | }
|
14711 | ctor = lodashWrapper;
|
14712 | source = object;
|
14713 | object = lodash;
|
14714 | methodNames = functions(source);
|
14715 | }
|
14716 | if (options === false) {
|
14717 | chain = false;
|
14718 | } else if (isObject(options) && 'chain' in options) {
|
14719 | chain = options.chain;
|
14720 | }
|
14721 | var ctor = object,
|
14722 | isFunc = isFunction(ctor);
|
14723 |
|
14724 | forEach(methodNames, function(methodName) {
|
14725 | var func = object[methodName] = source[methodName];
|
14726 | if (isFunc) {
|
14727 | ctor.prototype[methodName] = function() {
|
14728 | var chainAll = this.__chain__,
|
14729 | value = this.__wrapped__,
|
14730 | args = [value];
|
14731 |
|
14732 | push.apply(args, arguments);
|
14733 | var result = func.apply(object, args);
|
14734 | if (chain || chainAll) {
|
14735 | if (value === result && isObject(result)) {
|
14736 | return this;
|
14737 | }
|
14738 | result = new ctor(result);
|
14739 | result.__chain__ = chainAll;
|
14740 | }
|
14741 | return result;
|
14742 | };
|
14743 | }
|
14744 | });
|
14745 | }
|
14746 |
|
14747 | |
14748 |
|
14749 |
|
14750 |
|
14751 |
|
14752 |
|
14753 |
|
14754 |
|
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 | function noConflict() {
|
14760 | context._ = oldDash;
|
14761 | return this;
|
14762 | }
|
14763 |
|
14764 | |
14765 |
|
14766 |
|
14767 |
|
14768 |
|
14769 |
|
14770 |
|
14771 |
|
14772 |
|
14773 |
|
14774 |
|
14775 |
|
14776 | function noop() {
|
14777 |
|
14778 | }
|
14779 |
|
14780 | |
14781 |
|
14782 |
|
14783 |
|
14784 |
|
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 |
|
14792 |
|
14793 | var now = isNative(now = Date.now) && now || function() {
|
14794 | return new Date().getTime();
|
14795 | };
|
14796 |
|
14797 | |
14798 |
|
14799 |
|
14800 |
|
14801 |
|
14802 |
|
14803 |
|
14804 |
|
14805 |
|
14806 |
|
14807 |
|
14808 |
|
14809 |
|
14810 |
|
14811 |
|
14812 |
|
14813 |
|
14814 |
|
14815 |
|
14816 | var parseInt = nativeParseInt(whitespace + '08') == 8 ? nativeParseInt : function(value, radix) {
|
14817 |
|
14818 | return nativeParseInt(isString(value) ? value.replace(reLeadingSpacesAndZeros, '') : value, radix || 0);
|
14819 | };
|
14820 |
|
14821 | |
14822 |
|
14823 |
|
14824 |
|
14825 |
|
14826 |
|
14827 |
|
14828 |
|
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 |
|
14834 |
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 | function property(key) {
|
14846 | return function(object) {
|
14847 | return object[key];
|
14848 | };
|
14849 | }
|
14850 |
|
14851 | |
14852 |
|
14853 |
|
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 |
|
14860 |
|
14861 |
|
14862 |
|
14863 |
|
14864 |
|
14865 |
|
14866 |
|
14867 |
|
14868 |
|
14869 |
|
14870 |
|
14871 |
|
14872 |
|
14873 |
|
14874 |
|
14875 |
|
14876 |
|
14877 |
|
14878 | function random(min, max, floating) {
|
14879 | var noMin = min == null,
|
14880 | noMax = max == null;
|
14881 |
|
14882 | if (floating == null) {
|
14883 | if (typeof min == 'boolean' && noMax) {
|
14884 | floating = min;
|
14885 | min = 1;
|
14886 | }
|
14887 | else if (!noMax && typeof max == 'boolean') {
|
14888 | floating = max;
|
14889 | noMax = true;
|
14890 | }
|
14891 | }
|
14892 | if (noMin && noMax) {
|
14893 | max = 1;
|
14894 | }
|
14895 | min = +min || 0;
|
14896 | if (noMax) {
|
14897 | max = min;
|
14898 | min = 0;
|
14899 | } else {
|
14900 | max = +max || 0;
|
14901 | }
|
14902 | if (floating || min % 1 || max % 1) {
|
14903 | var rand = nativeRandom();
|
14904 | return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max);
|
14905 | }
|
14906 | return baseRandom(min, max);
|
14907 | }
|
14908 |
|
14909 | |
14910 |
|
14911 |
|
14912 |
|
14913 |
|
14914 |
|
14915 |
|
14916 |
|
14917 |
|
14918 |
|
14919 |
|
14920 |
|
14921 |
|
14922 |
|
14923 |
|
14924 |
|
14925 |
|
14926 |
|
14927 |
|
14928 |
|
14929 |
|
14930 |
|
14931 |
|
14932 |
|
14933 |
|
14934 |
|
14935 |
|
14936 | function result(object, key) {
|
14937 | if (object) {
|
14938 | var value = object[key];
|
14939 | return isFunction(value) ? object[key]() : value;
|
14940 | }
|
14941 | }
|
14942 |
|
14943 | |
14944 |
|
14945 |
|
14946 |
|
14947 |
|
14948 |
|
14949 |
|
14950 |
|
14951 |
|
14952 |
|
14953 |
|
14954 |
|
14955 |
|
14956 |
|
14957 |
|
14958 |
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 |
|
14964 |
|
14965 |
|
14966 |
|
14967 |
|
14968 |
|
14969 |
|
14970 |
|
14971 |
|
14972 |
|
14973 |
|
14974 |
|
14975 |
|
14976 |
|
14977 |
|
14978 |
|
14979 |
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 |
|
14986 |
|
14987 |
|
14988 |
|
14989 |
|
14990 |
|
14991 |
|
14992 |
|
14993 |
|
14994 |
|
14995 |
|
14996 |
|
14997 |
|
14998 |
|
14999 |
|
15000 |
|
15001 |
|
15002 |
|
15003 |
|
15004 |
|
15005 |
|
15006 |
|
15007 |
|
15008 |
|
15009 |
|
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 |
|
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 |
|
15027 |
|
15028 |
|
15029 | function template(text, data, options) {
|
15030 |
|
15031 |
|
15032 |
|
15033 |
|
15034 | var settings = lodash.templateSettings;
|
15035 | text = String(text || '');
|
15036 |
|
15037 |
|
15038 | options = defaults({}, options, settings);
|
15039 |
|
15040 | var imports = defaults({}, options.imports, settings.imports),
|
15041 | importsKeys = keys(imports),
|
15042 | importsValues = values(imports);
|
15043 |
|
15044 | var isEvaluating,
|
15045 | index = 0,
|
15046 | interpolate = options.interpolate || reNoMatch,
|
15047 | source = "__p += '";
|
15048 |
|
15049 |
|
15050 | var reDelimiters = RegExp(
|
15051 | (options.escape || reNoMatch).source + '|' +
|
15052 | interpolate.source + '|' +
|
15053 | (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
15054 | (options.evaluate || reNoMatch).source + '|$'
|
15055 | , 'g');
|
15056 |
|
15057 | text.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
15058 | interpolateValue || (interpolateValue = esTemplateValue);
|
15059 |
|
15060 |
|
15061 | source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);
|
15062 |
|
15063 |
|
15064 | if (escapeValue) {
|
15065 | source += "' +\n__e(" + escapeValue + ") +\n'";
|
15066 | }
|
15067 | if (evaluateValue) {
|
15068 | isEvaluating = true;
|
15069 | source += "';\n" + evaluateValue + ";\n__p += '";
|
15070 | }
|
15071 | if (interpolateValue) {
|
15072 | source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
|
15073 | }
|
15074 | index = offset + match.length;
|
15075 |
|
15076 |
|
15077 |
|
15078 | return match;
|
15079 | });
|
15080 |
|
15081 | source += "';\n";
|
15082 |
|
15083 |
|
15084 |
|
15085 | var variable = options.variable,
|
15086 | hasVariable = variable;
|
15087 |
|
15088 | if (!hasVariable) {
|
15089 | variable = 'obj';
|
15090 | source = 'with (' + variable + ') {\n' + source + '\n}\n';
|
15091 | }
|
15092 |
|
15093 | source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
15094 | .replace(reEmptyStringMiddle, '$1')
|
15095 | .replace(reEmptyStringTrailing, '$1;');
|
15096 |
|
15097 |
|
15098 | source = 'function(' + variable + ') {\n' +
|
15099 | (hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') +
|
15100 | "var __t, __p = '', __e = _.escape" +
|
15101 | (isEvaluating
|
15102 | ? ', __j = Array.prototype.join;\n' +
|
15103 | "function print() { __p += __j.call(arguments, '') }\n"
|
15104 | : ';\n'
|
15105 | ) +
|
15106 | source +
|
15107 | 'return __p\n}';
|
15108 |
|
15109 |
|
15110 |
|
15111 | var sourceURL = '\n/*\n//# sourceURL=' + (options.sourceURL || '/lodash/template/source[' + (templateCounter++) + ']') + '\n*/';
|
15112 |
|
15113 | try {
|
15114 | var result = Function(importsKeys, 'return ' + source + sourceURL).apply(undefined, importsValues);
|
15115 | } catch(e) {
|
15116 | e.source = source;
|
15117 | throw e;
|
15118 | }
|
15119 | if (data) {
|
15120 | return result(data);
|
15121 | }
|
15122 |
|
15123 |
|
15124 |
|
15125 | result.source = source;
|
15126 | return result;
|
15127 | }
|
15128 |
|
15129 | |
15130 |
|
15131 |
|
15132 |
|
15133 |
|
15134 |
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 |
|
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 |
|
15152 | function times(n, callback, thisArg) {
|
15153 | n = (n = +n) > -1 ? n : 0;
|
15154 | var index = -1,
|
15155 | result = Array(n);
|
15156 |
|
15157 | callback = baseCreateCallback(callback, thisArg, 1);
|
15158 | while (++index < n) {
|
15159 | result[index] = callback(index);
|
15160 | }
|
15161 | return result;
|
15162 | }
|
15163 |
|
15164 | |
15165 |
|
15166 |
|
15167 |
|
15168 |
|
15169 |
|
15170 |
|
15171 |
|
15172 |
|
15173 |
|
15174 |
|
15175 |
|
15176 |
|
15177 |
|
15178 |
|
15179 | function unescape(string) {
|
15180 | return string == null ? '' : String(string).replace(reEscapedHtml, unescapeHtmlChar);
|
15181 | }
|
15182 |
|
15183 | |
15184 |
|
15185 |
|
15186 |
|
15187 |
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 |
|
15193 |
|
15194 |
|
15195 |
|
15196 |
|
15197 |
|
15198 |
|
15199 | function uniqueId(prefix) {
|
15200 | var id = ++idCounter;
|
15201 | return String(prefix == null ? '' : prefix) + id;
|
15202 | }
|
15203 |
|
15204 |
|
15205 |
|
15206 | |
15207 |
|
15208 |
|
15209 |
|
15210 |
|
15211 |
|
15212 |
|
15213 |
|
15214 |
|
15215 |
|
15216 |
|
15217 |
|
15218 |
|
15219 |
|
15220 |
|
15221 |
|
15222 |
|
15223 |
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 | function chain(value) {
|
15231 | value = new lodashWrapper(value);
|
15232 | value.__chain__ = true;
|
15233 | return value;
|
15234 | }
|
15235 |
|
15236 | |
15237 |
|
15238 |
|
15239 |
|
15240 |
|
15241 |
|
15242 |
|
15243 |
|
15244 |
|
15245 |
|
15246 |
|
15247 |
|
15248 |
|
15249 |
|
15250 |
|
15251 |
|
15252 |
|
15253 |
|
15254 |
|
15255 |
|
15256 | function tap(value, interceptor) {
|
15257 | interceptor(value);
|
15258 | return value;
|
15259 | }
|
15260 |
|
15261 | |
15262 |
|
15263 |
|
15264 |
|
15265 |
|
15266 |
|
15267 |
|
15268 |
|
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 |
|
15274 |
|
15275 |
|
15276 |
|
15277 |
|
15278 |
|
15279 |
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 |
|
15285 |
|
15286 | function wrapperChain() {
|
15287 | this.__chain__ = true;
|
15288 | return this;
|
15289 | }
|
15290 |
|
15291 | |
15292 |
|
15293 |
|
15294 |
|
15295 |
|
15296 |
|
15297 |
|
15298 |
|
15299 |
|
15300 |
|
15301 |
|
15302 |
|
15303 | function wrapperToString() {
|
15304 | return String(this.__wrapped__);
|
15305 | }
|
15306 |
|
15307 | |
15308 |
|
15309 |
|
15310 |
|
15311 |
|
15312 |
|
15313 |
|
15314 |
|
15315 |
|
15316 |
|
15317 |
|
15318 |
|
15319 |
|
15320 | function wrapperValueOf() {
|
15321 | return this.__wrapped__;
|
15322 | }
|
15323 |
|
15324 |
|
15325 |
|
15326 |
|
15327 | lodash.after = after;
|
15328 | lodash.assign = assign;
|
15329 | lodash.at = at;
|
15330 | lodash.bind = bind;
|
15331 | lodash.bindAll = bindAll;
|
15332 | lodash.bindKey = bindKey;
|
15333 | lodash.chain = chain;
|
15334 | lodash.compact = compact;
|
15335 | lodash.compose = compose;
|
15336 | lodash.constant = constant;
|
15337 | lodash.countBy = countBy;
|
15338 | lodash.create = create;
|
15339 | lodash.createCallback = createCallback;
|
15340 | lodash.curry = curry;
|
15341 | lodash.debounce = debounce;
|
15342 | lodash.defaults = defaults;
|
15343 | lodash.defer = defer;
|
15344 | lodash.delay = delay;
|
15345 | lodash.difference = difference;
|
15346 | lodash.filter = filter;
|
15347 | lodash.flatten = flatten;
|
15348 | lodash.forEach = forEach;
|
15349 | lodash.forEachRight = forEachRight;
|
15350 | lodash.forIn = forIn;
|
15351 | lodash.forInRight = forInRight;
|
15352 | lodash.forOwn = forOwn;
|
15353 | lodash.forOwnRight = forOwnRight;
|
15354 | lodash.functions = functions;
|
15355 | lodash.groupBy = groupBy;
|
15356 | lodash.indexBy = indexBy;
|
15357 | lodash.initial = initial;
|
15358 | lodash.intersection = intersection;
|
15359 | lodash.invert = invert;
|
15360 | lodash.invoke = invoke;
|
15361 | lodash.keys = keys;
|
15362 | lodash.map = map;
|
15363 | lodash.mapValues = mapValues;
|
15364 | lodash.max = max;
|
15365 | lodash.memoize = memoize;
|
15366 | lodash.merge = merge;
|
15367 | lodash.min = min;
|
15368 | lodash.omit = omit;
|
15369 | lodash.once = once;
|
15370 | lodash.pairs = pairs;
|
15371 | lodash.partial = partial;
|
15372 | lodash.partialRight = partialRight;
|
15373 | lodash.pick = pick;
|
15374 | lodash.pluck = pluck;
|
15375 | lodash.property = property;
|
15376 | lodash.pull = pull;
|
15377 | lodash.range = range;
|
15378 | lodash.reject = reject;
|
15379 | lodash.remove = remove;
|
15380 | lodash.rest = rest;
|
15381 | lodash.shuffle = shuffle;
|
15382 | lodash.sortBy = sortBy;
|
15383 | lodash.tap = tap;
|
15384 | lodash.throttle = throttle;
|
15385 | lodash.times = times;
|
15386 | lodash.toArray = toArray;
|
15387 | lodash.transform = transform;
|
15388 | lodash.union = union;
|
15389 | lodash.uniq = uniq;
|
15390 | lodash.values = values;
|
15391 | lodash.where = where;
|
15392 | lodash.without = without;
|
15393 | lodash.wrap = wrap;
|
15394 | lodash.xor = xor;
|
15395 | lodash.zip = zip;
|
15396 | lodash.zipObject = zipObject;
|
15397 |
|
15398 |
|
15399 | lodash.collect = map;
|
15400 | lodash.drop = rest;
|
15401 | lodash.each = forEach;
|
15402 | lodash.eachRight = forEachRight;
|
15403 | lodash.extend = assign;
|
15404 | lodash.methods = functions;
|
15405 | lodash.object = zipObject;
|
15406 | lodash.select = filter;
|
15407 | lodash.tail = rest;
|
15408 | lodash.unique = uniq;
|
15409 | lodash.unzip = zip;
|
15410 |
|
15411 |
|
15412 | mixin(lodash);
|
15413 |
|
15414 |
|
15415 |
|
15416 |
|
15417 | lodash.clone = clone;
|
15418 | lodash.cloneDeep = cloneDeep;
|
15419 | lodash.contains = contains;
|
15420 | lodash.escape = escape;
|
15421 | lodash.every = every;
|
15422 | lodash.find = find;
|
15423 | lodash.findIndex = findIndex;
|
15424 | lodash.findKey = findKey;
|
15425 | lodash.findLast = findLast;
|
15426 | lodash.findLastIndex = findLastIndex;
|
15427 | lodash.findLastKey = findLastKey;
|
15428 | lodash.has = has;
|
15429 | lodash.identity = identity;
|
15430 | lodash.indexOf = indexOf;
|
15431 | lodash.isArguments = isArguments;
|
15432 | lodash.isArray = isArray;
|
15433 | lodash.isBoolean = isBoolean;
|
15434 | lodash.isDate = isDate;
|
15435 | lodash.isElement = isElement;
|
15436 | lodash.isEmpty = isEmpty;
|
15437 | lodash.isEqual = isEqual;
|
15438 | lodash.isFinite = isFinite;
|
15439 | lodash.isFunction = isFunction;
|
15440 | lodash.isNaN = isNaN;
|
15441 | lodash.isNull = isNull;
|
15442 | lodash.isNumber = isNumber;
|
15443 | lodash.isObject = isObject;
|
15444 | lodash.isPlainObject = isPlainObject;
|
15445 | lodash.isRegExp = isRegExp;
|
15446 | lodash.isString = isString;
|
15447 | lodash.isUndefined = isUndefined;
|
15448 | lodash.lastIndexOf = lastIndexOf;
|
15449 | lodash.mixin = mixin;
|
15450 | lodash.noConflict = noConflict;
|
15451 | lodash.noop = noop;
|
15452 | lodash.now = now;
|
15453 | lodash.parseInt = parseInt;
|
15454 | lodash.random = random;
|
15455 | lodash.reduce = reduce;
|
15456 | lodash.reduceRight = reduceRight;
|
15457 | lodash.result = result;
|
15458 | lodash.runInContext = runInContext;
|
15459 | lodash.size = size;
|
15460 | lodash.some = some;
|
15461 | lodash.sortedIndex = sortedIndex;
|
15462 | lodash.template = template;
|
15463 | lodash.unescape = unescape;
|
15464 | lodash.uniqueId = uniqueId;
|
15465 |
|
15466 |
|
15467 | lodash.all = every;
|
15468 | lodash.any = some;
|
15469 | lodash.detect = find;
|
15470 | lodash.findWhere = find;
|
15471 | lodash.foldl = reduce;
|
15472 | lodash.foldr = reduceRight;
|
15473 | lodash.include = contains;
|
15474 | lodash.inject = reduce;
|
15475 |
|
15476 | mixin(function() {
|
15477 | var source = {}
|
15478 | forOwn(lodash, function(func, methodName) {
|
15479 | if (!lodash.prototype[methodName]) {
|
15480 | source[methodName] = func;
|
15481 | }
|
15482 | });
|
15483 | return source;
|
15484 | }(), false);
|
15485 |
|
15486 |
|
15487 |
|
15488 |
|
15489 | lodash.first = first;
|
15490 | lodash.last = last;
|
15491 | lodash.sample = sample;
|
15492 |
|
15493 |
|
15494 | lodash.take = first;
|
15495 | lodash.head = first;
|
15496 |
|
15497 | forOwn(lodash, function(func, methodName) {
|
15498 | var callbackable = methodName !== 'sample';
|
15499 | if (!lodash.prototype[methodName]) {
|
15500 | lodash.prototype[methodName]= function(n, guard) {
|
15501 | var chainAll = this.__chain__,
|
15502 | result = func(this.__wrapped__, n, guard);
|
15503 |
|
15504 | return !chainAll && (n == null || (guard && !(callbackable && typeof n == 'function')))
|
15505 | ? result
|
15506 | : new lodashWrapper(result, chainAll);
|
15507 | };
|
15508 | }
|
15509 | });
|
15510 |
|
15511 |
|
15512 |
|
15513 | |
15514 |
|
15515 |
|
15516 |
|
15517 |
|
15518 |
|
15519 |
|
15520 | lodash.VERSION = '2.4.1';
|
15521 |
|
15522 |
|
15523 | lodash.prototype.chain = wrapperChain;
|
15524 | lodash.prototype.toString = wrapperToString;
|
15525 | lodash.prototype.value = wrapperValueOf;
|
15526 | lodash.prototype.valueOf = wrapperValueOf;
|
15527 |
|
15528 |
|
15529 | forEach(['join', 'pop', 'shift'], function(methodName) {
|
15530 | var func = arrayRef[methodName];
|
15531 | lodash.prototype[methodName] = function() {
|
15532 | var chainAll = this.__chain__,
|
15533 | result = func.apply(this.__wrapped__, arguments);
|
15534 |
|
15535 | return chainAll
|
15536 | ? new lodashWrapper(result, chainAll)
|
15537 | : result;
|
15538 | };
|
15539 | });
|
15540 |
|
15541 |
|
15542 | forEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
|
15543 | var func = arrayRef[methodName];
|
15544 | lodash.prototype[methodName] = function() {
|
15545 | func.apply(this.__wrapped__, arguments);
|
15546 | return this;
|
15547 | };
|
15548 | });
|
15549 |
|
15550 |
|
15551 | forEach(['concat', 'slice', 'splice'], function(methodName) {
|
15552 | var func = arrayRef[methodName];
|
15553 | lodash.prototype[methodName] = function() {
|
15554 | return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__);
|
15555 | };
|
15556 | });
|
15557 |
|
15558 | return lodash;
|
15559 | }
|
15560 |
|
15561 |
|
15562 |
|
15563 |
|
15564 | var _ = runInContext();
|
15565 |
|
15566 |
|
15567 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
15568 |
|
15569 |
|
15570 |
|
15571 | root._ = _;
|
15572 |
|
15573 |
|
15574 |
|
15575 | define(function() {
|
15576 | return _;
|
15577 | });
|
15578 | }
|
15579 |
|
15580 | else if (freeExports && freeModule) {
|
15581 |
|
15582 | if (moduleExports) {
|
15583 | (freeModule.exports = _)._ = _;
|
15584 | }
|
15585 |
|
15586 | else {
|
15587 | freeExports._ = _;
|
15588 | }
|
15589 | }
|
15590 | else {
|
15591 |
|
15592 | root._ = _;
|
15593 | }
|
15594 | }.call(this));
|
15595 |
|
15596 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
15597 | },{}],55:[function(require,module,exports){
|
15598 | (function (process){
|
15599 |
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 |
|
15605 |
|
15606 |
|
15607 |
|
15608 |
|
15609 |
|
15610 |
|
15611 |
|
15612 |
|
15613 | var optional = require('./lib/optional')
|
15614 | , cookie = optional('tough-cookie')
|
15615 | , Cookie = cookie && cookie.Cookie
|
15616 | , CookieJar = cookie && cookie.CookieJar
|
15617 | , cookieJar = CookieJar && new CookieJar
|
15618 |
|
15619 | , copy = require('./lib/copy')
|
15620 | , Request = require('./request')
|
15621 | ;
|
15622 |
|
15623 |
|
15624 |
|
15625 |
|
15626 | function initParams(uri, options, callback) {
|
15627 | if ((typeof options === 'function') && !callback) callback = options
|
15628 | if (options && typeof options === 'object') {
|
15629 | options.uri = uri
|
15630 | } else if (typeof uri === 'string') {
|
15631 | options = {uri:uri}
|
15632 | } else {
|
15633 | options = uri
|
15634 | uri = options.uri
|
15635 | }
|
15636 | return { uri: uri, options: options, callback: callback }
|
15637 | }
|
15638 |
|
15639 | function request (uri, options, callback) {
|
15640 | if (typeof uri === 'undefined') throw new Error('undefined is not a valid uri or options object.')
|
15641 | if ((typeof options === 'function') && !callback) callback = options
|
15642 | if (options && typeof options === 'object') {
|
15643 | options.uri = uri
|
15644 | } else if (typeof uri === 'string') {
|
15645 | options = {uri:uri}
|
15646 | } else {
|
15647 | options = uri
|
15648 | }
|
15649 |
|
15650 | options = copy(options)
|
15651 |
|
15652 | if (callback) options.callback = callback
|
15653 | var r = new Request(options)
|
15654 | return r
|
15655 | }
|
15656 |
|
15657 | module.exports = request
|
15658 |
|
15659 | request.Request = Request;
|
15660 |
|
15661 | request.debug = process.env.NODE_DEBUG && /request/.test(process.env.NODE_DEBUG)
|
15662 |
|
15663 | request.initParams = initParams
|
15664 |
|
15665 | request.defaults = function (options, requester) {
|
15666 | var def = function (method) {
|
15667 | var d = function (uri, opts, callback) {
|
15668 | var params = initParams(uri, opts, callback)
|
15669 | for (var i in options) {
|
15670 | if (params.options[i] === undefined) params.options[i] = options[i]
|
15671 | }
|
15672 | if(typeof requester === 'function') {
|
15673 | if(method === request) {
|
15674 | method = requester
|
15675 | } else {
|
15676 | params.options._requester = requester
|
15677 | }
|
15678 | }
|
15679 | return method(params.options, params.callback)
|
15680 | }
|
15681 | return d
|
15682 | }
|
15683 | var de = def(request)
|
15684 | de.get = def(request.get)
|
15685 | de.patch = def(request.patch)
|
15686 | de.post = def(request.post)
|
15687 | de.put = def(request.put)
|
15688 | de.head = def(request.head)
|
15689 | de.del = def(request.del)
|
15690 | de.cookie = def(request.cookie)
|
15691 | de.jar = request.jar
|
15692 | return de
|
15693 | }
|
15694 |
|
15695 | function requester(params) {
|
15696 | if(typeof params.options._requester === 'function') {
|
15697 | return params.options._requester
|
15698 | } else {
|
15699 | return request
|
15700 | }
|
15701 | }
|
15702 |
|
15703 | request.forever = function (agentOptions, optionsArg) {
|
15704 | var options = {}
|
15705 | if (optionsArg) {
|
15706 | for (var option in optionsArg) {
|
15707 | options[option] = optionsArg[option]
|
15708 | }
|
15709 | }
|
15710 | if (agentOptions) options.agentOptions = agentOptions
|
15711 | options.forever = true
|
15712 | return request.defaults(options)
|
15713 | }
|
15714 |
|
15715 | request.get = request
|
15716 | request.post = function (uri, options, callback) {
|
15717 | var params = initParams(uri, options, callback)
|
15718 | params.options.method = 'POST'
|
15719 | return requester(params)(params.uri || null, params.options, params.callback)
|
15720 | }
|
15721 | request.put = function (uri, options, callback) {
|
15722 | var params = initParams(uri, options, callback)
|
15723 | params.options.method = 'PUT'
|
15724 | return requester(params)(params.uri || null, params.options, params.callback)
|
15725 | }
|
15726 | request.patch = function (uri, options, callback) {
|
15727 | var params = initParams(uri, options, callback)
|
15728 | params.options.method = 'PATCH'
|
15729 | return requester(params)(params.uri || null, params.options, params.callback)
|
15730 | }
|
15731 | request.head = function (uri, options, callback) {
|
15732 | var params = initParams(uri, options, callback)
|
15733 | params.options.method = 'HEAD'
|
15734 | if (params.options.body ||
|
15735 | params.options.requestBodyStream ||
|
15736 | (params.options.json && typeof params.options.json !== 'boolean') ||
|
15737 | params.options.multipart) {
|
15738 | throw new Error("HTTP HEAD requests MUST NOT include a request body.")
|
15739 | }
|
15740 |
|
15741 | return requester(params)(params.uri || null, params.options, params.callback)
|
15742 | }
|
15743 | request.del = function (uri, options, callback) {
|
15744 | var params = initParams(uri, options, callback)
|
15745 | params.options.method = 'DELETE'
|
15746 | return requester(params)(params.uri || null, params.options, params.callback)
|
15747 | }
|
15748 | request.jar = function () {
|
15749 | return new CookieJar
|
15750 | }
|
15751 | request.cookie = function (str) {
|
15752 | if (str && str.uri) str = str.uri
|
15753 | if (typeof str !== 'string') throw new Error("The cookie function only accepts STRING as param")
|
15754 | return new Cookie(str)
|
15755 | }
|
15756 |
|
15757 | }).call(this,require('_process'))
|
15758 | },{"./lib/copy":56,"./lib/optional":59,"./request":65,"_process":31}],56:[function(require,module,exports){
|
15759 | module.exports =
|
15760 | function copy (obj) {
|
15761 | var o = {}
|
15762 | Object.keys(obj).forEach(function (i) {
|
15763 | o[i] = obj[i]
|
15764 | })
|
15765 | return o
|
15766 | }
|
15767 | },{}],57:[function(require,module,exports){
|
15768 | (function (process){
|
15769 | var util = require('util')
|
15770 |
|
15771 | module.exports =
|
15772 | function debug () {
|
15773 | if (/\brequest\b/.test(process.env.NODE_DEBUG))
|
15774 | console.error('REQUEST %s', util.format.apply(util, arguments))
|
15775 | }
|
15776 |
|
15777 | }).call(this,require('_process'))
|
15778 | },{"_process":31,"util":51}],58:[function(require,module,exports){
|
15779 |
|
15780 | module.exports =
|
15781 | function getSafe (self, uuid) {
|
15782 | if (typeof self === 'object' || typeof self === 'function') var safe = {}
|
15783 | if (Array.isArray(self)) var safe = []
|
15784 |
|
15785 | var recurse = []
|
15786 |
|
15787 | Object.defineProperty(self, uuid, {})
|
15788 |
|
15789 | var attrs = Object.keys(self).filter(function (i) {
|
15790 | if (i === uuid) return false
|
15791 | if ( (typeof self[i] !== 'object' && typeof self[i] !== 'function') || self[i] === null) return true
|
15792 | return !(Object.getOwnPropertyDescriptor(self[i], uuid))
|
15793 | })
|
15794 |
|
15795 |
|
15796 | for (var i=0;i<attrs.length;i++) {
|
15797 | if ( (typeof self[attrs[i]] !== 'object' && typeof self[attrs[i]] !== 'function') ||
|
15798 | self[attrs[i]] === null
|
15799 | ) {
|
15800 | safe[attrs[i]] = self[attrs[i]]
|
15801 | } else {
|
15802 | recurse.push(attrs[i])
|
15803 | Object.defineProperty(self[attrs[i]], uuid, {})
|
15804 | }
|
15805 | }
|
15806 |
|
15807 | for (var i=0;i<recurse.length;i++) {
|
15808 | safe[recurse[i]] = getSafe(self[recurse[i]], uuid)
|
15809 | }
|
15810 |
|
15811 | return safe
|
15812 | }
|
15813 | },{}],59:[function(require,module,exports){
|
15814 | module.exports = function(module) {
|
15815 | try {
|
15816 | return require(module);
|
15817 | } catch (e) {}
|
15818 | };
|
15819 |
|
15820 | },{}],60:[function(require,module,exports){
|
15821 | module.exports = ForeverAgent
|
15822 | ForeverAgent.SSL = ForeverAgentSSL
|
15823 |
|
15824 | var util = require('util')
|
15825 | , Agent = require('http').Agent
|
15826 | , net = require('net')
|
15827 | , tls = require('tls')
|
15828 | , AgentSSL = require('https').Agent
|
15829 |
|
15830 | function ForeverAgent(options) {
|
15831 | var self = this
|
15832 | self.options = options || {}
|
15833 | self.requests = {}
|
15834 | self.sockets = {}
|
15835 | self.freeSockets = {}
|
15836 | self.maxSockets = self.options.maxSockets || Agent.defaultMaxSockets
|
15837 | self.minSockets = self.options.minSockets || ForeverAgent.defaultMinSockets
|
15838 | self.on('free', function(socket, host, port) {
|
15839 | var name = host + ':' + port
|
15840 | if (self.requests[name] && self.requests[name].length) {
|
15841 | self.requests[name].shift().onSocket(socket)
|
15842 | } else if (self.sockets[name].length < self.minSockets) {
|
15843 | if (!self.freeSockets[name]) self.freeSockets[name] = []
|
15844 | self.freeSockets[name].push(socket)
|
15845 |
|
15846 |
|
15847 | var onIdleError = function() {
|
15848 | socket.destroy()
|
15849 | }
|
15850 | socket._onIdleError = onIdleError
|
15851 | socket.on('error', onIdleError)
|
15852 | } else {
|
15853 |
|
15854 |
|
15855 |
|
15856 |
|
15857 | socket.destroy()
|
15858 | }
|
15859 | })
|
15860 |
|
15861 | }
|
15862 | util.inherits(ForeverAgent, Agent)
|
15863 |
|
15864 | ForeverAgent.defaultMinSockets = 5
|
15865 |
|
15866 |
|
15867 | ForeverAgent.prototype.createConnection = net.createConnection
|
15868 | ForeverAgent.prototype.addRequestNoreuse = Agent.prototype.addRequest
|
15869 | ForeverAgent.prototype.addRequest = function(req, host, port) {
|
15870 | var name = host + ':' + port
|
15871 | if (this.freeSockets[name] && this.freeSockets[name].length > 0 && !req.useChunkedEncodingByDefault) {
|
15872 | var idleSocket = this.freeSockets[name].pop()
|
15873 | idleSocket.removeListener('error', idleSocket._onIdleError)
|
15874 | delete idleSocket._onIdleError
|
15875 | req._reusedSocket = true
|
15876 | req.onSocket(idleSocket)
|
15877 | } else {
|
15878 | this.addRequestNoreuse(req, host, port)
|
15879 | }
|
15880 | }
|
15881 |
|
15882 | ForeverAgent.prototype.removeSocket = function(s, name, host, port) {
|
15883 | if (this.sockets[name]) {
|
15884 | var index = this.sockets[name].indexOf(s)
|
15885 | if (index !== -1) {
|
15886 | this.sockets[name].splice(index, 1)
|
15887 | }
|
15888 | } else if (this.sockets[name] && this.sockets[name].length === 0) {
|
15889 |
|
15890 | delete this.sockets[name]
|
15891 | delete this.requests[name]
|
15892 | }
|
15893 |
|
15894 | if (this.freeSockets[name]) {
|
15895 | var index = this.freeSockets[name].indexOf(s)
|
15896 | if (index !== -1) {
|
15897 | this.freeSockets[name].splice(index, 1)
|
15898 | if (this.freeSockets[name].length === 0) {
|
15899 | delete this.freeSockets[name]
|
15900 | }
|
15901 | }
|
15902 | }
|
15903 |
|
15904 | if (this.requests[name] && this.requests[name].length) {
|
15905 |
|
15906 |
|
15907 | this.createSocket(name, host, port).emit('free')
|
15908 | }
|
15909 | }
|
15910 |
|
15911 | function ForeverAgentSSL (options) {
|
15912 | ForeverAgent.call(this, options)
|
15913 | }
|
15914 | util.inherits(ForeverAgentSSL, ForeverAgent)
|
15915 |
|
15916 | ForeverAgentSSL.prototype.createConnection = createConnectionSSL
|
15917 | ForeverAgentSSL.prototype.addRequestNoreuse = AgentSSL.prototype.addRequest
|
15918 |
|
15919 | function createConnectionSSL (port, host, options) {
|
15920 | if (typeof port === 'object') {
|
15921 | options = port;
|
15922 | } else if (typeof host === 'object') {
|
15923 | options = host;
|
15924 | } else if (typeof options === 'object') {
|
15925 | options = options;
|
15926 | } else {
|
15927 | options = {};
|
15928 | }
|
15929 |
|
15930 | if (typeof port === 'number') {
|
15931 | options.port = port;
|
15932 | }
|
15933 |
|
15934 | if (typeof host === 'string') {
|
15935 | options.host = host;
|
15936 | }
|
15937 |
|
15938 | return tls.connect(options);
|
15939 | }
|
15940 |
|
15941 | },{"http":23,"https":27,"net":2,"tls":2,"util":51}],61:[function(require,module,exports){
|
15942 | module.exports = stringify;
|
15943 |
|
15944 | function getSerialize (fn, decycle) {
|
15945 | var seen = [], keys = [];
|
15946 | decycle = decycle || function(key, value) {
|
15947 | return '[Circular ' + getPath(value, seen, keys) + ']'
|
15948 | };
|
15949 | return function(key, value) {
|
15950 | var ret = value;
|
15951 | if (typeof value === 'object' && value) {
|
15952 | if (seen.indexOf(value) !== -1)
|
15953 | ret = decycle(key, value);
|
15954 | else {
|
15955 | seen.push(value);
|
15956 | keys.push(key);
|
15957 | }
|
15958 | }
|
15959 | if (fn) ret = fn(key, ret);
|
15960 | return ret;
|
15961 | }
|
15962 | }
|
15963 |
|
15964 | function getPath (value, seen, keys) {
|
15965 | var index = seen.indexOf(value);
|
15966 | var path = [ keys[index] ];
|
15967 | for (index--; index >= 0; index--) {
|
15968 | if (seen[index][ path[0] ] === value) {
|
15969 | value = seen[index];
|
15970 | path.unshift(keys[index]);
|
15971 | }
|
15972 | }
|
15973 | return '~' + path.join('.');
|
15974 | }
|
15975 |
|
15976 | function stringify(obj, fn, spaces, decycle) {
|
15977 | return JSON.stringify(obj, getSerialize(fn, decycle), spaces);
|
15978 | }
|
15979 |
|
15980 | stringify.getSerialize = getSerialize;
|
15981 |
|
15982 | },{}],62:[function(require,module,exports){
|
15983 | (function (process,__dirname){
|
15984 | var path = require('path');
|
15985 | var fs = require('fs');
|
15986 |
|
15987 | function Mime() {
|
15988 |
|
15989 | this.types = Object.create(null);
|
15990 |
|
15991 |
|
15992 | this.extensions = Object.create(null);
|
15993 | }
|
15994 |
|
15995 |
|
15996 |
|
15997 |
|
15998 |
|
15999 |
|
16000 |
|
16001 |
|
16002 |
|
16003 |
|
16004 | Mime.prototype.define = function (map) {
|
16005 | for (var type in map) {
|
16006 | var exts = map[type];
|
16007 |
|
16008 | for (var i = 0; i < exts.length; i++) {
|
16009 | if (process.env.DEBUG_MIME && this.types[exts]) {
|
16010 | console.warn(this._loading.replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
|
16011 | this.types[exts] + ' to ' + type);
|
16012 | }
|
16013 |
|
16014 | this.types[exts[i]] = type;
|
16015 | }
|
16016 |
|
16017 |
|
16018 | if (!this.extensions[type]) {
|
16019 | this.extensions[type] = exts[0];
|
16020 | }
|
16021 | }
|
16022 | };
|
16023 |
|
16024 |
|
16025 |
|
16026 |
|
16027 |
|
16028 |
|
16029 |
|
16030 |
|
16031 |
|
16032 | Mime.prototype.load = function(file) {
|
16033 |
|
16034 | this._loading = file;
|
16035 |
|
16036 | var map = {},
|
16037 | content = fs.readFileSync(file, 'ascii'),
|
16038 | lines = content.split(/[\r\n]+/);
|
16039 |
|
16040 | lines.forEach(function(line) {
|
16041 |
|
16042 | var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
|
16043 | map[fields.shift()] = fields;
|
16044 | });
|
16045 |
|
16046 | this.define(map);
|
16047 |
|
16048 | this._loading = null;
|
16049 | };
|
16050 |
|
16051 |
|
16052 |
|
16053 |
|
16054 | Mime.prototype.lookup = function(path, fallback) {
|
16055 | var ext = path.replace(/.*[\.\/\\]/, '').toLowerCase();
|
16056 |
|
16057 | return this.types[ext] || fallback || this.default_type;
|
16058 | };
|
16059 |
|
16060 |
|
16061 |
|
16062 |
|
16063 | Mime.prototype.extension = function(mimeType) {
|
16064 | var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
|
16065 | return this.extensions[type];
|
16066 | };
|
16067 |
|
16068 |
|
16069 | var mime = new Mime();
|
16070 |
|
16071 |
|
16072 |
|
16073 | mime.load(path.join(__dirname, 'types/mime.types'));
|
16074 |
|
16075 |
|
16076 | mime.load(path.join(__dirname, 'types/node.types'));
|
16077 |
|
16078 |
|
16079 | mime.default_type = mime.lookup('bin');
|
16080 |
|
16081 |
|
16082 |
|
16083 |
|
16084 |
|
16085 | mime.Mime = Mime;
|
16086 |
|
16087 |
|
16088 |
|
16089 |
|
16090 | mime.charsets = {
|
16091 | lookup: function(mimeType, fallback) {
|
16092 |
|
16093 | return (/^text\//).test(mimeType) ? 'UTF-8' : fallback;
|
16094 | }
|
16095 | };
|
16096 |
|
16097 | module.exports = mime;
|
16098 |
|
16099 | }).call(this,require('_process'),"/node_modules/request/node_modules/mime")
|
16100 | },{"_process":31,"fs":2,"path":30}],63:[function(require,module,exports){
|
16101 | (function (Buffer){
|
16102 |
|
16103 |
|
16104 |
|
16105 |
|
16106 |
|
16107 | (function() {
|
16108 | var _global = this;
|
16109 |
|
16110 |
|
16111 |
|
16112 |
|
16113 | var _rng;
|
16114 |
|
16115 |
|
16116 |
|
16117 |
|
16118 | if (typeof(require) == 'function') {
|
16119 | try {
|
16120 | var _rb = require('crypto').randomBytes;
|
16121 | _rng = _rb && function() {return _rb(16);};
|
16122 | } catch(e) {}
|
16123 | }
|
16124 |
|
16125 | if (!_rng && _global.crypto && crypto.getRandomValues) {
|
16126 |
|
16127 |
|
16128 |
|
16129 | var _rnds8 = new Uint8Array(16);
|
16130 | _rng = function whatwgRNG() {
|
16131 | crypto.getRandomValues(_rnds8);
|
16132 | return _rnds8;
|
16133 | };
|
16134 | }
|
16135 |
|
16136 | if (!_rng) {
|
16137 |
|
16138 |
|
16139 |
|
16140 |
|
16141 | var _rnds = new Array(16);
|
16142 | _rng = function() {
|
16143 | for (var i = 0, r; i < 16; i++) {
|
16144 | if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
16145 | _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
16146 | }
|
16147 |
|
16148 | return _rnds;
|
16149 | };
|
16150 | }
|
16151 |
|
16152 |
|
16153 | var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array;
|
16154 |
|
16155 |
|
16156 | var _byteToHex = [];
|
16157 | var _hexToByte = {};
|
16158 | for (var i = 0; i < 256; i++) {
|
16159 | _byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
16160 | _hexToByte[_byteToHex[i]] = i;
|
16161 | }
|
16162 |
|
16163 |
|
16164 | function parse(s, buf, offset) {
|
16165 | var i = (buf && offset) || 0, ii = 0;
|
16166 |
|
16167 | buf = buf || [];
|
16168 | s.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) {
|
16169 | if (ii < 16) {
|
16170 | buf[i + ii++] = _hexToByte[oct];
|
16171 | }
|
16172 | });
|
16173 |
|
16174 |
|
16175 | while (ii < 16) {
|
16176 | buf[i + ii++] = 0;
|
16177 | }
|
16178 |
|
16179 | return buf;
|
16180 | }
|
16181 |
|
16182 |
|
16183 | function unparse(buf, offset) {
|
16184 | var i = offset || 0, bth = _byteToHex;
|
16185 | return bth[buf[i++]] + bth[buf[i++]] +
|
16186 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
16187 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
16188 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
16189 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
16190 | bth[buf[i++]] + bth[buf[i++]] +
|
16191 | bth[buf[i++]] + bth[buf[i++]] +
|
16192 | bth[buf[i++]] + bth[buf[i++]];
|
16193 | }
|
16194 |
|
16195 |
|
16196 |
|
16197 |
|
16198 |
|
16199 |
|
16200 |
|
16201 | var _seedBytes = _rng();
|
16202 |
|
16203 |
|
16204 | var _nodeId = [
|
16205 | _seedBytes[0] | 0x01,
|
16206 | _seedBytes[1], _seedBytes[2], _seedBytes[3], _seedBytes[4], _seedBytes[5]
|
16207 | ];
|
16208 |
|
16209 |
|
16210 | var _clockseq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3fff;
|
16211 |
|
16212 |
|
16213 | var _lastMSecs = 0, _lastNSecs = 0;
|
16214 |
|
16215 |
|
16216 | function v1(options, buf, offset) {
|
16217 | var i = buf && offset || 0;
|
16218 | var b = buf || [];
|
16219 |
|
16220 | options = options || {};
|
16221 |
|
16222 | var clockseq = options.clockseq != null ? options.clockseq : _clockseq;
|
16223 |
|
16224 |
|
16225 |
|
16226 |
|
16227 |
|
16228 | var msecs = options.msecs != null ? options.msecs : new Date().getTime();
|
16229 |
|
16230 |
|
16231 |
|
16232 | var nsecs = options.nsecs != null ? options.nsecs : _lastNSecs + 1;
|
16233 |
|
16234 |
|
16235 | var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
16236 |
|
16237 |
|
16238 | if (dt < 0 && options.clockseq == null) {
|
16239 | clockseq = clockseq + 1 & 0x3fff;
|
16240 | }
|
16241 |
|
16242 |
|
16243 |
|
16244 | if ((dt < 0 || msecs > _lastMSecs) && options.nsecs == null) {
|
16245 | nsecs = 0;
|
16246 | }
|
16247 |
|
16248 |
|
16249 | if (nsecs >= 10000) {
|
16250 | throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
16251 | }
|
16252 |
|
16253 | _lastMSecs = msecs;
|
16254 | _lastNSecs = nsecs;
|
16255 | _clockseq = clockseq;
|
16256 |
|
16257 |
|
16258 | msecs += 12219292800000;
|
16259 |
|
16260 |
|
16261 | var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
16262 | b[i++] = tl >>> 24 & 0xff;
|
16263 | b[i++] = tl >>> 16 & 0xff;
|
16264 | b[i++] = tl >>> 8 & 0xff;
|
16265 | b[i++] = tl & 0xff;
|
16266 |
|
16267 |
|
16268 | var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
16269 | b[i++] = tmh >>> 8 & 0xff;
|
16270 | b[i++] = tmh & 0xff;
|
16271 |
|
16272 |
|
16273 | b[i++] = tmh >>> 24 & 0xf | 0x10;
|
16274 | b[i++] = tmh >>> 16 & 0xff;
|
16275 |
|
16276 |
|
16277 | b[i++] = clockseq >>> 8 | 0x80;
|
16278 |
|
16279 |
|
16280 | b[i++] = clockseq & 0xff;
|
16281 |
|
16282 |
|
16283 | var node = options.node || _nodeId;
|
16284 | for (var n = 0; n < 6; n++) {
|
16285 | b[i + n] = node[n];
|
16286 | }
|
16287 |
|
16288 | return buf ? buf : unparse(b);
|
16289 | }
|
16290 |
|
16291 |
|
16292 |
|
16293 |
|
16294 | function v4(options, buf, offset) {
|
16295 |
|
16296 | var i = buf && offset || 0;
|
16297 |
|
16298 | if (typeof(options) == 'string') {
|
16299 | buf = options == 'binary' ? new BufferClass(16) : null;
|
16300 | options = null;
|
16301 | }
|
16302 | options = options || {};
|
16303 |
|
16304 | var rnds = options.random || (options.rng || _rng)();
|
16305 |
|
16306 |
|
16307 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
16308 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
16309 |
|
16310 |
|
16311 | if (buf) {
|
16312 | for (var ii = 0; ii < 16; ii++) {
|
16313 | buf[i + ii] = rnds[ii];
|
16314 | }
|
16315 | }
|
16316 |
|
16317 | return buf || unparse(rnds);
|
16318 | }
|
16319 |
|
16320 |
|
16321 | var uuid = v4;
|
16322 | uuid.v1 = v1;
|
16323 | uuid.v4 = v4;
|
16324 | uuid.parse = parse;
|
16325 | uuid.unparse = unparse;
|
16326 | uuid.BufferClass = BufferClass;
|
16327 |
|
16328 | if (typeof define === 'function' && define.amd) {
|
16329 |
|
16330 | define(function() {return uuid;});
|
16331 | } else if (typeof(module) != 'undefined' && module.exports) {
|
16332 |
|
16333 | module.exports = uuid;
|
16334 | } else {
|
16335 |
|
16336 | var _previousRoot = _global.uuid;
|
16337 |
|
16338 |
|
16339 | uuid.noConflict = function() {
|
16340 | _global.uuid = _previousRoot;
|
16341 | return uuid;
|
16342 | };
|
16343 |
|
16344 | _global.uuid = uuid;
|
16345 | }
|
16346 | }).call(this);
|
16347 |
|
16348 | }).call(this,require("buffer").Buffer)
|
16349 | },{"buffer":3,"crypto":10}],64:[function(require,module,exports){
|
16350 |
|
16351 |
|
16352 |
|
16353 |
|
16354 | var toString = Object.prototype.toString;
|
16355 |
|
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
16361 |
|
16362 |
|
16363 |
|
16364 |
|
16365 |
|
16366 | var indexOf = typeof Array.prototype.indexOf === 'function'
|
16367 | ? function(arr, el) { return arr.indexOf(el); }
|
16368 | : function(arr, el) {
|
16369 | for (var i = 0; i < arr.length; i++) {
|
16370 | if (arr[i] === el) return i;
|
16371 | }
|
16372 | return -1;
|
16373 | };
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 | var isArray = Array.isArray || function(arr) {
|
16380 | return toString.call(arr) == '[object Array]';
|
16381 | };
|
16382 |
|
16383 |
|
16384 |
|
16385 |
|
16386 |
|
16387 | var objectKeys = Object.keys || function(obj) {
|
16388 | var ret = [];
|
16389 | for (var key in obj) {
|
16390 | if (obj.hasOwnProperty(key)) {
|
16391 | ret.push(key);
|
16392 | }
|
16393 | }
|
16394 | return ret;
|
16395 | };
|
16396 |
|
16397 |
|
16398 |
|
16399 |
|
16400 |
|
16401 | var forEach = typeof Array.prototype.forEach === 'function'
|
16402 | ? function(arr, fn) { return arr.forEach(fn); }
|
16403 | : function(arr, fn) {
|
16404 | for (var i = 0; i < arr.length; i++) fn(arr[i]);
|
16405 | };
|
16406 |
|
16407 |
|
16408 |
|
16409 |
|
16410 |
|
16411 | var reduce = function(arr, fn, initial) {
|
16412 | if (typeof arr.reduce === 'function') return arr.reduce(fn, initial);
|
16413 | var res = initial;
|
16414 | for (var i = 0; i < arr.length; i++) res = fn(res, arr[i]);
|
16415 | return res;
|
16416 | };
|
16417 |
|
16418 |
|
16419 |
|
16420 |
|
16421 |
|
16422 | var isint = /^[0-9]+$/;
|
16423 |
|
16424 | function promote(parent, key) {
|
16425 | if (parent[key].length == 0) return parent[key] = {}
|
16426 | var t = {};
|
16427 | for (var i in parent[key]) {
|
16428 | if (hasOwnProperty.call(parent[key], i)) {
|
16429 | t[i] = parent[key][i];
|
16430 | }
|
16431 | }
|
16432 | parent[key] = t;
|
16433 | return t;
|
16434 | }
|
16435 |
|
16436 | function parse(parts, parent, key, val) {
|
16437 | var part = parts.shift();
|
16438 |
|
16439 |
|
16440 | if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
|
16441 |
|
16442 |
|
16443 | if (!part) {
|
16444 | if (isArray(parent[key])) {
|
16445 | parent[key].push(val);
|
16446 | } else if ('object' == typeof parent[key]) {
|
16447 | parent[key] = val;
|
16448 | } else if ('undefined' == typeof parent[key]) {
|
16449 | parent[key] = val;
|
16450 | } else {
|
16451 | parent[key] = [parent[key], val];
|
16452 | }
|
16453 |
|
16454 | } else {
|
16455 | var obj = parent[key] = parent[key] || [];
|
16456 | if (']' == part) {
|
16457 | if (isArray(obj)) {
|
16458 | if ('' != val) obj.push(val);
|
16459 | } else if ('object' == typeof obj) {
|
16460 | obj[objectKeys(obj).length] = val;
|
16461 | } else {
|
16462 | obj = parent[key] = [parent[key], val];
|
16463 | }
|
16464 |
|
16465 | } else if (~indexOf(part, ']')) {
|
16466 | part = part.substr(0, part.length - 1);
|
16467 | if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
|
16468 | parse(parts, obj, part, val);
|
16469 |
|
16470 | } else {
|
16471 | if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
|
16472 | parse(parts, obj, part, val);
|
16473 | }
|
16474 | }
|
16475 | }
|
16476 |
|
16477 |
|
16478 |
|
16479 |
|
16480 |
|
16481 | function merge(parent, key, val){
|
16482 | if (~indexOf(key, ']')) {
|
16483 | var parts = key.split('[')
|
16484 | , len = parts.length
|
16485 | , last = len - 1;
|
16486 | parse(parts, parent, 'base', val);
|
16487 |
|
16488 | } else {
|
16489 | if (!isint.test(key) && isArray(parent.base)) {
|
16490 | var t = {};
|
16491 | for (var k in parent.base) t[k] = parent.base[k];
|
16492 | parent.base = t;
|
16493 | }
|
16494 | set(parent.base, key, val);
|
16495 | }
|
16496 |
|
16497 | return parent;
|
16498 | }
|
16499 |
|
16500 | /**
|
16501 | * Compact sparse arrays.
|
16502 | */
|
16503 |
|
16504 | function compact(obj) {
|
16505 | if ('object' != typeof obj) return obj;
|
16506 |
|
16507 | if (isArray(obj)) {
|
16508 | var ret = [];
|
16509 |
|
16510 | for (var i in obj) {
|
16511 | if (hasOwnProperty.call(obj, i)) {
|
16512 | ret.push(obj[i]);
|
16513 | }
|
16514 | }
|
16515 |
|
16516 | return ret;
|
16517 | }
|
16518 |
|
16519 | for (var key in obj) {
|
16520 | obj[key] = compact(obj[key]);
|
16521 | }
|
16522 |
|
16523 | return obj;
|
16524 | }
|
16525 |
|
16526 |
|
16527 |
|
16528 |
|
16529 |
|
16530 | function parseObject(obj){
|
16531 | var ret = { base: {} };
|
16532 |
|
16533 | forEach(objectKeys(obj), function(name){
|
16534 | merge(ret, name, obj[name]);
|
16535 | });
|
16536 |
|
16537 | return compact(ret.base);
|
16538 | }
|
16539 |
|
16540 |
|
16541 |
|
16542 |
|
16543 |
|
16544 | function parseString(str){
|
16545 | var ret = reduce(String(str).split('&'), function(ret, pair){
|
16546 | var eql = indexOf(pair, '=')
|
16547 | , brace = lastBraceInKey(pair)
|
16548 | , key = pair.substr(0, brace || eql)
|
16549 | , val = pair.substr(brace || eql, pair.length)
|
16550 | , val = val.substr(indexOf(val, '=') + 1, val.length);
|
16551 |
|
16552 |
|
16553 | if ('' == key) key = pair, val = '';
|
16554 | if ('' == key) return ret;
|
16555 |
|
16556 | return merge(ret, decode(key), decode(val));
|
16557 | }, { base: {} }).base;
|
16558 |
|
16559 | return compact(ret);
|
16560 | }
|
16561 |
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 |
|
16567 |
|
16568 |
|
16569 |
|
16570 | exports.parse = function(str){
|
16571 | if (null == str || '' == str) return {};
|
16572 | return 'object' == typeof str
|
16573 | ? parseObject(str)
|
16574 | : parseString(str);
|
16575 | };
|
16576 |
|
16577 |
|
16578 |
|
16579 |
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 |
|
16585 | var stringify = exports.stringify = function(obj, prefix) {
|
16586 | if (isArray(obj)) {
|
16587 | return stringifyArray(obj, prefix);
|
16588 | } else if ('[object Object]' == toString.call(obj)) {
|
16589 | return stringifyObject(obj, prefix);
|
16590 | } else if ('string' == typeof obj) {
|
16591 | return stringifyString(obj, prefix);
|
16592 | } else {
|
16593 | return prefix + '=' + encodeURIComponent(String(obj));
|
16594 | }
|
16595 | };
|
16596 |
|
16597 |
|
16598 |
|
16599 |
|
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 | function stringifyString(str, prefix) {
|
16607 | if (!prefix) throw new TypeError('stringify expects an object');
|
16608 | return prefix + '=' + encodeURIComponent(str);
|
16609 | }
|
16610 |
|
16611 |
|
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 |
|
16618 |
|
16619 |
|
16620 | function stringifyArray(arr, prefix) {
|
16621 | var ret = [];
|
16622 | if (!prefix) throw new TypeError('stringify expects an object');
|
16623 | for (var i = 0; i < arr.length; i++) {
|
16624 | ret.push(stringify(arr[i], prefix + '[' + i + ']'));
|
16625 | }
|
16626 | return ret.join('&');
|
16627 | }
|
16628 |
|
16629 |
|
16630 |
|
16631 |
|
16632 |
|
16633 |
|
16634 |
|
16635 |
|
16636 |
|
16637 |
|
16638 | function stringifyObject(obj, prefix) {
|
16639 | var ret = []
|
16640 | , keys = objectKeys(obj)
|
16641 | , key;
|
16642 |
|
16643 | for (var i = 0, len = keys.length; i < len; ++i) {
|
16644 | key = keys[i];
|
16645 | if ('' == key) continue;
|
16646 | if (null == obj[key]) {
|
16647 | ret.push(encodeURIComponent(key) + '=');
|
16648 | } else {
|
16649 | ret.push(stringify(obj[key], prefix
|
16650 | ? prefix + '[' + encodeURIComponent(key) + ']'
|
16651 | : encodeURIComponent(key)));
|
16652 | }
|
16653 | }
|
16654 |
|
16655 | return ret.join('&');
|
16656 | }
|
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 |
|
16665 |
|
16666 |
|
16667 |
|
16668 |
|
16669 | function set(obj, key, val) {
|
16670 | var v = obj[key];
|
16671 | if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
|
16672 | if (undefined === v) {
|
16673 | obj[key] = val;
|
16674 | } else if (isArray(v)) {
|
16675 | v.push(val);
|
16676 | } else {
|
16677 | obj[key] = [v, val];
|
16678 | }
|
16679 | }
|
16680 |
|
16681 |
|
16682 |
|
16683 |
|
16684 |
|
16685 |
|
16686 |
|
16687 |
|
16688 |
|
16689 | function lastBraceInKey(str) {
|
16690 | var len = str.length
|
16691 | , brace
|
16692 | , c;
|
16693 | for (var i = 0; i < len; ++i) {
|
16694 | c = str[i];
|
16695 | if (']' == c) brace = false;
|
16696 | if ('[' == c) brace = true;
|
16697 | if ('=' == c && !brace) return i;
|
16698 | }
|
16699 | }
|
16700 |
|
16701 |
|
16702 |
|
16703 |
|
16704 |
|
16705 |
|
16706 |
|
16707 |
|
16708 |
|
16709 | function decode(str) {
|
16710 | try {
|
16711 | return decodeURIComponent(str.replace(/\+/g, ' '));
|
16712 | } catch (err) {
|
16713 | return str;
|
16714 | }
|
16715 | }
|
16716 |
|
16717 | },{}],65:[function(require,module,exports){
|
16718 | (function (process,Buffer){
|
16719 | var optional = require('./lib/optional')
|
16720 | , http = require('http')
|
16721 | , https = optional('https')
|
16722 | , tls = optional('tls')
|
16723 | , url = require('url')
|
16724 | , util = require('util')
|
16725 | , stream = require('stream')
|
16726 | , qs = require('qs')
|
16727 | , querystring = require('querystring')
|
16728 | , crypto = require('crypto')
|
16729 |
|
16730 | , oauth = optional('oauth-sign')
|
16731 | , hawk = optional('hawk')
|
16732 | , aws = optional('aws-sign')
|
16733 | , httpSignature = optional('http-signature')
|
16734 | , uuid = require('node-uuid')
|
16735 | , mime = require('mime')
|
16736 | , tunnel = optional('tunnel-agent')
|
16737 | , _safeStringify = require('json-stringify-safe')
|
16738 |
|
16739 | , ForeverAgent = require('forever-agent')
|
16740 | , FormData = optional('form-data')
|
16741 |
|
16742 | , Cookie = optional('tough-cookie')
|
16743 | , CookieJar = Cookie && Cookie.CookieJar
|
16744 | , cookieJar = CookieJar && new CookieJar
|
16745 |
|
16746 | , copy = require('./lib/copy')
|
16747 | , debug = require('./lib/debug')
|
16748 | , getSafe = require('./lib/getSafe')
|
16749 | ;
|
16750 |
|
16751 | function safeStringify (obj) {
|
16752 | var ret
|
16753 | try { ret = JSON.stringify(obj) }
|
16754 | catch (e) { ret = _safeStringify(obj) }
|
16755 | return ret
|
16756 | }
|
16757 |
|
16758 | var globalPool = {}
|
16759 | var isUrl = /^https?:/i
|
16760 |
|
16761 |
|
16762 |
|
16763 | if (https && !https.Agent) {
|
16764 | https.Agent = function (options) {
|
16765 | http.Agent.call(this, options)
|
16766 | }
|
16767 | util.inherits(https.Agent, http.Agent)
|
16768 | https.Agent.prototype._getConnection = function (host, port, cb) {
|
16769 | var s = tls.connect(port, host, this.options, function () {
|
16770 |
|
16771 | if (cb) cb()
|
16772 | })
|
16773 | return s
|
16774 | }
|
16775 | }
|
16776 |
|
16777 | function isReadStream (rs) {
|
16778 | if (rs.readable && rs.path && rs.mode) {
|
16779 | return true
|
16780 | }
|
16781 | }
|
16782 |
|
16783 | function toBase64 (str) {
|
16784 | return (new Buffer(str || "", "ascii")).toString("base64")
|
16785 | }
|
16786 |
|
16787 | function md5 (str) {
|
16788 | return crypto.createHash('md5').update(str).digest('hex')
|
16789 | }
|
16790 |
|
16791 | function Request (options) {
|
16792 | stream.Stream.call(this)
|
16793 | this.readable = true
|
16794 | this.writable = true
|
16795 |
|
16796 | if (typeof options === 'string') {
|
16797 | options = {uri:options}
|
16798 | }
|
16799 |
|
16800 | var reserved = Object.keys(Request.prototype)
|
16801 | for (var i in options) {
|
16802 | if (reserved.indexOf(i) === -1) {
|
16803 | this[i] = options[i]
|
16804 | } else {
|
16805 | if (typeof options[i] === 'function') {
|
16806 | delete options[i]
|
16807 | }
|
16808 | }
|
16809 | }
|
16810 |
|
16811 | if (options.method) {
|
16812 | this.explicitMethod = true
|
16813 | }
|
16814 |
|
16815 | this.canTunnel = options.tunnel !== false && tunnel;
|
16816 |
|
16817 | this.init(options)
|
16818 | }
|
16819 | util.inherits(Request, stream.Stream)
|
16820 | Request.prototype.init = function (options) {
|
16821 |
|
16822 |
|
16823 |
|
16824 | var self = this
|
16825 | if (!options) options = {}
|
16826 |
|
16827 | if (!self.method) self.method = options.method || 'GET'
|
16828 | self.localAddress = options.localAddress
|
16829 |
|
16830 | debug(options)
|
16831 | if (!self.pool && self.pool !== false) self.pool = globalPool
|
16832 | self.dests = self.dests || []
|
16833 | self.__isRequestRequest = true
|
16834 |
|
16835 |
|
16836 | if (!self._callback && self.callback) {
|
16837 | self._callback = self.callback
|
16838 | self.callback = function () {
|
16839 | if (self._callbackCalled) return
|
16840 | self._callbackCalled = true
|
16841 | self._callback.apply(self, arguments)
|
16842 | }
|
16843 | self.on('error', self.callback.bind())
|
16844 | self.on('complete', self.callback.bind(self, null))
|
16845 | }
|
16846 |
|
16847 | if (self.url && !self.uri) {
|
16848 |
|
16849 | self.uri = self.url
|
16850 | delete self.url
|
16851 | }
|
16852 |
|
16853 | if (!self.uri) {
|
16854 |
|
16855 | return self.emit('error', new Error("options.uri is a required argument"))
|
16856 | } else {
|
16857 | if (typeof self.uri == "string") self.uri = url.parse(self.uri)
|
16858 | }
|
16859 |
|
16860 | if (self.strictSSL === false) {
|
16861 | self.rejectUnauthorized = false
|
16862 | }
|
16863 |
|
16864 | if (self.proxy) {
|
16865 | if (typeof self.proxy == 'string') self.proxy = url.parse(self.proxy)
|
16866 |
|
16867 |
|
16868 | if (http.globalAgent && self.uri.protocol === "https:" && self.canTunnel) {
|
16869 | var tunnelFn = self.proxy.protocol === "http:"
|
16870 | ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
|
16871 |
|
16872 | var tunnelOptions = { proxy: { host: self.proxy.hostname
|
16873 | , port: +self.proxy.port
|
16874 | , proxyAuth: self.proxy.auth
|
16875 | , headers: { Host: self.uri.hostname + ':' +
|
16876 | (self.uri.port || self.uri.protocol === 'https:' ? 443 : 80) }}
|
16877 | , rejectUnauthorized: self.rejectUnauthorized
|
16878 | , ca: this.ca }
|
16879 |
|
16880 | self.agent = tunnelFn(tunnelOptions)
|
16881 | self.tunnel = true
|
16882 | }
|
16883 | }
|
16884 |
|
16885 | if (!self.uri.pathname) {self.uri.pathname = '/'}
|
16886 |
|
16887 | if (!self.uri.host) {
|
16888 |
|
16889 |
|
16890 | var faultyUri = url.format(self.uri)
|
16891 | var message = 'Invalid URI "' + faultyUri + '"'
|
16892 | if (Object.keys(options).length === 0) {
|
16893 |
|
16894 |
|
16895 |
|
16896 | message += '. This can be caused by a crappy redirection.'
|
16897 | }
|
16898 | self.emit('error', new Error(message))
|
16899 | return
|
16900 | }
|
16901 |
|
16902 | self._redirectsFollowed = self._redirectsFollowed || 0
|
16903 | self.maxRedirects = (self.maxRedirects !== undefined) ? self.maxRedirects : 10
|
16904 | self.followRedirect = (self.followRedirect !== undefined) ? self.followRedirect : true
|
16905 | self.followAllRedirects = (self.followAllRedirects !== undefined) ? self.followAllRedirects : false
|
16906 | if (self.followRedirect || self.followAllRedirects)
|
16907 | self.redirects = self.redirects || []
|
16908 |
|
16909 | self.headers = self.headers ? copy(self.headers) : {}
|
16910 |
|
16911 | self.setHost = false
|
16912 | if (!self.hasHeader('host')) {
|
16913 | self.setHeader('host', self.uri.hostname)
|
16914 | if (self.uri.port) {
|
16915 | if ( !(self.uri.port === 80 && self.uri.protocol === 'http:') &&
|
16916 | !(self.uri.port === 443 && self.uri.protocol === 'https:') )
|
16917 | self.setHeader('host', self.getHeader('host') + (':'+self.uri.port) )
|
16918 | }
|
16919 | self.setHost = true
|
16920 | }
|
16921 |
|
16922 | self.jar(self._jar || options.jar)
|
16923 |
|
16924 | if (!self.uri.port) {
|
16925 | if (self.uri.protocol == 'http:') {self.uri.port = 80}
|
16926 | else if (self.uri.protocol == 'https:') {self.uri.port = 443}
|
16927 | }
|
16928 |
|
16929 | if (self.proxy && !self.tunnel) {
|
16930 | self.port = self.proxy.port
|
16931 | self.host = self.proxy.hostname
|
16932 | } else {
|
16933 | self.port = self.uri.port
|
16934 | self.host = self.uri.hostname
|
16935 | }
|
16936 |
|
16937 | self.clientErrorHandler = function (error) {
|
16938 | if (self._aborted) return
|
16939 | if (self.req && self.req._reusedSocket && error.code === 'ECONNRESET'
|
16940 | && self.agent.addRequestNoreuse) {
|
16941 | self.agent = { addRequest: self.agent.addRequestNoreuse.bind(self.agent) }
|
16942 | self.start()
|
16943 | self.req.end()
|
16944 | return
|
16945 | }
|
16946 | if (self.timeout && self.timeoutTimer) {
|
16947 | clearTimeout(self.timeoutTimer)
|
16948 | self.timeoutTimer = null
|
16949 | }
|
16950 | self.emit('error', error)
|
16951 | }
|
16952 |
|
16953 | self._parserErrorHandler = function (error) {
|
16954 | if (this.res) {
|
16955 | if (this.res.request) {
|
16956 | this.res.request.emit('error', error)
|
16957 | } else {
|
16958 | this.res.emit('error', error)
|
16959 | }
|
16960 | } else {
|
16961 | this._httpMessage.emit('error', error)
|
16962 | }
|
16963 | }
|
16964 |
|
16965 | if (options.form) {
|
16966 | self.form(options.form)
|
16967 | }
|
16968 |
|
16969 | if (options.qs) self.qs(options.qs)
|
16970 |
|
16971 | if (self.uri.path) {
|
16972 | self.path = self.uri.path
|
16973 | } else {
|
16974 | self.path = self.uri.pathname + (self.uri.search || "")
|
16975 | }
|
16976 |
|
16977 | if (self.path.length === 0) self.path = '/'
|
16978 |
|
16979 |
|
16980 |
|
16981 | if (options.oauth) {
|
16982 | self.oauth(options.oauth)
|
16983 | }
|
16984 |
|
16985 | if (options.aws) {
|
16986 | self.aws(options.aws)
|
16987 | }
|
16988 |
|
16989 | if (options.hawk) {
|
16990 | self.hawk(options.hawk)
|
16991 | }
|
16992 |
|
16993 | if (options.httpSignature) {
|
16994 | self.httpSignature(options.httpSignature)
|
16995 | }
|
16996 |
|
16997 | if (options.auth) {
|
16998 | if (Object.prototype.hasOwnProperty.call(options.auth, 'username')) options.auth.user = options.auth.username
|
16999 | if (Object.prototype.hasOwnProperty.call(options.auth, 'password')) options.auth.pass = options.auth.password
|
17000 |
|
17001 | self.auth(
|
17002 | options.auth.user,
|
17003 | options.auth.pass,
|
17004 | options.auth.sendImmediately
|
17005 | )
|
17006 | }
|
17007 |
|
17008 | if (self.uri.auth && !self.hasHeader('authorization')) {
|
17009 | var authPieces = self.uri.auth.split(':').map(function(item){ return querystring.unescape(item) })
|
17010 | self.auth(authPieces[0], authPieces.slice(1).join(':'), true)
|
17011 | }
|
17012 | if (self.proxy && self.proxy.auth && !self.hasHeader('proxy-authorization') && !self.tunnel) {
|
17013 | self.setHeader('proxy-authorization', "Basic " + toBase64(self.proxy.auth.split(':').map(function(item){ return querystring.unescape(item)}).join(':')))
|
17014 | }
|
17015 |
|
17016 |
|
17017 | if (self.proxy && !self.tunnel) self.path = (self.uri.protocol + '//' + self.uri.host + self.path)
|
17018 |
|
17019 | if (options.json) {
|
17020 | self.json(options.json)
|
17021 | } else if (options.multipart) {
|
17022 | self.boundary = uuid()
|
17023 | self.multipart(options.multipart)
|
17024 | }
|
17025 |
|
17026 | if (self.body) {
|
17027 | var length = 0
|
17028 | if (!Buffer.isBuffer(self.body)) {
|
17029 | if (Array.isArray(self.body)) {
|
17030 | for (var i = 0; i < self.body.length; i++) {
|
17031 | length += self.body[i].length
|
17032 | }
|
17033 | } else {
|
17034 | self.body = new Buffer(self.body)
|
17035 | length = self.body.length
|
17036 | }
|
17037 | } else {
|
17038 | length = self.body.length
|
17039 | }
|
17040 | if (length) {
|
17041 | if (!self.hasHeader('content-length')) self.setHeader('content-length', length)
|
17042 | } else {
|
17043 | throw new Error('Argument error, options.body.')
|
17044 | }
|
17045 | }
|
17046 |
|
17047 | var protocol = self.proxy && !self.tunnel ? self.proxy.protocol : self.uri.protocol
|
17048 | , defaultModules = {'http:':http, 'https:':https}
|
17049 | , httpModules = self.httpModules || {}
|
17050 | ;
|
17051 | self.httpModule = httpModules[protocol] || defaultModules[protocol]
|
17052 |
|
17053 | if (!self.httpModule) return this.emit('error', new Error("Invalid protocol"))
|
17054 |
|
17055 | if (options.ca) self.ca = options.ca
|
17056 |
|
17057 | if (!self.agent) {
|
17058 | if (options.agentOptions) self.agentOptions = options.agentOptions
|
17059 |
|
17060 | if (options.agentClass) {
|
17061 | self.agentClass = options.agentClass
|
17062 | } else if (options.forever) {
|
17063 | self.agentClass = protocol === 'http:' ? ForeverAgent : ForeverAgent.SSL
|
17064 | } else {
|
17065 | self.agentClass = self.httpModule.Agent
|
17066 | }
|
17067 | }
|
17068 |
|
17069 | if (self.pool === false) {
|
17070 | self.agent = false
|
17071 | } else {
|
17072 | self.agent = self.agent || self.getAgent()
|
17073 | if (self.maxSockets) {
|
17074 |
|
17075 | self.agent.maxSockets = self.maxSockets
|
17076 | }
|
17077 | if (self.pool.maxSockets) {
|
17078 |
|
17079 | self.agent.maxSockets = self.pool.maxSockets
|
17080 | }
|
17081 | }
|
17082 |
|
17083 | self.on('pipe', function (src) {
|
17084 | if (self.ntick && self._started) throw new Error("You cannot pipe to this stream after the outbound request has started.")
|
17085 | self.src = src
|
17086 | if (isReadStream(src)) {
|
17087 | if (!self.hasHeader('content-type')) self.setHeader('content-type', mime.lookup(src.path))
|
17088 | } else {
|
17089 | if (src.headers) {
|
17090 | for (var i in src.headers) {
|
17091 | if (!self.hasHeader(i)) {
|
17092 | self.setHeader(i, src.headers[i])
|
17093 | }
|
17094 | }
|
17095 | }
|
17096 | if (self._json && !self.hasHeader('content-type'))
|
17097 | self.setHeader('content-type', 'application/json')
|
17098 | if (src.method && !self.explicitMethod) {
|
17099 | self.method = src.method
|
17100 | }
|
17101 | }
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 | })
|
17107 |
|
17108 | process.nextTick(function () {
|
17109 | if (self._aborted) return
|
17110 |
|
17111 | if (self._form) {
|
17112 | self.setHeaders(self._form.getHeaders())
|
17113 | self._form.pipe(self)
|
17114 | }
|
17115 | if (self.body) {
|
17116 | if (Array.isArray(self.body)) {
|
17117 | self.body.forEach(function (part) {
|
17118 | self.write(part)
|
17119 | })
|
17120 | } else {
|
17121 | self.write(self.body)
|
17122 | }
|
17123 | self.end()
|
17124 | } else if (self.requestBodyStream) {
|
17125 | console.warn("options.requestBodyStream is deprecated, please pass the request object to stream.pipe.")
|
17126 | self.requestBodyStream.pipe(self)
|
17127 | } else if (!self.src) {
|
17128 | if (self.method !== 'GET' && typeof self.method !== 'undefined') {
|
17129 | self.setHeader('content-length', 0)
|
17130 | }
|
17131 | self.end()
|
17132 | }
|
17133 | self.ntick = true
|
17134 | })
|
17135 | }
|
17136 |
|
17137 |
|
17138 |
|
17139 |
|
17140 | Request.prototype._updateProtocol = function () {
|
17141 | var self = this
|
17142 | var protocol = self.uri.protocol
|
17143 |
|
17144 | if (protocol === 'https:') {
|
17145 |
|
17146 |
|
17147 | if (self.proxy && self.canTunnel) {
|
17148 | self.tunnel = true
|
17149 | var tunnelFn = self.proxy.protocol === 'http:'
|
17150 | ? tunnel.httpsOverHttp : tunnel.httpsOverHttps
|
17151 | var tunnelOptions = { proxy: { host: self.proxy.hostname
|
17152 | , port: +self.proxy.port
|
17153 | , proxyAuth: self.proxy.auth }
|
17154 | , rejectUnauthorized: self.rejectUnauthorized
|
17155 | , ca: self.ca }
|
17156 | self.agent = tunnelFn(tunnelOptions)
|
17157 | return
|
17158 | }
|
17159 |
|
17160 | self.httpModule = https
|
17161 | switch (self.agentClass) {
|
17162 | case ForeverAgent:
|
17163 | self.agentClass = ForeverAgent.SSL
|
17164 | break
|
17165 | case http.Agent:
|
17166 | self.agentClass = https.Agent
|
17167 | break
|
17168 | default:
|
17169 |
|
17170 | return
|
17171 | }
|
17172 |
|
17173 |
|
17174 | if (self.agent) self.agent = self.getAgent()
|
17175 |
|
17176 | } else {
|
17177 |
|
17178 |
|
17179 | if (self.tunnel) self.tunnel = false
|
17180 | self.httpModule = http
|
17181 | switch (self.agentClass) {
|
17182 | case ForeverAgent.SSL:
|
17183 | self.agentClass = ForeverAgent
|
17184 | break
|
17185 | case https.Agent:
|
17186 | self.agentClass = http.Agent
|
17187 | break
|
17188 | default:
|
17189 |
|
17190 | return
|
17191 | }
|
17192 |
|
17193 |
|
17194 | if (self.agent) {
|
17195 | self.agent = null
|
17196 | self.agent = self.getAgent()
|
17197 | }
|
17198 | }
|
17199 | }
|
17200 |
|
17201 | Request.prototype.getAgent = function () {
|
17202 | var Agent = this.agentClass
|
17203 | var options = {}
|
17204 | if (this.agentOptions) {
|
17205 | for (var i in this.agentOptions) {
|
17206 | options[i] = this.agentOptions[i]
|
17207 | }
|
17208 | }
|
17209 | if (this.ca) options.ca = this.ca
|
17210 | if (this.ciphers) options.ciphers = this.ciphers
|
17211 | if (this.secureProtocol) options.secureProtocol = this.secureProtocol
|
17212 | if (typeof this.rejectUnauthorized !== 'undefined') options.rejectUnauthorized = this.rejectUnauthorized
|
17213 |
|
17214 | if (this.cert && this.key) {
|
17215 | options.key = this.key
|
17216 | options.cert = this.cert
|
17217 | }
|
17218 |
|
17219 | var poolKey = ''
|
17220 |
|
17221 |
|
17222 | if (Agent !== this.httpModule.Agent) {
|
17223 | poolKey += Agent.name
|
17224 | }
|
17225 |
|
17226 | if (!this.httpModule.globalAgent) {
|
17227 |
|
17228 | options.host = this.host
|
17229 | options.port = this.port
|
17230 | if (poolKey) poolKey += ':'
|
17231 | poolKey += this.host + ':' + this.port
|
17232 | }
|
17233 |
|
17234 |
|
17235 | var proxy = this.proxy
|
17236 | if (typeof proxy === 'string') proxy = url.parse(proxy)
|
17237 | var isHttps = (proxy && proxy.protocol === 'https:') || this.uri.protocol === 'https:'
|
17238 | if (isHttps) {
|
17239 | if (options.ca) {
|
17240 | if (poolKey) poolKey += ':'
|
17241 | poolKey += options.ca
|
17242 | }
|
17243 |
|
17244 | if (typeof options.rejectUnauthorized !== 'undefined') {
|
17245 | if (poolKey) poolKey += ':'
|
17246 | poolKey += options.rejectUnauthorized
|
17247 | }
|
17248 |
|
17249 | if (options.cert)
|
17250 | poolKey += options.cert.toString('ascii') + options.key.toString('ascii')
|
17251 |
|
17252 | if (options.ciphers) {
|
17253 | if (poolKey) poolKey += ':'
|
17254 | poolKey += options.ciphers
|
17255 | }
|
17256 |
|
17257 | if (options.secureProtocol) {
|
17258 | if (poolKey) poolKey += ':'
|
17259 | poolKey += options.secureProtocol
|
17260 | }
|
17261 | }
|
17262 |
|
17263 | if (this.pool === globalPool && !poolKey && Object.keys(options).length === 0 && this.httpModule.globalAgent) {
|
17264 |
|
17265 | return this.httpModule.globalAgent
|
17266 | }
|
17267 |
|
17268 |
|
17269 | poolKey = this.uri.protocol + poolKey
|
17270 |
|
17271 |
|
17272 | if (this.pool[poolKey]) return this.pool[poolKey]
|
17273 |
|
17274 | return this.pool[poolKey] = new Agent(options)
|
17275 | }
|
17276 |
|
17277 | Request.prototype.start = function () {
|
17278 |
|
17279 |
|
17280 | var self = this
|
17281 |
|
17282 | if (self._aborted) return
|
17283 |
|
17284 | self._started = true
|
17285 | self.method = self.method || 'GET'
|
17286 | self.href = self.uri.href
|
17287 |
|
17288 | if (self.src && self.src.stat && self.src.stat.size && !self.hasHeader('content-length')) {
|
17289 | self.setHeader('content-length', self.src.stat.size)
|
17290 | }
|
17291 | if (self._aws) {
|
17292 | self.aws(self._aws, true)
|
17293 | }
|
17294 |
|
17295 |
|
17296 |
|
17297 | var reqOptions = copy(self)
|
17298 | delete reqOptions.auth
|
17299 |
|
17300 | debug('make request', self.uri.href)
|
17301 | self.req = self.httpModule.request(reqOptions, self.onResponse.bind(self))
|
17302 |
|
17303 | if (self.timeout && !self.timeoutTimer) {
|
17304 | self.timeoutTimer = setTimeout(function () {
|
17305 | self.req.abort()
|
17306 | var e = new Error("ETIMEDOUT")
|
17307 | e.code = "ETIMEDOUT"
|
17308 | self.emit("error", e)
|
17309 | }, self.timeout)
|
17310 |
|
17311 |
|
17312 |
|
17313 | if (self.req.setTimeout) {
|
17314 | self.req.setTimeout(self.timeout, function () {
|
17315 | if (self.req) {
|
17316 | self.req.abort()
|
17317 | var e = new Error("ESOCKETTIMEDOUT")
|
17318 | e.code = "ESOCKETTIMEDOUT"
|
17319 | self.emit("error", e)
|
17320 | }
|
17321 | })
|
17322 | }
|
17323 | }
|
17324 |
|
17325 | self.req.on('error', self.clientErrorHandler)
|
17326 | self.req.on('drain', function() {
|
17327 | self.emit('drain')
|
17328 | })
|
17329 | self.on('end', function() {
|
17330 | if ( self.req.connection ) self.req.connection.removeListener('error', self._parserErrorHandler)
|
17331 | })
|
17332 | self.emit('request', self.req)
|
17333 | }
|
17334 | Request.prototype.onResponse = function (response) {
|
17335 | var self = this
|
17336 | debug('onResponse', self.uri.href, response.statusCode, response.headers)
|
17337 | response.on('end', function() {
|
17338 | debug('response end', self.uri.href, response.statusCode, response.headers)
|
17339 | });
|
17340 |
|
17341 | if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
|
17342 | response.connection.once('error', self._parserErrorHandler)
|
17343 | }
|
17344 | if (self._aborted) {
|
17345 | debug('aborted', self.uri.href)
|
17346 | response.resume()
|
17347 | return
|
17348 | }
|
17349 | if (self._paused) response.pause()
|
17350 | else response.resume()
|
17351 |
|
17352 | self.response = response
|
17353 | response.request = self
|
17354 | response.toJSON = toJSON
|
17355 |
|
17356 |
|
17357 | if (self.httpModule === https &&
|
17358 | self.strictSSL &&
|
17359 | !response.client.authorized) {
|
17360 | debug('strict ssl error', self.uri.href)
|
17361 | var sslErr = response.client.authorizationError
|
17362 | self.emit('error', new Error('SSL Error: '+ sslErr))
|
17363 | return
|
17364 | }
|
17365 |
|
17366 | if (self.setHost && self.hasHeader('host')) delete self.headers[self.hasHeader('host')]
|
17367 | if (self.timeout && self.timeoutTimer) {
|
17368 | clearTimeout(self.timeoutTimer)
|
17369 | self.timeoutTimer = null
|
17370 | }
|
17371 |
|
17372 | var addCookie = function (cookie) {
|
17373 | if (self._jar){
|
17374 | var targetCookieJar = self._jar.setCookie?self._jar:cookieJar;
|
17375 |
|
17376 |
|
17377 | targetCookieJar.setCookie(cookie, self.uri.href, function(err){
|
17378 | if (err){
|
17379 | console.warn('set cookie failed,'+ err)
|
17380 | }
|
17381 | })
|
17382 | }
|
17383 |
|
17384 | }
|
17385 |
|
17386 | if (hasHeader('set-cookie', response.headers) && (!self._disableCookies)) {
|
17387 | var headerName = hasHeader('set-cookie', response.headers)
|
17388 | if (Array.isArray(response.headers[headerName])) response.headers[headerName].forEach(addCookie)
|
17389 | else addCookie(response.headers[headerName])
|
17390 | }
|
17391 |
|
17392 | var redirectTo = null
|
17393 | if (response.statusCode >= 300 && response.statusCode < 400 && hasHeader('location', response.headers)) {
|
17394 | var location = response.headers[hasHeader('location', response.headers)]
|
17395 | debug('redirect', location)
|
17396 |
|
17397 | if (self.followAllRedirects) {
|
17398 | redirectTo = location
|
17399 | } else if (self.followRedirect) {
|
17400 | switch (self.method) {
|
17401 | case 'PATCH':
|
17402 | case 'PUT':
|
17403 | case 'POST':
|
17404 | case 'DELETE':
|
17405 |
|
17406 | break
|
17407 | default:
|
17408 | redirectTo = location
|
17409 | break
|
17410 | }
|
17411 | }
|
17412 | } else if (response.statusCode == 401 && self._hasAuth && !self._sentAuth) {
|
17413 | var authHeader = response.headers[hasHeader('www-authenticate', response.headers)]
|
17414 | var authVerb = authHeader && authHeader.split(' ')[0]
|
17415 | debug('reauth', authVerb)
|
17416 |
|
17417 | switch (authVerb) {
|
17418 | case 'Basic':
|
17419 | self.auth(self._user, self._pass, true)
|
17420 | redirectTo = self.uri
|
17421 | break
|
17422 |
|
17423 | case 'Digest':
|
17424 |
|
17425 |
|
17426 |
|
17427 |
|
17428 |
|
17429 |
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 |
|
17435 |
|
17436 | var challenge = {}
|
17437 | var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi
|
17438 | for (;;) {
|
17439 | var match = re.exec(authHeader)
|
17440 | if (!match) break
|
17441 | challenge[match[1]] = match[2] || match[3];
|
17442 | }
|
17443 |
|
17444 | var ha1 = md5(self._user + ':' + challenge.realm + ':' + self._pass)
|
17445 | var ha2 = md5(self.method + ':' + self.uri.path)
|
17446 | var qop = /(^|,)\s*auth\s*($|,)/.test(challenge.qop) && 'auth'
|
17447 | var nc = qop && '00000001'
|
17448 | var cnonce = qop && uuid().replace(/-/g, '')
|
17449 | var digestResponse = qop ? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2) : md5(ha1 + ':' + challenge.nonce + ':' + ha2)
|
17450 | var authValues = {
|
17451 | username: self._user,
|
17452 | realm: challenge.realm,
|
17453 | nonce: challenge.nonce,
|
17454 | uri: self.uri.path,
|
17455 | qop: qop,
|
17456 | response: digestResponse,
|
17457 | nc: nc,
|
17458 | cnonce: cnonce,
|
17459 | algorithm: challenge.algorithm,
|
17460 | opaque: challenge.opaque
|
17461 | }
|
17462 |
|
17463 | authHeader = []
|
17464 | for (var k in authValues) {
|
17465 | if (!authValues[k]) {
|
17466 |
|
17467 | } else if (k === 'qop' || k === 'nc' || k === 'algorithm') {
|
17468 | authHeader.push(k + '=' + authValues[k])
|
17469 | } else {
|
17470 | authHeader.push(k + '="' + authValues[k] + '"')
|
17471 | }
|
17472 | }
|
17473 | authHeader = 'Digest ' + authHeader.join(', ')
|
17474 | self.setHeader('authorization', authHeader)
|
17475 | self._sentAuth = true
|
17476 |
|
17477 | redirectTo = self.uri
|
17478 | break
|
17479 | }
|
17480 | }
|
17481 |
|
17482 | if (redirectTo) {
|
17483 | debug('redirect to', redirectTo)
|
17484 |
|
17485 |
|
17486 |
|
17487 | if (self._paused) response.resume()
|
17488 |
|
17489 | if (self._redirectsFollowed >= self.maxRedirects) {
|
17490 | self.emit('error', new Error("Exceeded maxRedirects. Probably stuck in a redirect loop "+self.uri.href))
|
17491 | return
|
17492 | }
|
17493 | self._redirectsFollowed += 1
|
17494 |
|
17495 | if (!isUrl.test(redirectTo)) {
|
17496 | redirectTo = url.resolve(self.uri.href, redirectTo)
|
17497 | }
|
17498 |
|
17499 | var uriPrev = self.uri
|
17500 | self.uri = url.parse(redirectTo)
|
17501 |
|
17502 |
|
17503 | if (self.uri.protocol !== uriPrev.protocol) {
|
17504 | self._updateProtocol()
|
17505 | }
|
17506 |
|
17507 | self.redirects.push(
|
17508 | { statusCode : response.statusCode
|
17509 | , redirectUri: redirectTo
|
17510 | }
|
17511 | )
|
17512 | if (self.followAllRedirects && response.statusCode != 401) self.method = 'GET'
|
17513 |
|
17514 | delete self.src
|
17515 | delete self.req
|
17516 | delete self.agent
|
17517 | delete self._started
|
17518 | if (response.statusCode != 401) {
|
17519 |
|
17520 |
|
17521 | delete self.body
|
17522 | delete self._form
|
17523 | if (self.headers) {
|
17524 | if (self.hasHeader('host')) delete self.headers[self.hasHeader('host')]
|
17525 | if (self.hasHeader('content-type')) delete self.headers[self.hasHeader('content-type')]
|
17526 | if (self.hasHeader('content-length')) delete self.headers[self.hasHeader('content-length')]
|
17527 | }
|
17528 | }
|
17529 |
|
17530 | self.emit('redirect');
|
17531 |
|
17532 | self.init()
|
17533 | return
|
17534 | } else {
|
17535 | self._redirectsFollowed = self._redirectsFollowed || 0
|
17536 |
|
17537 |
|
17538 | response.on('close', function () {
|
17539 | if (!self._ended) self.response.emit('end')
|
17540 | })
|
17541 |
|
17542 | if (self.encoding) {
|
17543 | if (self.dests.length !== 0) {
|
17544 | console.error("Ignoring encoding parameter as this stream is being piped to another stream which makes the encoding option invalid.")
|
17545 | } else {
|
17546 | response.setEncoding(self.encoding)
|
17547 | }
|
17548 | }
|
17549 |
|
17550 | self.emit('response', response)
|
17551 |
|
17552 | self.dests.forEach(function (dest) {
|
17553 | self.pipeDest(dest)
|
17554 | })
|
17555 |
|
17556 | response.on("data", function (chunk) {
|
17557 | self._destdata = true
|
17558 | self.emit("data", chunk)
|
17559 | })
|
17560 | response.on("end", function (chunk) {
|
17561 | self._ended = true
|
17562 | self.emit("end", chunk)
|
17563 | })
|
17564 | response.on("close", function () {self.emit("close")})
|
17565 |
|
17566 | if (self.callback) {
|
17567 | var buffer = []
|
17568 | var bodyLen = 0
|
17569 | self.on("data", function (chunk) {
|
17570 | buffer.push(chunk)
|
17571 | bodyLen += chunk.length
|
17572 | })
|
17573 | self.on("end", function () {
|
17574 | debug('end event', self.uri.href)
|
17575 | if (self._aborted) {
|
17576 | debug('aborted', self.uri.href)
|
17577 | return
|
17578 | }
|
17579 |
|
17580 | if (buffer.length && Buffer.isBuffer(buffer[0])) {
|
17581 | debug('has body', self.uri.href, bodyLen)
|
17582 | var body = new Buffer(bodyLen)
|
17583 | var i = 0
|
17584 | buffer.forEach(function (chunk) {
|
17585 | chunk.copy(body, i, 0, chunk.length)
|
17586 | i += chunk.length
|
17587 | })
|
17588 | if (self.encoding === null) {
|
17589 | response.body = body
|
17590 | } else {
|
17591 | response.body = body.toString(self.encoding)
|
17592 | }
|
17593 | } else if (buffer.length) {
|
17594 |
|
17595 |
|
17596 | if (self.encoding === 'utf8' && buffer[0].length > 0 && buffer[0][0] === "\uFEFF") {
|
17597 | buffer[0] = buffer[0].substring(1)
|
17598 | }
|
17599 | response.body = buffer.join('')
|
17600 | }
|
17601 |
|
17602 | if (self._json) {
|
17603 | try {
|
17604 | response.body = JSON.parse(response.body)
|
17605 | } catch (e) {}
|
17606 | }
|
17607 | debug('emitting complete', self.uri.href)
|
17608 | if(response.body == undefined && !self._json) {
|
17609 | response.body = "";
|
17610 | }
|
17611 | self.emit('complete', response, response.body)
|
17612 | })
|
17613 | }
|
17614 |
|
17615 | else{
|
17616 | self.on("end", function () {
|
17617 | if (self._aborted) {
|
17618 | debug('aborted', self.uri.href)
|
17619 | return
|
17620 | }
|
17621 | self.emit('complete', response);
|
17622 | });
|
17623 | }
|
17624 | }
|
17625 | debug('finish init function', self.uri.href)
|
17626 | }
|
17627 |
|
17628 | Request.prototype.abort = function () {
|
17629 | this._aborted = true
|
17630 |
|
17631 | if (this.req) {
|
17632 | this.req.abort()
|
17633 | }
|
17634 | else if (this.response) {
|
17635 | this.response.abort()
|
17636 | }
|
17637 |
|
17638 | this.emit("abort")
|
17639 | }
|
17640 |
|
17641 | Request.prototype.pipeDest = function (dest) {
|
17642 | var response = this.response
|
17643 |
|
17644 | if (dest.headers && !dest.headersSent) {
|
17645 | if (hasHeader('content-type', response.headers)) {
|
17646 | var ctname = hasHeader('content-type', response.headers)
|
17647 | if (dest.setHeader) dest.setHeader(ctname, response.headers[ctname])
|
17648 | else dest.headers[ctname] = response.headers[ctname]
|
17649 | }
|
17650 |
|
17651 | if (hasHeader('content-length', response.headers)) {
|
17652 | var clname = hasHeader('content-length', response.headers)
|
17653 | if (dest.setHeader) dest.setHeader(clname, response.headers[clname])
|
17654 | else dest.headers[clname] = response.headers[clname]
|
17655 | }
|
17656 | }
|
17657 | if (dest.setHeader && !dest.headersSent) {
|
17658 | for (var i in response.headers) {
|
17659 | dest.setHeader(i, response.headers[i])
|
17660 | }
|
17661 | dest.statusCode = response.statusCode
|
17662 | }
|
17663 | if (this.pipefilter) this.pipefilter(response, dest)
|
17664 | }
|
17665 |
|
17666 |
|
17667 | Request.prototype.setHeader = function (name, value, clobber) {
|
17668 | if (clobber === undefined) clobber = true
|
17669 | if (clobber || !this.hasHeader(name)) this.headers[name] = value
|
17670 | else this.headers[this.hasHeader(name)] += ',' + value
|
17671 | return this
|
17672 | }
|
17673 | Request.prototype.setHeaders = function (headers) {
|
17674 | for (var i in headers) {this.setHeader(i, headers[i])}
|
17675 | return this
|
17676 | }
|
17677 | Request.prototype.hasHeader = function (header, headers) {
|
17678 | var headers = Object.keys(headers || this.headers)
|
17679 | , lheaders = headers.map(function (h) {return h.toLowerCase()})
|
17680 | ;
|
17681 | header = header.toLowerCase()
|
17682 | for (var i=0;i<lheaders.length;i++) {
|
17683 | if (lheaders[i] === header) return headers[i]
|
17684 | }
|
17685 | return false
|
17686 | }
|
17687 |
|
17688 | var hasHeader = Request.prototype.hasHeader
|
17689 |
|
17690 | Request.prototype.qs = function (q, clobber) {
|
17691 | var base
|
17692 | if (!clobber && this.uri.query) base = qs.parse(this.uri.query)
|
17693 | else base = {}
|
17694 |
|
17695 | for (var i in q) {
|
17696 | base[i] = q[i]
|
17697 | }
|
17698 |
|
17699 | if (qs.stringify(base) === ''){
|
17700 | return this
|
17701 | }
|
17702 |
|
17703 | this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base))
|
17704 | this.url = this.uri
|
17705 | this.path = this.uri.path
|
17706 |
|
17707 | return this
|
17708 | }
|
17709 | Request.prototype.form = function (form) {
|
17710 | if (form) {
|
17711 | this.setHeader('content-type', 'application/x-www-form-urlencoded; charset=utf-8')
|
17712 | this.body = qs.stringify(form).toString('utf8')
|
17713 | return this
|
17714 | }
|
17715 |
|
17716 | this._form = new FormData()
|
17717 | return this._form
|
17718 | }
|
17719 | Request.prototype.multipart = function (multipart) {
|
17720 | var self = this
|
17721 | self.body = []
|
17722 |
|
17723 | if (!self.hasHeader('content-type')) {
|
17724 | self.setHeader('content-type', 'multipart/related; boundary=' + self.boundary)
|
17725 | } else {
|
17726 | var headerName = self.hasHeader('content-type');
|
17727 | self.setHeader(headerName, self.headers[headerName].split(';')[0] + '; boundary=' + self.boundary)
|
17728 | }
|
17729 |
|
17730 | if (!multipart.forEach) throw new Error('Argument error, options.multipart.')
|
17731 |
|
17732 | if (self.preambleCRLF) {
|
17733 | self.body.push(new Buffer('\r\n'))
|
17734 | }
|
17735 |
|
17736 | multipart.forEach(function (part) {
|
17737 | var body = part.body
|
17738 | if(body == null) throw Error('Body attribute missing in multipart.')
|
17739 | delete part.body
|
17740 | var preamble = '--' + self.boundary + '\r\n'
|
17741 | Object.keys(part).forEach(function (key) {
|
17742 | preamble += key + ': ' + part[key] + '\r\n'
|
17743 | })
|
17744 | preamble += '\r\n'
|
17745 | self.body.push(new Buffer(preamble))
|
17746 | self.body.push(new Buffer(body))
|
17747 | self.body.push(new Buffer('\r\n'))
|
17748 | })
|
17749 | self.body.push(new Buffer('--' + self.boundary + '--'))
|
17750 | return self
|
17751 | }
|
17752 | Request.prototype.json = function (val) {
|
17753 | var self = this
|
17754 |
|
17755 | if (!self.hasHeader('accept')) self.setHeader('accept', 'application/json')
|
17756 |
|
17757 | this._json = true
|
17758 | if (typeof val === 'boolean') {
|
17759 | if (typeof this.body === 'object') {
|
17760 | this.body = safeStringify(this.body)
|
17761 | self.setHeader('content-type', 'application/json')
|
17762 | }
|
17763 | } else {
|
17764 | this.body = safeStringify(val)
|
17765 | self.setHeader('content-type', 'application/json')
|
17766 | }
|
17767 | return this
|
17768 | }
|
17769 | Request.prototype.getHeader = function (name, headers) {
|
17770 | var result, re, match
|
17771 | if (!headers) headers = this.headers
|
17772 | Object.keys(headers).forEach(function (key) {
|
17773 | re = new RegExp(name, 'i')
|
17774 | match = key.match(re)
|
17775 | if (match) result = headers[key]
|
17776 | })
|
17777 | return result
|
17778 | }
|
17779 | var getHeader = Request.prototype.getHeader
|
17780 |
|
17781 | Request.prototype.auth = function (user, pass, sendImmediately) {
|
17782 | if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {
|
17783 | throw new Error('auth() received invalid user or password')
|
17784 | }
|
17785 | this._user = user
|
17786 | this._pass = pass
|
17787 | this._hasAuth = true
|
17788 | var header = typeof pass !== 'undefined' ? user + ':' + pass : user
|
17789 | if (sendImmediately || typeof sendImmediately == 'undefined') {
|
17790 | this.setHeader('authorization', 'Basic ' + toBase64(header))
|
17791 | this._sentAuth = true
|
17792 | }
|
17793 | return this
|
17794 | }
|
17795 | Request.prototype.aws = function (opts, now) {
|
17796 | if (!now) {
|
17797 | this._aws = opts
|
17798 | return this
|
17799 | }
|
17800 | var date = new Date()
|
17801 | this.setHeader('date', date.toUTCString())
|
17802 | var auth =
|
17803 | { key: opts.key
|
17804 | , secret: opts.secret
|
17805 | , verb: this.method.toUpperCase()
|
17806 | , date: date
|
17807 | , contentType: this.getHeader('content-type') || ''
|
17808 | , md5: this.getHeader('content-md5') || ''
|
17809 | , amazonHeaders: aws.canonicalizeHeaders(this.headers)
|
17810 | }
|
17811 | if (opts.bucket && this.path) {
|
17812 | auth.resource = '/' + opts.bucket + this.path
|
17813 | } else if (opts.bucket && !this.path) {
|
17814 | auth.resource = '/' + opts.bucket
|
17815 | } else if (!opts.bucket && this.path) {
|
17816 | auth.resource = this.path
|
17817 | } else if (!opts.bucket && !this.path) {
|
17818 | auth.resource = '/'
|
17819 | }
|
17820 | auth.resource = aws.canonicalizeResource(auth.resource)
|
17821 | this.setHeader('authorization', aws.authorization(auth))
|
17822 |
|
17823 | return this
|
17824 | }
|
17825 | Request.prototype.httpSignature = function (opts) {
|
17826 | var req = this
|
17827 | httpSignature.signRequest({
|
17828 | getHeader: function(header) {
|
17829 | return getHeader(header, req.headers)
|
17830 | },
|
17831 | setHeader: function(header, value) {
|
17832 | req.setHeader(header, value)
|
17833 | },
|
17834 | method: this.method,
|
17835 | path: this.path
|
17836 | }, opts)
|
17837 | debug('httpSignature authorization', this.getHeader('authorization'))
|
17838 |
|
17839 | return this
|
17840 | }
|
17841 |
|
17842 | Request.prototype.hawk = function (opts) {
|
17843 | this.setHeader('Authorization', hawk.client.header(this.uri, this.method, opts).field)
|
17844 | }
|
17845 |
|
17846 | Request.prototype.oauth = function (_oauth) {
|
17847 | var form
|
17848 | if (this.hasHeader('content-type') &&
|
17849 | this.getHeader('content-type').slice(0, 'application/x-www-form-urlencoded'.length) ===
|
17850 | 'application/x-www-form-urlencoded'
|
17851 | ) {
|
17852 | form = qs.parse(this.body)
|
17853 | }
|
17854 | if (this.uri.query) {
|
17855 | form = qs.parse(this.uri.query)
|
17856 | }
|
17857 | if (!form) form = {}
|
17858 | var oa = {}
|
17859 | for (var i in form) oa[i] = form[i]
|
17860 | for (var i in _oauth) oa['oauth_'+i] = _oauth[i]
|
17861 | if (!oa.oauth_version) oa.oauth_version = '1.0'
|
17862 | if (!oa.oauth_timestamp) oa.oauth_timestamp = Math.floor( Date.now() / 1000 ).toString()
|
17863 | if (!oa.oauth_nonce) oa.oauth_nonce = uuid().replace(/-/g, '')
|
17864 |
|
17865 | oa.oauth_signature_method = 'HMAC-SHA1'
|
17866 |
|
17867 | var consumer_secret = oa.oauth_consumer_secret
|
17868 | delete oa.oauth_consumer_secret
|
17869 | var token_secret = oa.oauth_token_secret
|
17870 | delete oa.oauth_token_secret
|
17871 | var timestamp = oa.oauth_timestamp
|
17872 |
|
17873 | var baseurl = this.uri.protocol + '//' + this.uri.host + this.uri.pathname
|
17874 | var signature = oauth.hmacsign(this.method, baseurl, oa, consumer_secret, token_secret)
|
17875 |
|
17876 |
|
17877 | for (var i in form) {
|
17878 | if ( i.slice(0, 'oauth_') in _oauth) {
|
17879 |
|
17880 | } else {
|
17881 | delete oa['oauth_'+i]
|
17882 | if (i !== 'x_auth_mode') delete oa[i]
|
17883 | }
|
17884 | }
|
17885 | oa.oauth_timestamp = timestamp
|
17886 | var authHeader = 'OAuth '+Object.keys(oa).sort().map(function (i) {return i+'="'+oauth.rfc3986(oa[i])+'"'}).join(',')
|
17887 | authHeader += ',oauth_signature="' + oauth.rfc3986(signature) + '"'
|
17888 | this.setHeader('Authorization', authHeader)
|
17889 | return this
|
17890 | }
|
17891 | Request.prototype.jar = function (jar) {
|
17892 | var cookies
|
17893 |
|
17894 | if (this._redirectsFollowed === 0) {
|
17895 | this.originalCookieHeader = this.getHeader('cookie')
|
17896 | }
|
17897 |
|
17898 | if (!jar) {
|
17899 |
|
17900 | cookies = false
|
17901 | this._disableCookies = true
|
17902 | } else {
|
17903 | var targetCookieJar = (jar && jar.getCookieString)?jar:cookieJar;
|
17904 | var urihref = this.uri.href
|
17905 |
|
17906 |
|
17907 | targetCookieJar.getCookieString(urihref, function(err, hrefCookie){
|
17908 | if (err){
|
17909 | console.warn('get cookieString failed,' +err)
|
17910 | } else {
|
17911 | cookies = hrefCookie
|
17912 | }
|
17913 | })
|
17914 |
|
17915 | }
|
17916 |
|
17917 |
|
17918 | if (cookies && cookies.length) {
|
17919 | if (this.originalCookieHeader) {
|
17920 |
|
17921 | this.setHeader('cookie', this.originalCookieHeader + '; ' + cookies)
|
17922 | } else {
|
17923 | this.setHeader('cookie', cookies)
|
17924 | }
|
17925 | }
|
17926 | this._jar = jar
|
17927 | return this
|
17928 | }
|
17929 |
|
17930 |
|
17931 |
|
17932 | Request.prototype.pipe = function (dest, opts) {
|
17933 | if (this.response) {
|
17934 | if (this._destdata) {
|
17935 | throw new Error("You cannot pipe after data has been emitted from the response.")
|
17936 | } else if (this._ended) {
|
17937 | throw new Error("You cannot pipe after the response has been ended.")
|
17938 | } else {
|
17939 | stream.Stream.prototype.pipe.call(this, dest, opts)
|
17940 | this.pipeDest(dest)
|
17941 | return dest
|
17942 | }
|
17943 | } else {
|
17944 | this.dests.push(dest)
|
17945 | stream.Stream.prototype.pipe.call(this, dest, opts)
|
17946 | return dest
|
17947 | }
|
17948 | }
|
17949 | Request.prototype.write = function () {
|
17950 | if (!this._started) this.start()
|
17951 | return this.req.write.apply(this.req, arguments)
|
17952 | }
|
17953 | Request.prototype.end = function (chunk) {
|
17954 | if (chunk) this.write(chunk)
|
17955 | if (!this._started) this.start()
|
17956 | this.req.end()
|
17957 | }
|
17958 | Request.prototype.pause = function () {
|
17959 | if (!this.response) this._paused = true
|
17960 | else this.response.pause.apply(this.response, arguments)
|
17961 | }
|
17962 | Request.prototype.resume = function () {
|
17963 | if (!this.response) this._paused = false
|
17964 | else this.response.resume.apply(this.response, arguments)
|
17965 | }
|
17966 | Request.prototype.destroy = function () {
|
17967 | if (!this._ended) this.end()
|
17968 | else if (this.response) this.response.destroy()
|
17969 | }
|
17970 |
|
17971 | function toJSON () {
|
17972 | return getSafe(this, '__' + (((1+Math.random())*0x10000)|0).toString(16))
|
17973 | }
|
17974 |
|
17975 | Request.prototype.toJSON = toJSON
|
17976 |
|
17977 |
|
17978 | module.exports = Request
|
17979 |
|
17980 | }).call(this,require('_process'),require("buffer").Buffer)
|
17981 | },{"./lib/copy":56,"./lib/debug":57,"./lib/getSafe":58,"./lib/optional":59,"_process":31,"buffer":3,"crypto":10,"forever-agent":60,"http":23,"json-stringify-safe":61,"mime":62,"node-uuid":63,"qs":64,"querystring":35,"stream":48,"url":49,"util":51}],66:[function(require,module,exports){
|
17982 |
|
17983 |
|
17984 |
|
17985 |
|
17986 | (function(define) { 'use strict';
|
17987 | define(function (require) {
|
17988 |
|
17989 | var makePromise = require('./makePromise');
|
17990 | var Scheduler = require('./scheduler');
|
17991 | var async = require('./async');
|
17992 |
|
17993 | return makePromise({
|
17994 | scheduler: new Scheduler(async)
|
17995 | });
|
17996 |
|
17997 | });
|
17998 | })(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); });
|
17999 |
|
18000 | },{"./async":69,"./makePromise":79,"./scheduler":80}],67:[function(require,module,exports){
|
18001 |
|
18002 |
|
18003 |
|
18004 |
|
18005 | (function(define) { 'use strict';
|
18006 | define(function() {
|
18007 | |
18008 |
|
18009 |
|
18010 |
|
18011 |
|
18012 |
|
18013 |
|
18014 | function Queue(capacityPow2) {
|
18015 | this.head = this.tail = this.length = 0;
|
18016 | this.buffer = new Array(1 << capacityPow2);
|
18017 | }
|
18018 |
|
18019 | Queue.prototype.push = function(x) {
|
18020 | if(this.length === this.buffer.length) {
|
18021 | this._ensureCapacity(this.length * 2);
|
18022 | }
|
18023 |
|
18024 | this.buffer[this.tail] = x;
|
18025 | this.tail = (this.tail + 1) & (this.buffer.length - 1);
|
18026 | ++this.length;
|
18027 | return this.length;
|
18028 | };
|
18029 |
|
18030 | Queue.prototype.shift = function() {
|
18031 | var x = this.buffer[this.head];
|
18032 | this.buffer[this.head] = void 0;
|
18033 | this.head = (this.head + 1) & (this.buffer.length - 1);
|
18034 | --this.length;
|
18035 | return x;
|
18036 | };
|
18037 |
|
18038 | Queue.prototype._ensureCapacity = function(capacity) {
|
18039 | var head = this.head;
|
18040 | var buffer = this.buffer;
|
18041 | var newBuffer = new Array(capacity);
|
18042 | var i = 0;
|
18043 | var len;
|
18044 |
|
18045 | if(head === 0) {
|
18046 | len = this.length;
|
18047 | for(; i<len; ++i) {
|
18048 | newBuffer[i] = buffer[i];
|
18049 | }
|
18050 | } else {
|
18051 | capacity = buffer.length;
|
18052 | len = this.tail;
|
18053 | for(; head<capacity; ++i, ++head) {
|
18054 | newBuffer[i] = buffer[head];
|
18055 | }
|
18056 |
|
18057 | for(head=0; head<len; ++i, ++head) {
|
18058 | newBuffer[i] = buffer[head];
|
18059 | }
|
18060 | }
|
18061 |
|
18062 | this.buffer = newBuffer;
|
18063 | this.head = 0;
|
18064 | this.tail = this.length;
|
18065 | };
|
18066 |
|
18067 | return Queue;
|
18068 |
|
18069 | });
|
18070 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18071 |
|
18072 | },{}],68:[function(require,module,exports){
|
18073 |
|
18074 |
|
18075 |
|
18076 |
|
18077 | (function(define) { 'use strict';
|
18078 | define(function() {
|
18079 |
|
18080 | |
18081 |
|
18082 |
|
18083 |
|
18084 |
|
18085 | function TimeoutError (message) {
|
18086 | Error.call(this);
|
18087 | this.message = message;
|
18088 | this.name = TimeoutError.name;
|
18089 | if (typeof Error.captureStackTrace === 'function') {
|
18090 | Error.captureStackTrace(this, TimeoutError);
|
18091 | }
|
18092 | }
|
18093 |
|
18094 | TimeoutError.prototype = Object.create(Error.prototype);
|
18095 | TimeoutError.prototype.constructor = TimeoutError;
|
18096 |
|
18097 | return TimeoutError;
|
18098 | });
|
18099 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18100 | },{}],69:[function(require,module,exports){
|
18101 | (function (process){
|
18102 |
|
18103 |
|
18104 |
|
18105 |
|
18106 | (function(define) { 'use strict';
|
18107 | define(function(require) {
|
18108 |
|
18109 |
|
18110 |
|
18111 |
|
18112 |
|
18113 |
|
18114 |
|
18115 | var nextTick, MutationObs;
|
18116 |
|
18117 | if (typeof process !== 'undefined' && process !== null &&
|
18118 | typeof process.nextTick === 'function') {
|
18119 | nextTick = function(f) {
|
18120 | process.nextTick(f);
|
18121 | };
|
18122 |
|
18123 | } else if (MutationObs =
|
18124 | (typeof MutationObserver === 'function' && MutationObserver) ||
|
18125 | (typeof WebKitMutationObserver === 'function' && WebKitMutationObserver)) {
|
18126 | nextTick = (function (document, MutationObserver) {
|
18127 | var scheduled;
|
18128 | var el = document.createElement('div');
|
18129 | var o = new MutationObserver(run);
|
18130 | o.observe(el, { attributes: true });
|
18131 |
|
18132 | function run() {
|
18133 | var f = scheduled;
|
18134 | scheduled = void 0;
|
18135 | f();
|
18136 | }
|
18137 |
|
18138 | return function (f) {
|
18139 | scheduled = f;
|
18140 | el.setAttribute('class', 'x');
|
18141 | };
|
18142 | }(document, MutationObs));
|
18143 |
|
18144 | } else {
|
18145 | nextTick = (function(cjsRequire) {
|
18146 | try {
|
18147 |
|
18148 | return cjsRequire('vertx').runOnLoop || cjsRequire('vertx').runOnContext;
|
18149 | } catch (ignore) {}
|
18150 |
|
18151 |
|
18152 |
|
18153 | var capturedSetTimeout = setTimeout;
|
18154 | return function (t) {
|
18155 | capturedSetTimeout(t, 0);
|
18156 | };
|
18157 | }(require));
|
18158 | }
|
18159 |
|
18160 | return nextTick;
|
18161 | });
|
18162 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
18163 |
|
18164 | }).call(this,require('_process'))
|
18165 | },{"_process":31}],70:[function(require,module,exports){
|
18166 |
|
18167 |
|
18168 |
|
18169 |
|
18170 | (function(define) { 'use strict';
|
18171 | define(function() {
|
18172 |
|
18173 | return function array(Promise) {
|
18174 |
|
18175 | var arrayMap = Array.prototype.map;
|
18176 | var arrayReduce = Array.prototype.reduce;
|
18177 | var arrayReduceRight = Array.prototype.reduceRight;
|
18178 | var arrayForEach = Array.prototype.forEach;
|
18179 |
|
18180 | var toPromise = Promise.resolve;
|
18181 | var all = Promise.all;
|
18182 |
|
18183 |
|
18184 |
|
18185 | Promise.any = any;
|
18186 | Promise.some = some;
|
18187 | Promise.settle = settle;
|
18188 |
|
18189 | Promise.map = map;
|
18190 | Promise.reduce = reduce;
|
18191 | Promise.reduceRight = reduceRight;
|
18192 |
|
18193 | |
18194 |
|
18195 |
|
18196 |
|
18197 |
|
18198 |
|
18199 | Promise.prototype.spread = function(onFulfilled) {
|
18200 | return this.then(all).then(function(array) {
|
18201 | return onFulfilled.apply(void 0, array);
|
18202 | });
|
18203 | };
|
18204 |
|
18205 | return Promise;
|
18206 |
|
18207 | |
18208 |
|
18209 |
|
18210 |
|
18211 |
|
18212 |
|
18213 |
|
18214 |
|
18215 | function any(promises) {
|
18216 | return new Promise(function(resolve, reject) {
|
18217 | var pending = 0;
|
18218 | var errors = [];
|
18219 |
|
18220 | arrayForEach.call(promises, function(p) {
|
18221 | ++pending;
|
18222 | toPromise(p).then(resolve, handleReject);
|
18223 | });
|
18224 |
|
18225 | if(pending === 0) {
|
18226 | resolve();
|
18227 | }
|
18228 |
|
18229 | function handleReject(e) {
|
18230 | errors.push(e);
|
18231 | if(--pending === 0) {
|
18232 | reject(errors);
|
18233 | }
|
18234 | }
|
18235 | });
|
18236 | }
|
18237 |
|
18238 | |
18239 |
|
18240 |
|
18241 |
|
18242 |
|
18243 |
|
18244 |
|
18245 |
|
18246 |
|
18247 |
|
18248 |
|
18249 |
|
18250 | function some(promises, n) {
|
18251 | return new Promise(function(resolve, reject, notify) {
|
18252 | var nFulfill = 0;
|
18253 | var nReject;
|
18254 | var results = [];
|
18255 | var errors = [];
|
18256 |
|
18257 | arrayForEach.call(promises, function(p) {
|
18258 | ++nFulfill;
|
18259 | toPromise(p).then(handleResolve, handleReject, notify);
|
18260 | });
|
18261 |
|
18262 | n = Math.max(n, 0);
|
18263 | nReject = (nFulfill - n + 1);
|
18264 | nFulfill = Math.min(n, nFulfill);
|
18265 |
|
18266 | if(nFulfill === 0) {
|
18267 | resolve(results);
|
18268 | return;
|
18269 | }
|
18270 |
|
18271 | function handleResolve(x) {
|
18272 | if(nFulfill > 0) {
|
18273 | --nFulfill;
|
18274 | results.push(x);
|
18275 |
|
18276 | if(nFulfill === 0) {
|
18277 | resolve(results);
|
18278 | }
|
18279 | }
|
18280 | }
|
18281 |
|
18282 | function handleReject(e) {
|
18283 | if(nReject > 0) {
|
18284 | --nReject;
|
18285 | errors.push(e);
|
18286 |
|
18287 | if(nReject === 0) {
|
18288 | reject(errors);
|
18289 | }
|
18290 | }
|
18291 | }
|
18292 | });
|
18293 | }
|
18294 |
|
18295 | |
18296 |
|
18297 |
|
18298 |
|
18299 |
|
18300 |
|
18301 |
|
18302 |
|
18303 | function map(promises, f, fallback) {
|
18304 | return all(arrayMap.call(promises, function(x) {
|
18305 | return toPromise(x).then(f, fallback);
|
18306 | }));
|
18307 | }
|
18308 |
|
18309 | |
18310 |
|
18311 |
|
18312 |
|
18313 |
|
18314 |
|
18315 |
|
18316 | function settle(promises) {
|
18317 | return all(arrayMap.call(promises, function(p) {
|
18318 | p = toPromise(p);
|
18319 | return p.then(inspect, inspect);
|
18320 |
|
18321 | function inspect() {
|
18322 | return p.inspect();
|
18323 | }
|
18324 | }));
|
18325 | }
|
18326 |
|
18327 | function reduce(promises, f) {
|
18328 | return arguments.length > 2
|
18329 | ? arrayReduce.call(promises, reducer, arguments[2])
|
18330 | : arrayReduce.call(promises, reducer);
|
18331 |
|
18332 | function reducer(result, x, i) {
|
18333 | return toPromise(result).then(function(r) {
|
18334 | return toPromise(x).then(function(x) {
|
18335 | return f(r, x, i);
|
18336 | });
|
18337 | });
|
18338 | }
|
18339 | }
|
18340 |
|
18341 | function reduceRight(promises, f) {
|
18342 | return arguments.length > 2
|
18343 | ? arrayReduceRight.call(promises, reducer, arguments[2])
|
18344 | : arrayReduceRight.call(promises, reducer);
|
18345 |
|
18346 | function reducer(result, x, i) {
|
18347 | return toPromise(result).then(function(r) {
|
18348 | return toPromise(x).then(function(x) {
|
18349 | return f(r, x, i);
|
18350 | });
|
18351 | });
|
18352 | }
|
18353 | }
|
18354 | };
|
18355 |
|
18356 |
|
18357 | });
|
18358 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18359 |
|
18360 | },{}],71:[function(require,module,exports){
|
18361 |
|
18362 |
|
18363 |
|
18364 |
|
18365 | (function(define) { 'use strict';
|
18366 | define(function() {
|
18367 |
|
18368 | return function flow(Promise) {
|
18369 |
|
18370 | var reject = Promise.reject;
|
18371 | var origCatch = Promise.prototype['catch'];
|
18372 |
|
18373 | |
18374 |
|
18375 |
|
18376 |
|
18377 |
|
18378 |
|
18379 |
|
18380 |
|
18381 |
|
18382 | Promise.prototype.done = function(onResult, onError) {
|
18383 | var h = this._handler;
|
18384 | h.when({ resolve: this._maybeFatal, notify: noop, context: this,
|
18385 | receiver: h.receiver, fulfilled: onResult, rejected: onError,
|
18386 | progress: void 0 });
|
18387 | };
|
18388 |
|
18389 | |
18390 |
|
18391 |
|
18392 |
|
18393 |
|
18394 |
|
18395 |
|
18396 |
|
18397 | Promise.prototype['catch'] = Promise.prototype.otherwise = function(onRejected) {
|
18398 | if (arguments.length === 1) {
|
18399 | return origCatch.call(this, onRejected);
|
18400 | } else {
|
18401 | if(typeof onRejected !== 'function') {
|
18402 | return this.ensure(rejectInvalidPredicate);
|
18403 | }
|
18404 |
|
18405 | return origCatch.call(this, createCatchFilter(arguments[1], onRejected));
|
18406 | }
|
18407 | };
|
18408 |
|
18409 | |
18410 |
|
18411 |
|
18412 |
|
18413 |
|
18414 |
|
18415 |
|
18416 | function createCatchFilter(handler, predicate) {
|
18417 | return function(e) {
|
18418 | return evaluatePredicate(e, predicate)
|
18419 | ? handler.call(this, e)
|
18420 | : reject(e);
|
18421 | };
|
18422 | }
|
18423 |
|
18424 | |
18425 |
|
18426 |
|
18427 |
|
18428 |
|
18429 |
|
18430 |
|
18431 |
|
18432 |
|
18433 |
|
18434 | Promise.prototype['finally'] = Promise.prototype.ensure = function(handler) {
|
18435 | if(typeof handler !== 'function') {
|
18436 |
|
18437 | return this;
|
18438 | }
|
18439 |
|
18440 | handler = isolate(handler, this);
|
18441 | return this.then(handler, handler);
|
18442 | };
|
18443 |
|
18444 | |
18445 |
|
18446 |
|
18447 |
|
18448 |
|
18449 |
|
18450 |
|
18451 |
|
18452 | Promise.prototype['else'] = Promise.prototype.orElse = function(defaultValue) {
|
18453 | return this.then(void 0, function() {
|
18454 | return defaultValue;
|
18455 | });
|
18456 | };
|
18457 |
|
18458 | |
18459 |
|
18460 |
|
18461 |
|
18462 |
|
18463 |
|
18464 |
|
18465 |
|
18466 | Promise.prototype['yield'] = function(value) {
|
18467 | return this.then(function() {
|
18468 | return value;
|
18469 | });
|
18470 | };
|
18471 |
|
18472 | |
18473 |
|
18474 |
|
18475 |
|
18476 |
|
18477 |
|
18478 | Promise.prototype.tap = function(onFulfilledSideEffect) {
|
18479 | return this.then(onFulfilledSideEffect)['yield'](this);
|
18480 | };
|
18481 |
|
18482 | return Promise;
|
18483 | };
|
18484 |
|
18485 | function rejectInvalidPredicate() {
|
18486 | throw new TypeError('catch predicate must be a function');
|
18487 | }
|
18488 |
|
18489 | function evaluatePredicate(e, predicate) {
|
18490 | return isError(predicate) ? e instanceof predicate : predicate(e);
|
18491 | }
|
18492 |
|
18493 | function isError(predicate) {
|
18494 | return predicate === Error
|
18495 | || (predicate != null && predicate.prototype instanceof Error);
|
18496 | }
|
18497 |
|
18498 |
|
18499 | function isolate(f, x) {
|
18500 | return function() {
|
18501 | f.call(this);
|
18502 | return x;
|
18503 | };
|
18504 | }
|
18505 |
|
18506 | function noop() {}
|
18507 |
|
18508 | });
|
18509 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18510 |
|
18511 | },{}],72:[function(require,module,exports){
|
18512 |
|
18513 |
|
18514 |
|
18515 |
|
18516 |
|
18517 | (function(define) { 'use strict';
|
18518 | define(function() {
|
18519 |
|
18520 | return function fold(Promise) {
|
18521 |
|
18522 | Promise.prototype.fold = function(fn, arg) {
|
18523 | var promise = this._beget();
|
18524 | this._handler.fold(promise._handler, fn, arg);
|
18525 | return promise;
|
18526 | };
|
18527 |
|
18528 | return Promise;
|
18529 | };
|
18530 |
|
18531 | });
|
18532 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18533 |
|
18534 | },{}],73:[function(require,module,exports){
|
18535 |
|
18536 |
|
18537 |
|
18538 |
|
18539 | (function(define) { 'use strict';
|
18540 | define(function() {
|
18541 |
|
18542 | return function inspect(Promise) {
|
18543 |
|
18544 | Promise.prototype.inspect = function() {
|
18545 | return this._handler.inspect();
|
18546 | };
|
18547 |
|
18548 | return Promise;
|
18549 | };
|
18550 |
|
18551 | });
|
18552 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18553 |
|
18554 | },{}],74:[function(require,module,exports){
|
18555 |
|
18556 |
|
18557 |
|
18558 |
|
18559 | (function(define) { 'use strict';
|
18560 | define(function() {
|
18561 |
|
18562 | return function generate(Promise) {
|
18563 |
|
18564 | var resolve = Promise.resolve;
|
18565 |
|
18566 | Promise.iterate = iterate;
|
18567 | Promise.unfold = unfold;
|
18568 |
|
18569 | return Promise;
|
18570 |
|
18571 | |
18572 |
|
18573 |
|
18574 |
|
18575 |
|
18576 |
|
18577 |
|
18578 |
|
18579 |
|
18580 |
|
18581 |
|
18582 | function iterate(f, condition, handler, x) {
|
18583 | return unfold(function(x) {
|
18584 | return [x, f(x)];
|
18585 | }, condition, handler, x);
|
18586 | }
|
18587 |
|
18588 | |
18589 |
|
18590 |
|
18591 |
|
18592 |
|
18593 |
|
18594 |
|
18595 |
|
18596 |
|
18597 |
|
18598 |
|
18599 |
|
18600 |
|
18601 | function unfold(unspool, condition, handler, x) {
|
18602 | return resolve(x).then(function(seed) {
|
18603 | return resolve(condition(seed)).then(function(done) {
|
18604 | return done ? seed : resolve(unspool(seed)).spread(next);
|
18605 | });
|
18606 | });
|
18607 |
|
18608 | function next(item, newSeed) {
|
18609 | return resolve(handler(item)).then(function() {
|
18610 | return unfold(unspool, condition, handler, newSeed);
|
18611 | });
|
18612 | }
|
18613 | }
|
18614 | };
|
18615 |
|
18616 | });
|
18617 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18618 |
|
18619 | },{}],75:[function(require,module,exports){
|
18620 |
|
18621 |
|
18622 |
|
18623 |
|
18624 | (function(define) { 'use strict';
|
18625 | define(function() {
|
18626 |
|
18627 | return function progress(Promise) {
|
18628 |
|
18629 | |
18630 |
|
18631 |
|
18632 |
|
18633 |
|
18634 | Promise.prototype.progress = function(onProgress) {
|
18635 | return this.then(void 0, void 0, onProgress);
|
18636 | };
|
18637 |
|
18638 | return Promise;
|
18639 | };
|
18640 |
|
18641 | });
|
18642 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18643 |
|
18644 | },{}],76:[function(require,module,exports){
|
18645 |
|
18646 |
|
18647 |
|
18648 |
|
18649 | (function(define) { 'use strict';
|
18650 | define(function(require) {
|
18651 |
|
18652 | var timer = require('../timer');
|
18653 | var TimeoutError = require('../TimeoutError');
|
18654 |
|
18655 | return function timed(Promise) {
|
18656 | |
18657 |
|
18658 |
|
18659 |
|
18660 |
|
18661 |
|
18662 | Promise.prototype.delay = function(ms) {
|
18663 | var p = this._beget();
|
18664 | var h = p._handler;
|
18665 |
|
18666 | this._handler.map(function delay(x) {
|
18667 | timer.set(function() { h.resolve(x); }, ms);
|
18668 | }, h);
|
18669 |
|
18670 | return p;
|
18671 | };
|
18672 |
|
18673 | |
18674 |
|
18675 |
|
18676 |
|
18677 |
|
18678 |
|
18679 |
|
18680 |
|
18681 |
|
18682 | Promise.prototype.timeout = function(ms, reason) {
|
18683 | var hasReason = arguments.length > 1;
|
18684 | var p = this._beget();
|
18685 | var h = p._handler;
|
18686 |
|
18687 | var t = timer.set(onTimeout, ms);
|
18688 |
|
18689 | this._handler.chain(h,
|
18690 | function onFulfill(x) {
|
18691 | timer.clear(t);
|
18692 | this.resolve(x);
|
18693 | },
|
18694 | function onReject(x) {
|
18695 | timer.clear(t);
|
18696 | this.reject(x);
|
18697 | },
|
18698 | h.notify);
|
18699 |
|
18700 | return p;
|
18701 |
|
18702 | function onTimeout() {
|
18703 | h.reject(hasReason
|
18704 | ? reason : new TimeoutError('timed out after ' + ms + 'ms'));
|
18705 | }
|
18706 | };
|
18707 |
|
18708 | return Promise;
|
18709 | };
|
18710 |
|
18711 | });
|
18712 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
18713 |
|
18714 | },{"../TimeoutError":68,"../timer":81}],77:[function(require,module,exports){
|
18715 |
|
18716 |
|
18717 |
|
18718 |
|
18719 | (function(define) { 'use strict';
|
18720 | define(function(require) {
|
18721 |
|
18722 | var async = require('../async');
|
18723 |
|
18724 | return function unhandledRejection(Promise) {
|
18725 | var logError = (function() {
|
18726 | if(typeof console !== 'undefined') {
|
18727 | if(typeof console.error !== 'undefined') {
|
18728 | return function(e) {
|
18729 | console.error(e);
|
18730 | };
|
18731 | }
|
18732 |
|
18733 | return function(e) {
|
18734 | console.log(e);
|
18735 | };
|
18736 | }
|
18737 |
|
18738 | return noop;
|
18739 | }());
|
18740 |
|
18741 | Promise.onPotentiallyUnhandledRejection = function(rejection) {
|
18742 | logError('Potentially unhandled rejection ' + formatError(rejection.value));
|
18743 | };
|
18744 |
|
18745 | Promise.onFatalRejection = function(rejection) {
|
18746 | async(function() {
|
18747 | throw rejection.value;
|
18748 | });
|
18749 | };
|
18750 |
|
18751 | return Promise;
|
18752 | };
|
18753 |
|
18754 | function formatError(e) {
|
18755 | var s;
|
18756 | if(typeof e === 'object' && e.stack) {
|
18757 | s = e.stack;
|
18758 | } else {
|
18759 | s = String(e);
|
18760 | if(s === '[object Object]' && typeof JSON !== 'undefined') {
|
18761 | s = tryStringify(e, s);
|
18762 | }
|
18763 | }
|
18764 |
|
18765 | return e instanceof Error ? s : s + ' (WARNING: non-Error used)';
|
18766 | }
|
18767 |
|
18768 | function tryStringify(e, defaultValue) {
|
18769 | try {
|
18770 | return JSON.stringify(e);
|
18771 | } catch(e) {
|
18772 |
|
18773 | return defaultValue;
|
18774 | }
|
18775 | }
|
18776 |
|
18777 | function noop() {}
|
18778 |
|
18779 | });
|
18780 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
18781 |
|
18782 | },{"../async":69}],78:[function(require,module,exports){
|
18783 |
|
18784 |
|
18785 |
|
18786 |
|
18787 | (function(define) { 'use strict';
|
18788 | define(function() {
|
18789 |
|
18790 | return function addWith(Promise) {
|
18791 | |
18792 |
|
18793 |
|
18794 |
|
18795 |
|
18796 |
|
18797 |
|
18798 |
|
18799 |
|
18800 |
|
18801 |
|
18802 |
|
18803 |
|
18804 |
|
18805 |
|
18806 | Promise.prototype['with'] = Promise.prototype.withThis
|
18807 | = Promise.prototype._bindContext;
|
18808 |
|
18809 | return Promise;
|
18810 | };
|
18811 |
|
18812 | });
|
18813 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
18814 |
|
18815 |
|
18816 | },{}],79:[function(require,module,exports){
|
18817 |
|
18818 |
|
18819 |
|
18820 |
|
18821 | (function(define) { 'use strict';
|
18822 | define(function() {
|
18823 |
|
18824 | return function makePromise(environment) {
|
18825 |
|
18826 | var tasks = environment.scheduler;
|
18827 |
|
18828 | var objectCreate = Object.create ||
|
18829 | function(proto) {
|
18830 | function Child() {}
|
18831 | Child.prototype = proto;
|
18832 | return new Child();
|
18833 | };
|
18834 |
|
18835 | |
18836 |
|
18837 |
|
18838 |
|
18839 |
|
18840 |
|
18841 | function Promise(resolver, handler) {
|
18842 | this._handler = resolver === Handler ? handler : init(resolver);
|
18843 |
|
18844 |
|
18845 | }
|
18846 |
|
18847 | |
18848 |
|
18849 |
|
18850 |
|
18851 |
|
18852 | function init(resolver) {
|
18853 | var handler = new DeferredHandler();
|
18854 |
|
18855 | try {
|
18856 | resolver(promiseResolve, promiseReject, promiseNotify);
|
18857 | } catch (e) {
|
18858 | promiseReject(e);
|
18859 | }
|
18860 |
|
18861 | return handler;
|
18862 |
|
18863 | |
18864 |
|
18865 |
|
18866 |
|
18867 |
|
18868 | function promiseResolve (x) {
|
18869 | handler.resolve(x);
|
18870 | }
|
18871 | |
18872 |
|
18873 |
|
18874 |
|
18875 |
|
18876 | function promiseReject (reason) {
|
18877 | handler.reject(reason);
|
18878 | }
|
18879 |
|
18880 | |
18881 |
|
18882 |
|
18883 |
|
18884 | function promiseNotify (x) {
|
18885 | handler.notify(x);
|
18886 | }
|
18887 | }
|
18888 |
|
18889 |
|
18890 |
|
18891 | Promise.resolve = resolve;
|
18892 | Promise.reject = reject;
|
18893 | Promise.never = never;
|
18894 |
|
18895 | Promise._defer = defer;
|
18896 |
|
18897 | |
18898 |
|
18899 |
|
18900 |
|
18901 |
|
18902 |
|
18903 | function resolve(x) {
|
18904 | return x instanceof Promise ? x
|
18905 | : new Promise(Handler, new AsyncHandler(getHandler(x)));
|
18906 | }
|
18907 |
|
18908 | |
18909 |
|
18910 |
|
18911 |
|
18912 |
|
18913 | function reject(x) {
|
18914 | return new Promise(Handler, new AsyncHandler(new RejectedHandler(x)));
|
18915 | }
|
18916 |
|
18917 | |
18918 |
|
18919 |
|
18920 |
|
18921 | function never() {
|
18922 | return foreverPendingPromise;
|
18923 | }
|
18924 |
|
18925 | |
18926 |
|
18927 |
|
18928 |
|
18929 |
|
18930 | function defer() {
|
18931 | return new Promise(Handler, new DeferredHandler());
|
18932 | }
|
18933 |
|
18934 |
|
18935 |
|
18936 | |
18937 |
|
18938 |
|
18939 |
|
18940 |
|
18941 |
|
18942 |
|
18943 |
|
18944 |
|
18945 |
|
18946 | Promise.prototype.then = function(onFulfilled, onRejected) {
|
18947 | var parent = this._handler;
|
18948 |
|
18949 | if (typeof onFulfilled !== 'function' && parent.join().state > 0) {
|
18950 |
|
18951 | return new Promise(Handler, parent);
|
18952 | }
|
18953 |
|
18954 | var p = this._beget();
|
18955 | var child = p._handler;
|
18956 |
|
18957 | parent.when({
|
18958 | resolve: child.resolve,
|
18959 | notify: child.notify,
|
18960 | context: child,
|
18961 | receiver: parent.receiver,
|
18962 | fulfilled: onFulfilled,
|
18963 | rejected: onRejected,
|
18964 | progress: arguments.length > 2 ? arguments[2] : void 0
|
18965 | });
|
18966 |
|
18967 | return p;
|
18968 | };
|
18969 |
|
18970 | |
18971 |
|
18972 |
|
18973 |
|
18974 |
|
18975 |
|
18976 | Promise.prototype['catch'] = function(onRejected) {
|
18977 | return this.then(void 0, onRejected);
|
18978 | };
|
18979 |
|
18980 | |
18981 |
|
18982 |
|
18983 |
|
18984 |
|
18985 |
|
18986 |
|
18987 | Promise.prototype._bindContext = function(thisArg) {
|
18988 | return new Promise(Handler, new BoundHandler(this._handler, thisArg));
|
18989 | };
|
18990 |
|
18991 | |
18992 |
|
18993 |
|
18994 |
|
18995 |
|
18996 | Promise.prototype._beget = function() {
|
18997 | var parent = this._handler;
|
18998 | var child = new DeferredHandler(parent.receiver, parent.join().context);
|
18999 | return new this.constructor(Handler, child);
|
19000 | };
|
19001 |
|
19002 | |
19003 |
|
19004 |
|
19005 |
|
19006 |
|
19007 | Promise.prototype._maybeFatal = function(x) {
|
19008 | if(!maybeThenable(x)) {
|
19009 | return;
|
19010 | }
|
19011 |
|
19012 | var handler = getHandler(x);
|
19013 | var context = this._handler.context;
|
19014 | handler.catchError(function() {
|
19015 | this._fatal(context);
|
19016 | }, handler);
|
19017 | };
|
19018 |
|
19019 |
|
19020 |
|
19021 | Promise.all = all;
|
19022 | Promise.race = race;
|
19023 |
|
19024 | |
19025 |
|
19026 |
|
19027 |
|
19028 |
|
19029 |
|
19030 |
|
19031 | function all(promises) {
|
19032 |
|
19033 | var resolver = new DeferredHandler();
|
19034 | var pending = promises.length >>> 0;
|
19035 | var results = new Array(pending);
|
19036 |
|
19037 | var i, h, x;
|
19038 | for (i = 0; i < promises.length; ++i) {
|
19039 | x = promises[i];
|
19040 |
|
19041 | if (x === void 0 && !(i in promises)) {
|
19042 | --pending;
|
19043 | continue;
|
19044 | }
|
19045 |
|
19046 | if (maybeThenable(x)) {
|
19047 | h = x instanceof Promise
|
19048 | ? x._handler.join()
|
19049 | : getHandlerUntrusted(x);
|
19050 |
|
19051 | if (h.state === 0) {
|
19052 | resolveOne(resolver, results, h, i);
|
19053 | } else if (h.state > 0) {
|
19054 | results[i] = h.value;
|
19055 | --pending;
|
19056 | } else {
|
19057 | h.catchError(resolver.reject, resolver);
|
19058 | break;
|
19059 | }
|
19060 |
|
19061 | } else {
|
19062 | results[i] = x;
|
19063 | --pending;
|
19064 | }
|
19065 | }
|
19066 |
|
19067 | if(pending === 0) {
|
19068 | resolver.resolve(results);
|
19069 | }
|
19070 |
|
19071 | return new Promise(Handler, resolver);
|
19072 | function resolveOne(resolver, results, handler, i) {
|
19073 | handler.map(function(x) {
|
19074 | results[i] = x;
|
19075 | if(--pending === 0) {
|
19076 | this.resolve(results);
|
19077 | }
|
19078 | }, resolver);
|
19079 | }
|
19080 | }
|
19081 |
|
19082 | |
19083 |
|
19084 |
|
19085 |
|
19086 |
|
19087 |
|
19088 |
|
19089 |
|
19090 |
|
19091 |
|
19092 |
|
19093 |
|
19094 |
|
19095 |
|
19096 | function race(promises) {
|
19097 |
|
19098 |
|
19099 | if(Object(promises) === promises && promises.length === 0) {
|
19100 | return never();
|
19101 | }
|
19102 |
|
19103 | var h = new DeferredHandler();
|
19104 | var i, x;
|
19105 | for(i=0; i<promises.length; ++i) {
|
19106 | x = promises[i];
|
19107 | if (x !== void 0 && i in promises) {
|
19108 | getHandler(x).chain(h, h.resolve, h.reject);
|
19109 | }
|
19110 | }
|
19111 | return new Promise(Handler, h);
|
19112 | }
|
19113 |
|
19114 |
|
19115 |
|
19116 | |
19117 |
|
19118 |
|
19119 |
|
19120 |
|
19121 |
|
19122 | function getHandler(x) {
|
19123 | if(x instanceof Promise) {
|
19124 | return x._handler.join();
|
19125 | }
|
19126 | return maybeThenable(x) ? getHandlerUntrusted(x) : new FulfilledHandler(x);
|
19127 | }
|
19128 |
|
19129 | |
19130 |
|
19131 |
|
19132 |
|
19133 |
|
19134 | function getHandlerUntrusted(x) {
|
19135 | try {
|
19136 | var untrustedThen = x.then;
|
19137 | return typeof untrustedThen === 'function'
|
19138 | ? new ThenableHandler(untrustedThen, x)
|
19139 | : new FulfilledHandler(x);
|
19140 | } catch(e) {
|
19141 | return new RejectedHandler(e);
|
19142 | }
|
19143 | }
|
19144 |
|
19145 | |
19146 |
|
19147 |
|
19148 |
|
19149 |
|
19150 | function Handler() {
|
19151 | this.state = 0;
|
19152 | }
|
19153 |
|
19154 | Handler.prototype.when
|
19155 | = Handler.prototype.resolve
|
19156 | = Handler.prototype.reject
|
19157 | = Handler.prototype.notify
|
19158 | = Handler.prototype._fatal
|
19159 | = Handler.prototype._unreport
|
19160 | = Handler.prototype._report
|
19161 | = noop;
|
19162 |
|
19163 | Handler.prototype.inspect = toPendingState;
|
19164 |
|
19165 | |
19166 |
|
19167 |
|
19168 |
|
19169 |
|
19170 | Handler.prototype.join = function() {
|
19171 | var h = this;
|
19172 | while(h.handler !== void 0) {
|
19173 | h = h.handler;
|
19174 | }
|
19175 | return h;
|
19176 | };
|
19177 |
|
19178 | Handler.prototype.chain = function(to, fulfilled, rejected, progress) {
|
19179 | this.when({
|
19180 | resolve: noop,
|
19181 | notify: noop,
|
19182 | context: void 0,
|
19183 | receiver: to,
|
19184 | fulfilled: fulfilled,
|
19185 | rejected: rejected,
|
19186 | progress: progress
|
19187 | });
|
19188 | };
|
19189 |
|
19190 | Handler.prototype.map = function(f, to) {
|
19191 | this.chain(to, f, to.reject, to.notify);
|
19192 | };
|
19193 |
|
19194 | Handler.prototype.catchError = function(f, to) {
|
19195 | this.chain(to, to.resolve, f, to.notify);
|
19196 | };
|
19197 |
|
19198 | Handler.prototype.fold = function(to, f, z) {
|
19199 | this.join().map(function(x) {
|
19200 | getHandler(z).map(function(z) {
|
19201 | this.resolve(tryCatchReject2(f, z, x, this.receiver));
|
19202 | }, this);
|
19203 | }, to);
|
19204 | };
|
19205 |
|
19206 | |
19207 |
|
19208 |
|
19209 |
|
19210 |
|
19211 | function DeferredHandler(receiver, inheritedContext) {
|
19212 | Promise.createContext(this, inheritedContext);
|
19213 |
|
19214 | this.consumers = void 0;
|
19215 | this.receiver = receiver;
|
19216 | this.handler = void 0;
|
19217 | this.resolved = false;
|
19218 | this.state = 0;
|
19219 | }
|
19220 |
|
19221 | inherit(Handler, DeferredHandler);
|
19222 |
|
19223 | DeferredHandler.prototype.inspect = function() {
|
19224 | return this.resolved ? this.join().inspect() : toPendingState();
|
19225 | };
|
19226 |
|
19227 | DeferredHandler.prototype.resolve = function(x) {
|
19228 | if(!this.resolved) {
|
19229 | this.become(getHandler(x));
|
19230 | }
|
19231 | };
|
19232 |
|
19233 | DeferredHandler.prototype.reject = function(x) {
|
19234 | if(!this.resolved) {
|
19235 | this.become(new RejectedHandler(x));
|
19236 | }
|
19237 | };
|
19238 |
|
19239 | DeferredHandler.prototype.join = function() {
|
19240 | if (this.resolved) {
|
19241 | var h = this;
|
19242 | while(h.handler !== void 0) {
|
19243 | h = h.handler;
|
19244 | if(h === this) {
|
19245 | return this.handler = new Cycle();
|
19246 | }
|
19247 | }
|
19248 | return h;
|
19249 | } else {
|
19250 | return this;
|
19251 | }
|
19252 | };
|
19253 |
|
19254 | DeferredHandler.prototype.run = function() {
|
19255 | var q = this.consumers;
|
19256 | var handler = this.join();
|
19257 | this.consumers = void 0;
|
19258 |
|
19259 | for (var i = 0; i < q.length; ++i) {
|
19260 | handler.when(q[i]);
|
19261 | }
|
19262 | };
|
19263 |
|
19264 | DeferredHandler.prototype.become = function(handler) {
|
19265 | this.resolved = true;
|
19266 | this.handler = handler;
|
19267 | if(this.consumers !== void 0) {
|
19268 | tasks.enqueue(this);
|
19269 | }
|
19270 |
|
19271 | if(this.context !== void 0) {
|
19272 | handler._report(this.context);
|
19273 | }
|
19274 | };
|
19275 |
|
19276 | DeferredHandler.prototype.when = function(continuation) {
|
19277 | if(this.resolved) {
|
19278 | tasks.enqueue(new ContinuationTask(continuation, this.handler));
|
19279 | } else {
|
19280 | if(this.consumers === void 0) {
|
19281 | this.consumers = [continuation];
|
19282 | } else {
|
19283 | this.consumers.push(continuation);
|
19284 | }
|
19285 | }
|
19286 | };
|
19287 |
|
19288 | DeferredHandler.prototype.notify = function(x) {
|
19289 | if(!this.resolved) {
|
19290 | tasks.enqueue(new ProgressTask(this, x));
|
19291 | }
|
19292 | };
|
19293 |
|
19294 | DeferredHandler.prototype._report = function(context) {
|
19295 | this.resolved && this.handler.join()._report(context);
|
19296 | };
|
19297 |
|
19298 | DeferredHandler.prototype._unreport = function() {
|
19299 | this.resolved && this.handler.join()._unreport();
|
19300 | };
|
19301 |
|
19302 | DeferredHandler.prototype._fatal = function(context) {
|
19303 | var c = typeof context === 'undefined' ? this.context : context;
|
19304 | this.resolved && this.handler.join()._fatal(c);
|
19305 | };
|
19306 |
|
19307 | |
19308 |
|
19309 |
|
19310 |
|
19311 |
|
19312 |
|
19313 | function DelegateHandler(handler) {
|
19314 | this.handler = handler;
|
19315 | this.state = 0;
|
19316 | }
|
19317 |
|
19318 | inherit(Handler, DelegateHandler);
|
19319 |
|
19320 | DelegateHandler.prototype.inspect = function() {
|
19321 | return this.join().inspect();
|
19322 | };
|
19323 |
|
19324 | DelegateHandler.prototype._report = function(context) {
|
19325 | this.join()._report(context);
|
19326 | };
|
19327 |
|
19328 | DelegateHandler.prototype._unreport = function() {
|
19329 | this.join()._unreport();
|
19330 | };
|
19331 |
|
19332 | |
19333 |
|
19334 |
|
19335 |
|
19336 |
|
19337 |
|
19338 | function AsyncHandler(handler) {
|
19339 | DelegateHandler.call(this, handler);
|
19340 | }
|
19341 |
|
19342 | inherit(DelegateHandler, AsyncHandler);
|
19343 |
|
19344 | AsyncHandler.prototype.when = function(continuation) {
|
19345 | tasks.enqueue(new ContinuationTask(continuation, this.join()));
|
19346 | };
|
19347 |
|
19348 | |
19349 |
|
19350 |
|
19351 |
|
19352 |
|
19353 |
|
19354 |
|
19355 | function BoundHandler(handler, receiver) {
|
19356 | DelegateHandler.call(this, handler);
|
19357 | this.receiver = receiver;
|
19358 | }
|
19359 |
|
19360 | inherit(DelegateHandler, BoundHandler);
|
19361 |
|
19362 | BoundHandler.prototype.when = function(continuation) {
|
19363 |
|
19364 |
|
19365 |
|
19366 |
|
19367 | if(this.receiver !== void 0) {
|
19368 | continuation.receiver = this.receiver;
|
19369 | }
|
19370 | this.join().when(continuation);
|
19371 | };
|
19372 |
|
19373 | |
19374 |
|
19375 |
|
19376 |
|
19377 |
|
19378 |
|
19379 |
|
19380 | function ThenableHandler(then, thenable) {
|
19381 | DeferredHandler.call(this);
|
19382 | this.assimilated = false;
|
19383 | this.untrustedThen = then;
|
19384 | this.thenable = thenable;
|
19385 | }
|
19386 |
|
19387 | inherit(DeferredHandler, ThenableHandler);
|
19388 |
|
19389 | ThenableHandler.prototype.when = function(continuation) {
|
19390 | if(!this.assimilated) {
|
19391 | this.assimilated = true;
|
19392 | assimilate(this);
|
19393 | }
|
19394 | DeferredHandler.prototype.when.call(this, continuation);
|
19395 | };
|
19396 |
|
19397 | function assimilate(h) {
|
19398 | tryAssimilate(h.untrustedThen, h.thenable, _resolve, _reject, _notify);
|
19399 |
|
19400 | function _resolve(x) { h.resolve(x); }
|
19401 | function _reject(x) { h.reject(x); }
|
19402 | function _notify(x) { h.notify(x); }
|
19403 | }
|
19404 |
|
19405 | function tryAssimilate(then, thenable, resolve, reject, notify) {
|
19406 | try {
|
19407 | then.call(thenable, resolve, reject, notify);
|
19408 | } catch (e) {
|
19409 | reject(e);
|
19410 | }
|
19411 | }
|
19412 |
|
19413 | |
19414 |
|
19415 |
|
19416 |
|
19417 |
|
19418 |
|
19419 | function FulfilledHandler(x) {
|
19420 | Promise.createContext(this);
|
19421 |
|
19422 | this.value = x;
|
19423 | this.state = 1;
|
19424 | }
|
19425 |
|
19426 | inherit(Handler, FulfilledHandler);
|
19427 |
|
19428 | FulfilledHandler.prototype.inspect = function() {
|
19429 | return { state: 'fulfilled', value: this.value };
|
19430 | };
|
19431 |
|
19432 | FulfilledHandler.prototype.when = function(cont) {
|
19433 | var x;
|
19434 |
|
19435 | if (typeof cont.fulfilled === 'function') {
|
19436 | Promise.enterContext(this);
|
19437 | x = tryCatchReject(cont.fulfilled, this.value, cont.receiver);
|
19438 | Promise.exitContext();
|
19439 | } else {
|
19440 | x = this.value;
|
19441 | }
|
19442 |
|
19443 | cont.resolve.call(cont.context, x);
|
19444 | };
|
19445 |
|
19446 | |
19447 |
|
19448 |
|
19449 |
|
19450 |
|
19451 |
|
19452 | function RejectedHandler(x) {
|
19453 | Promise.createContext(this);
|
19454 |
|
19455 | this.value = x;
|
19456 | this.state = -1;
|
19457 | this.handled = false;
|
19458 |
|
19459 | this._report();
|
19460 | }
|
19461 |
|
19462 | inherit(Handler, RejectedHandler);
|
19463 |
|
19464 | RejectedHandler.prototype.inspect = function() {
|
19465 | return { state: 'rejected', reason: this.value };
|
19466 | };
|
19467 |
|
19468 | RejectedHandler.prototype.when = function(cont) {
|
19469 | var x;
|
19470 |
|
19471 | if (typeof cont.rejected === 'function') {
|
19472 | this._unreport();
|
19473 | Promise.enterContext(this);
|
19474 | x = tryCatchReject(cont.rejected, this.value, cont.receiver);
|
19475 | Promise.exitContext();
|
19476 | } else {
|
19477 | x = new Promise(Handler, this);
|
19478 | }
|
19479 |
|
19480 |
|
19481 | cont.resolve.call(cont.context, x);
|
19482 | };
|
19483 |
|
19484 | RejectedHandler.prototype._report = function(context) {
|
19485 | tasks.afterQueue(reportUnhandled, this, context);
|
19486 | };
|
19487 |
|
19488 | RejectedHandler.prototype._unreport = function() {
|
19489 | this.handled = true;
|
19490 | tasks.afterQueue(reportHandled, this);
|
19491 | };
|
19492 |
|
19493 | RejectedHandler.prototype._fatal = function(context) {
|
19494 | Promise.onFatalRejection(this, context);
|
19495 | };
|
19496 |
|
19497 | function reportUnhandled(rejection, context) {
|
19498 | if(!rejection.handled) {
|
19499 | rejection.state = -2;
|
19500 | Promise.onPotentiallyUnhandledRejection(rejection, context);
|
19501 | }
|
19502 | }
|
19503 |
|
19504 | function reportHandled(rejection) {
|
19505 | if(rejection.state === -2) {
|
19506 | Promise.onPotentiallyUnhandledRejectionHandled(rejection);
|
19507 | }
|
19508 | }
|
19509 |
|
19510 |
|
19511 |
|
19512 |
|
19513 |
|
19514 | Promise.createContext
|
19515 | = Promise.enterContext
|
19516 | = Promise.exitContext
|
19517 | = Promise.onPotentiallyUnhandledRejection
|
19518 | = Promise.onPotentiallyUnhandledRejectionHandled
|
19519 | = Promise.onFatalRejection
|
19520 | = noop;
|
19521 |
|
19522 |
|
19523 |
|
19524 | var foreverPendingHandler = new Handler();
|
19525 | var foreverPendingPromise = new Promise(Handler, foreverPendingHandler);
|
19526 |
|
19527 | function Cycle() {
|
19528 | RejectedHandler.call(this, new TypeError('Promise cycle'));
|
19529 | }
|
19530 |
|
19531 | inherit(RejectedHandler, Cycle);
|
19532 |
|
19533 |
|
19534 |
|
19535 | |
19536 |
|
19537 |
|
19538 |
|
19539 |
|
19540 | function toPendingState() {
|
19541 | return { state: 'pending' };
|
19542 | }
|
19543 |
|
19544 |
|
19545 |
|
19546 | |
19547 |
|
19548 |
|
19549 |
|
19550 |
|
19551 | function ContinuationTask(continuation, handler) {
|
19552 | this.continuation = continuation;
|
19553 | this.handler = handler;
|
19554 | }
|
19555 |
|
19556 | ContinuationTask.prototype.run = function() {
|
19557 | this.handler.join().when(this.continuation);
|
19558 | };
|
19559 |
|
19560 | |
19561 |
|
19562 |
|
19563 |
|
19564 |
|
19565 | function ProgressTask(handler, value) {
|
19566 | this.handler = handler;
|
19567 | this.value = value;
|
19568 | }
|
19569 |
|
19570 | ProgressTask.prototype.run = function() {
|
19571 | var q = this.handler.consumers;
|
19572 | if(q === void 0) {
|
19573 | return;
|
19574 | }
|
19575 |
|
19576 | for (var i = 0; i < q.length; ++i) {
|
19577 | this._notify(q[i]);
|
19578 | }
|
19579 | };
|
19580 |
|
19581 | ProgressTask.prototype._notify = function(continuation) {
|
19582 | var x = typeof continuation.progress === 'function'
|
19583 | ? tryCatchReturn(continuation.progress, this.value, continuation.receiver)
|
19584 | : this.value;
|
19585 |
|
19586 | continuation.notify.call(continuation.context, x);
|
19587 | };
|
19588 |
|
19589 |
|
19590 |
|
19591 | |
19592 |
|
19593 |
|
19594 |
|
19595 | function maybeThenable(x) {
|
19596 | return (typeof x === 'object' || typeof x === 'function') && x !== null;
|
19597 | }
|
19598 |
|
19599 | |
19600 |
|
19601 |
|
19602 |
|
19603 |
|
19604 | function tryCatchReject(f, x, thisArg) {
|
19605 | try {
|
19606 | return f.call(thisArg, x);
|
19607 | } catch(e) {
|
19608 | return reject(e);
|
19609 | }
|
19610 | }
|
19611 |
|
19612 | |
19613 |
|
19614 |
|
19615 |
|
19616 | function tryCatchReject2(f, x, y, thisArg) {
|
19617 | try {
|
19618 | return f.call(thisArg, x, y);
|
19619 | } catch(e) {
|
19620 | return reject(e);
|
19621 | }
|
19622 | }
|
19623 |
|
19624 | |
19625 |
|
19626 |
|
19627 |
|
19628 | function tryCatchReturn(f, x, thisArg) {
|
19629 | try {
|
19630 | return f.call(thisArg, x);
|
19631 | } catch(e) {
|
19632 | return e;
|
19633 | }
|
19634 | }
|
19635 |
|
19636 | function inherit(Parent, Child) {
|
19637 | Child.prototype = objectCreate(Parent.prototype);
|
19638 | Child.prototype.constructor = Child;
|
19639 | }
|
19640 |
|
19641 | function noop() {}
|
19642 |
|
19643 | return Promise;
|
19644 | };
|
19645 | });
|
19646 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));
|
19647 |
|
19648 | },{}],80:[function(require,module,exports){
|
19649 |
|
19650 |
|
19651 |
|
19652 |
|
19653 | (function(define) { 'use strict';
|
19654 | define(function(require) {
|
19655 |
|
19656 | var Queue = require('./Queue');
|
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 | function Scheduler(enqueue) {
|
19662 | this._enqueue = enqueue;
|
19663 | this._handlerQueue = new Queue(15);
|
19664 | this._afterQueue = new Queue(5);
|
19665 | this._running = false;
|
19666 |
|
19667 | var self = this;
|
19668 | this.drain = function() {
|
19669 | self._drain();
|
19670 | };
|
19671 | }
|
19672 |
|
19673 | |
19674 |
|
19675 |
|
19676 |
|
19677 |
|
19678 | Scheduler.prototype.enqueue = function(task) {
|
19679 | this._handlerQueue.push(task);
|
19680 | if(!this._running) {
|
19681 | this._running = true;
|
19682 | this._enqueue(this.drain);
|
19683 | }
|
19684 | };
|
19685 |
|
19686 | Scheduler.prototype.afterQueue = function(f, x, y) {
|
19687 | this._afterQueue.push(f);
|
19688 | this._afterQueue.push(x);
|
19689 | this._afterQueue.push(y);
|
19690 | if(!this._running) {
|
19691 | this._running = true;
|
19692 | this._enqueue(this.drain);
|
19693 | }
|
19694 | };
|
19695 |
|
19696 | |
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 | Scheduler.prototype._drain = function() {
|
19702 | var q = this._handlerQueue;
|
19703 | while(q.length > 0) {
|
19704 | q.shift().run();
|
19705 | }
|
19706 |
|
19707 | q = this._afterQueue;
|
19708 | while(q.length > 0) {
|
19709 | q.shift()(q.shift(), q.shift());
|
19710 | }
|
19711 |
|
19712 | this._running = false;
|
19713 | };
|
19714 |
|
19715 | return Scheduler;
|
19716 |
|
19717 | });
|
19718 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
19719 |
|
19720 | },{"./Queue":67}],81:[function(require,module,exports){
|
19721 |
|
19722 |
|
19723 |
|
19724 |
|
19725 | (function(define) { 'use strict';
|
19726 | define(function(require) {
|
19727 |
|
19728 | var cjsRequire, vertx, setTimer, clearTimer;
|
19729 |
|
19730 | cjsRequire = require;
|
19731 |
|
19732 | try {
|
19733 | vertx = cjsRequire('vertx');
|
19734 | setTimer = function (f, ms) { return vertx.setTimer(ms, f); };
|
19735 | clearTimer = vertx.cancelTimer;
|
19736 | } catch (e) {
|
19737 | setTimer = function(f, ms) { return setTimeout(f, ms); };
|
19738 | clearTimer = function(t) { return clearTimeout(t); };
|
19739 | }
|
19740 |
|
19741 | return {
|
19742 | set: setTimer,
|
19743 | clear: clearTimer
|
19744 | };
|
19745 |
|
19746 | });
|
19747 | }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); }));
|
19748 |
|
19749 | },{}],82:[function(require,module,exports){
|
19750 |
|
19751 |
|
19752 |
|
19753 |
|
19754 |
|
19755 |
|
19756 |
|
19757 |
|
19758 |
|
19759 | (function(define) { 'use strict';
|
19760 | define(function (require) {
|
19761 |
|
19762 | var timed = require('./lib/decorators/timed');
|
19763 | var array = require('./lib/decorators/array');
|
19764 | var flow = require('./lib/decorators/flow');
|
19765 | var fold = require('./lib/decorators/fold');
|
19766 | var inspect = require('./lib/decorators/inspect');
|
19767 | var generate = require('./lib/decorators/iterate');
|
19768 | var progress = require('./lib/decorators/progress');
|
19769 | var withThis = require('./lib/decorators/with');
|
19770 | var unhandledRejection = require('./lib/decorators/unhandledRejection');
|
19771 | var TimeoutError = require('./lib/TimeoutError');
|
19772 |
|
19773 | var Promise = [array, flow, fold, generate, progress,
|
19774 | inspect, withThis, timed, unhandledRejection]
|
19775 | .reduce(function(Promise, feature) {
|
19776 | return feature(Promise);
|
19777 | }, require('./lib/Promise'));
|
19778 |
|
19779 | var slice = Array.prototype.slice;
|
19780 |
|
19781 |
|
19782 |
|
19783 | when.promise = promise;
|
19784 | when.resolve = Promise.resolve;
|
19785 | when.reject = Promise.reject;
|
19786 |
|
19787 | when.lift = lift;
|
19788 | when['try'] = attempt;
|
19789 | when.attempt = attempt;
|
19790 |
|
19791 | when.iterate = Promise.iterate;
|
19792 | when.unfold = Promise.unfold;
|
19793 |
|
19794 | when.join = join;
|
19795 |
|
19796 | when.all = all;
|
19797 | when.settle = settle;
|
19798 |
|
19799 | when.any = lift(Promise.any);
|
19800 | when.some = lift(Promise.some);
|
19801 |
|
19802 | when.map = map;
|
19803 | when.reduce = reduce;
|
19804 | when.reduceRight = reduceRight;
|
19805 |
|
19806 | when.isPromiseLike = isPromiseLike;
|
19807 |
|
19808 | when.Promise = Promise;
|
19809 | when.defer = defer;
|
19810 |
|
19811 |
|
19812 |
|
19813 | when.TimeoutError = TimeoutError;
|
19814 |
|
19815 | |
19816 |
|
19817 |
|
19818 |
|
19819 |
|
19820 |
|
19821 |
|
19822 |
|
19823 |
|
19824 |
|
19825 |
|
19826 |
|
19827 |
|
19828 |
|
19829 |
|
19830 | function when(x, onFulfilled, onRejected) {
|
19831 | var p = Promise.resolve(x);
|
19832 | if(arguments.length < 2) {
|
19833 | return p;
|
19834 | }
|
19835 |
|
19836 | return arguments.length > 3
|
19837 | ? p.then(onFulfilled, onRejected, arguments[3])
|
19838 | : p.then(onFulfilled, onRejected);
|
19839 | }
|
19840 |
|
19841 | |
19842 |
|
19843 |
|
19844 |
|
19845 |
|
19846 | function promise(resolver) {
|
19847 | return new Promise(resolver);
|
19848 | }
|
19849 |
|
19850 | |
19851 |
|
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 | function lift(f) {
|
19857 | return function() {
|
19858 | return _apply(f, this, slice.call(arguments));
|
19859 | };
|
19860 | }
|
19861 |
|
19862 | |
19863 |
|
19864 |
|
19865 |
|
19866 |
|
19867 |
|
19868 | function attempt(f /*, args... */) {
|
19869 |
|
19870 | return _apply(f, this, slice.call(arguments, 1));
|
19871 | }
|
19872 |
|
19873 | |
19874 |
|
19875 |
|
19876 |
|
19877 | function _apply(f, thisArg, args) {
|
19878 | return Promise.all(args).then(function(args) {
|
19879 | return f.apply(thisArg, args);
|
19880 | });
|
19881 | }
|
19882 |
|
19883 | |
19884 |
|
19885 |
|
19886 |
|
19887 |
|
19888 | function defer() {
|
19889 | return new Deferred();
|
19890 | }
|
19891 |
|
19892 | function Deferred() {
|
19893 | var p = Promise._defer();
|
19894 |
|
19895 | function resolve(x) { p._handler.resolve(x); }
|
19896 | function reject(x) { p._handler.reject(x); }
|
19897 | function notify(x) { p._handler.notify(x); }
|
19898 |
|
19899 | this.promise = p;
|
19900 | this.resolve = resolve;
|
19901 | this.reject = reject;
|
19902 | this.notify = notify;
|
19903 | this.resolver = { resolve: resolve, reject: reject, notify: notify };
|
19904 | }
|
19905 |
|
19906 | |
19907 |
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 |
|
19913 |
|
19914 | function isPromiseLike(x) {
|
19915 | return x && typeof x.then === 'function';
|
19916 | }
|
19917 |
|
19918 | |
19919 |
|
19920 |
|
19921 |
|
19922 |
|
19923 |
|
19924 |
|
19925 | function join(/* ...promises */) {
|
19926 | return Promise.all(arguments);
|
19927 | }
|
19928 |
|
19929 | |
19930 |
|
19931 |
|
19932 |
|
19933 |
|
19934 |
|
19935 | function all(promises) {
|
19936 | return when(promises, Promise.all);
|
19937 | }
|
19938 |
|
19939 | |
19940 |
|
19941 |
|
19942 |
|
19943 |
|
19944 |
|
19945 |
|
19946 | function settle(promises) {
|
19947 | return when(promises, Promise.settle);
|
19948 | }
|
19949 |
|
19950 | |
19951 |
|
19952 |
|
19953 |
|
19954 |
|
19955 |
|
19956 |
|
19957 |
|
19958 | function map(promises, mapFunc) {
|
19959 | return when(promises, function(promises) {
|
19960 | return Promise.map(promises, mapFunc);
|
19961 | });
|
19962 | }
|
19963 |
|
19964 | |
19965 |
|
19966 |
|
19967 |
|
19968 |
|
19969 |
|
19970 |
|
19971 |
|
19972 |
|
19973 |
|
19974 |
|
19975 | function reduce(promises, f /*, initialValue */) {
|
19976 |
|
19977 | var args = slice.call(arguments, 1);
|
19978 | return when(promises, function(array) {
|
19979 | args.unshift(array);
|
19980 | return Promise.reduce.apply(Promise, args);
|
19981 | });
|
19982 | }
|
19983 |
|
19984 | |
19985 |
|
19986 |
|
19987 |
|
19988 |
|
19989 |
|
19990 |
|
19991 |
|
19992 |
|
19993 |
|
19994 |
|
19995 | function reduceRight(promises, f /*, initialValue */) {
|
19996 |
|
19997 | var args = slice.call(arguments, 1);
|
19998 | return when(promises, function(array) {
|
19999 | args.unshift(array);
|
20000 | return Promise.reduceRight.apply(Promise, args);
|
20001 | });
|
20002 | }
|
20003 |
|
20004 | return when;
|
20005 | });
|
20006 | })(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); });
|
20007 |
|
20008 | },{"./lib/Promise":66,"./lib/TimeoutError":68,"./lib/decorators/array":70,"./lib/decorators/flow":71,"./lib/decorators/fold":72,"./lib/decorators/inspect":73,"./lib/decorators/iterate":74,"./lib/decorators/progress":75,"./lib/decorators/timed":76,"./lib/decorators/unhandledRejection":77,"./lib/decorators/with":78}]},{},[1])(1)
|
20009 | }); |
\ | No newline at end of file |