tiny-essentials 1.1.1 → 1.2.0

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.
Files changed (42) hide show
  1. package/README.md +3 -1
  2. package/dist/TinyBasicsEs.js +2784 -0
  3. package/dist/TinyBasicsEs.min.js +2 -0
  4. package/dist/TinyBasicsEs.min.js.LICENSE.txt +8 -0
  5. package/dist/TinyCertCrypto.js +76229 -0
  6. package/dist/TinyCertCrypto.min.js +2 -0
  7. package/dist/TinyCertCrypto.min.js.LICENSE.txt +10 -0
  8. package/dist/TinyCrypto.js +48115 -0
  9. package/dist/TinyCrypto.min.js +2 -0
  10. package/dist/TinyCrypto.min.js.LICENSE.txt +10 -0
  11. package/dist/TinyEssentials.js +77599 -0
  12. package/dist/TinyEssentials.min.js +2 -1
  13. package/dist/TinyEssentials.min.js.LICENSE.txt +10 -0
  14. package/dist/TinyLevelUp.js +173 -0
  15. package/dist/TinyLevelUp.min.js +1 -0
  16. package/dist/v1/basics/index.cjs +27 -0
  17. package/dist/v1/basics/index.d.mts +17 -0
  18. package/dist/v1/basics/index.mjs +7 -0
  19. package/dist/v1/basics/objFilter.cjs +3 -1
  20. package/dist/v1/basics/objFilter.mjs +1 -0
  21. package/dist/v1/build/TinyCertCrypto.cjs +7 -0
  22. package/dist/v1/build/TinyCertCrypto.d.mts +2 -0
  23. package/dist/v1/build/TinyCertCrypto.mjs +2 -0
  24. package/dist/v1/build/TinyCrypto.cjs +7 -0
  25. package/dist/v1/build/TinyCrypto.d.mts +2 -0
  26. package/dist/v1/build/TinyCrypto.mjs +2 -0
  27. package/dist/v1/build/TinyLevelUp.cjs +7 -0
  28. package/dist/v1/build/TinyLevelUp.d.mts +2 -0
  29. package/dist/v1/build/TinyLevelUp.mjs +2 -0
  30. package/dist/v1/index.cjs +2 -0
  31. package/dist/v1/index.d.mts +2 -1
  32. package/dist/v1/index.mjs +2 -1
  33. package/dist/v1/libs/TinyCertCrypto.cjs +514 -0
  34. package/dist/v1/libs/TinyCertCrypto.d.mts +191 -0
  35. package/dist/v1/libs/TinyCertCrypto.mjs +450 -0
  36. package/dist/v1/libs/TinyCrypto.cjs +21 -12
  37. package/dist/v1/libs/TinyCrypto.d.mts +1 -0
  38. package/dist/v1/libs/TinyCrypto.mjs +10 -1
  39. package/docs/README.md +2 -0
  40. package/docs/libs/TinyCertCrypto.md +202 -0
  41. package/package.json +11 -6
  42. package/webpack.config.mjs +69 -0
@@ -0,0 +1,2784 @@
1
+ /******/ (() => { // webpackBootstrap
2
+ /******/ var __webpack_modules__ = ({
3
+
4
+ /***/ 251:
5
+ /***/ ((__unused_webpack_module, exports) => {
6
+
7
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
8
+ exports.read = function (buffer, offset, isLE, mLen, nBytes) {
9
+ var e, m
10
+ var eLen = (nBytes * 8) - mLen - 1
11
+ var eMax = (1 << eLen) - 1
12
+ var eBias = eMax >> 1
13
+ var nBits = -7
14
+ var i = isLE ? (nBytes - 1) : 0
15
+ var d = isLE ? -1 : 1
16
+ var s = buffer[offset + i]
17
+
18
+ i += d
19
+
20
+ e = s & ((1 << (-nBits)) - 1)
21
+ s >>= (-nBits)
22
+ nBits += eLen
23
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
24
+
25
+ m = e & ((1 << (-nBits)) - 1)
26
+ e >>= (-nBits)
27
+ nBits += mLen
28
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
29
+
30
+ if (e === 0) {
31
+ e = 1 - eBias
32
+ } else if (e === eMax) {
33
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
34
+ } else {
35
+ m = m + Math.pow(2, mLen)
36
+ e = e - eBias
37
+ }
38
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
39
+ }
40
+
41
+ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
42
+ var e, m, c
43
+ var eLen = (nBytes * 8) - mLen - 1
44
+ var eMax = (1 << eLen) - 1
45
+ var eBias = eMax >> 1
46
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
47
+ var i = isLE ? 0 : (nBytes - 1)
48
+ var d = isLE ? 1 : -1
49
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
50
+
51
+ value = Math.abs(value)
52
+
53
+ if (isNaN(value) || value === Infinity) {
54
+ m = isNaN(value) ? 1 : 0
55
+ e = eMax
56
+ } else {
57
+ e = Math.floor(Math.log(value) / Math.LN2)
58
+ if (value * (c = Math.pow(2, -e)) < 1) {
59
+ e--
60
+ c *= 2
61
+ }
62
+ if (e + eBias >= 1) {
63
+ value += rt / c
64
+ } else {
65
+ value += rt * Math.pow(2, 1 - eBias)
66
+ }
67
+ if (value * c >= 2) {
68
+ e++
69
+ c /= 2
70
+ }
71
+
72
+ if (e + eBias >= eMax) {
73
+ m = 0
74
+ e = eMax
75
+ } else if (e + eBias >= 1) {
76
+ m = ((value * c) - 1) * Math.pow(2, mLen)
77
+ e = e + eBias
78
+ } else {
79
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
80
+ e = 0
81
+ }
82
+ }
83
+
84
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
85
+
86
+ e = (e << mLen) | m
87
+ eLen += mLen
88
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
89
+
90
+ buffer[offset + i - d] |= s * 128
91
+ }
92
+
93
+
94
+ /***/ }),
95
+
96
+ /***/ 287:
97
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
98
+
99
+ "use strict";
100
+ var __webpack_unused_export__;
101
+ /*!
102
+ * The buffer module from node.js, for the browser.
103
+ *
104
+ * @author Feross Aboukhadijeh <https://feross.org>
105
+ * @license MIT
106
+ */
107
+ /* eslint-disable no-proto */
108
+
109
+
110
+
111
+ var base64 = __webpack_require__(526)
112
+ var ieee754 = __webpack_require__(251)
113
+ var customInspectSymbol =
114
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
115
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
116
+ : null
117
+
118
+ exports.hp = Buffer
119
+ __webpack_unused_export__ = SlowBuffer
120
+ exports.IS = 50
121
+
122
+ var K_MAX_LENGTH = 0x7fffffff
123
+ __webpack_unused_export__ = K_MAX_LENGTH
124
+
125
+ /**
126
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
127
+ * === true Use Uint8Array implementation (fastest)
128
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
129
+ * implementation (most compatible, even IE6)
130
+ *
131
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
132
+ * Opera 11.6+, iOS 4.2+.
133
+ *
134
+ * We report that the browser does not support typed arrays if the are not subclassable
135
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
136
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
137
+ * for __proto__ and has a buggy typed array implementation.
138
+ */
139
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
140
+
141
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
142
+ typeof console.error === 'function') {
143
+ console.error(
144
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
145
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
146
+ )
147
+ }
148
+
149
+ function typedArraySupport () {
150
+ // Can typed array instances can be augmented?
151
+ try {
152
+ var arr = new Uint8Array(1)
153
+ var proto = { foo: function () { return 42 } }
154
+ Object.setPrototypeOf(proto, Uint8Array.prototype)
155
+ Object.setPrototypeOf(arr, proto)
156
+ return arr.foo() === 42
157
+ } catch (e) {
158
+ return false
159
+ }
160
+ }
161
+
162
+ Object.defineProperty(Buffer.prototype, 'parent', {
163
+ enumerable: true,
164
+ get: function () {
165
+ if (!Buffer.isBuffer(this)) return undefined
166
+ return this.buffer
167
+ }
168
+ })
169
+
170
+ Object.defineProperty(Buffer.prototype, 'offset', {
171
+ enumerable: true,
172
+ get: function () {
173
+ if (!Buffer.isBuffer(this)) return undefined
174
+ return this.byteOffset
175
+ }
176
+ })
177
+
178
+ function createBuffer (length) {
179
+ if (length > K_MAX_LENGTH) {
180
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
181
+ }
182
+ // Return an augmented `Uint8Array` instance
183
+ var buf = new Uint8Array(length)
184
+ Object.setPrototypeOf(buf, Buffer.prototype)
185
+ return buf
186
+ }
187
+
188
+ /**
189
+ * The Buffer constructor returns instances of `Uint8Array` that have their
190
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
191
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
192
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
193
+ * returns a single octet.
194
+ *
195
+ * The `Uint8Array` prototype remains unmodified.
196
+ */
197
+
198
+ function Buffer (arg, encodingOrOffset, length) {
199
+ // Common case.
200
+ if (typeof arg === 'number') {
201
+ if (typeof encodingOrOffset === 'string') {
202
+ throw new TypeError(
203
+ 'The "string" argument must be of type string. Received type number'
204
+ )
205
+ }
206
+ return allocUnsafe(arg)
207
+ }
208
+ return from(arg, encodingOrOffset, length)
209
+ }
210
+
211
+ Buffer.poolSize = 8192 // not used by this implementation
212
+
213
+ function from (value, encodingOrOffset, length) {
214
+ if (typeof value === 'string') {
215
+ return fromString(value, encodingOrOffset)
216
+ }
217
+
218
+ if (ArrayBuffer.isView(value)) {
219
+ return fromArrayView(value)
220
+ }
221
+
222
+ if (value == null) {
223
+ throw new TypeError(
224
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
225
+ 'or Array-like Object. Received type ' + (typeof value)
226
+ )
227
+ }
228
+
229
+ if (isInstance(value, ArrayBuffer) ||
230
+ (value && isInstance(value.buffer, ArrayBuffer))) {
231
+ return fromArrayBuffer(value, encodingOrOffset, length)
232
+ }
233
+
234
+ if (typeof SharedArrayBuffer !== 'undefined' &&
235
+ (isInstance(value, SharedArrayBuffer) ||
236
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
237
+ return fromArrayBuffer(value, encodingOrOffset, length)
238
+ }
239
+
240
+ if (typeof value === 'number') {
241
+ throw new TypeError(
242
+ 'The "value" argument must not be of type number. Received type number'
243
+ )
244
+ }
245
+
246
+ var valueOf = value.valueOf && value.valueOf()
247
+ if (valueOf != null && valueOf !== value) {
248
+ return Buffer.from(valueOf, encodingOrOffset, length)
249
+ }
250
+
251
+ var b = fromObject(value)
252
+ if (b) return b
253
+
254
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
255
+ typeof value[Symbol.toPrimitive] === 'function') {
256
+ return Buffer.from(
257
+ value[Symbol.toPrimitive]('string'), encodingOrOffset, length
258
+ )
259
+ }
260
+
261
+ throw new TypeError(
262
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
263
+ 'or Array-like Object. Received type ' + (typeof value)
264
+ )
265
+ }
266
+
267
+ /**
268
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
269
+ * if value is a number.
270
+ * Buffer.from(str[, encoding])
271
+ * Buffer.from(array)
272
+ * Buffer.from(buffer)
273
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
274
+ **/
275
+ Buffer.from = function (value, encodingOrOffset, length) {
276
+ return from(value, encodingOrOffset, length)
277
+ }
278
+
279
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
280
+ // https://github.com/feross/buffer/pull/148
281
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
282
+ Object.setPrototypeOf(Buffer, Uint8Array)
283
+
284
+ function assertSize (size) {
285
+ if (typeof size !== 'number') {
286
+ throw new TypeError('"size" argument must be of type number')
287
+ } else if (size < 0) {
288
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
289
+ }
290
+ }
291
+
292
+ function alloc (size, fill, encoding) {
293
+ assertSize(size)
294
+ if (size <= 0) {
295
+ return createBuffer(size)
296
+ }
297
+ if (fill !== undefined) {
298
+ // Only pay attention to encoding if it's a string. This
299
+ // prevents accidentally sending in a number that would
300
+ // be interpreted as a start offset.
301
+ return typeof encoding === 'string'
302
+ ? createBuffer(size).fill(fill, encoding)
303
+ : createBuffer(size).fill(fill)
304
+ }
305
+ return createBuffer(size)
306
+ }
307
+
308
+ /**
309
+ * Creates a new filled Buffer instance.
310
+ * alloc(size[, fill[, encoding]])
311
+ **/
312
+ Buffer.alloc = function (size, fill, encoding) {
313
+ return alloc(size, fill, encoding)
314
+ }
315
+
316
+ function allocUnsafe (size) {
317
+ assertSize(size)
318
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
319
+ }
320
+
321
+ /**
322
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
323
+ * */
324
+ Buffer.allocUnsafe = function (size) {
325
+ return allocUnsafe(size)
326
+ }
327
+ /**
328
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
329
+ */
330
+ Buffer.allocUnsafeSlow = function (size) {
331
+ return allocUnsafe(size)
332
+ }
333
+
334
+ function fromString (string, encoding) {
335
+ if (typeof encoding !== 'string' || encoding === '') {
336
+ encoding = 'utf8'
337
+ }
338
+
339
+ if (!Buffer.isEncoding(encoding)) {
340
+ throw new TypeError('Unknown encoding: ' + encoding)
341
+ }
342
+
343
+ var length = byteLength(string, encoding) | 0
344
+ var buf = createBuffer(length)
345
+
346
+ var actual = buf.write(string, encoding)
347
+
348
+ if (actual !== length) {
349
+ // Writing a hex string, for example, that contains invalid characters will
350
+ // cause everything after the first invalid character to be ignored. (e.g.
351
+ // 'abxxcd' will be treated as 'ab')
352
+ buf = buf.slice(0, actual)
353
+ }
354
+
355
+ return buf
356
+ }
357
+
358
+ function fromArrayLike (array) {
359
+ var length = array.length < 0 ? 0 : checked(array.length) | 0
360
+ var buf = createBuffer(length)
361
+ for (var i = 0; i < length; i += 1) {
362
+ buf[i] = array[i] & 255
363
+ }
364
+ return buf
365
+ }
366
+
367
+ function fromArrayView (arrayView) {
368
+ if (isInstance(arrayView, Uint8Array)) {
369
+ var copy = new Uint8Array(arrayView)
370
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
371
+ }
372
+ return fromArrayLike(arrayView)
373
+ }
374
+
375
+ function fromArrayBuffer (array, byteOffset, length) {
376
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
377
+ throw new RangeError('"offset" is outside of buffer bounds')
378
+ }
379
+
380
+ if (array.byteLength < byteOffset + (length || 0)) {
381
+ throw new RangeError('"length" is outside of buffer bounds')
382
+ }
383
+
384
+ var buf
385
+ if (byteOffset === undefined && length === undefined) {
386
+ buf = new Uint8Array(array)
387
+ } else if (length === undefined) {
388
+ buf = new Uint8Array(array, byteOffset)
389
+ } else {
390
+ buf = new Uint8Array(array, byteOffset, length)
391
+ }
392
+
393
+ // Return an augmented `Uint8Array` instance
394
+ Object.setPrototypeOf(buf, Buffer.prototype)
395
+
396
+ return buf
397
+ }
398
+
399
+ function fromObject (obj) {
400
+ if (Buffer.isBuffer(obj)) {
401
+ var len = checked(obj.length) | 0
402
+ var buf = createBuffer(len)
403
+
404
+ if (buf.length === 0) {
405
+ return buf
406
+ }
407
+
408
+ obj.copy(buf, 0, 0, len)
409
+ return buf
410
+ }
411
+
412
+ if (obj.length !== undefined) {
413
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
414
+ return createBuffer(0)
415
+ }
416
+ return fromArrayLike(obj)
417
+ }
418
+
419
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
420
+ return fromArrayLike(obj.data)
421
+ }
422
+ }
423
+
424
+ function checked (length) {
425
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
426
+ // length is NaN (which is otherwise coerced to zero.)
427
+ if (length >= K_MAX_LENGTH) {
428
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
429
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
430
+ }
431
+ return length | 0
432
+ }
433
+
434
+ function SlowBuffer (length) {
435
+ if (+length != length) { // eslint-disable-line eqeqeq
436
+ length = 0
437
+ }
438
+ return Buffer.alloc(+length)
439
+ }
440
+
441
+ Buffer.isBuffer = function isBuffer (b) {
442
+ return b != null && b._isBuffer === true &&
443
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
444
+ }
445
+
446
+ Buffer.compare = function compare (a, b) {
447
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
448
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
449
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
450
+ throw new TypeError(
451
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
452
+ )
453
+ }
454
+
455
+ if (a === b) return 0
456
+
457
+ var x = a.length
458
+ var y = b.length
459
+
460
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
461
+ if (a[i] !== b[i]) {
462
+ x = a[i]
463
+ y = b[i]
464
+ break
465
+ }
466
+ }
467
+
468
+ if (x < y) return -1
469
+ if (y < x) return 1
470
+ return 0
471
+ }
472
+
473
+ Buffer.isEncoding = function isEncoding (encoding) {
474
+ switch (String(encoding).toLowerCase()) {
475
+ case 'hex':
476
+ case 'utf8':
477
+ case 'utf-8':
478
+ case 'ascii':
479
+ case 'latin1':
480
+ case 'binary':
481
+ case 'base64':
482
+ case 'ucs2':
483
+ case 'ucs-2':
484
+ case 'utf16le':
485
+ case 'utf-16le':
486
+ return true
487
+ default:
488
+ return false
489
+ }
490
+ }
491
+
492
+ Buffer.concat = function concat (list, length) {
493
+ if (!Array.isArray(list)) {
494
+ throw new TypeError('"list" argument must be an Array of Buffers')
495
+ }
496
+
497
+ if (list.length === 0) {
498
+ return Buffer.alloc(0)
499
+ }
500
+
501
+ var i
502
+ if (length === undefined) {
503
+ length = 0
504
+ for (i = 0; i < list.length; ++i) {
505
+ length += list[i].length
506
+ }
507
+ }
508
+
509
+ var buffer = Buffer.allocUnsafe(length)
510
+ var pos = 0
511
+ for (i = 0; i < list.length; ++i) {
512
+ var buf = list[i]
513
+ if (isInstance(buf, Uint8Array)) {
514
+ if (pos + buf.length > buffer.length) {
515
+ Buffer.from(buf).copy(buffer, pos)
516
+ } else {
517
+ Uint8Array.prototype.set.call(
518
+ buffer,
519
+ buf,
520
+ pos
521
+ )
522
+ }
523
+ } else if (!Buffer.isBuffer(buf)) {
524
+ throw new TypeError('"list" argument must be an Array of Buffers')
525
+ } else {
526
+ buf.copy(buffer, pos)
527
+ }
528
+ pos += buf.length
529
+ }
530
+ return buffer
531
+ }
532
+
533
+ function byteLength (string, encoding) {
534
+ if (Buffer.isBuffer(string)) {
535
+ return string.length
536
+ }
537
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
538
+ return string.byteLength
539
+ }
540
+ if (typeof string !== 'string') {
541
+ throw new TypeError(
542
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
543
+ 'Received type ' + typeof string
544
+ )
545
+ }
546
+
547
+ var len = string.length
548
+ var mustMatch = (arguments.length > 2 && arguments[2] === true)
549
+ if (!mustMatch && len === 0) return 0
550
+
551
+ // Use a for loop to avoid recursion
552
+ var loweredCase = false
553
+ for (;;) {
554
+ switch (encoding) {
555
+ case 'ascii':
556
+ case 'latin1':
557
+ case 'binary':
558
+ return len
559
+ case 'utf8':
560
+ case 'utf-8':
561
+ return utf8ToBytes(string).length
562
+ case 'ucs2':
563
+ case 'ucs-2':
564
+ case 'utf16le':
565
+ case 'utf-16le':
566
+ return len * 2
567
+ case 'hex':
568
+ return len >>> 1
569
+ case 'base64':
570
+ return base64ToBytes(string).length
571
+ default:
572
+ if (loweredCase) {
573
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
574
+ }
575
+ encoding = ('' + encoding).toLowerCase()
576
+ loweredCase = true
577
+ }
578
+ }
579
+ }
580
+ Buffer.byteLength = byteLength
581
+
582
+ function slowToString (encoding, start, end) {
583
+ var loweredCase = false
584
+
585
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
586
+ // property of a typed array.
587
+
588
+ // This behaves neither like String nor Uint8Array in that we set start/end
589
+ // to their upper/lower bounds if the value passed is out of range.
590
+ // undefined is handled specially as per ECMA-262 6th Edition,
591
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
592
+ if (start === undefined || start < 0) {
593
+ start = 0
594
+ }
595
+ // Return early if start > this.length. Done here to prevent potential uint32
596
+ // coercion fail below.
597
+ if (start > this.length) {
598
+ return ''
599
+ }
600
+
601
+ if (end === undefined || end > this.length) {
602
+ end = this.length
603
+ }
604
+
605
+ if (end <= 0) {
606
+ return ''
607
+ }
608
+
609
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
610
+ end >>>= 0
611
+ start >>>= 0
612
+
613
+ if (end <= start) {
614
+ return ''
615
+ }
616
+
617
+ if (!encoding) encoding = 'utf8'
618
+
619
+ while (true) {
620
+ switch (encoding) {
621
+ case 'hex':
622
+ return hexSlice(this, start, end)
623
+
624
+ case 'utf8':
625
+ case 'utf-8':
626
+ return utf8Slice(this, start, end)
627
+
628
+ case 'ascii':
629
+ return asciiSlice(this, start, end)
630
+
631
+ case 'latin1':
632
+ case 'binary':
633
+ return latin1Slice(this, start, end)
634
+
635
+ case 'base64':
636
+ return base64Slice(this, start, end)
637
+
638
+ case 'ucs2':
639
+ case 'ucs-2':
640
+ case 'utf16le':
641
+ case 'utf-16le':
642
+ return utf16leSlice(this, start, end)
643
+
644
+ default:
645
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
646
+ encoding = (encoding + '').toLowerCase()
647
+ loweredCase = true
648
+ }
649
+ }
650
+ }
651
+
652
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
653
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
654
+ // reliably in a browserify context because there could be multiple different
655
+ // copies of the 'buffer' package in use. This method works even for Buffer
656
+ // instances that were created from another copy of the `buffer` package.
657
+ // See: https://github.com/feross/buffer/issues/154
658
+ Buffer.prototype._isBuffer = true
659
+
660
+ function swap (b, n, m) {
661
+ var i = b[n]
662
+ b[n] = b[m]
663
+ b[m] = i
664
+ }
665
+
666
+ Buffer.prototype.swap16 = function swap16 () {
667
+ var len = this.length
668
+ if (len % 2 !== 0) {
669
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
670
+ }
671
+ for (var i = 0; i < len; i += 2) {
672
+ swap(this, i, i + 1)
673
+ }
674
+ return this
675
+ }
676
+
677
+ Buffer.prototype.swap32 = function swap32 () {
678
+ var len = this.length
679
+ if (len % 4 !== 0) {
680
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
681
+ }
682
+ for (var i = 0; i < len; i += 4) {
683
+ swap(this, i, i + 3)
684
+ swap(this, i + 1, i + 2)
685
+ }
686
+ return this
687
+ }
688
+
689
+ Buffer.prototype.swap64 = function swap64 () {
690
+ var len = this.length
691
+ if (len % 8 !== 0) {
692
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
693
+ }
694
+ for (var i = 0; i < len; i += 8) {
695
+ swap(this, i, i + 7)
696
+ swap(this, i + 1, i + 6)
697
+ swap(this, i + 2, i + 5)
698
+ swap(this, i + 3, i + 4)
699
+ }
700
+ return this
701
+ }
702
+
703
+ Buffer.prototype.toString = function toString () {
704
+ var length = this.length
705
+ if (length === 0) return ''
706
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
707
+ return slowToString.apply(this, arguments)
708
+ }
709
+
710
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString
711
+
712
+ Buffer.prototype.equals = function equals (b) {
713
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
714
+ if (this === b) return true
715
+ return Buffer.compare(this, b) === 0
716
+ }
717
+
718
+ Buffer.prototype.inspect = function inspect () {
719
+ var str = ''
720
+ var max = exports.IS
721
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
722
+ if (this.length > max) str += ' ... '
723
+ return '<Buffer ' + str + '>'
724
+ }
725
+ if (customInspectSymbol) {
726
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
727
+ }
728
+
729
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
730
+ if (isInstance(target, Uint8Array)) {
731
+ target = Buffer.from(target, target.offset, target.byteLength)
732
+ }
733
+ if (!Buffer.isBuffer(target)) {
734
+ throw new TypeError(
735
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
736
+ 'Received type ' + (typeof target)
737
+ )
738
+ }
739
+
740
+ if (start === undefined) {
741
+ start = 0
742
+ }
743
+ if (end === undefined) {
744
+ end = target ? target.length : 0
745
+ }
746
+ if (thisStart === undefined) {
747
+ thisStart = 0
748
+ }
749
+ if (thisEnd === undefined) {
750
+ thisEnd = this.length
751
+ }
752
+
753
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
754
+ throw new RangeError('out of range index')
755
+ }
756
+
757
+ if (thisStart >= thisEnd && start >= end) {
758
+ return 0
759
+ }
760
+ if (thisStart >= thisEnd) {
761
+ return -1
762
+ }
763
+ if (start >= end) {
764
+ return 1
765
+ }
766
+
767
+ start >>>= 0
768
+ end >>>= 0
769
+ thisStart >>>= 0
770
+ thisEnd >>>= 0
771
+
772
+ if (this === target) return 0
773
+
774
+ var x = thisEnd - thisStart
775
+ var y = end - start
776
+ var len = Math.min(x, y)
777
+
778
+ var thisCopy = this.slice(thisStart, thisEnd)
779
+ var targetCopy = target.slice(start, end)
780
+
781
+ for (var i = 0; i < len; ++i) {
782
+ if (thisCopy[i] !== targetCopy[i]) {
783
+ x = thisCopy[i]
784
+ y = targetCopy[i]
785
+ break
786
+ }
787
+ }
788
+
789
+ if (x < y) return -1
790
+ if (y < x) return 1
791
+ return 0
792
+ }
793
+
794
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
795
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
796
+ //
797
+ // Arguments:
798
+ // - buffer - a Buffer to search
799
+ // - val - a string, Buffer, or number
800
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
801
+ // - encoding - an optional encoding, relevant is val is a string
802
+ // - dir - true for indexOf, false for lastIndexOf
803
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
804
+ // Empty buffer means no match
805
+ if (buffer.length === 0) return -1
806
+
807
+ // Normalize byteOffset
808
+ if (typeof byteOffset === 'string') {
809
+ encoding = byteOffset
810
+ byteOffset = 0
811
+ } else if (byteOffset > 0x7fffffff) {
812
+ byteOffset = 0x7fffffff
813
+ } else if (byteOffset < -0x80000000) {
814
+ byteOffset = -0x80000000
815
+ }
816
+ byteOffset = +byteOffset // Coerce to Number.
817
+ if (numberIsNaN(byteOffset)) {
818
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
819
+ byteOffset = dir ? 0 : (buffer.length - 1)
820
+ }
821
+
822
+ // Normalize byteOffset: negative offsets start from the end of the buffer
823
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset
824
+ if (byteOffset >= buffer.length) {
825
+ if (dir) return -1
826
+ else byteOffset = buffer.length - 1
827
+ } else if (byteOffset < 0) {
828
+ if (dir) byteOffset = 0
829
+ else return -1
830
+ }
831
+
832
+ // Normalize val
833
+ if (typeof val === 'string') {
834
+ val = Buffer.from(val, encoding)
835
+ }
836
+
837
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
838
+ if (Buffer.isBuffer(val)) {
839
+ // Special case: looking for empty string/buffer always fails
840
+ if (val.length === 0) {
841
+ return -1
842
+ }
843
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
844
+ } else if (typeof val === 'number') {
845
+ val = val & 0xFF // Search for a byte value [0-255]
846
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
847
+ if (dir) {
848
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
849
+ } else {
850
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
851
+ }
852
+ }
853
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
854
+ }
855
+
856
+ throw new TypeError('val must be string, number or Buffer')
857
+ }
858
+
859
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
860
+ var indexSize = 1
861
+ var arrLength = arr.length
862
+ var valLength = val.length
863
+
864
+ if (encoding !== undefined) {
865
+ encoding = String(encoding).toLowerCase()
866
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
867
+ encoding === 'utf16le' || encoding === 'utf-16le') {
868
+ if (arr.length < 2 || val.length < 2) {
869
+ return -1
870
+ }
871
+ indexSize = 2
872
+ arrLength /= 2
873
+ valLength /= 2
874
+ byteOffset /= 2
875
+ }
876
+ }
877
+
878
+ function read (buf, i) {
879
+ if (indexSize === 1) {
880
+ return buf[i]
881
+ } else {
882
+ return buf.readUInt16BE(i * indexSize)
883
+ }
884
+ }
885
+
886
+ var i
887
+ if (dir) {
888
+ var foundIndex = -1
889
+ for (i = byteOffset; i < arrLength; i++) {
890
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
891
+ if (foundIndex === -1) foundIndex = i
892
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
893
+ } else {
894
+ if (foundIndex !== -1) i -= i - foundIndex
895
+ foundIndex = -1
896
+ }
897
+ }
898
+ } else {
899
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
900
+ for (i = byteOffset; i >= 0; i--) {
901
+ var found = true
902
+ for (var j = 0; j < valLength; j++) {
903
+ if (read(arr, i + j) !== read(val, j)) {
904
+ found = false
905
+ break
906
+ }
907
+ }
908
+ if (found) return i
909
+ }
910
+ }
911
+
912
+ return -1
913
+ }
914
+
915
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
916
+ return this.indexOf(val, byteOffset, encoding) !== -1
917
+ }
918
+
919
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
920
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
921
+ }
922
+
923
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
924
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
925
+ }
926
+
927
+ function hexWrite (buf, string, offset, length) {
928
+ offset = Number(offset) || 0
929
+ var remaining = buf.length - offset
930
+ if (!length) {
931
+ length = remaining
932
+ } else {
933
+ length = Number(length)
934
+ if (length > remaining) {
935
+ length = remaining
936
+ }
937
+ }
938
+
939
+ var strLen = string.length
940
+
941
+ if (length > strLen / 2) {
942
+ length = strLen / 2
943
+ }
944
+ for (var i = 0; i < length; ++i) {
945
+ var parsed = parseInt(string.substr(i * 2, 2), 16)
946
+ if (numberIsNaN(parsed)) return i
947
+ buf[offset + i] = parsed
948
+ }
949
+ return i
950
+ }
951
+
952
+ function utf8Write (buf, string, offset, length) {
953
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
954
+ }
955
+
956
+ function asciiWrite (buf, string, offset, length) {
957
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
958
+ }
959
+
960
+ function base64Write (buf, string, offset, length) {
961
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
962
+ }
963
+
964
+ function ucs2Write (buf, string, offset, length) {
965
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
966
+ }
967
+
968
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
969
+ // Buffer#write(string)
970
+ if (offset === undefined) {
971
+ encoding = 'utf8'
972
+ length = this.length
973
+ offset = 0
974
+ // Buffer#write(string, encoding)
975
+ } else if (length === undefined && typeof offset === 'string') {
976
+ encoding = offset
977
+ length = this.length
978
+ offset = 0
979
+ // Buffer#write(string, offset[, length][, encoding])
980
+ } else if (isFinite(offset)) {
981
+ offset = offset >>> 0
982
+ if (isFinite(length)) {
983
+ length = length >>> 0
984
+ if (encoding === undefined) encoding = 'utf8'
985
+ } else {
986
+ encoding = length
987
+ length = undefined
988
+ }
989
+ } else {
990
+ throw new Error(
991
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
992
+ )
993
+ }
994
+
995
+ var remaining = this.length - offset
996
+ if (length === undefined || length > remaining) length = remaining
997
+
998
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
999
+ throw new RangeError('Attempt to write outside buffer bounds')
1000
+ }
1001
+
1002
+ if (!encoding) encoding = 'utf8'
1003
+
1004
+ var loweredCase = false
1005
+ for (;;) {
1006
+ switch (encoding) {
1007
+ case 'hex':
1008
+ return hexWrite(this, string, offset, length)
1009
+
1010
+ case 'utf8':
1011
+ case 'utf-8':
1012
+ return utf8Write(this, string, offset, length)
1013
+
1014
+ case 'ascii':
1015
+ case 'latin1':
1016
+ case 'binary':
1017
+ return asciiWrite(this, string, offset, length)
1018
+
1019
+ case 'base64':
1020
+ // Warning: maxLength not taken into account in base64Write
1021
+ return base64Write(this, string, offset, length)
1022
+
1023
+ case 'ucs2':
1024
+ case 'ucs-2':
1025
+ case 'utf16le':
1026
+ case 'utf-16le':
1027
+ return ucs2Write(this, string, offset, length)
1028
+
1029
+ default:
1030
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1031
+ encoding = ('' + encoding).toLowerCase()
1032
+ loweredCase = true
1033
+ }
1034
+ }
1035
+ }
1036
+
1037
+ Buffer.prototype.toJSON = function toJSON () {
1038
+ return {
1039
+ type: 'Buffer',
1040
+ data: Array.prototype.slice.call(this._arr || this, 0)
1041
+ }
1042
+ }
1043
+
1044
+ function base64Slice (buf, start, end) {
1045
+ if (start === 0 && end === buf.length) {
1046
+ return base64.fromByteArray(buf)
1047
+ } else {
1048
+ return base64.fromByteArray(buf.slice(start, end))
1049
+ }
1050
+ }
1051
+
1052
+ function utf8Slice (buf, start, end) {
1053
+ end = Math.min(buf.length, end)
1054
+ var res = []
1055
+
1056
+ var i = start
1057
+ while (i < end) {
1058
+ var firstByte = buf[i]
1059
+ var codePoint = null
1060
+ var bytesPerSequence = (firstByte > 0xEF)
1061
+ ? 4
1062
+ : (firstByte > 0xDF)
1063
+ ? 3
1064
+ : (firstByte > 0xBF)
1065
+ ? 2
1066
+ : 1
1067
+
1068
+ if (i + bytesPerSequence <= end) {
1069
+ var secondByte, thirdByte, fourthByte, tempCodePoint
1070
+
1071
+ switch (bytesPerSequence) {
1072
+ case 1:
1073
+ if (firstByte < 0x80) {
1074
+ codePoint = firstByte
1075
+ }
1076
+ break
1077
+ case 2:
1078
+ secondByte = buf[i + 1]
1079
+ if ((secondByte & 0xC0) === 0x80) {
1080
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
1081
+ if (tempCodePoint > 0x7F) {
1082
+ codePoint = tempCodePoint
1083
+ }
1084
+ }
1085
+ break
1086
+ case 3:
1087
+ secondByte = buf[i + 1]
1088
+ thirdByte = buf[i + 2]
1089
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1090
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
1091
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1092
+ codePoint = tempCodePoint
1093
+ }
1094
+ }
1095
+ break
1096
+ case 4:
1097
+ secondByte = buf[i + 1]
1098
+ thirdByte = buf[i + 2]
1099
+ fourthByte = buf[i + 3]
1100
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1101
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
1102
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1103
+ codePoint = tempCodePoint
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+
1109
+ if (codePoint === null) {
1110
+ // we did not generate a valid codePoint so insert a
1111
+ // replacement char (U+FFFD) and advance only 1 byte
1112
+ codePoint = 0xFFFD
1113
+ bytesPerSequence = 1
1114
+ } else if (codePoint > 0xFFFF) {
1115
+ // encode to utf16 (surrogate pair dance)
1116
+ codePoint -= 0x10000
1117
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800)
1118
+ codePoint = 0xDC00 | codePoint & 0x3FF
1119
+ }
1120
+
1121
+ res.push(codePoint)
1122
+ i += bytesPerSequence
1123
+ }
1124
+
1125
+ return decodeCodePointsArray(res)
1126
+ }
1127
+
1128
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1129
+ // the lowest limit is Chrome, with 0x10000 args.
1130
+ // We go 1 magnitude less, for safety
1131
+ var MAX_ARGUMENTS_LENGTH = 0x1000
1132
+
1133
+ function decodeCodePointsArray (codePoints) {
1134
+ var len = codePoints.length
1135
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1136
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1137
+ }
1138
+
1139
+ // Decode in chunks to avoid "call stack size exceeded".
1140
+ var res = ''
1141
+ var i = 0
1142
+ while (i < len) {
1143
+ res += String.fromCharCode.apply(
1144
+ String,
1145
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1146
+ )
1147
+ }
1148
+ return res
1149
+ }
1150
+
1151
+ function asciiSlice (buf, start, end) {
1152
+ var ret = ''
1153
+ end = Math.min(buf.length, end)
1154
+
1155
+ for (var i = start; i < end; ++i) {
1156
+ ret += String.fromCharCode(buf[i] & 0x7F)
1157
+ }
1158
+ return ret
1159
+ }
1160
+
1161
+ function latin1Slice (buf, start, end) {
1162
+ var ret = ''
1163
+ end = Math.min(buf.length, end)
1164
+
1165
+ for (var i = start; i < end; ++i) {
1166
+ ret += String.fromCharCode(buf[i])
1167
+ }
1168
+ return ret
1169
+ }
1170
+
1171
+ function hexSlice (buf, start, end) {
1172
+ var len = buf.length
1173
+
1174
+ if (!start || start < 0) start = 0
1175
+ if (!end || end < 0 || end > len) end = len
1176
+
1177
+ var out = ''
1178
+ for (var i = start; i < end; ++i) {
1179
+ out += hexSliceLookupTable[buf[i]]
1180
+ }
1181
+ return out
1182
+ }
1183
+
1184
+ function utf16leSlice (buf, start, end) {
1185
+ var bytes = buf.slice(start, end)
1186
+ var res = ''
1187
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
1188
+ for (var i = 0; i < bytes.length - 1; i += 2) {
1189
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
1190
+ }
1191
+ return res
1192
+ }
1193
+
1194
+ Buffer.prototype.slice = function slice (start, end) {
1195
+ var len = this.length
1196
+ start = ~~start
1197
+ end = end === undefined ? len : ~~end
1198
+
1199
+ if (start < 0) {
1200
+ start += len
1201
+ if (start < 0) start = 0
1202
+ } else if (start > len) {
1203
+ start = len
1204
+ }
1205
+
1206
+ if (end < 0) {
1207
+ end += len
1208
+ if (end < 0) end = 0
1209
+ } else if (end > len) {
1210
+ end = len
1211
+ }
1212
+
1213
+ if (end < start) end = start
1214
+
1215
+ var newBuf = this.subarray(start, end)
1216
+ // Return an augmented `Uint8Array` instance
1217
+ Object.setPrototypeOf(newBuf, Buffer.prototype)
1218
+
1219
+ return newBuf
1220
+ }
1221
+
1222
+ /*
1223
+ * Need to make sure that buffer isn't trying to write out of bounds.
1224
+ */
1225
+ function checkOffset (offset, ext, length) {
1226
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1227
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1228
+ }
1229
+
1230
+ Buffer.prototype.readUintLE =
1231
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1232
+ offset = offset >>> 0
1233
+ byteLength = byteLength >>> 0
1234
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
1235
+
1236
+ var val = this[offset]
1237
+ var mul = 1
1238
+ var i = 0
1239
+ while (++i < byteLength && (mul *= 0x100)) {
1240
+ val += this[offset + i] * mul
1241
+ }
1242
+
1243
+ return val
1244
+ }
1245
+
1246
+ Buffer.prototype.readUintBE =
1247
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1248
+ offset = offset >>> 0
1249
+ byteLength = byteLength >>> 0
1250
+ if (!noAssert) {
1251
+ checkOffset(offset, byteLength, this.length)
1252
+ }
1253
+
1254
+ var val = this[offset + --byteLength]
1255
+ var mul = 1
1256
+ while (byteLength > 0 && (mul *= 0x100)) {
1257
+ val += this[offset + --byteLength] * mul
1258
+ }
1259
+
1260
+ return val
1261
+ }
1262
+
1263
+ Buffer.prototype.readUint8 =
1264
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1265
+ offset = offset >>> 0
1266
+ if (!noAssert) checkOffset(offset, 1, this.length)
1267
+ return this[offset]
1268
+ }
1269
+
1270
+ Buffer.prototype.readUint16LE =
1271
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1272
+ offset = offset >>> 0
1273
+ if (!noAssert) checkOffset(offset, 2, this.length)
1274
+ return this[offset] | (this[offset + 1] << 8)
1275
+ }
1276
+
1277
+ Buffer.prototype.readUint16BE =
1278
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1279
+ offset = offset >>> 0
1280
+ if (!noAssert) checkOffset(offset, 2, this.length)
1281
+ return (this[offset] << 8) | this[offset + 1]
1282
+ }
1283
+
1284
+ Buffer.prototype.readUint32LE =
1285
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1286
+ offset = offset >>> 0
1287
+ if (!noAssert) checkOffset(offset, 4, this.length)
1288
+
1289
+ return ((this[offset]) |
1290
+ (this[offset + 1] << 8) |
1291
+ (this[offset + 2] << 16)) +
1292
+ (this[offset + 3] * 0x1000000)
1293
+ }
1294
+
1295
+ Buffer.prototype.readUint32BE =
1296
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1297
+ offset = offset >>> 0
1298
+ if (!noAssert) checkOffset(offset, 4, this.length)
1299
+
1300
+ return (this[offset] * 0x1000000) +
1301
+ ((this[offset + 1] << 16) |
1302
+ (this[offset + 2] << 8) |
1303
+ this[offset + 3])
1304
+ }
1305
+
1306
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1307
+ offset = offset >>> 0
1308
+ byteLength = byteLength >>> 0
1309
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
1310
+
1311
+ var val = this[offset]
1312
+ var mul = 1
1313
+ var i = 0
1314
+ while (++i < byteLength && (mul *= 0x100)) {
1315
+ val += this[offset + i] * mul
1316
+ }
1317
+ mul *= 0x80
1318
+
1319
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1320
+
1321
+ return val
1322
+ }
1323
+
1324
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1325
+ offset = offset >>> 0
1326
+ byteLength = byteLength >>> 0
1327
+ if (!noAssert) checkOffset(offset, byteLength, this.length)
1328
+
1329
+ var i = byteLength
1330
+ var mul = 1
1331
+ var val = this[offset + --i]
1332
+ while (i > 0 && (mul *= 0x100)) {
1333
+ val += this[offset + --i] * mul
1334
+ }
1335
+ mul *= 0x80
1336
+
1337
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1338
+
1339
+ return val
1340
+ }
1341
+
1342
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1343
+ offset = offset >>> 0
1344
+ if (!noAssert) checkOffset(offset, 1, this.length)
1345
+ if (!(this[offset] & 0x80)) return (this[offset])
1346
+ return ((0xff - this[offset] + 1) * -1)
1347
+ }
1348
+
1349
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1350
+ offset = offset >>> 0
1351
+ if (!noAssert) checkOffset(offset, 2, this.length)
1352
+ var val = this[offset] | (this[offset + 1] << 8)
1353
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1354
+ }
1355
+
1356
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1357
+ offset = offset >>> 0
1358
+ if (!noAssert) checkOffset(offset, 2, this.length)
1359
+ var val = this[offset + 1] | (this[offset] << 8)
1360
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1361
+ }
1362
+
1363
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1364
+ offset = offset >>> 0
1365
+ if (!noAssert) checkOffset(offset, 4, this.length)
1366
+
1367
+ return (this[offset]) |
1368
+ (this[offset + 1] << 8) |
1369
+ (this[offset + 2] << 16) |
1370
+ (this[offset + 3] << 24)
1371
+ }
1372
+
1373
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1374
+ offset = offset >>> 0
1375
+ if (!noAssert) checkOffset(offset, 4, this.length)
1376
+
1377
+ return (this[offset] << 24) |
1378
+ (this[offset + 1] << 16) |
1379
+ (this[offset + 2] << 8) |
1380
+ (this[offset + 3])
1381
+ }
1382
+
1383
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1384
+ offset = offset >>> 0
1385
+ if (!noAssert) checkOffset(offset, 4, this.length)
1386
+ return ieee754.read(this, offset, true, 23, 4)
1387
+ }
1388
+
1389
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1390
+ offset = offset >>> 0
1391
+ if (!noAssert) checkOffset(offset, 4, this.length)
1392
+ return ieee754.read(this, offset, false, 23, 4)
1393
+ }
1394
+
1395
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1396
+ offset = offset >>> 0
1397
+ if (!noAssert) checkOffset(offset, 8, this.length)
1398
+ return ieee754.read(this, offset, true, 52, 8)
1399
+ }
1400
+
1401
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1402
+ offset = offset >>> 0
1403
+ if (!noAssert) checkOffset(offset, 8, this.length)
1404
+ return ieee754.read(this, offset, false, 52, 8)
1405
+ }
1406
+
1407
+ function checkInt (buf, value, offset, ext, max, min) {
1408
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1409
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1410
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1411
+ }
1412
+
1413
+ Buffer.prototype.writeUintLE =
1414
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1415
+ value = +value
1416
+ offset = offset >>> 0
1417
+ byteLength = byteLength >>> 0
1418
+ if (!noAssert) {
1419
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
1420
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
1421
+ }
1422
+
1423
+ var mul = 1
1424
+ var i = 0
1425
+ this[offset] = value & 0xFF
1426
+ while (++i < byteLength && (mul *= 0x100)) {
1427
+ this[offset + i] = (value / mul) & 0xFF
1428
+ }
1429
+
1430
+ return offset + byteLength
1431
+ }
1432
+
1433
+ Buffer.prototype.writeUintBE =
1434
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1435
+ value = +value
1436
+ offset = offset >>> 0
1437
+ byteLength = byteLength >>> 0
1438
+ if (!noAssert) {
1439
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1
1440
+ checkInt(this, value, offset, byteLength, maxBytes, 0)
1441
+ }
1442
+
1443
+ var i = byteLength - 1
1444
+ var mul = 1
1445
+ this[offset + i] = value & 0xFF
1446
+ while (--i >= 0 && (mul *= 0x100)) {
1447
+ this[offset + i] = (value / mul) & 0xFF
1448
+ }
1449
+
1450
+ return offset + byteLength
1451
+ }
1452
+
1453
+ Buffer.prototype.writeUint8 =
1454
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1455
+ value = +value
1456
+ offset = offset >>> 0
1457
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
1458
+ this[offset] = (value & 0xff)
1459
+ return offset + 1
1460
+ }
1461
+
1462
+ Buffer.prototype.writeUint16LE =
1463
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1464
+ value = +value
1465
+ offset = offset >>> 0
1466
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1467
+ this[offset] = (value & 0xff)
1468
+ this[offset + 1] = (value >>> 8)
1469
+ return offset + 2
1470
+ }
1471
+
1472
+ Buffer.prototype.writeUint16BE =
1473
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1474
+ value = +value
1475
+ offset = offset >>> 0
1476
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1477
+ this[offset] = (value >>> 8)
1478
+ this[offset + 1] = (value & 0xff)
1479
+ return offset + 2
1480
+ }
1481
+
1482
+ Buffer.prototype.writeUint32LE =
1483
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1484
+ value = +value
1485
+ offset = offset >>> 0
1486
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1487
+ this[offset + 3] = (value >>> 24)
1488
+ this[offset + 2] = (value >>> 16)
1489
+ this[offset + 1] = (value >>> 8)
1490
+ this[offset] = (value & 0xff)
1491
+ return offset + 4
1492
+ }
1493
+
1494
+ Buffer.prototype.writeUint32BE =
1495
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1496
+ value = +value
1497
+ offset = offset >>> 0
1498
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1499
+ this[offset] = (value >>> 24)
1500
+ this[offset + 1] = (value >>> 16)
1501
+ this[offset + 2] = (value >>> 8)
1502
+ this[offset + 3] = (value & 0xff)
1503
+ return offset + 4
1504
+ }
1505
+
1506
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1507
+ value = +value
1508
+ offset = offset >>> 0
1509
+ if (!noAssert) {
1510
+ var limit = Math.pow(2, (8 * byteLength) - 1)
1511
+
1512
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
1513
+ }
1514
+
1515
+ var i = 0
1516
+ var mul = 1
1517
+ var sub = 0
1518
+ this[offset] = value & 0xFF
1519
+ while (++i < byteLength && (mul *= 0x100)) {
1520
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1521
+ sub = 1
1522
+ }
1523
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1524
+ }
1525
+
1526
+ return offset + byteLength
1527
+ }
1528
+
1529
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1530
+ value = +value
1531
+ offset = offset >>> 0
1532
+ if (!noAssert) {
1533
+ var limit = Math.pow(2, (8 * byteLength) - 1)
1534
+
1535
+ checkInt(this, value, offset, byteLength, limit - 1, -limit)
1536
+ }
1537
+
1538
+ var i = byteLength - 1
1539
+ var mul = 1
1540
+ var sub = 0
1541
+ this[offset + i] = value & 0xFF
1542
+ while (--i >= 0 && (mul *= 0x100)) {
1543
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1544
+ sub = 1
1545
+ }
1546
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1547
+ }
1548
+
1549
+ return offset + byteLength
1550
+ }
1551
+
1552
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1553
+ value = +value
1554
+ offset = offset >>> 0
1555
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
1556
+ if (value < 0) value = 0xff + value + 1
1557
+ this[offset] = (value & 0xff)
1558
+ return offset + 1
1559
+ }
1560
+
1561
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1562
+ value = +value
1563
+ offset = offset >>> 0
1564
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1565
+ this[offset] = (value & 0xff)
1566
+ this[offset + 1] = (value >>> 8)
1567
+ return offset + 2
1568
+ }
1569
+
1570
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1571
+ value = +value
1572
+ offset = offset >>> 0
1573
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1574
+ this[offset] = (value >>> 8)
1575
+ this[offset + 1] = (value & 0xff)
1576
+ return offset + 2
1577
+ }
1578
+
1579
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1580
+ value = +value
1581
+ offset = offset >>> 0
1582
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1583
+ this[offset] = (value & 0xff)
1584
+ this[offset + 1] = (value >>> 8)
1585
+ this[offset + 2] = (value >>> 16)
1586
+ this[offset + 3] = (value >>> 24)
1587
+ return offset + 4
1588
+ }
1589
+
1590
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1591
+ value = +value
1592
+ offset = offset >>> 0
1593
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1594
+ if (value < 0) value = 0xffffffff + value + 1
1595
+ this[offset] = (value >>> 24)
1596
+ this[offset + 1] = (value >>> 16)
1597
+ this[offset + 2] = (value >>> 8)
1598
+ this[offset + 3] = (value & 0xff)
1599
+ return offset + 4
1600
+ }
1601
+
1602
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
1603
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1604
+ if (offset < 0) throw new RangeError('Index out of range')
1605
+ }
1606
+
1607
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
1608
+ value = +value
1609
+ offset = offset >>> 0
1610
+ if (!noAssert) {
1611
+ checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
1612
+ }
1613
+ ieee754.write(buf, value, offset, littleEndian, 23, 4)
1614
+ return offset + 4
1615
+ }
1616
+
1617
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1618
+ return writeFloat(this, value, offset, true, noAssert)
1619
+ }
1620
+
1621
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1622
+ return writeFloat(this, value, offset, false, noAssert)
1623
+ }
1624
+
1625
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
1626
+ value = +value
1627
+ offset = offset >>> 0
1628
+ if (!noAssert) {
1629
+ checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
1630
+ }
1631
+ ieee754.write(buf, value, offset, littleEndian, 52, 8)
1632
+ return offset + 8
1633
+ }
1634
+
1635
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1636
+ return writeDouble(this, value, offset, true, noAssert)
1637
+ }
1638
+
1639
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1640
+ return writeDouble(this, value, offset, false, noAssert)
1641
+ }
1642
+
1643
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1644
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1645
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
1646
+ if (!start) start = 0
1647
+ if (!end && end !== 0) end = this.length
1648
+ if (targetStart >= target.length) targetStart = target.length
1649
+ if (!targetStart) targetStart = 0
1650
+ if (end > 0 && end < start) end = start
1651
+
1652
+ // Copy 0 bytes; we're done
1653
+ if (end === start) return 0
1654
+ if (target.length === 0 || this.length === 0) return 0
1655
+
1656
+ // Fatal error conditions
1657
+ if (targetStart < 0) {
1658
+ throw new RangeError('targetStart out of bounds')
1659
+ }
1660
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
1661
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
1662
+
1663
+ // Are we oob?
1664
+ if (end > this.length) end = this.length
1665
+ if (target.length - targetStart < end - start) {
1666
+ end = target.length - targetStart + start
1667
+ }
1668
+
1669
+ var len = end - start
1670
+
1671
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
1672
+ // Use built-in when available, missing from IE11
1673
+ this.copyWithin(targetStart, start, end)
1674
+ } else {
1675
+ Uint8Array.prototype.set.call(
1676
+ target,
1677
+ this.subarray(start, end),
1678
+ targetStart
1679
+ )
1680
+ }
1681
+
1682
+ return len
1683
+ }
1684
+
1685
+ // Usage:
1686
+ // buffer.fill(number[, offset[, end]])
1687
+ // buffer.fill(buffer[, offset[, end]])
1688
+ // buffer.fill(string[, offset[, end]][, encoding])
1689
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1690
+ // Handle string cases:
1691
+ if (typeof val === 'string') {
1692
+ if (typeof start === 'string') {
1693
+ encoding = start
1694
+ start = 0
1695
+ end = this.length
1696
+ } else if (typeof end === 'string') {
1697
+ encoding = end
1698
+ end = this.length
1699
+ }
1700
+ if (encoding !== undefined && typeof encoding !== 'string') {
1701
+ throw new TypeError('encoding must be a string')
1702
+ }
1703
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1704
+ throw new TypeError('Unknown encoding: ' + encoding)
1705
+ }
1706
+ if (val.length === 1) {
1707
+ var code = val.charCodeAt(0)
1708
+ if ((encoding === 'utf8' && code < 128) ||
1709
+ encoding === 'latin1') {
1710
+ // Fast path: If `val` fits into a single byte, use that numeric value.
1711
+ val = code
1712
+ }
1713
+ }
1714
+ } else if (typeof val === 'number') {
1715
+ val = val & 255
1716
+ } else if (typeof val === 'boolean') {
1717
+ val = Number(val)
1718
+ }
1719
+
1720
+ // Invalid ranges are not set to a default, so can range check early.
1721
+ if (start < 0 || this.length < start || this.length < end) {
1722
+ throw new RangeError('Out of range index')
1723
+ }
1724
+
1725
+ if (end <= start) {
1726
+ return this
1727
+ }
1728
+
1729
+ start = start >>> 0
1730
+ end = end === undefined ? this.length : end >>> 0
1731
+
1732
+ if (!val) val = 0
1733
+
1734
+ var i
1735
+ if (typeof val === 'number') {
1736
+ for (i = start; i < end; ++i) {
1737
+ this[i] = val
1738
+ }
1739
+ } else {
1740
+ var bytes = Buffer.isBuffer(val)
1741
+ ? val
1742
+ : Buffer.from(val, encoding)
1743
+ var len = bytes.length
1744
+ if (len === 0) {
1745
+ throw new TypeError('The value "' + val +
1746
+ '" is invalid for argument "value"')
1747
+ }
1748
+ for (i = 0; i < end - start; ++i) {
1749
+ this[i + start] = bytes[i % len]
1750
+ }
1751
+ }
1752
+
1753
+ return this
1754
+ }
1755
+
1756
+ // HELPER FUNCTIONS
1757
+ // ================
1758
+
1759
+ var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
1760
+
1761
+ function base64clean (str) {
1762
+ // Node takes equal signs as end of the Base64 encoding
1763
+ str = str.split('=')[0]
1764
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
1765
+ str = str.trim().replace(INVALID_BASE64_RE, '')
1766
+ // Node converts strings with length < 2 to ''
1767
+ if (str.length < 2) return ''
1768
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1769
+ while (str.length % 4 !== 0) {
1770
+ str = str + '='
1771
+ }
1772
+ return str
1773
+ }
1774
+
1775
+ function utf8ToBytes (string, units) {
1776
+ units = units || Infinity
1777
+ var codePoint
1778
+ var length = string.length
1779
+ var leadSurrogate = null
1780
+ var bytes = []
1781
+
1782
+ for (var i = 0; i < length; ++i) {
1783
+ codePoint = string.charCodeAt(i)
1784
+
1785
+ // is surrogate component
1786
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
1787
+ // last char was a lead
1788
+ if (!leadSurrogate) {
1789
+ // no lead yet
1790
+ if (codePoint > 0xDBFF) {
1791
+ // unexpected trail
1792
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1793
+ continue
1794
+ } else if (i + 1 === length) {
1795
+ // unpaired lead
1796
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1797
+ continue
1798
+ }
1799
+
1800
+ // valid lead
1801
+ leadSurrogate = codePoint
1802
+
1803
+ continue
1804
+ }
1805
+
1806
+ // 2 leads in a row
1807
+ if (codePoint < 0xDC00) {
1808
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1809
+ leadSurrogate = codePoint
1810
+ continue
1811
+ }
1812
+
1813
+ // valid surrogate pair
1814
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
1815
+ } else if (leadSurrogate) {
1816
+ // valid bmp char, but last char was a lead
1817
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1818
+ }
1819
+
1820
+ leadSurrogate = null
1821
+
1822
+ // encode utf8
1823
+ if (codePoint < 0x80) {
1824
+ if ((units -= 1) < 0) break
1825
+ bytes.push(codePoint)
1826
+ } else if (codePoint < 0x800) {
1827
+ if ((units -= 2) < 0) break
1828
+ bytes.push(
1829
+ codePoint >> 0x6 | 0xC0,
1830
+ codePoint & 0x3F | 0x80
1831
+ )
1832
+ } else if (codePoint < 0x10000) {
1833
+ if ((units -= 3) < 0) break
1834
+ bytes.push(
1835
+ codePoint >> 0xC | 0xE0,
1836
+ codePoint >> 0x6 & 0x3F | 0x80,
1837
+ codePoint & 0x3F | 0x80
1838
+ )
1839
+ } else if (codePoint < 0x110000) {
1840
+ if ((units -= 4) < 0) break
1841
+ bytes.push(
1842
+ codePoint >> 0x12 | 0xF0,
1843
+ codePoint >> 0xC & 0x3F | 0x80,
1844
+ codePoint >> 0x6 & 0x3F | 0x80,
1845
+ codePoint & 0x3F | 0x80
1846
+ )
1847
+ } else {
1848
+ throw new Error('Invalid code point')
1849
+ }
1850
+ }
1851
+
1852
+ return bytes
1853
+ }
1854
+
1855
+ function asciiToBytes (str) {
1856
+ var byteArray = []
1857
+ for (var i = 0; i < str.length; ++i) {
1858
+ // Node's code seems to be doing this and not & 0x7F..
1859
+ byteArray.push(str.charCodeAt(i) & 0xFF)
1860
+ }
1861
+ return byteArray
1862
+ }
1863
+
1864
+ function utf16leToBytes (str, units) {
1865
+ var c, hi, lo
1866
+ var byteArray = []
1867
+ for (var i = 0; i < str.length; ++i) {
1868
+ if ((units -= 2) < 0) break
1869
+
1870
+ c = str.charCodeAt(i)
1871
+ hi = c >> 8
1872
+ lo = c % 256
1873
+ byteArray.push(lo)
1874
+ byteArray.push(hi)
1875
+ }
1876
+
1877
+ return byteArray
1878
+ }
1879
+
1880
+ function base64ToBytes (str) {
1881
+ return base64.toByteArray(base64clean(str))
1882
+ }
1883
+
1884
+ function blitBuffer (src, dst, offset, length) {
1885
+ for (var i = 0; i < length; ++i) {
1886
+ if ((i + offset >= dst.length) || (i >= src.length)) break
1887
+ dst[i + offset] = src[i]
1888
+ }
1889
+ return i
1890
+ }
1891
+
1892
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
1893
+ // the `instanceof` check but they should be treated as of that type.
1894
+ // See: https://github.com/feross/buffer/issues/166
1895
+ function isInstance (obj, type) {
1896
+ return obj instanceof type ||
1897
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
1898
+ obj.constructor.name === type.name)
1899
+ }
1900
+ function numberIsNaN (obj) {
1901
+ // For IE11 support
1902
+ return obj !== obj // eslint-disable-line no-self-compare
1903
+ }
1904
+
1905
+ // Create lookup table for `toString('hex')`
1906
+ // See: https://github.com/feross/buffer/issues/219
1907
+ var hexSliceLookupTable = (function () {
1908
+ var alphabet = '0123456789abcdef'
1909
+ var table = new Array(256)
1910
+ for (var i = 0; i < 16; ++i) {
1911
+ var i16 = i * 16
1912
+ for (var j = 0; j < 16; ++j) {
1913
+ table[i16 + j] = alphabet[i] + alphabet[j]
1914
+ }
1915
+ }
1916
+ return table
1917
+ })()
1918
+
1919
+
1920
+ /***/ }),
1921
+
1922
+ /***/ 526:
1923
+ /***/ ((__unused_webpack_module, exports) => {
1924
+
1925
+ "use strict";
1926
+
1927
+
1928
+ exports.byteLength = byteLength
1929
+ exports.toByteArray = toByteArray
1930
+ exports.fromByteArray = fromByteArray
1931
+
1932
+ var lookup = []
1933
+ var revLookup = []
1934
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
1935
+
1936
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
1937
+ for (var i = 0, len = code.length; i < len; ++i) {
1938
+ lookup[i] = code[i]
1939
+ revLookup[code.charCodeAt(i)] = i
1940
+ }
1941
+
1942
+ // Support decoding URL-safe base64 strings, as Node.js does.
1943
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
1944
+ revLookup['-'.charCodeAt(0)] = 62
1945
+ revLookup['_'.charCodeAt(0)] = 63
1946
+
1947
+ function getLens (b64) {
1948
+ var len = b64.length
1949
+
1950
+ if (len % 4 > 0) {
1951
+ throw new Error('Invalid string. Length must be a multiple of 4')
1952
+ }
1953
+
1954
+ // Trim off extra bytes after placeholder bytes are found
1955
+ // See: https://github.com/beatgammit/base64-js/issues/42
1956
+ var validLen = b64.indexOf('=')
1957
+ if (validLen === -1) validLen = len
1958
+
1959
+ var placeHoldersLen = validLen === len
1960
+ ? 0
1961
+ : 4 - (validLen % 4)
1962
+
1963
+ return [validLen, placeHoldersLen]
1964
+ }
1965
+
1966
+ // base64 is 4/3 + up to two characters of the original data
1967
+ function byteLength (b64) {
1968
+ var lens = getLens(b64)
1969
+ var validLen = lens[0]
1970
+ var placeHoldersLen = lens[1]
1971
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
1972
+ }
1973
+
1974
+ function _byteLength (b64, validLen, placeHoldersLen) {
1975
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
1976
+ }
1977
+
1978
+ function toByteArray (b64) {
1979
+ var tmp
1980
+ var lens = getLens(b64)
1981
+ var validLen = lens[0]
1982
+ var placeHoldersLen = lens[1]
1983
+
1984
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
1985
+
1986
+ var curByte = 0
1987
+
1988
+ // if there are placeholders, only get up to the last complete 4 chars
1989
+ var len = placeHoldersLen > 0
1990
+ ? validLen - 4
1991
+ : validLen
1992
+
1993
+ var i
1994
+ for (i = 0; i < len; i += 4) {
1995
+ tmp =
1996
+ (revLookup[b64.charCodeAt(i)] << 18) |
1997
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
1998
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
1999
+ revLookup[b64.charCodeAt(i + 3)]
2000
+ arr[curByte++] = (tmp >> 16) & 0xFF
2001
+ arr[curByte++] = (tmp >> 8) & 0xFF
2002
+ arr[curByte++] = tmp & 0xFF
2003
+ }
2004
+
2005
+ if (placeHoldersLen === 2) {
2006
+ tmp =
2007
+ (revLookup[b64.charCodeAt(i)] << 2) |
2008
+ (revLookup[b64.charCodeAt(i + 1)] >> 4)
2009
+ arr[curByte++] = tmp & 0xFF
2010
+ }
2011
+
2012
+ if (placeHoldersLen === 1) {
2013
+ tmp =
2014
+ (revLookup[b64.charCodeAt(i)] << 10) |
2015
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
2016
+ (revLookup[b64.charCodeAt(i + 2)] >> 2)
2017
+ arr[curByte++] = (tmp >> 8) & 0xFF
2018
+ arr[curByte++] = tmp & 0xFF
2019
+ }
2020
+
2021
+ return arr
2022
+ }
2023
+
2024
+ function tripletToBase64 (num) {
2025
+ return lookup[num >> 18 & 0x3F] +
2026
+ lookup[num >> 12 & 0x3F] +
2027
+ lookup[num >> 6 & 0x3F] +
2028
+ lookup[num & 0x3F]
2029
+ }
2030
+
2031
+ function encodeChunk (uint8, start, end) {
2032
+ var tmp
2033
+ var output = []
2034
+ for (var i = start; i < end; i += 3) {
2035
+ tmp =
2036
+ ((uint8[i] << 16) & 0xFF0000) +
2037
+ ((uint8[i + 1] << 8) & 0xFF00) +
2038
+ (uint8[i + 2] & 0xFF)
2039
+ output.push(tripletToBase64(tmp))
2040
+ }
2041
+ return output.join('')
2042
+ }
2043
+
2044
+ function fromByteArray (uint8) {
2045
+ var tmp
2046
+ var len = uint8.length
2047
+ var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
2048
+ var parts = []
2049
+ var maxChunkLength = 16383 // must be multiple of 3
2050
+
2051
+ // go through the array every three bytes, we'll deal with trailing stuff later
2052
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
2053
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
2054
+ }
2055
+
2056
+ // pad the end with zeros, but make sure to not forget the extra bytes
2057
+ if (extraBytes === 1) {
2058
+ tmp = uint8[len - 1]
2059
+ parts.push(
2060
+ lookup[tmp >> 2] +
2061
+ lookup[(tmp << 4) & 0x3F] +
2062
+ '=='
2063
+ )
2064
+ } else if (extraBytes === 2) {
2065
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1]
2066
+ parts.push(
2067
+ lookup[tmp >> 10] +
2068
+ lookup[(tmp >> 4) & 0x3F] +
2069
+ lookup[(tmp << 2) & 0x3F] +
2070
+ '='
2071
+ )
2072
+ }
2073
+
2074
+ return parts.join('')
2075
+ }
2076
+
2077
+
2078
+ /***/ })
2079
+
2080
+ /******/ });
2081
+ /************************************************************************/
2082
+ /******/ // The module cache
2083
+ /******/ var __webpack_module_cache__ = {};
2084
+ /******/
2085
+ /******/ // The require function
2086
+ /******/ function __webpack_require__(moduleId) {
2087
+ /******/ // Check if module is in cache
2088
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
2089
+ /******/ if (cachedModule !== undefined) {
2090
+ /******/ return cachedModule.exports;
2091
+ /******/ }
2092
+ /******/ // Create a new module (and put it into the cache)
2093
+ /******/ var module = __webpack_module_cache__[moduleId] = {
2094
+ /******/ // no module.id needed
2095
+ /******/ // no module.loaded needed
2096
+ /******/ exports: {}
2097
+ /******/ };
2098
+ /******/
2099
+ /******/ // Execute the module function
2100
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
2101
+ /******/
2102
+ /******/ // Return the exports of the module
2103
+ /******/ return module.exports;
2104
+ /******/ }
2105
+ /******/
2106
+ /************************************************************************/
2107
+ /******/ /* webpack/runtime/define property getters */
2108
+ /******/ (() => {
2109
+ /******/ // define getter functions for harmony exports
2110
+ /******/ __webpack_require__.d = (exports, definition) => {
2111
+ /******/ for(var key in definition) {
2112
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
2113
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
2114
+ /******/ }
2115
+ /******/ }
2116
+ /******/ };
2117
+ /******/ })();
2118
+ /******/
2119
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
2120
+ /******/ (() => {
2121
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
2122
+ /******/ })();
2123
+ /******/
2124
+ /******/ /* webpack/runtime/make namespace object */
2125
+ /******/ (() => {
2126
+ /******/ // define __esModule on exports
2127
+ /******/ __webpack_require__.r = (exports) => {
2128
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
2129
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2130
+ /******/ }
2131
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
2132
+ /******/ };
2133
+ /******/ })();
2134
+ /******/
2135
+ /************************************************************************/
2136
+ var __webpack_exports__ = {};
2137
+ // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
2138
+ (() => {
2139
+ "use strict";
2140
+ // ESM COMPAT FLAG
2141
+ __webpack_require__.r(__webpack_exports__);
2142
+
2143
+ // EXPORTS
2144
+ __webpack_require__.d(__webpack_exports__, {
2145
+ asyncReplace: () => (/* reexport */ asyncReplace),
2146
+ cloneObjTypeOrder: () => (/* reexport */ cloneObjTypeOrder),
2147
+ countObj: () => (/* reexport */ countObj),
2148
+ extendObjType: () => (/* reexport */ extendObjType),
2149
+ formatCustomTimer: () => (/* reexport */ formatCustomTimer),
2150
+ formatDayTimer: () => (/* reexport */ formatDayTimer),
2151
+ formatTimer: () => (/* reexport */ formatTimer),
2152
+ getAge: () => (/* reexport */ getAge),
2153
+ getSimplePerc: () => (/* reexport */ getSimplePerc),
2154
+ getTimeDuration: () => (/* reexport */ getTimeDuration),
2155
+ objType: () => (/* reexport */ objType),
2156
+ reorderObjTypeOrder: () => (/* reexport */ reorderObjTypeOrder),
2157
+ ruleOfThree: () => (/* reexport */ ruleOfThree),
2158
+ shuffleArray: () => (/* reexport */ shuffleArray),
2159
+ toTitleCase: () => (/* reexport */ toTitleCase),
2160
+ toTitleCaseLowerFirst: () => (/* reexport */ toTitleCaseLowerFirst)
2161
+ });
2162
+
2163
+ ;// ./src/legacy/libs/replaceAsync.mjs
2164
+ /**
2165
+ * Asynchronously replaces matches in a string using a regex and an async function.
2166
+ *
2167
+ * @param {string} str - The input string to perform replacements on.
2168
+ * @param {RegExp} regex - The regular expression to match substrings for replacement.
2169
+ * @param {Function} asyncFn - An asynchronous function that returns a replacement for each match.
2170
+ * It receives the same arguments as a standard `replace` callback.
2171
+ * @returns {Promise<string>} The resulting string with all async replacements applied.
2172
+ *
2173
+ * @example
2174
+ * await asyncReplace("Hello @user1 and @user2!", /@\w+/g, async (mention) => {
2175
+ * return await getUserNameFromMention(mention);
2176
+ * });
2177
+ */
2178
+ async function asyncReplace(str, regex, asyncFn) {
2179
+ const promises = [];
2180
+
2181
+ // Collect promises
2182
+ str.replace(regex, (match, ...args) => {
2183
+ promises.push(asyncFn(match, ...args));
2184
+ return match;
2185
+ });
2186
+
2187
+ const data = await Promise.all(promises);
2188
+
2189
+ // Replace using the resolved data
2190
+ return str.replace(regex, () => data.shift());
2191
+ }
2192
+
2193
+ ;// ./src/v1/basics/array.mjs
2194
+ // https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
2195
+
2196
+ /**
2197
+ * Randomly shuffles the elements of an array in place using the Fisher–Yates algorithm.
2198
+ *
2199
+ * This implementation ensures a uniform distribution of permutations.
2200
+ * Original algorithm source: StackOverflow (link above).
2201
+ *
2202
+ * @param {string[]} items - The array to shuffle.
2203
+ * @returns {string[]} The same array instance, now shuffled in place.
2204
+ */
2205
+ function shuffleArray(items) {
2206
+ let currentIndex = items.length,
2207
+ randomIndex;
2208
+
2209
+ // While there remain elements to shuffle...
2210
+ while (currentIndex !== 0) {
2211
+ // Pick a remaining element...
2212
+ randomIndex = Math.floor(Math.random() * currentIndex);
2213
+ currentIndex--;
2214
+
2215
+ // And swap it with the current element.
2216
+ [items[currentIndex], items[randomIndex]] = [items[randomIndex], items[currentIndex]];
2217
+ }
2218
+
2219
+ return items;
2220
+ }
2221
+
2222
+ ;// ./src/v1/basics/clock.mjs
2223
+ /**
2224
+ * Calculates the time duration between the current time and a given time offset.
2225
+ *
2226
+ * @param {Date} timeData - The target time as a Date object.
2227
+ * @param {string} [durationType='asSeconds'] - The type of duration to return. Can be 'asMilliseconds', 'asSeconds', 'asMinutes', 'asHours', 'asDays'.
2228
+ * @param {Date|null} [now=null] - The current time as a Date object. Defaults to the current date and time if not provided.
2229
+ * @returns {number|null} The calculated duration in the specified unit, or `null` if `timeData` is not provided.
2230
+ */
2231
+ function getTimeDuration(timeData = new Date(), durationType = 'asSeconds', now = null) {
2232
+ if (timeData instanceof Date) {
2233
+ const currentTime = now instanceof Date ? now : new Date();
2234
+ const diffMs = timeData - currentTime;
2235
+
2236
+ switch (durationType) {
2237
+ case 'asMilliseconds':
2238
+ return diffMs;
2239
+ case 'asSeconds':
2240
+ return diffMs / 1000;
2241
+ case 'asMinutes':
2242
+ return diffMs / (1000 * 60);
2243
+ case 'asHours':
2244
+ return diffMs / (1000 * 60 * 60);
2245
+ case 'asDays':
2246
+ return diffMs / (1000 * 60 * 60 * 24);
2247
+ default:
2248
+ return diffMs / 1000; // default to seconds
2249
+ }
2250
+ }
2251
+
2252
+ return null;
2253
+ }
2254
+
2255
+ /**
2256
+ * Formats a custom timer string based on total seconds and a detail level.
2257
+ * Includes proper reallocation of lower units into higher ones, ensuring consistent hierarchy.
2258
+ *
2259
+ * @param {number} totalSeconds - The total amount of seconds to convert.
2260
+ * @param {'seconds'|'minutes'|'hours'|'days'|'months'|'years'} level - The highest level to calculate and display.
2261
+ * @param {string} [format='{time}'] - Output template with placeholders like {years}, {months}, {days}, {hours}, {minutes}, {seconds}, {time}, {total}.
2262
+ * @returns {string} The formatted timer string.
2263
+ */
2264
+ function formatCustomTimer(totalSeconds, level = 'seconds', format = '{time}') {
2265
+ totalSeconds = Math.max(0, Math.floor(totalSeconds));
2266
+
2267
+ const levels = ['seconds', 'minutes', 'hours', 'days', 'months', 'years'];
2268
+ const index = levels.indexOf(level);
2269
+
2270
+ const include = {
2271
+ years: index >= 5,
2272
+ months: index >= 4,
2273
+ days: index >= 3,
2274
+ hours: index >= 2,
2275
+ minutes: index >= 1,
2276
+ seconds: index >= 0,
2277
+ };
2278
+
2279
+ const parts = {
2280
+ years: include.years ? 0 : NaN,
2281
+ months: include.months ? 0 : NaN,
2282
+ days: include.days ? 0 : NaN,
2283
+ hours: include.hours ? 0 : NaN,
2284
+ minutes: include.minutes ? 0 : NaN,
2285
+ seconds: include.seconds ? 0 : NaN,
2286
+ total: NaN,
2287
+ };
2288
+
2289
+ let remaining = totalSeconds;
2290
+
2291
+ if (include.years || include.months || include.days) {
2292
+ const baseDate = new Date(1980, 0, 1);
2293
+ const targetDate = new Date(baseDate.getTime() + remaining * 1000);
2294
+ const workingDate = new Date(baseDate);
2295
+
2296
+ // Years
2297
+ if (include.years) {
2298
+ while (
2299
+ new Date(workingDate.getFullYear() + 1, workingDate.getMonth(), workingDate.getDate()) <=
2300
+ targetDate
2301
+ ) {
2302
+ workingDate.setFullYear(workingDate.getFullYear() + 1);
2303
+ parts.years++;
2304
+ }
2305
+ }
2306
+
2307
+ // Months
2308
+ if (include.months) {
2309
+ while (
2310
+ new Date(workingDate.getFullYear(), workingDate.getMonth() + 1, workingDate.getDate()) <=
2311
+ targetDate
2312
+ ) {
2313
+ workingDate.setMonth(workingDate.getMonth() + 1);
2314
+ parts.months++;
2315
+ }
2316
+ }
2317
+
2318
+ // Days
2319
+ if (include.days) {
2320
+ while (
2321
+ new Date(workingDate.getFullYear(), workingDate.getMonth(), workingDate.getDate() + 1) <=
2322
+ targetDate
2323
+ ) {
2324
+ workingDate.setDate(workingDate.getDate() + 1);
2325
+ parts.days++;
2326
+ }
2327
+ }
2328
+
2329
+ remaining = Math.floor((targetDate - workingDate) / 1000);
2330
+ }
2331
+
2332
+ if (include.hours) {
2333
+ parts.hours = Math.floor(remaining / 3600);
2334
+ remaining %= 3600;
2335
+ }
2336
+
2337
+ if (include.minutes) {
2338
+ parts.minutes = Math.floor(remaining / 60);
2339
+ remaining %= 60;
2340
+ }
2341
+
2342
+ if (include.seconds) {
2343
+ parts.seconds = remaining;
2344
+ }
2345
+
2346
+ // Calculate total
2347
+ const totalMap = {
2348
+ seconds: include.seconds ? totalSeconds : NaN,
2349
+ minutes: include.minutes ? totalSeconds / 60 : NaN,
2350
+ hours: include.hours ? totalSeconds / 3600 : NaN,
2351
+ days: include.days ? totalSeconds / 86400 : NaN,
2352
+ months: include.months ? parts.years * 12 + parts.months + (parts.days || 0) / 30 : NaN,
2353
+ years: include.years ? parts.years + (parts.months || 0) / 12 + (parts.days || 0) / 365 : NaN,
2354
+ };
2355
+
2356
+ parts.total = +(totalMap[level] || 0).toFixed(2).replace(/\.00$/, '');
2357
+
2358
+ const pad = (n) => (isNaN(n) ? 'NaN' : String(n).padStart(2, '0'));
2359
+
2360
+ const timeString = [
2361
+ include.hours ? pad(parts.hours) : null,
2362
+ include.minutes ? pad(parts.minutes) : null,
2363
+ include.seconds ? pad(parts.seconds) : null,
2364
+ ]
2365
+ .filter((v) => v !== null)
2366
+ .join(':');
2367
+
2368
+ return format
2369
+ .replace(/\{years\}/g, parts.years)
2370
+ .replace(/\{months\}/g, parts.months)
2371
+ .replace(/\{days\}/g, parts.days)
2372
+ .replace(/\{hours\}/g, pad(parts.hours))
2373
+ .replace(/\{minutes\}/g, pad(parts.minutes))
2374
+ .replace(/\{seconds\}/g, pad(parts.seconds))
2375
+ .replace(/\{time\}/g, timeString)
2376
+ .replace(/\{total\}/g, parts.total)
2377
+ .trim();
2378
+ }
2379
+
2380
+ /**
2381
+ * Formats a duration (in seconds) into a timer string showing only hours, minutes, and seconds.
2382
+ *
2383
+ * Example output: "05:32:10"
2384
+ *
2385
+ * @param {number} seconds - The total number of seconds to format.
2386
+ * @returns {string} The formatted timer string in "HH:MM:SS" format.
2387
+ */
2388
+ function formatTimer(seconds) {
2389
+ return formatCustomTimer(seconds, 'hours', '{hours}:{minutes}:{seconds}');
2390
+ }
2391
+
2392
+ /**
2393
+ * Formats a duration (in seconds) into a timer string including days, hours, minutes, and seconds.
2394
+ *
2395
+ * Example output: "2d 05:32:10"
2396
+ *
2397
+ * @param {number} seconds - The total number of seconds to format.
2398
+ * @returns {string} The formatted timer string in "Xd HH:MM:SS" format.
2399
+ */
2400
+ function formatDayTimer(seconds) {
2401
+ return formatCustomTimer(seconds, 'days', '{days}d {hours}:{minutes}:{seconds}');
2402
+ }
2403
+
2404
+ // EXTERNAL MODULE: ./node_modules/buffer/index.js
2405
+ var buffer = __webpack_require__(287);
2406
+ ;// ./src/v1/basics/objFilter.mjs
2407
+
2408
+
2409
+ /**
2410
+ * An object containing type validation functions and their evaluation order.
2411
+ *
2412
+ * Each item in `typeValidator.items` is a function that receives any value
2413
+ * and returns a boolean indicating whether the value matches the corresponding type.
2414
+ *
2415
+ * The `order` array defines the priority in which types should be checked,
2416
+ * which can be useful for functions that infer types in a consistent manner.
2417
+ *
2418
+ * @typedef {Object} TypeValidator
2419
+ * @property {Object.<string, (val: any) => boolean>} items - A dictionary of type validation functions.
2420
+ * @property {string[]} order - The order in which types should be evaluated.
2421
+ */
2422
+
2423
+ /**
2424
+ * Validates values against specific types using predefined functions.
2425
+ *
2426
+ * @type {TypeValidator}
2427
+ */
2428
+ const typeValidator = {
2429
+ items: {
2430
+ /** Checks if the value is undefined. */
2431
+ undefined: (val) => typeof val === 'undefined',
2432
+
2433
+ /** Checks if the value is null. */
2434
+ null: (val) => val === null,
2435
+
2436
+ /** Checks if the value is a boolean. */
2437
+ boolean: (val) => typeof val === 'boolean',
2438
+
2439
+ /** Checks if the value is a number. */
2440
+ number: (val) => typeof val === 'number' && !isNaN(val),
2441
+
2442
+ /** Checks if the value is a bigint. */
2443
+ bigint: (val) => typeof val === 'bigint',
2444
+
2445
+ /** Checks if the value is a string. */
2446
+ string: (val) => typeof val === 'string',
2447
+
2448
+ /** Checks if the value is a symbol. */
2449
+ symbol: (val) => typeof val === 'symbol',
2450
+
2451
+ /** Checks if the value is a function. */
2452
+ function: (val) => typeof val === 'function',
2453
+
2454
+ /** Checks if the value is an array. */
2455
+ array: (val) => Array.isArray(val),
2456
+
2457
+ /** Checks if the value is a Date object. */
2458
+ date: (val) => val instanceof Date,
2459
+
2460
+ /** Checks if the value is a regular expression. */
2461
+ regexp: (val) => val instanceof RegExp,
2462
+
2463
+ /** Checks if the value is a Map. */
2464
+ map: (val) => val instanceof Map,
2465
+
2466
+ /** Checks if the value is a Set. */
2467
+ set: (val) => val instanceof Set,
2468
+
2469
+ /** Checks if the value is a WeakMap. */
2470
+ weakmap: (val) => val instanceof WeakMap,
2471
+
2472
+ /** Checks if the value is a WeakSet. */
2473
+ weakset: (val) => val instanceof WeakSet,
2474
+
2475
+ /** Checks if the value is a Promise. */
2476
+ promise: (val) => val instanceof Promise,
2477
+
2478
+ /** Checks if the value is a Buffer. */
2479
+ buffer: (val) => typeof buffer/* Buffer */.hp !== 'undefined' && buffer/* Buffer */.hp.isBuffer(val),
2480
+
2481
+ /** Checks if the value is a Html Element. */
2482
+ htmlelement: (val) => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement,
2483
+
2484
+ /** Checks if the value is a non-null plain object or instance of a class. */
2485
+ object: (val) => typeof val === 'object' && val !== null,
2486
+ },
2487
+
2488
+ /** Evaluation order of the type checkers. */
2489
+ order: [
2490
+ 'undefined',
2491
+ 'null',
2492
+ 'boolean',
2493
+ 'number',
2494
+ 'bigint',
2495
+ 'string',
2496
+ 'symbol',
2497
+ 'function',
2498
+ 'array',
2499
+ 'buffer',
2500
+ 'date',
2501
+ 'regexp',
2502
+ 'map',
2503
+ 'set',
2504
+ 'weakmap',
2505
+ 'weakset',
2506
+ 'promise',
2507
+ 'htmlelement',
2508
+ 'object',
2509
+ ],
2510
+ };
2511
+
2512
+ /**
2513
+ * Adds new type checkers to the typeValidator without overwriting existing ones.
2514
+ *
2515
+ * Optionally, you can specify the index at which the new type should be inserted in the order.
2516
+ * If no index is provided, the type is inserted just before 'object' (if it exists), or at the end.
2517
+ *
2518
+ * @param {Object.<string, (val: any) => boolean>} newItems - New type validators to be added.
2519
+ * @param {number} [index] - Optional. Position at which to insert each new type. Ignored if the type already exists.
2520
+ * @returns {string[]} - A list of successfully added type names.
2521
+ *
2522
+ * @example
2523
+ * extendObjType({
2524
+ * htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement
2525
+ * });
2526
+ */
2527
+ function extendObjType(newItems, index) {
2528
+ const added = [];
2529
+
2530
+ for (const [key, fn] of Object.entries(newItems)) {
2531
+ if (!typeValidator.items.hasOwnProperty(key)) {
2532
+ typeValidator.items[key] = fn;
2533
+
2534
+ let insertAt = typeof index === 'number' ? index : -1; // Default to -1 if index isn't provided
2535
+
2536
+ // Default to before 'object', or to the end
2537
+ if (insertAt === -1) {
2538
+ const objectIndex = typeValidator.order.indexOf('object');
2539
+ insertAt = objectIndex > -1 ? objectIndex : typeValidator.order.length;
2540
+ }
2541
+
2542
+ // Ensure insertAt is a valid number and not out of bounds
2543
+ insertAt = Math.min(Math.max(0, insertAt), typeValidator.order.length);
2544
+
2545
+ typeValidator.order.splice(insertAt, 0, key);
2546
+ added.push(key);
2547
+ }
2548
+ }
2549
+
2550
+ return added;
2551
+ }
2552
+
2553
+ /**
2554
+ * Reorders the typeValidator.order array according to a custom new order.
2555
+ * All values in the new order must already exist in the current order.
2556
+ * The function does not mutate the original array structure directly.
2557
+ *
2558
+ * @param {string[]} newOrder - The new order of type names.
2559
+ * @returns {boolean} - Returns true if the reorder was successful, false if invalid keys were found.
2560
+ *
2561
+ * @example
2562
+ * reorderObjTypeOrder([
2563
+ * 'string', 'number', 'array', 'object'
2564
+ * ]);
2565
+ */
2566
+ function reorderObjTypeOrder(newOrder) {
2567
+ const currentOrder = [...typeValidator.order]; // shallow clone
2568
+
2569
+ // All keys in newOrder must exist in currentOrder
2570
+ const isValid = newOrder.every((type) => currentOrder.includes(type));
2571
+
2572
+ if (!isValid) return false;
2573
+
2574
+ // Reassign only if valid
2575
+ typeValidator.order = newOrder.slice(); // assign shallow copy
2576
+ return true;
2577
+ }
2578
+
2579
+ /**
2580
+ * Returns a cloned version of the `typeValidator.order` array.
2581
+ * The cloned array will not be affected by future changes to the original `order`.
2582
+ *
2583
+ * @returns {string[]} - A new array with the same values as `typeValidator.order`.
2584
+ */
2585
+ function cloneObjTypeOrder() {
2586
+ return [...typeValidator.order]; // Creates a shallow copy of the array
2587
+ }
2588
+
2589
+ /**
2590
+ * Returns the detected type name of a given value based on predefined type validators.
2591
+ *
2592
+ * This function uses `getType` with a predefined `typeValidator` to determine or compare types safely.
2593
+ * in the specified `typeValidator.order`. The first matching type is returned.
2594
+ *
2595
+ * If `val` is `null`, it immediately returns `'null'`.
2596
+ * If no match is found, it returns `'unknown'`.
2597
+ *
2598
+ * @param {any} val - The value whose type should be determined.
2599
+ * @returns {string} - The type name of the value (e.g., "array", "date", "map"), or "unknown" if no match is found.
2600
+ *
2601
+ * @example
2602
+ * getType([]); // "array"
2603
+ * getType(null); // "null"
2604
+ * getType(new Set()); // "set"
2605
+ * getType(() => {}); // "unknown"
2606
+ */
2607
+ const getType = (val) => {
2608
+ if (val === null) return 'null';
2609
+ for (const name of typeValidator.order)
2610
+ if (!typeValidator.items[name] || typeValidator.items[name](val)) return name;
2611
+ return 'unknown';
2612
+ };
2613
+
2614
+ /**
2615
+ * Checks the type of a given object or returns its type as a string.
2616
+ *
2617
+ * @param {*} obj - The object to check or identify.
2618
+ * @param {string} [type] - Optional. If provided, checks whether the object matches this type (e.g., "object", "array", "string").
2619
+ * @returns {boolean|string|null} - Returns `true` if the type matches, `false` if not,
2620
+ * the type string if no type is provided, or `null` if the object is `undefined`.
2621
+ *
2622
+ * @example
2623
+ * objType([], 'array'); // true
2624
+ * objType({}, 'object'); // true
2625
+ * objType('hello'); // "string"
2626
+ * objType(undefined); // null
2627
+ */
2628
+ function objType(obj, type) {
2629
+ if (typeof obj === 'undefined') return null;
2630
+ const result = getType(obj);
2631
+ if (typeof type === 'string') return result === type.toLowerCase();
2632
+ return result;
2633
+ }
2634
+
2635
+ /**
2636
+ * Counts the number of elements in an array or the number of properties in an object.
2637
+ *
2638
+ * @param {*} obj - The array or object to count.
2639
+ * @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
2640
+ *
2641
+ * @example
2642
+ * countObj([1, 2, 3]); // 3
2643
+ * countObj({ a: 1, b: 2 }); // 2
2644
+ * countObj('not an object'); // 0
2645
+ */
2646
+ function countObj(obj) {
2647
+ // Is Array
2648
+ if (Array.isArray(obj)) return obj.length;
2649
+ // Object
2650
+ if (objType(obj, 'object')) return Object.keys(obj).length;
2651
+ // Nothing
2652
+ return 0;
2653
+ }
2654
+
2655
+ ;// ./src/v1/basics/simpleMath.mjs
2656
+ /**
2657
+ * Executes a Rule of Three calculation.
2658
+ *
2659
+ * @param {number} val1 - The first reference value (numerator in direct proportion, denominator in inverse).
2660
+ * @param {number} val2 - The second reference value (denominator in direct proportion, numerator in inverse).
2661
+ * @param {number} val3 - The third value (numerator in direct proportion, denominator in inverse).
2662
+ * @param {boolean} inverse - Whether the calculation should use inverse proportion (true for inverse, false for direct).
2663
+ * @returns {number} The result of the Rule of Three operation.
2664
+ *
2665
+ * Rule of Three Formula (Direct Proportion):
2666
+ * val1 / val2 = val3 / result
2667
+ *
2668
+ * For Inverse Proportion:
2669
+ * val1 / val3 = val2 / result
2670
+ *
2671
+ * Visual Representation:
2672
+ *
2673
+ * For Direct Proportion:
2674
+ * val1 val2
2675
+ * ----- = ------
2676
+ * val3 result
2677
+ *
2678
+ * For Inverse Proportion:
2679
+ * val1 val2
2680
+ * ----- = ------
2681
+ * val3 result
2682
+ *
2683
+ * @example
2684
+ * // Direct proportion:
2685
+ * ruleOfThree.execute(2, 6, 3, false); // → 9
2686
+ *
2687
+ * @example
2688
+ * // Inverse proportion:
2689
+ * ruleOfThree.execute(2, 6, 3, true); // → 4
2690
+ */
2691
+ function ruleOfThree(val1, val2, val3, inverse) {
2692
+ return inverse ? Number(val1 * val2) / val3 : Number(val3 * val2) / val1;
2693
+ }
2694
+
2695
+ /**
2696
+ * Calculates a percentage of a given base value.
2697
+ * @param {number} price - The base value.
2698
+ * @param {number} percentage - The percentage to apply.
2699
+ * @returns {number} The result of the percentage calculation.
2700
+ *
2701
+ * @example
2702
+ * getSimplePerc(200, 15); // 30
2703
+ */
2704
+ function getSimplePerc(price, percentage) {
2705
+ return price * (percentage / 100);
2706
+ }
2707
+
2708
+ /**
2709
+ * Calculates the age based on the given date.
2710
+ *
2711
+ * @param {number|string|Date} timeData - The birth date (can be a timestamp, ISO string, or Date object).
2712
+ * @param {Date|null} [now=null] - The Date object representing the current date. Defaults to the current date and time if not provided.
2713
+ * @returns {number|null} The age in years, or null if `timeData` is not provided or invalid.
2714
+ */
2715
+ function getAge(timeData = 0, now = null) {
2716
+ if (typeof timeData !== 'undefined' && timeData !== null && timeData !== 0) {
2717
+ const birthDate = new Date(timeData);
2718
+ if (isNaN(birthDate)) return null;
2719
+
2720
+ const currentDate = now instanceof Date ? now : new Date();
2721
+
2722
+ let age = currentDate.getFullYear() - birthDate.getFullYear();
2723
+
2724
+ const currentMonth = currentDate.getMonth();
2725
+ const birthMonth = birthDate.getMonth();
2726
+
2727
+ const currentDay = currentDate.getDate();
2728
+ const birthDay = birthDate.getDate();
2729
+
2730
+ // Adjust if birthday hasn't occurred yet this year
2731
+ if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) age--;
2732
+
2733
+ return Math.abs(age);
2734
+ }
2735
+
2736
+ return null;
2737
+ }
2738
+
2739
+ ;// ./src/v1/basics/text.mjs
2740
+ /**
2741
+ * Converts a string to title case where the first letter of each word is capitalized.
2742
+ * All other letters are converted to lowercase.
2743
+ *
2744
+ * Example: "hello world" -> "Hello World"
2745
+ *
2746
+ * @param {string} str - The string to be converted to title case.
2747
+ * @returns {string} The string converted to title case.
2748
+ */
2749
+ function toTitleCase(str) {
2750
+ return str.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
2751
+ }
2752
+
2753
+ /**
2754
+ * Converts a string to title case where the first letter of each word is capitalized,
2755
+ * but the first letter of the entire string is left lowercase.
2756
+ *
2757
+ * Example: "hello world" -> "hello World"
2758
+ *
2759
+ * @param {string} str - The string to be converted to title case with the first letter in lowercase.
2760
+ * @returns {string} The string converted to title case with the first letter in lowercase.
2761
+ */
2762
+ function toTitleCaseLowerFirst(str) {
2763
+ const titleCased = str.replace(
2764
+ /\w\S*/g,
2765
+ (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(),
2766
+ );
2767
+ return titleCased.charAt(0).toLowerCase() + titleCased.slice(1);
2768
+ }
2769
+
2770
+ ;// ./src/v1/basics/index.mjs
2771
+
2772
+
2773
+
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+
2780
+ })();
2781
+
2782
+ window.TinyBasicsEs = __webpack_exports__;
2783
+ /******/ })()
2784
+ ;