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

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