@ywfe/fe-tools 1.2.1-beta.13 → 1.2.1-beta.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,6 +60,1983 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
60
60
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
61
61
  };
62
62
 
63
+ var global$1 = (typeof global !== "undefined" ? global :
64
+ typeof self !== "undefined" ? self :
65
+ typeof window !== "undefined" ? window : {});
66
+
67
+ var lookup = [];
68
+ var revLookup = [];
69
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
70
+ var inited = false;
71
+ function init () {
72
+ inited = true;
73
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
74
+ for (var i = 0, len = code.length; i < len; ++i) {
75
+ lookup[i] = code[i];
76
+ revLookup[code.charCodeAt(i)] = i;
77
+ }
78
+
79
+ revLookup['-'.charCodeAt(0)] = 62;
80
+ revLookup['_'.charCodeAt(0)] = 63;
81
+ }
82
+
83
+ function toByteArray (b64) {
84
+ if (!inited) {
85
+ init();
86
+ }
87
+ var i, j, l, tmp, placeHolders, arr;
88
+ var len = b64.length;
89
+
90
+ if (len % 4 > 0) {
91
+ throw new Error('Invalid string. Length must be a multiple of 4')
92
+ }
93
+
94
+ // the number of equal signs (place holders)
95
+ // if there are two placeholders, than the two characters before it
96
+ // represent one byte
97
+ // if there is only one, then the three characters before it represent 2 bytes
98
+ // this is just a cheap hack to not do indexOf twice
99
+ placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
100
+
101
+ // base64 is 4/3 + up to two characters of the original data
102
+ arr = new Arr(len * 3 / 4 - placeHolders);
103
+
104
+ // if there are placeholders, only get up to the last complete 4 chars
105
+ l = placeHolders > 0 ? len - 4 : len;
106
+
107
+ var L = 0;
108
+
109
+ for (i = 0, j = 0; i < l; i += 4, j += 3) {
110
+ tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
111
+ arr[L++] = (tmp >> 16) & 0xFF;
112
+ arr[L++] = (tmp >> 8) & 0xFF;
113
+ arr[L++] = tmp & 0xFF;
114
+ }
115
+
116
+ if (placeHolders === 2) {
117
+ tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
118
+ arr[L++] = tmp & 0xFF;
119
+ } else if (placeHolders === 1) {
120
+ tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
121
+ arr[L++] = (tmp >> 8) & 0xFF;
122
+ arr[L++] = tmp & 0xFF;
123
+ }
124
+
125
+ return arr
126
+ }
127
+
128
+ function tripletToBase64 (num) {
129
+ return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
130
+ }
131
+
132
+ function encodeChunk (uint8, start, end) {
133
+ var tmp;
134
+ var output = [];
135
+ for (var i = start; i < end; i += 3) {
136
+ tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
137
+ output.push(tripletToBase64(tmp));
138
+ }
139
+ return output.join('')
140
+ }
141
+
142
+ function fromByteArray (uint8) {
143
+ if (!inited) {
144
+ init();
145
+ }
146
+ var tmp;
147
+ var len = uint8.length;
148
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
149
+ var output = '';
150
+ var parts = [];
151
+ var maxChunkLength = 16383; // must be multiple of 3
152
+
153
+ // go through the array every three bytes, we'll deal with trailing stuff later
154
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
155
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
156
+ }
157
+
158
+ // pad the end with zeros, but make sure to not forget the extra bytes
159
+ if (extraBytes === 1) {
160
+ tmp = uint8[len - 1];
161
+ output += lookup[tmp >> 2];
162
+ output += lookup[(tmp << 4) & 0x3F];
163
+ output += '==';
164
+ } else if (extraBytes === 2) {
165
+ tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
166
+ output += lookup[tmp >> 10];
167
+ output += lookup[(tmp >> 4) & 0x3F];
168
+ output += lookup[(tmp << 2) & 0x3F];
169
+ output += '=';
170
+ }
171
+
172
+ parts.push(output);
173
+
174
+ return parts.join('')
175
+ }
176
+
177
+ function read (buffer, offset, isLE, mLen, nBytes) {
178
+ var e, m;
179
+ var eLen = nBytes * 8 - mLen - 1;
180
+ var eMax = (1 << eLen) - 1;
181
+ var eBias = eMax >> 1;
182
+ var nBits = -7;
183
+ var i = isLE ? (nBytes - 1) : 0;
184
+ var d = isLE ? -1 : 1;
185
+ var s = buffer[offset + i];
186
+
187
+ i += d;
188
+
189
+ e = s & ((1 << (-nBits)) - 1);
190
+ s >>= (-nBits);
191
+ nBits += eLen;
192
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
193
+
194
+ m = e & ((1 << (-nBits)) - 1);
195
+ e >>= (-nBits);
196
+ nBits += mLen;
197
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
198
+
199
+ if (e === 0) {
200
+ e = 1 - eBias;
201
+ } else if (e === eMax) {
202
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
203
+ } else {
204
+ m = m + Math.pow(2, mLen);
205
+ e = e - eBias;
206
+ }
207
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
208
+ }
209
+
210
+ function write (buffer, value, offset, isLE, mLen, nBytes) {
211
+ var e, m, c;
212
+ var eLen = nBytes * 8 - mLen - 1;
213
+ var eMax = (1 << eLen) - 1;
214
+ var eBias = eMax >> 1;
215
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
216
+ var i = isLE ? 0 : (nBytes - 1);
217
+ var d = isLE ? 1 : -1;
218
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
219
+
220
+ value = Math.abs(value);
221
+
222
+ if (isNaN(value) || value === Infinity) {
223
+ m = isNaN(value) ? 1 : 0;
224
+ e = eMax;
225
+ } else {
226
+ e = Math.floor(Math.log(value) / Math.LN2);
227
+ if (value * (c = Math.pow(2, -e)) < 1) {
228
+ e--;
229
+ c *= 2;
230
+ }
231
+ if (e + eBias >= 1) {
232
+ value += rt / c;
233
+ } else {
234
+ value += rt * Math.pow(2, 1 - eBias);
235
+ }
236
+ if (value * c >= 2) {
237
+ e++;
238
+ c /= 2;
239
+ }
240
+
241
+ if (e + eBias >= eMax) {
242
+ m = 0;
243
+ e = eMax;
244
+ } else if (e + eBias >= 1) {
245
+ m = (value * c - 1) * Math.pow(2, mLen);
246
+ e = e + eBias;
247
+ } else {
248
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
249
+ e = 0;
250
+ }
251
+ }
252
+
253
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
254
+
255
+ e = (e << mLen) | m;
256
+ eLen += mLen;
257
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
258
+
259
+ buffer[offset + i - d] |= s * 128;
260
+ }
261
+
262
+ var toString = {}.toString;
263
+
264
+ var isArray = Array.isArray || function (arr) {
265
+ return toString.call(arr) == '[object Array]';
266
+ };
267
+
268
+ /*!
269
+ * The buffer module from node.js, for the browser.
270
+ *
271
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
272
+ * @license MIT
273
+ */
274
+
275
+ var INSPECT_MAX_BYTES = 50;
276
+
277
+ /**
278
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
279
+ * === true Use Uint8Array implementation (fastest)
280
+ * === false Use Object implementation (most compatible, even IE6)
281
+ *
282
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
283
+ * Opera 11.6+, iOS 4.2+.
284
+ *
285
+ * Due to various browser bugs, sometimes the Object implementation will be used even
286
+ * when the browser supports typed arrays.
287
+ *
288
+ * Note:
289
+ *
290
+ * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
291
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
292
+ *
293
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
294
+ *
295
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
296
+ * incorrect length in some situations.
297
+
298
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
299
+ * get the Object implementation, which is slower but behaves correctly.
300
+ */
301
+ Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
302
+ ? global$1.TYPED_ARRAY_SUPPORT
303
+ : true;
304
+
305
+ /*
306
+ * Export kMaxLength after typed array support is determined.
307
+ */
308
+ kMaxLength();
309
+
310
+ function kMaxLength () {
311
+ return Buffer.TYPED_ARRAY_SUPPORT
312
+ ? 0x7fffffff
313
+ : 0x3fffffff
314
+ }
315
+
316
+ function createBuffer (that, length) {
317
+ if (kMaxLength() < length) {
318
+ throw new RangeError('Invalid typed array length')
319
+ }
320
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
321
+ // Return an augmented `Uint8Array` instance, for best performance
322
+ that = new Uint8Array(length);
323
+ that.__proto__ = Buffer.prototype;
324
+ } else {
325
+ // Fallback: Return an object instance of the Buffer class
326
+ if (that === null) {
327
+ that = new Buffer(length);
328
+ }
329
+ that.length = length;
330
+ }
331
+
332
+ return that
333
+ }
334
+
335
+ /**
336
+ * The Buffer constructor returns instances of `Uint8Array` that have their
337
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
338
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
339
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
340
+ * returns a single octet.
341
+ *
342
+ * The `Uint8Array` prototype remains unmodified.
343
+ */
344
+
345
+ function Buffer (arg, encodingOrOffset, length) {
346
+ if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
347
+ return new Buffer(arg, encodingOrOffset, length)
348
+ }
349
+
350
+ // Common case.
351
+ if (typeof arg === 'number') {
352
+ if (typeof encodingOrOffset === 'string') {
353
+ throw new Error(
354
+ 'If encoding is specified then the first argument must be a string'
355
+ )
356
+ }
357
+ return allocUnsafe(this, arg)
358
+ }
359
+ return from(this, arg, encodingOrOffset, length)
360
+ }
361
+
362
+ Buffer.poolSize = 8192; // not used by this implementation
363
+
364
+ // TODO: Legacy, not needed anymore. Remove in next major version.
365
+ Buffer._augment = function (arr) {
366
+ arr.__proto__ = Buffer.prototype;
367
+ return arr
368
+ };
369
+
370
+ function from (that, value, encodingOrOffset, length) {
371
+ if (typeof value === 'number') {
372
+ throw new TypeError('"value" argument must not be a number')
373
+ }
374
+
375
+ if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
376
+ return fromArrayBuffer(that, value, encodingOrOffset, length)
377
+ }
378
+
379
+ if (typeof value === 'string') {
380
+ return fromString(that, value, encodingOrOffset)
381
+ }
382
+
383
+ return fromObject(that, value)
384
+ }
385
+
386
+ /**
387
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
388
+ * if value is a number.
389
+ * Buffer.from(str[, encoding])
390
+ * Buffer.from(array)
391
+ * Buffer.from(buffer)
392
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
393
+ **/
394
+ Buffer.from = function (value, encodingOrOffset, length) {
395
+ return from(null, value, encodingOrOffset, length)
396
+ };
397
+
398
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
399
+ Buffer.prototype.__proto__ = Uint8Array.prototype;
400
+ Buffer.__proto__ = Uint8Array;
401
+ }
402
+
403
+ function assertSize (size) {
404
+ if (typeof size !== 'number') {
405
+ throw new TypeError('"size" argument must be a number')
406
+ } else if (size < 0) {
407
+ throw new RangeError('"size" argument must not be negative')
408
+ }
409
+ }
410
+
411
+ function alloc (that, size, fill, encoding) {
412
+ assertSize(size);
413
+ if (size <= 0) {
414
+ return createBuffer(that, size)
415
+ }
416
+ if (fill !== undefined) {
417
+ // Only pay attention to encoding if it's a string. This
418
+ // prevents accidentally sending in a number that would
419
+ // be interpretted as a start offset.
420
+ return typeof encoding === 'string'
421
+ ? createBuffer(that, size).fill(fill, encoding)
422
+ : createBuffer(that, size).fill(fill)
423
+ }
424
+ return createBuffer(that, size)
425
+ }
426
+
427
+ /**
428
+ * Creates a new filled Buffer instance.
429
+ * alloc(size[, fill[, encoding]])
430
+ **/
431
+ Buffer.alloc = function (size, fill, encoding) {
432
+ return alloc(null, size, fill, encoding)
433
+ };
434
+
435
+ function allocUnsafe (that, size) {
436
+ assertSize(size);
437
+ that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
438
+ if (!Buffer.TYPED_ARRAY_SUPPORT) {
439
+ for (var i = 0; i < size; ++i) {
440
+ that[i] = 0;
441
+ }
442
+ }
443
+ return that
444
+ }
445
+
446
+ /**
447
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
448
+ * */
449
+ Buffer.allocUnsafe = function (size) {
450
+ return allocUnsafe(null, size)
451
+ };
452
+ /**
453
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
454
+ */
455
+ Buffer.allocUnsafeSlow = function (size) {
456
+ return allocUnsafe(null, size)
457
+ };
458
+
459
+ function fromString (that, string, encoding) {
460
+ if (typeof encoding !== 'string' || encoding === '') {
461
+ encoding = 'utf8';
462
+ }
463
+
464
+ if (!Buffer.isEncoding(encoding)) {
465
+ throw new TypeError('"encoding" must be a valid string encoding')
466
+ }
467
+
468
+ var length = byteLength(string, encoding) | 0;
469
+ that = createBuffer(that, length);
470
+
471
+ var actual = that.write(string, encoding);
472
+
473
+ if (actual !== length) {
474
+ // Writing a hex string, for example, that contains invalid characters will
475
+ // cause everything after the first invalid character to be ignored. (e.g.
476
+ // 'abxxcd' will be treated as 'ab')
477
+ that = that.slice(0, actual);
478
+ }
479
+
480
+ return that
481
+ }
482
+
483
+ function fromArrayLike (that, array) {
484
+ var length = array.length < 0 ? 0 : checked(array.length) | 0;
485
+ that = createBuffer(that, length);
486
+ for (var i = 0; i < length; i += 1) {
487
+ that[i] = array[i] & 255;
488
+ }
489
+ return that
490
+ }
491
+
492
+ function fromArrayBuffer (that, array, byteOffset, length) {
493
+ array.byteLength; // this throws if `array` is not a valid ArrayBuffer
494
+
495
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
496
+ throw new RangeError('\'offset\' is out of bounds')
497
+ }
498
+
499
+ if (array.byteLength < byteOffset + (length || 0)) {
500
+ throw new RangeError('\'length\' is out of bounds')
501
+ }
502
+
503
+ if (byteOffset === undefined && length === undefined) {
504
+ array = new Uint8Array(array);
505
+ } else if (length === undefined) {
506
+ array = new Uint8Array(array, byteOffset);
507
+ } else {
508
+ array = new Uint8Array(array, byteOffset, length);
509
+ }
510
+
511
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
512
+ // Return an augmented `Uint8Array` instance, for best performance
513
+ that = array;
514
+ that.__proto__ = Buffer.prototype;
515
+ } else {
516
+ // Fallback: Return an object instance of the Buffer class
517
+ that = fromArrayLike(that, array);
518
+ }
519
+ return that
520
+ }
521
+
522
+ function fromObject (that, obj) {
523
+ if (internalIsBuffer(obj)) {
524
+ var len = checked(obj.length) | 0;
525
+ that = createBuffer(that, len);
526
+
527
+ if (that.length === 0) {
528
+ return that
529
+ }
530
+
531
+ obj.copy(that, 0, 0, len);
532
+ return that
533
+ }
534
+
535
+ if (obj) {
536
+ if ((typeof ArrayBuffer !== 'undefined' &&
537
+ obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
538
+ if (typeof obj.length !== 'number' || isnan(obj.length)) {
539
+ return createBuffer(that, 0)
540
+ }
541
+ return fromArrayLike(that, obj)
542
+ }
543
+
544
+ if (obj.type === 'Buffer' && isArray(obj.data)) {
545
+ return fromArrayLike(that, obj.data)
546
+ }
547
+ }
548
+
549
+ throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
550
+ }
551
+
552
+ function checked (length) {
553
+ // Note: cannot use `length < kMaxLength()` here because that fails when
554
+ // length is NaN (which is otherwise coerced to zero.)
555
+ if (length >= kMaxLength()) {
556
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
557
+ 'size: 0x' + kMaxLength().toString(16) + ' bytes')
558
+ }
559
+ return length | 0
560
+ }
561
+ Buffer.isBuffer = isBuffer;
562
+ function internalIsBuffer (b) {
563
+ return !!(b != null && b._isBuffer)
564
+ }
565
+
566
+ Buffer.compare = function compare (a, b) {
567
+ if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
568
+ throw new TypeError('Arguments must be Buffers')
569
+ }
570
+
571
+ if (a === b) return 0
572
+
573
+ var x = a.length;
574
+ var y = b.length;
575
+
576
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
577
+ if (a[i] !== b[i]) {
578
+ x = a[i];
579
+ y = b[i];
580
+ break
581
+ }
582
+ }
583
+
584
+ if (x < y) return -1
585
+ if (y < x) return 1
586
+ return 0
587
+ };
588
+
589
+ Buffer.isEncoding = function isEncoding (encoding) {
590
+ switch (String(encoding).toLowerCase()) {
591
+ case 'hex':
592
+ case 'utf8':
593
+ case 'utf-8':
594
+ case 'ascii':
595
+ case 'latin1':
596
+ case 'binary':
597
+ case 'base64':
598
+ case 'ucs2':
599
+ case 'ucs-2':
600
+ case 'utf16le':
601
+ case 'utf-16le':
602
+ return true
603
+ default:
604
+ return false
605
+ }
606
+ };
607
+
608
+ Buffer.concat = function concat (list, length) {
609
+ if (!isArray(list)) {
610
+ throw new TypeError('"list" argument must be an Array of Buffers')
611
+ }
612
+
613
+ if (list.length === 0) {
614
+ return Buffer.alloc(0)
615
+ }
616
+
617
+ var i;
618
+ if (length === undefined) {
619
+ length = 0;
620
+ for (i = 0; i < list.length; ++i) {
621
+ length += list[i].length;
622
+ }
623
+ }
624
+
625
+ var buffer = Buffer.allocUnsafe(length);
626
+ var pos = 0;
627
+ for (i = 0; i < list.length; ++i) {
628
+ var buf = list[i];
629
+ if (!internalIsBuffer(buf)) {
630
+ throw new TypeError('"list" argument must be an Array of Buffers')
631
+ }
632
+ buf.copy(buffer, pos);
633
+ pos += buf.length;
634
+ }
635
+ return buffer
636
+ };
637
+
638
+ function byteLength (string, encoding) {
639
+ if (internalIsBuffer(string)) {
640
+ return string.length
641
+ }
642
+ if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
643
+ (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
644
+ return string.byteLength
645
+ }
646
+ if (typeof string !== 'string') {
647
+ string = '' + string;
648
+ }
649
+
650
+ var len = string.length;
651
+ if (len === 0) return 0
652
+
653
+ // Use a for loop to avoid recursion
654
+ var loweredCase = false;
655
+ for (;;) {
656
+ switch (encoding) {
657
+ case 'ascii':
658
+ case 'latin1':
659
+ case 'binary':
660
+ return len
661
+ case 'utf8':
662
+ case 'utf-8':
663
+ case undefined:
664
+ return utf8ToBytes(string).length
665
+ case 'ucs2':
666
+ case 'ucs-2':
667
+ case 'utf16le':
668
+ case 'utf-16le':
669
+ return len * 2
670
+ case 'hex':
671
+ return len >>> 1
672
+ case 'base64':
673
+ return base64ToBytes(string).length
674
+ default:
675
+ if (loweredCase) return utf8ToBytes(string).length // assume utf8
676
+ encoding = ('' + encoding).toLowerCase();
677
+ loweredCase = true;
678
+ }
679
+ }
680
+ }
681
+ Buffer.byteLength = byteLength;
682
+
683
+ function slowToString (encoding, start, end) {
684
+ var loweredCase = false;
685
+
686
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
687
+ // property of a typed array.
688
+
689
+ // This behaves neither like String nor Uint8Array in that we set start/end
690
+ // to their upper/lower bounds if the value passed is out of range.
691
+ // undefined is handled specially as per ECMA-262 6th Edition,
692
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
693
+ if (start === undefined || start < 0) {
694
+ start = 0;
695
+ }
696
+ // Return early if start > this.length. Done here to prevent potential uint32
697
+ // coercion fail below.
698
+ if (start > this.length) {
699
+ return ''
700
+ }
701
+
702
+ if (end === undefined || end > this.length) {
703
+ end = this.length;
704
+ }
705
+
706
+ if (end <= 0) {
707
+ return ''
708
+ }
709
+
710
+ // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
711
+ end >>>= 0;
712
+ start >>>= 0;
713
+
714
+ if (end <= start) {
715
+ return ''
716
+ }
717
+
718
+ if (!encoding) encoding = 'utf8';
719
+
720
+ while (true) {
721
+ switch (encoding) {
722
+ case 'hex':
723
+ return hexSlice(this, start, end)
724
+
725
+ case 'utf8':
726
+ case 'utf-8':
727
+ return utf8Slice(this, start, end)
728
+
729
+ case 'ascii':
730
+ return asciiSlice(this, start, end)
731
+
732
+ case 'latin1':
733
+ case 'binary':
734
+ return latin1Slice(this, start, end)
735
+
736
+ case 'base64':
737
+ return base64Slice(this, start, end)
738
+
739
+ case 'ucs2':
740
+ case 'ucs-2':
741
+ case 'utf16le':
742
+ case 'utf-16le':
743
+ return utf16leSlice(this, start, end)
744
+
745
+ default:
746
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
747
+ encoding = (encoding + '').toLowerCase();
748
+ loweredCase = true;
749
+ }
750
+ }
751
+ }
752
+
753
+ // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
754
+ // Buffer instances.
755
+ Buffer.prototype._isBuffer = true;
756
+
757
+ function swap (b, n, m) {
758
+ var i = b[n];
759
+ b[n] = b[m];
760
+ b[m] = i;
761
+ }
762
+
763
+ Buffer.prototype.swap16 = function swap16 () {
764
+ var len = this.length;
765
+ if (len % 2 !== 0) {
766
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
767
+ }
768
+ for (var i = 0; i < len; i += 2) {
769
+ swap(this, i, i + 1);
770
+ }
771
+ return this
772
+ };
773
+
774
+ Buffer.prototype.swap32 = function swap32 () {
775
+ var len = this.length;
776
+ if (len % 4 !== 0) {
777
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
778
+ }
779
+ for (var i = 0; i < len; i += 4) {
780
+ swap(this, i, i + 3);
781
+ swap(this, i + 1, i + 2);
782
+ }
783
+ return this
784
+ };
785
+
786
+ Buffer.prototype.swap64 = function swap64 () {
787
+ var len = this.length;
788
+ if (len % 8 !== 0) {
789
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
790
+ }
791
+ for (var i = 0; i < len; i += 8) {
792
+ swap(this, i, i + 7);
793
+ swap(this, i + 1, i + 6);
794
+ swap(this, i + 2, i + 5);
795
+ swap(this, i + 3, i + 4);
796
+ }
797
+ return this
798
+ };
799
+
800
+ Buffer.prototype.toString = function toString () {
801
+ var length = this.length | 0;
802
+ if (length === 0) return ''
803
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
804
+ return slowToString.apply(this, arguments)
805
+ };
806
+
807
+ Buffer.prototype.equals = function equals (b) {
808
+ if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
809
+ if (this === b) return true
810
+ return Buffer.compare(this, b) === 0
811
+ };
812
+
813
+ Buffer.prototype.inspect = function inspect () {
814
+ var str = '';
815
+ var max = INSPECT_MAX_BYTES;
816
+ if (this.length > 0) {
817
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
818
+ if (this.length > max) str += ' ... ';
819
+ }
820
+ return '<Buffer ' + str + '>'
821
+ };
822
+
823
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
824
+ if (!internalIsBuffer(target)) {
825
+ throw new TypeError('Argument must be a Buffer')
826
+ }
827
+
828
+ if (start === undefined) {
829
+ start = 0;
830
+ }
831
+ if (end === undefined) {
832
+ end = target ? target.length : 0;
833
+ }
834
+ if (thisStart === undefined) {
835
+ thisStart = 0;
836
+ }
837
+ if (thisEnd === undefined) {
838
+ thisEnd = this.length;
839
+ }
840
+
841
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
842
+ throw new RangeError('out of range index')
843
+ }
844
+
845
+ if (thisStart >= thisEnd && start >= end) {
846
+ return 0
847
+ }
848
+ if (thisStart >= thisEnd) {
849
+ return -1
850
+ }
851
+ if (start >= end) {
852
+ return 1
853
+ }
854
+
855
+ start >>>= 0;
856
+ end >>>= 0;
857
+ thisStart >>>= 0;
858
+ thisEnd >>>= 0;
859
+
860
+ if (this === target) return 0
861
+
862
+ var x = thisEnd - thisStart;
863
+ var y = end - start;
864
+ var len = Math.min(x, y);
865
+
866
+ var thisCopy = this.slice(thisStart, thisEnd);
867
+ var targetCopy = target.slice(start, end);
868
+
869
+ for (var i = 0; i < len; ++i) {
870
+ if (thisCopy[i] !== targetCopy[i]) {
871
+ x = thisCopy[i];
872
+ y = targetCopy[i];
873
+ break
874
+ }
875
+ }
876
+
877
+ if (x < y) return -1
878
+ if (y < x) return 1
879
+ return 0
880
+ };
881
+
882
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
883
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
884
+ //
885
+ // Arguments:
886
+ // - buffer - a Buffer to search
887
+ // - val - a string, Buffer, or number
888
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
889
+ // - encoding - an optional encoding, relevant is val is a string
890
+ // - dir - true for indexOf, false for lastIndexOf
891
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
892
+ // Empty buffer means no match
893
+ if (buffer.length === 0) return -1
894
+
895
+ // Normalize byteOffset
896
+ if (typeof byteOffset === 'string') {
897
+ encoding = byteOffset;
898
+ byteOffset = 0;
899
+ } else if (byteOffset > 0x7fffffff) {
900
+ byteOffset = 0x7fffffff;
901
+ } else if (byteOffset < -0x80000000) {
902
+ byteOffset = -0x80000000;
903
+ }
904
+ byteOffset = +byteOffset; // Coerce to Number.
905
+ if (isNaN(byteOffset)) {
906
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
907
+ byteOffset = dir ? 0 : (buffer.length - 1);
908
+ }
909
+
910
+ // Normalize byteOffset: negative offsets start from the end of the buffer
911
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
912
+ if (byteOffset >= buffer.length) {
913
+ if (dir) return -1
914
+ else byteOffset = buffer.length - 1;
915
+ } else if (byteOffset < 0) {
916
+ if (dir) byteOffset = 0;
917
+ else return -1
918
+ }
919
+
920
+ // Normalize val
921
+ if (typeof val === 'string') {
922
+ val = Buffer.from(val, encoding);
923
+ }
924
+
925
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
926
+ if (internalIsBuffer(val)) {
927
+ // Special case: looking for empty string/buffer always fails
928
+ if (val.length === 0) {
929
+ return -1
930
+ }
931
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
932
+ } else if (typeof val === 'number') {
933
+ val = val & 0xFF; // Search for a byte value [0-255]
934
+ if (Buffer.TYPED_ARRAY_SUPPORT &&
935
+ typeof Uint8Array.prototype.indexOf === 'function') {
936
+ if (dir) {
937
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
938
+ } else {
939
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
940
+ }
941
+ }
942
+ return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
943
+ }
944
+
945
+ throw new TypeError('val must be string, number or Buffer')
946
+ }
947
+
948
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
949
+ var indexSize = 1;
950
+ var arrLength = arr.length;
951
+ var valLength = val.length;
952
+
953
+ if (encoding !== undefined) {
954
+ encoding = String(encoding).toLowerCase();
955
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
956
+ encoding === 'utf16le' || encoding === 'utf-16le') {
957
+ if (arr.length < 2 || val.length < 2) {
958
+ return -1
959
+ }
960
+ indexSize = 2;
961
+ arrLength /= 2;
962
+ valLength /= 2;
963
+ byteOffset /= 2;
964
+ }
965
+ }
966
+
967
+ function read (buf, i) {
968
+ if (indexSize === 1) {
969
+ return buf[i]
970
+ } else {
971
+ return buf.readUInt16BE(i * indexSize)
972
+ }
973
+ }
974
+
975
+ var i;
976
+ if (dir) {
977
+ var foundIndex = -1;
978
+ for (i = byteOffset; i < arrLength; i++) {
979
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
980
+ if (foundIndex === -1) foundIndex = i;
981
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
982
+ } else {
983
+ if (foundIndex !== -1) i -= i - foundIndex;
984
+ foundIndex = -1;
985
+ }
986
+ }
987
+ } else {
988
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
989
+ for (i = byteOffset; i >= 0; i--) {
990
+ var found = true;
991
+ for (var j = 0; j < valLength; j++) {
992
+ if (read(arr, i + j) !== read(val, j)) {
993
+ found = false;
994
+ break
995
+ }
996
+ }
997
+ if (found) return i
998
+ }
999
+ }
1000
+
1001
+ return -1
1002
+ }
1003
+
1004
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1005
+ return this.indexOf(val, byteOffset, encoding) !== -1
1006
+ };
1007
+
1008
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1009
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1010
+ };
1011
+
1012
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1013
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1014
+ };
1015
+
1016
+ function hexWrite (buf, string, offset, length) {
1017
+ offset = Number(offset) || 0;
1018
+ var remaining = buf.length - offset;
1019
+ if (!length) {
1020
+ length = remaining;
1021
+ } else {
1022
+ length = Number(length);
1023
+ if (length > remaining) {
1024
+ length = remaining;
1025
+ }
1026
+ }
1027
+
1028
+ // must be an even number of digits
1029
+ var strLen = string.length;
1030
+ if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
1031
+
1032
+ if (length > strLen / 2) {
1033
+ length = strLen / 2;
1034
+ }
1035
+ for (var i = 0; i < length; ++i) {
1036
+ var parsed = parseInt(string.substr(i * 2, 2), 16);
1037
+ if (isNaN(parsed)) return i
1038
+ buf[offset + i] = parsed;
1039
+ }
1040
+ return i
1041
+ }
1042
+
1043
+ function utf8Write (buf, string, offset, length) {
1044
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1045
+ }
1046
+
1047
+ function asciiWrite (buf, string, offset, length) {
1048
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
1049
+ }
1050
+
1051
+ function latin1Write (buf, string, offset, length) {
1052
+ return asciiWrite(buf, string, offset, length)
1053
+ }
1054
+
1055
+ function base64Write (buf, string, offset, length) {
1056
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
1057
+ }
1058
+
1059
+ function ucs2Write (buf, string, offset, length) {
1060
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1061
+ }
1062
+
1063
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
1064
+ // Buffer#write(string)
1065
+ if (offset === undefined) {
1066
+ encoding = 'utf8';
1067
+ length = this.length;
1068
+ offset = 0;
1069
+ // Buffer#write(string, encoding)
1070
+ } else if (length === undefined && typeof offset === 'string') {
1071
+ encoding = offset;
1072
+ length = this.length;
1073
+ offset = 0;
1074
+ // Buffer#write(string, offset[, length][, encoding])
1075
+ } else if (isFinite(offset)) {
1076
+ offset = offset | 0;
1077
+ if (isFinite(length)) {
1078
+ length = length | 0;
1079
+ if (encoding === undefined) encoding = 'utf8';
1080
+ } else {
1081
+ encoding = length;
1082
+ length = undefined;
1083
+ }
1084
+ // legacy write(string, encoding, offset, length) - remove in v0.13
1085
+ } else {
1086
+ throw new Error(
1087
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1088
+ )
1089
+ }
1090
+
1091
+ var remaining = this.length - offset;
1092
+ if (length === undefined || length > remaining) length = remaining;
1093
+
1094
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1095
+ throw new RangeError('Attempt to write outside buffer bounds')
1096
+ }
1097
+
1098
+ if (!encoding) encoding = 'utf8';
1099
+
1100
+ var loweredCase = false;
1101
+ for (;;) {
1102
+ switch (encoding) {
1103
+ case 'hex':
1104
+ return hexWrite(this, string, offset, length)
1105
+
1106
+ case 'utf8':
1107
+ case 'utf-8':
1108
+ return utf8Write(this, string, offset, length)
1109
+
1110
+ case 'ascii':
1111
+ return asciiWrite(this, string, offset, length)
1112
+
1113
+ case 'latin1':
1114
+ case 'binary':
1115
+ return latin1Write(this, string, offset, length)
1116
+
1117
+ case 'base64':
1118
+ // Warning: maxLength not taken into account in base64Write
1119
+ return base64Write(this, string, offset, length)
1120
+
1121
+ case 'ucs2':
1122
+ case 'ucs-2':
1123
+ case 'utf16le':
1124
+ case 'utf-16le':
1125
+ return ucs2Write(this, string, offset, length)
1126
+
1127
+ default:
1128
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1129
+ encoding = ('' + encoding).toLowerCase();
1130
+ loweredCase = true;
1131
+ }
1132
+ }
1133
+ };
1134
+
1135
+ Buffer.prototype.toJSON = function toJSON () {
1136
+ return {
1137
+ type: 'Buffer',
1138
+ data: Array.prototype.slice.call(this._arr || this, 0)
1139
+ }
1140
+ };
1141
+
1142
+ function base64Slice (buf, start, end) {
1143
+ if (start === 0 && end === buf.length) {
1144
+ return fromByteArray(buf)
1145
+ } else {
1146
+ return fromByteArray(buf.slice(start, end))
1147
+ }
1148
+ }
1149
+
1150
+ function utf8Slice (buf, start, end) {
1151
+ end = Math.min(buf.length, end);
1152
+ var res = [];
1153
+
1154
+ var i = start;
1155
+ while (i < end) {
1156
+ var firstByte = buf[i];
1157
+ var codePoint = null;
1158
+ var bytesPerSequence = (firstByte > 0xEF) ? 4
1159
+ : (firstByte > 0xDF) ? 3
1160
+ : (firstByte > 0xBF) ? 2
1161
+ : 1;
1162
+
1163
+ if (i + bytesPerSequence <= end) {
1164
+ var secondByte, thirdByte, fourthByte, tempCodePoint;
1165
+
1166
+ switch (bytesPerSequence) {
1167
+ case 1:
1168
+ if (firstByte < 0x80) {
1169
+ codePoint = firstByte;
1170
+ }
1171
+ break
1172
+ case 2:
1173
+ secondByte = buf[i + 1];
1174
+ if ((secondByte & 0xC0) === 0x80) {
1175
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1176
+ if (tempCodePoint > 0x7F) {
1177
+ codePoint = tempCodePoint;
1178
+ }
1179
+ }
1180
+ break
1181
+ case 3:
1182
+ secondByte = buf[i + 1];
1183
+ thirdByte = buf[i + 2];
1184
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1185
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1186
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1187
+ codePoint = tempCodePoint;
1188
+ }
1189
+ }
1190
+ break
1191
+ case 4:
1192
+ secondByte = buf[i + 1];
1193
+ thirdByte = buf[i + 2];
1194
+ fourthByte = buf[i + 3];
1195
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1196
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1197
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1198
+ codePoint = tempCodePoint;
1199
+ }
1200
+ }
1201
+ }
1202
+ }
1203
+
1204
+ if (codePoint === null) {
1205
+ // we did not generate a valid codePoint so insert a
1206
+ // replacement char (U+FFFD) and advance only 1 byte
1207
+ codePoint = 0xFFFD;
1208
+ bytesPerSequence = 1;
1209
+ } else if (codePoint > 0xFFFF) {
1210
+ // encode to utf16 (surrogate pair dance)
1211
+ codePoint -= 0x10000;
1212
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1213
+ codePoint = 0xDC00 | codePoint & 0x3FF;
1214
+ }
1215
+
1216
+ res.push(codePoint);
1217
+ i += bytesPerSequence;
1218
+ }
1219
+
1220
+ return decodeCodePointsArray(res)
1221
+ }
1222
+
1223
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1224
+ // the lowest limit is Chrome, with 0x10000 args.
1225
+ // We go 1 magnitude less, for safety
1226
+ var MAX_ARGUMENTS_LENGTH = 0x1000;
1227
+
1228
+ function decodeCodePointsArray (codePoints) {
1229
+ var len = codePoints.length;
1230
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1231
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1232
+ }
1233
+
1234
+ // Decode in chunks to avoid "call stack size exceeded".
1235
+ var res = '';
1236
+ var i = 0;
1237
+ while (i < len) {
1238
+ res += String.fromCharCode.apply(
1239
+ String,
1240
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1241
+ );
1242
+ }
1243
+ return res
1244
+ }
1245
+
1246
+ function asciiSlice (buf, start, end) {
1247
+ var ret = '';
1248
+ end = Math.min(buf.length, end);
1249
+
1250
+ for (var i = start; i < end; ++i) {
1251
+ ret += String.fromCharCode(buf[i] & 0x7F);
1252
+ }
1253
+ return ret
1254
+ }
1255
+
1256
+ function latin1Slice (buf, start, end) {
1257
+ var ret = '';
1258
+ end = Math.min(buf.length, end);
1259
+
1260
+ for (var i = start; i < end; ++i) {
1261
+ ret += String.fromCharCode(buf[i]);
1262
+ }
1263
+ return ret
1264
+ }
1265
+
1266
+ function hexSlice (buf, start, end) {
1267
+ var len = buf.length;
1268
+
1269
+ if (!start || start < 0) start = 0;
1270
+ if (!end || end < 0 || end > len) end = len;
1271
+
1272
+ var out = '';
1273
+ for (var i = start; i < end; ++i) {
1274
+ out += toHex(buf[i]);
1275
+ }
1276
+ return out
1277
+ }
1278
+
1279
+ function utf16leSlice (buf, start, end) {
1280
+ var bytes = buf.slice(start, end);
1281
+ var res = '';
1282
+ for (var i = 0; i < bytes.length; i += 2) {
1283
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1284
+ }
1285
+ return res
1286
+ }
1287
+
1288
+ Buffer.prototype.slice = function slice (start, end) {
1289
+ var len = this.length;
1290
+ start = ~~start;
1291
+ end = end === undefined ? len : ~~end;
1292
+
1293
+ if (start < 0) {
1294
+ start += len;
1295
+ if (start < 0) start = 0;
1296
+ } else if (start > len) {
1297
+ start = len;
1298
+ }
1299
+
1300
+ if (end < 0) {
1301
+ end += len;
1302
+ if (end < 0) end = 0;
1303
+ } else if (end > len) {
1304
+ end = len;
1305
+ }
1306
+
1307
+ if (end < start) end = start;
1308
+
1309
+ var newBuf;
1310
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1311
+ newBuf = this.subarray(start, end);
1312
+ newBuf.__proto__ = Buffer.prototype;
1313
+ } else {
1314
+ var sliceLen = end - start;
1315
+ newBuf = new Buffer(sliceLen, undefined);
1316
+ for (var i = 0; i < sliceLen; ++i) {
1317
+ newBuf[i] = this[i + start];
1318
+ }
1319
+ }
1320
+
1321
+ return newBuf
1322
+ };
1323
+
1324
+ /*
1325
+ * Need to make sure that buffer isn't trying to write out of bounds.
1326
+ */
1327
+ function checkOffset (offset, ext, length) {
1328
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1329
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1330
+ }
1331
+
1332
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1333
+ offset = offset | 0;
1334
+ byteLength = byteLength | 0;
1335
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1336
+
1337
+ var val = this[offset];
1338
+ var mul = 1;
1339
+ var i = 0;
1340
+ while (++i < byteLength && (mul *= 0x100)) {
1341
+ val += this[offset + i] * mul;
1342
+ }
1343
+
1344
+ return val
1345
+ };
1346
+
1347
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1348
+ offset = offset | 0;
1349
+ byteLength = byteLength | 0;
1350
+ if (!noAssert) {
1351
+ checkOffset(offset, byteLength, this.length);
1352
+ }
1353
+
1354
+ var val = this[offset + --byteLength];
1355
+ var mul = 1;
1356
+ while (byteLength > 0 && (mul *= 0x100)) {
1357
+ val += this[offset + --byteLength] * mul;
1358
+ }
1359
+
1360
+ return val
1361
+ };
1362
+
1363
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1364
+ if (!noAssert) checkOffset(offset, 1, this.length);
1365
+ return this[offset]
1366
+ };
1367
+
1368
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1369
+ if (!noAssert) checkOffset(offset, 2, this.length);
1370
+ return this[offset] | (this[offset + 1] << 8)
1371
+ };
1372
+
1373
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1374
+ if (!noAssert) checkOffset(offset, 2, this.length);
1375
+ return (this[offset] << 8) | this[offset + 1]
1376
+ };
1377
+
1378
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1379
+ if (!noAssert) checkOffset(offset, 4, this.length);
1380
+
1381
+ return ((this[offset]) |
1382
+ (this[offset + 1] << 8) |
1383
+ (this[offset + 2] << 16)) +
1384
+ (this[offset + 3] * 0x1000000)
1385
+ };
1386
+
1387
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1388
+ if (!noAssert) checkOffset(offset, 4, this.length);
1389
+
1390
+ return (this[offset] * 0x1000000) +
1391
+ ((this[offset + 1] << 16) |
1392
+ (this[offset + 2] << 8) |
1393
+ this[offset + 3])
1394
+ };
1395
+
1396
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1397
+ offset = offset | 0;
1398
+ byteLength = byteLength | 0;
1399
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1400
+
1401
+ var val = this[offset];
1402
+ var mul = 1;
1403
+ var i = 0;
1404
+ while (++i < byteLength && (mul *= 0x100)) {
1405
+ val += this[offset + i] * mul;
1406
+ }
1407
+ mul *= 0x80;
1408
+
1409
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1410
+
1411
+ return val
1412
+ };
1413
+
1414
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1415
+ offset = offset | 0;
1416
+ byteLength = byteLength | 0;
1417
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1418
+
1419
+ var i = byteLength;
1420
+ var mul = 1;
1421
+ var val = this[offset + --i];
1422
+ while (i > 0 && (mul *= 0x100)) {
1423
+ val += this[offset + --i] * mul;
1424
+ }
1425
+ mul *= 0x80;
1426
+
1427
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1428
+
1429
+ return val
1430
+ };
1431
+
1432
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1433
+ if (!noAssert) checkOffset(offset, 1, this.length);
1434
+ if (!(this[offset] & 0x80)) return (this[offset])
1435
+ return ((0xff - this[offset] + 1) * -1)
1436
+ };
1437
+
1438
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1439
+ if (!noAssert) checkOffset(offset, 2, this.length);
1440
+ var val = this[offset] | (this[offset + 1] << 8);
1441
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1442
+ };
1443
+
1444
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1445
+ if (!noAssert) checkOffset(offset, 2, this.length);
1446
+ var val = this[offset + 1] | (this[offset] << 8);
1447
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1448
+ };
1449
+
1450
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1451
+ if (!noAssert) checkOffset(offset, 4, this.length);
1452
+
1453
+ return (this[offset]) |
1454
+ (this[offset + 1] << 8) |
1455
+ (this[offset + 2] << 16) |
1456
+ (this[offset + 3] << 24)
1457
+ };
1458
+
1459
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1460
+ if (!noAssert) checkOffset(offset, 4, this.length);
1461
+
1462
+ return (this[offset] << 24) |
1463
+ (this[offset + 1] << 16) |
1464
+ (this[offset + 2] << 8) |
1465
+ (this[offset + 3])
1466
+ };
1467
+
1468
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1469
+ if (!noAssert) checkOffset(offset, 4, this.length);
1470
+ return read(this, offset, true, 23, 4)
1471
+ };
1472
+
1473
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1474
+ if (!noAssert) checkOffset(offset, 4, this.length);
1475
+ return read(this, offset, false, 23, 4)
1476
+ };
1477
+
1478
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1479
+ if (!noAssert) checkOffset(offset, 8, this.length);
1480
+ return read(this, offset, true, 52, 8)
1481
+ };
1482
+
1483
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1484
+ if (!noAssert) checkOffset(offset, 8, this.length);
1485
+ return read(this, offset, false, 52, 8)
1486
+ };
1487
+
1488
+ function checkInt (buf, value, offset, ext, max, min) {
1489
+ if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1490
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1491
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1492
+ }
1493
+
1494
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1495
+ value = +value;
1496
+ offset = offset | 0;
1497
+ byteLength = byteLength | 0;
1498
+ if (!noAssert) {
1499
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1500
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1501
+ }
1502
+
1503
+ var mul = 1;
1504
+ var i = 0;
1505
+ this[offset] = value & 0xFF;
1506
+ while (++i < byteLength && (mul *= 0x100)) {
1507
+ this[offset + i] = (value / mul) & 0xFF;
1508
+ }
1509
+
1510
+ return offset + byteLength
1511
+ };
1512
+
1513
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1514
+ value = +value;
1515
+ offset = offset | 0;
1516
+ byteLength = byteLength | 0;
1517
+ if (!noAssert) {
1518
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1519
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1520
+ }
1521
+
1522
+ var i = byteLength - 1;
1523
+ var mul = 1;
1524
+ this[offset + i] = value & 0xFF;
1525
+ while (--i >= 0 && (mul *= 0x100)) {
1526
+ this[offset + i] = (value / mul) & 0xFF;
1527
+ }
1528
+
1529
+ return offset + byteLength
1530
+ };
1531
+
1532
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1533
+ value = +value;
1534
+ offset = offset | 0;
1535
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1536
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1537
+ this[offset] = (value & 0xff);
1538
+ return offset + 1
1539
+ };
1540
+
1541
+ function objectWriteUInt16 (buf, value, offset, littleEndian) {
1542
+ if (value < 0) value = 0xffff + value + 1;
1543
+ for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1544
+ buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1545
+ (littleEndian ? i : 1 - i) * 8;
1546
+ }
1547
+ }
1548
+
1549
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1550
+ value = +value;
1551
+ offset = offset | 0;
1552
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1553
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1554
+ this[offset] = (value & 0xff);
1555
+ this[offset + 1] = (value >>> 8);
1556
+ } else {
1557
+ objectWriteUInt16(this, value, offset, true);
1558
+ }
1559
+ return offset + 2
1560
+ };
1561
+
1562
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1563
+ value = +value;
1564
+ offset = offset | 0;
1565
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1566
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1567
+ this[offset] = (value >>> 8);
1568
+ this[offset + 1] = (value & 0xff);
1569
+ } else {
1570
+ objectWriteUInt16(this, value, offset, false);
1571
+ }
1572
+ return offset + 2
1573
+ };
1574
+
1575
+ function objectWriteUInt32 (buf, value, offset, littleEndian) {
1576
+ if (value < 0) value = 0xffffffff + value + 1;
1577
+ for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1578
+ buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
1579
+ }
1580
+ }
1581
+
1582
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1583
+ value = +value;
1584
+ offset = offset | 0;
1585
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1586
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1587
+ this[offset + 3] = (value >>> 24);
1588
+ this[offset + 2] = (value >>> 16);
1589
+ this[offset + 1] = (value >>> 8);
1590
+ this[offset] = (value & 0xff);
1591
+ } else {
1592
+ objectWriteUInt32(this, value, offset, true);
1593
+ }
1594
+ return offset + 4
1595
+ };
1596
+
1597
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1598
+ value = +value;
1599
+ offset = offset | 0;
1600
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1601
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1602
+ this[offset] = (value >>> 24);
1603
+ this[offset + 1] = (value >>> 16);
1604
+ this[offset + 2] = (value >>> 8);
1605
+ this[offset + 3] = (value & 0xff);
1606
+ } else {
1607
+ objectWriteUInt32(this, value, offset, false);
1608
+ }
1609
+ return offset + 4
1610
+ };
1611
+
1612
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1613
+ value = +value;
1614
+ offset = offset | 0;
1615
+ if (!noAssert) {
1616
+ var limit = Math.pow(2, 8 * byteLength - 1);
1617
+
1618
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1619
+ }
1620
+
1621
+ var i = 0;
1622
+ var mul = 1;
1623
+ var sub = 0;
1624
+ this[offset] = value & 0xFF;
1625
+ while (++i < byteLength && (mul *= 0x100)) {
1626
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1627
+ sub = 1;
1628
+ }
1629
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1630
+ }
1631
+
1632
+ return offset + byteLength
1633
+ };
1634
+
1635
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1636
+ value = +value;
1637
+ offset = offset | 0;
1638
+ if (!noAssert) {
1639
+ var limit = Math.pow(2, 8 * byteLength - 1);
1640
+
1641
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1642
+ }
1643
+
1644
+ var i = byteLength - 1;
1645
+ var mul = 1;
1646
+ var sub = 0;
1647
+ this[offset + i] = value & 0xFF;
1648
+ while (--i >= 0 && (mul *= 0x100)) {
1649
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1650
+ sub = 1;
1651
+ }
1652
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1653
+ }
1654
+
1655
+ return offset + byteLength
1656
+ };
1657
+
1658
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1659
+ value = +value;
1660
+ offset = offset | 0;
1661
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
1662
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1663
+ if (value < 0) value = 0xff + value + 1;
1664
+ this[offset] = (value & 0xff);
1665
+ return offset + 1
1666
+ };
1667
+
1668
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1669
+ value = +value;
1670
+ offset = offset | 0;
1671
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1672
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1673
+ this[offset] = (value & 0xff);
1674
+ this[offset + 1] = (value >>> 8);
1675
+ } else {
1676
+ objectWriteUInt16(this, value, offset, true);
1677
+ }
1678
+ return offset + 2
1679
+ };
1680
+
1681
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1682
+ value = +value;
1683
+ offset = offset | 0;
1684
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
1685
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1686
+ this[offset] = (value >>> 8);
1687
+ this[offset + 1] = (value & 0xff);
1688
+ } else {
1689
+ objectWriteUInt16(this, value, offset, false);
1690
+ }
1691
+ return offset + 2
1692
+ };
1693
+
1694
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1695
+ value = +value;
1696
+ offset = offset | 0;
1697
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1698
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1699
+ this[offset] = (value & 0xff);
1700
+ this[offset + 1] = (value >>> 8);
1701
+ this[offset + 2] = (value >>> 16);
1702
+ this[offset + 3] = (value >>> 24);
1703
+ } else {
1704
+ objectWriteUInt32(this, value, offset, true);
1705
+ }
1706
+ return offset + 4
1707
+ };
1708
+
1709
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1710
+ value = +value;
1711
+ offset = offset | 0;
1712
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
1713
+ if (value < 0) value = 0xffffffff + value + 1;
1714
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1715
+ this[offset] = (value >>> 24);
1716
+ this[offset + 1] = (value >>> 16);
1717
+ this[offset + 2] = (value >>> 8);
1718
+ this[offset + 3] = (value & 0xff);
1719
+ } else {
1720
+ objectWriteUInt32(this, value, offset, false);
1721
+ }
1722
+ return offset + 4
1723
+ };
1724
+
1725
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
1726
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1727
+ if (offset < 0) throw new RangeError('Index out of range')
1728
+ }
1729
+
1730
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
1731
+ if (!noAssert) {
1732
+ checkIEEE754(buf, value, offset, 4);
1733
+ }
1734
+ write(buf, value, offset, littleEndian, 23, 4);
1735
+ return offset + 4
1736
+ }
1737
+
1738
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1739
+ return writeFloat(this, value, offset, true, noAssert)
1740
+ };
1741
+
1742
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1743
+ return writeFloat(this, value, offset, false, noAssert)
1744
+ };
1745
+
1746
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
1747
+ if (!noAssert) {
1748
+ checkIEEE754(buf, value, offset, 8);
1749
+ }
1750
+ write(buf, value, offset, littleEndian, 52, 8);
1751
+ return offset + 8
1752
+ }
1753
+
1754
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1755
+ return writeDouble(this, value, offset, true, noAssert)
1756
+ };
1757
+
1758
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1759
+ return writeDouble(this, value, offset, false, noAssert)
1760
+ };
1761
+
1762
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1763
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1764
+ if (!start) start = 0;
1765
+ if (!end && end !== 0) end = this.length;
1766
+ if (targetStart >= target.length) targetStart = target.length;
1767
+ if (!targetStart) targetStart = 0;
1768
+ if (end > 0 && end < start) end = start;
1769
+
1770
+ // Copy 0 bytes; we're done
1771
+ if (end === start) return 0
1772
+ if (target.length === 0 || this.length === 0) return 0
1773
+
1774
+ // Fatal error conditions
1775
+ if (targetStart < 0) {
1776
+ throw new RangeError('targetStart out of bounds')
1777
+ }
1778
+ if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1779
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
1780
+
1781
+ // Are we oob?
1782
+ if (end > this.length) end = this.length;
1783
+ if (target.length - targetStart < end - start) {
1784
+ end = target.length - targetStart + start;
1785
+ }
1786
+
1787
+ var len = end - start;
1788
+ var i;
1789
+
1790
+ if (this === target && start < targetStart && targetStart < end) {
1791
+ // descending copy from end
1792
+ for (i = len - 1; i >= 0; --i) {
1793
+ target[i + targetStart] = this[i + start];
1794
+ }
1795
+ } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1796
+ // ascending copy from start
1797
+ for (i = 0; i < len; ++i) {
1798
+ target[i + targetStart] = this[i + start];
1799
+ }
1800
+ } else {
1801
+ Uint8Array.prototype.set.call(
1802
+ target,
1803
+ this.subarray(start, start + len),
1804
+ targetStart
1805
+ );
1806
+ }
1807
+
1808
+ return len
1809
+ };
1810
+
1811
+ // Usage:
1812
+ // buffer.fill(number[, offset[, end]])
1813
+ // buffer.fill(buffer[, offset[, end]])
1814
+ // buffer.fill(string[, offset[, end]][, encoding])
1815
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1816
+ // Handle string cases:
1817
+ if (typeof val === 'string') {
1818
+ if (typeof start === 'string') {
1819
+ encoding = start;
1820
+ start = 0;
1821
+ end = this.length;
1822
+ } else if (typeof end === 'string') {
1823
+ encoding = end;
1824
+ end = this.length;
1825
+ }
1826
+ if (val.length === 1) {
1827
+ var code = val.charCodeAt(0);
1828
+ if (code < 256) {
1829
+ val = code;
1830
+ }
1831
+ }
1832
+ if (encoding !== undefined && typeof encoding !== 'string') {
1833
+ throw new TypeError('encoding must be a string')
1834
+ }
1835
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1836
+ throw new TypeError('Unknown encoding: ' + encoding)
1837
+ }
1838
+ } else if (typeof val === 'number') {
1839
+ val = val & 255;
1840
+ }
1841
+
1842
+ // Invalid ranges are not set to a default, so can range check early.
1843
+ if (start < 0 || this.length < start || this.length < end) {
1844
+ throw new RangeError('Out of range index')
1845
+ }
1846
+
1847
+ if (end <= start) {
1848
+ return this
1849
+ }
1850
+
1851
+ start = start >>> 0;
1852
+ end = end === undefined ? this.length : end >>> 0;
1853
+
1854
+ if (!val) val = 0;
1855
+
1856
+ var i;
1857
+ if (typeof val === 'number') {
1858
+ for (i = start; i < end; ++i) {
1859
+ this[i] = val;
1860
+ }
1861
+ } else {
1862
+ var bytes = internalIsBuffer(val)
1863
+ ? val
1864
+ : utf8ToBytes(new Buffer(val, encoding).toString());
1865
+ var len = bytes.length;
1866
+ for (i = 0; i < end - start; ++i) {
1867
+ this[i + start] = bytes[i % len];
1868
+ }
1869
+ }
1870
+
1871
+ return this
1872
+ };
1873
+
1874
+ // HELPER FUNCTIONS
1875
+ // ================
1876
+
1877
+ var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
1878
+
1879
+ function base64clean (str) {
1880
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
1881
+ str = stringtrim(str).replace(INVALID_BASE64_RE, '');
1882
+ // Node converts strings with length < 2 to ''
1883
+ if (str.length < 2) return ''
1884
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1885
+ while (str.length % 4 !== 0) {
1886
+ str = str + '=';
1887
+ }
1888
+ return str
1889
+ }
1890
+
1891
+ function stringtrim (str) {
1892
+ if (str.trim) return str.trim()
1893
+ return str.replace(/^\s+|\s+$/g, '')
1894
+ }
1895
+
1896
+ function toHex (n) {
1897
+ if (n < 16) return '0' + n.toString(16)
1898
+ return n.toString(16)
1899
+ }
1900
+
1901
+ function utf8ToBytes (string, units) {
1902
+ units = units || Infinity;
1903
+ var codePoint;
1904
+ var length = string.length;
1905
+ var leadSurrogate = null;
1906
+ var bytes = [];
1907
+
1908
+ for (var i = 0; i < length; ++i) {
1909
+ codePoint = string.charCodeAt(i);
1910
+
1911
+ // is surrogate component
1912
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
1913
+ // last char was a lead
1914
+ if (!leadSurrogate) {
1915
+ // no lead yet
1916
+ if (codePoint > 0xDBFF) {
1917
+ // unexpected trail
1918
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1919
+ continue
1920
+ } else if (i + 1 === length) {
1921
+ // unpaired lead
1922
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1923
+ continue
1924
+ }
1925
+
1926
+ // valid lead
1927
+ leadSurrogate = codePoint;
1928
+
1929
+ continue
1930
+ }
1931
+
1932
+ // 2 leads in a row
1933
+ if (codePoint < 0xDC00) {
1934
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1935
+ leadSurrogate = codePoint;
1936
+ continue
1937
+ }
1938
+
1939
+ // valid surrogate pair
1940
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
1941
+ } else if (leadSurrogate) {
1942
+ // valid bmp char, but last char was a lead
1943
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1944
+ }
1945
+
1946
+ leadSurrogate = null;
1947
+
1948
+ // encode utf8
1949
+ if (codePoint < 0x80) {
1950
+ if ((units -= 1) < 0) break
1951
+ bytes.push(codePoint);
1952
+ } else if (codePoint < 0x800) {
1953
+ if ((units -= 2) < 0) break
1954
+ bytes.push(
1955
+ codePoint >> 0x6 | 0xC0,
1956
+ codePoint & 0x3F | 0x80
1957
+ );
1958
+ } else if (codePoint < 0x10000) {
1959
+ if ((units -= 3) < 0) break
1960
+ bytes.push(
1961
+ codePoint >> 0xC | 0xE0,
1962
+ codePoint >> 0x6 & 0x3F | 0x80,
1963
+ codePoint & 0x3F | 0x80
1964
+ );
1965
+ } else if (codePoint < 0x110000) {
1966
+ if ((units -= 4) < 0) break
1967
+ bytes.push(
1968
+ codePoint >> 0x12 | 0xF0,
1969
+ codePoint >> 0xC & 0x3F | 0x80,
1970
+ codePoint >> 0x6 & 0x3F | 0x80,
1971
+ codePoint & 0x3F | 0x80
1972
+ );
1973
+ } else {
1974
+ throw new Error('Invalid code point')
1975
+ }
1976
+ }
1977
+
1978
+ return bytes
1979
+ }
1980
+
1981
+ function asciiToBytes (str) {
1982
+ var byteArray = [];
1983
+ for (var i = 0; i < str.length; ++i) {
1984
+ // Node's code seems to be doing this and not & 0x7F..
1985
+ byteArray.push(str.charCodeAt(i) & 0xFF);
1986
+ }
1987
+ return byteArray
1988
+ }
1989
+
1990
+ function utf16leToBytes (str, units) {
1991
+ var c, hi, lo;
1992
+ var byteArray = [];
1993
+ for (var i = 0; i < str.length; ++i) {
1994
+ if ((units -= 2) < 0) break
1995
+
1996
+ c = str.charCodeAt(i);
1997
+ hi = c >> 8;
1998
+ lo = c % 256;
1999
+ byteArray.push(lo);
2000
+ byteArray.push(hi);
2001
+ }
2002
+
2003
+ return byteArray
2004
+ }
2005
+
2006
+
2007
+ function base64ToBytes (str) {
2008
+ return toByteArray(base64clean(str))
2009
+ }
2010
+
2011
+ function blitBuffer (src, dst, offset, length) {
2012
+ for (var i = 0; i < length; ++i) {
2013
+ if ((i + offset >= dst.length) || (i >= src.length)) break
2014
+ dst[i + offset] = src[i];
2015
+ }
2016
+ return i
2017
+ }
2018
+
2019
+ function isnan (val) {
2020
+ return val !== val // eslint-disable-line no-self-compare
2021
+ }
2022
+
2023
+
2024
+ // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
2025
+ // The _isBuffer check is for Safari 5-7 support, because it's missing
2026
+ // Object.prototype.constructor. Remove this eventually
2027
+ function isBuffer(obj) {
2028
+ return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
2029
+ }
2030
+
2031
+ function isFastBuffer (obj) {
2032
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
2033
+ }
2034
+
2035
+ // For Node v0.10 support. Remove this eventually.
2036
+ function isSlowBuffer (obj) {
2037
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
2038
+ }
2039
+
63
2040
  function getAugmentedNamespace(n) {
64
2041
  if (n.__esModule) return n;
65
2042
  var f = n.default;
@@ -8706,29 +10683,29 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8706
10683
 
8707
10684
  function request(_a) {
8708
10685
  return __awaiter(this, arguments, void 0, function (_b) {
8709
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
10686
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8710
10687
  var input = _b.input;
8711
10688
  return __generator(this, function (_c) {
8712
10689
  switch (_c.label) {
8713
10690
  case 0:
8714
- method = input.method || 'GET';
10691
+ method = input.method || "GET";
8715
10692
  basePathMap = new Map([
8716
- ['prod', 'https://gateway.ywwl.com'],
8717
- ['test', 'https://test-gateway.ywwl.com'],
8718
- ['test2', 'https://test2-gateway.ywwl.com'],
8719
- ['dev', 'https://dev-gateway.ywwl.com'],
10693
+ ["prod", "https://gateway.ywwl.com"],
10694
+ ["test", "https://test-gateway.ywwl.com"],
10695
+ ["test2", "https://test2-gateway.ywwl.com"],
10696
+ ["dev", "https://dev-gateway.ywwl.com"],
8720
10697
  ]);
8721
10698
  getBasePath = function () {
8722
- var env = '{{env}}';
10699
+ var env = "{{env}}";
8723
10700
  return basePathMap.get(env);
8724
10701
  };
8725
10702
  isValidURL = function (url) {
8726
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8727
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8728
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8729
- '(\\:\\d+)?(\\/[-a-z\\d%_.&#126;+]*)*' + // port and path
8730
- '(\\?[;&a-z\\d%_.&#126;+=-]*)?' + // query string
8731
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
10703
+ var pattern = new RegExp("^(https?:\\/\\/)?" + // protocol
10704
+ "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
10705
+ "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
10706
+ "(\\:\\d+)?(\\/[-a-z\\d%_.&#126;+]*)*" + // port and path
10707
+ "(\\?[;&a-z\\d%_.&#126;+=-]*)?" + // query string
10708
+ "(\\#[-a-z\\d_]*)?$", "i"); // fragment locator
8732
10709
  return !!pattern.test(url);
8733
10710
  };
8734
10711
  prefix = getBasePath();
@@ -8736,54 +10713,43 @@ function request(_a) {
8736
10713
  fetchOption = {
8737
10714
  method: method,
8738
10715
  headers: {
8739
- 'Content-type': 'application/json',
8740
- 'x-token': '{{token}}',
10716
+ "Content-type": "application/json",
10717
+ "x-token": "{{token}}",
8741
10718
  },
8742
10719
  };
8743
- if (method.toUpperCase() === 'POST') {
10720
+ if (method.toUpperCase() === "POST") {
8744
10721
  fetchOption.body = JSON.stringify(input.params);
8745
10722
  }
8746
- else if (method.toUpperCase() === 'GET') {
10723
+ else if (method.toUpperCase() === "GET") {
8747
10724
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8748
10725
  }
8749
10726
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8750
10727
  case 1:
8751
- res = _c.sent();
8752
- return [2 /*return*/, res.json()];
10728
+ response = _c.sent();
10729
+ if (!response.ok) {
10730
+ message = "An error has occured: ".concat(response.status);
10731
+ return [2 /*return*/, { success: false, message: message }];
10732
+ }
10733
+ return [4 /*yield*/, response.json()];
10734
+ case 2:
10735
+ result = _c.sent();
10736
+ return [2 /*return*/, result];
8753
10737
  }
8754
10738
  });
8755
10739
  });
8756
10740
  }
8757
10741
 
8758
- function userInputToJson(_a) {
8759
- return __awaiter(this, arguments, void 0, function (_b) {
8760
- var res, result;
8761
- var input = _b.input;
8762
- return __generator(this, function (_c) {
8763
- switch (_c.label) {
8764
- case 0:
8765
- console.log("input", input);
8766
- return [4 /*yield*/, request({
8767
- input: {
8768
- url: "https://fc-typechat.ywwl.com/userInputToJson",
8769
- method: "GET",
8770
- params: input,
8771
- },
8772
- })];
8773
- case 1:
8774
- res = _c.sent();
8775
- if (res.success) {
8776
- result = res.data;
8777
- return [2 /*return*/, result.success ? result.data : result];
8778
- }
8779
- else {
8780
- return [2 /*return*/, res.success ? res.data : res];
8781
- }
8782
- }
8783
- });
8784
- });
10742
+ function JSON2String(_a) {
10743
+ var input = _a.input;
10744
+ var _b = input.data, data = _b === void 0 ? {} : _b;
10745
+ try {
10746
+ return "```json" + JSON.stringify(data) + "json```";
10747
+ }
10748
+ catch (error) {
10749
+ return "```json" + JSON.stringify({}) + "json```";
10750
+ }
8785
10751
  }
8786
10752
 
10753
+ exports.JSON2String = JSON2String;
8787
10754
  exports.request = request;
8788
- exports.userInputToJson = userInputToJson;
8789
10755
  //# sourceMappingURL=ywfe-tools.cjs.map