@hairy/utils 0.6.10 → 0.6.11

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.
package/dist/index.cjs CHANGED
@@ -20,16 +20,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ BIG_INTS: () => BIG_INTS,
24
+ Bignumber: () => bignumber_default,
23
25
  Deferred: () => Deferred,
24
26
  UA: () => UA,
25
27
  arange: () => arange,
28
+ average: () => average,
26
29
  compose: () => compose,
30
+ cover: () => cover,
31
+ decimal: () => decimal,
27
32
  delay: () => delay,
28
33
  formDataToObject: () => formDataToObject,
34
+ formatNumeric: () => formatNumeric,
29
35
  formatSize: () => formatSize,
30
36
  formatUnit: () => formatUnit,
31
37
  getTypeof: () => getTypeof,
38
+ gt: () => gt,
39
+ gte: () => gte,
40
+ integer: () => integer,
32
41
  isAndroid: () => isAndroid,
42
+ isArray: () => isArray,
33
43
  isBrowser: () => isBrowser,
34
44
  isChrome: () => isChrome,
35
45
  isEdge: () => isEdge,
@@ -40,6 +50,7 @@ __export(src_exports, {
40
50
  isIE9: () => isIE9,
41
51
  isIOS: () => isIOS,
42
52
  isMobile: () => isMobile,
53
+ isNull: () => isNull,
43
54
  isNumber: () => isNumber,
44
55
  isObject: () => isObject,
45
56
  isPhantomJS: () => isPhantomJS,
@@ -49,13 +60,21 @@ __export(src_exports, {
49
60
  isWeex: () => isWeex,
50
61
  isWindow: () => isWindow,
51
62
  loop: () => loop,
63
+ lt: () => lt,
64
+ lte: () => lte,
52
65
  noop: () => noop,
66
+ numerfix: () => numerfix,
53
67
  objectToFormData: () => objectToFormData,
54
68
  pPipe: () => pPipe,
69
+ parseNumeric: () => parseNumeric,
70
+ percentage: () => percentage,
55
71
  pipe: () => pipe,
72
+ plus: () => plus,
56
73
  riposte: () => riposte,
74
+ unum: () => unum,
57
75
  weexPlatform: () => weexPlatform,
58
- whenever: () => whenever
76
+ whenever: () => whenever,
77
+ zerofill: () => zerofill
59
78
  });
60
79
  module.exports = __toCommonJS(src_exports);
61
80
 
@@ -77,6 +96,8 @@ var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("
77
96
  var isObject = (value) => typeof value === "object" && !Array.isArray(value);
78
97
  var isNumber = (value) => typeof value === "number";
79
98
  var isString = (value) => typeof value === "string";
99
+ var isArray = (value) => Array.isArray(value);
100
+ var isNull = (value) => value === null;
80
101
  var isPlainObject = (value) => typeof value === "object" && value !== null && value.constructor === Object;
81
102
  var isFormData = (value) => isObject(value) && isBrowser() && value instanceof FormData;
82
103
  var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
@@ -182,18 +203,1605 @@ function riposte(...args) {
182
203
  }
183
204
  return void 0;
184
205
  }
206
+
207
+ // ../../node_modules/.pnpm/bignumber.js@9.1.2/node_modules/bignumber.js/bignumber.mjs
208
+ var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;
209
+ var mathceil = Math.ceil;
210
+ var mathfloor = Math.floor;
211
+ var bignumberError = "[BigNumber Error] ";
212
+ var tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ";
213
+ var BASE = 1e14;
214
+ var LOG_BASE = 14;
215
+ var MAX_SAFE_INTEGER = 9007199254740991;
216
+ var POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13];
217
+ var SQRT_BASE = 1e7;
218
+ var MAX = 1e9;
219
+ function clone(configObject) {
220
+ var div, convertBase, parseNumeric2, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
221
+ prefix: "",
222
+ groupSize: 3,
223
+ secondaryGroupSize: 0,
224
+ groupSeparator: ",",
225
+ decimalSeparator: ".",
226
+ fractionGroupSize: 0,
227
+ fractionGroupSeparator: "\xA0",
228
+ // non-breaking space
229
+ suffix: ""
230
+ }, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
231
+ function BigNumber2(v, b) {
232
+ var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
233
+ if (!(x instanceof BigNumber2))
234
+ return new BigNumber2(v, b);
235
+ if (b == null) {
236
+ if (v && v._isBigNumber === true) {
237
+ x.s = v.s;
238
+ if (!v.c || v.e > MAX_EXP) {
239
+ x.c = x.e = null;
240
+ } else if (v.e < MIN_EXP) {
241
+ x.c = [x.e = 0];
242
+ } else {
243
+ x.e = v.e;
244
+ x.c = v.c.slice();
245
+ }
246
+ return;
247
+ }
248
+ if ((isNum = typeof v == "number") && v * 0 == 0) {
249
+ x.s = 1 / v < 0 ? (v = -v, -1) : 1;
250
+ if (v === ~~v) {
251
+ for (e = 0, i = v; i >= 10; i /= 10, e++)
252
+ ;
253
+ if (e > MAX_EXP) {
254
+ x.c = x.e = null;
255
+ } else {
256
+ x.e = e;
257
+ x.c = [v];
258
+ }
259
+ return;
260
+ }
261
+ str = String(v);
262
+ } else {
263
+ if (!isNumeric.test(str = String(v)))
264
+ return parseNumeric2(x, str, isNum);
265
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
266
+ }
267
+ if ((e = str.indexOf(".")) > -1)
268
+ str = str.replace(".", "");
269
+ if ((i = str.search(/e/i)) > 0) {
270
+ if (e < 0)
271
+ e = i;
272
+ e += +str.slice(i + 1);
273
+ str = str.substring(0, i);
274
+ } else if (e < 0) {
275
+ e = str.length;
276
+ }
277
+ } else {
278
+ intCheck(b, 2, ALPHABET.length, "Base");
279
+ if (b == 10 && alphabetHasNormalDecimalDigits) {
280
+ x = new BigNumber2(v);
281
+ return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
282
+ }
283
+ str = String(v);
284
+ if (isNum = typeof v == "number") {
285
+ if (v * 0 != 0)
286
+ return parseNumeric2(x, str, isNum, b);
287
+ x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
288
+ if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
289
+ throw Error(tooManyDigits + v);
290
+ }
291
+ } else {
292
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
293
+ }
294
+ alphabet = ALPHABET.slice(0, b);
295
+ e = i = 0;
296
+ for (len = str.length; i < len; i++) {
297
+ if (alphabet.indexOf(c = str.charAt(i)) < 0) {
298
+ if (c == ".") {
299
+ if (i > e) {
300
+ e = len;
301
+ continue;
302
+ }
303
+ } else if (!caseChanged) {
304
+ if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
305
+ caseChanged = true;
306
+ i = -1;
307
+ e = 0;
308
+ continue;
309
+ }
310
+ }
311
+ return parseNumeric2(x, String(v), isNum, b);
312
+ }
313
+ }
314
+ isNum = false;
315
+ str = convertBase(str, b, 10, x.s);
316
+ if ((e = str.indexOf(".")) > -1)
317
+ str = str.replace(".", "");
318
+ else
319
+ e = str.length;
320
+ }
321
+ for (i = 0; str.charCodeAt(i) === 48; i++)
322
+ ;
323
+ for (len = str.length; str.charCodeAt(--len) === 48; )
324
+ ;
325
+ if (str = str.slice(i, ++len)) {
326
+ len -= i;
327
+ if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
328
+ throw Error(tooManyDigits + x.s * v);
329
+ }
330
+ if ((e = e - i - 1) > MAX_EXP) {
331
+ x.c = x.e = null;
332
+ } else if (e < MIN_EXP) {
333
+ x.c = [x.e = 0];
334
+ } else {
335
+ x.e = e;
336
+ x.c = [];
337
+ i = (e + 1) % LOG_BASE;
338
+ if (e < 0)
339
+ i += LOG_BASE;
340
+ if (i < len) {
341
+ if (i)
342
+ x.c.push(+str.slice(0, i));
343
+ for (len -= LOG_BASE; i < len; ) {
344
+ x.c.push(+str.slice(i, i += LOG_BASE));
345
+ }
346
+ i = LOG_BASE - (str = str.slice(i)).length;
347
+ } else {
348
+ i -= len;
349
+ }
350
+ for (; i--; str += "0")
351
+ ;
352
+ x.c.push(+str);
353
+ }
354
+ } else {
355
+ x.c = [x.e = 0];
356
+ }
357
+ }
358
+ BigNumber2.clone = clone;
359
+ BigNumber2.ROUND_UP = 0;
360
+ BigNumber2.ROUND_DOWN = 1;
361
+ BigNumber2.ROUND_CEIL = 2;
362
+ BigNumber2.ROUND_FLOOR = 3;
363
+ BigNumber2.ROUND_HALF_UP = 4;
364
+ BigNumber2.ROUND_HALF_DOWN = 5;
365
+ BigNumber2.ROUND_HALF_EVEN = 6;
366
+ BigNumber2.ROUND_HALF_CEIL = 7;
367
+ BigNumber2.ROUND_HALF_FLOOR = 8;
368
+ BigNumber2.EUCLID = 9;
369
+ BigNumber2.config = BigNumber2.set = function(obj) {
370
+ var p, v;
371
+ if (obj != null) {
372
+ if (typeof obj == "object") {
373
+ if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
374
+ v = obj[p];
375
+ intCheck(v, 0, MAX, p);
376
+ DECIMAL_PLACES = v;
377
+ }
378
+ if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
379
+ v = obj[p];
380
+ intCheck(v, 0, 8, p);
381
+ ROUNDING_MODE = v;
382
+ }
383
+ if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
384
+ v = obj[p];
385
+ if (v && v.pop) {
386
+ intCheck(v[0], -MAX, 0, p);
387
+ intCheck(v[1], 0, MAX, p);
388
+ TO_EXP_NEG = v[0];
389
+ TO_EXP_POS = v[1];
390
+ } else {
391
+ intCheck(v, -MAX, MAX, p);
392
+ TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
393
+ }
394
+ }
395
+ if (obj.hasOwnProperty(p = "RANGE")) {
396
+ v = obj[p];
397
+ if (v && v.pop) {
398
+ intCheck(v[0], -MAX, -1, p);
399
+ intCheck(v[1], 1, MAX, p);
400
+ MIN_EXP = v[0];
401
+ MAX_EXP = v[1];
402
+ } else {
403
+ intCheck(v, -MAX, MAX, p);
404
+ if (v) {
405
+ MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
406
+ } else {
407
+ throw Error(bignumberError + p + " cannot be zero: " + v);
408
+ }
409
+ }
410
+ }
411
+ if (obj.hasOwnProperty(p = "CRYPTO")) {
412
+ v = obj[p];
413
+ if (v === !!v) {
414
+ if (v) {
415
+ if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
416
+ CRYPTO = v;
417
+ } else {
418
+ CRYPTO = !v;
419
+ throw Error(bignumberError + "crypto unavailable");
420
+ }
421
+ } else {
422
+ CRYPTO = v;
423
+ }
424
+ } else {
425
+ throw Error(bignumberError + p + " not true or false: " + v);
426
+ }
427
+ }
428
+ if (obj.hasOwnProperty(p = "MODULO_MODE")) {
429
+ v = obj[p];
430
+ intCheck(v, 0, 9, p);
431
+ MODULO_MODE = v;
432
+ }
433
+ if (obj.hasOwnProperty(p = "POW_PRECISION")) {
434
+ v = obj[p];
435
+ intCheck(v, 0, MAX, p);
436
+ POW_PRECISION = v;
437
+ }
438
+ if (obj.hasOwnProperty(p = "FORMAT")) {
439
+ v = obj[p];
440
+ if (typeof v == "object")
441
+ FORMAT = v;
442
+ else
443
+ throw Error(bignumberError + p + " not an object: " + v);
444
+ }
445
+ if (obj.hasOwnProperty(p = "ALPHABET")) {
446
+ v = obj[p];
447
+ if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
448
+ alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
449
+ ALPHABET = v;
450
+ } else {
451
+ throw Error(bignumberError + p + " invalid: " + v);
452
+ }
453
+ }
454
+ } else {
455
+ throw Error(bignumberError + "Object expected: " + obj);
456
+ }
457
+ }
458
+ return {
459
+ DECIMAL_PLACES,
460
+ ROUNDING_MODE,
461
+ EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
462
+ RANGE: [MIN_EXP, MAX_EXP],
463
+ CRYPTO,
464
+ MODULO_MODE,
465
+ POW_PRECISION,
466
+ FORMAT,
467
+ ALPHABET
468
+ };
469
+ };
470
+ BigNumber2.isBigNumber = function(v) {
471
+ if (!v || v._isBigNumber !== true)
472
+ return false;
473
+ if (!BigNumber2.DEBUG)
474
+ return true;
475
+ var i, n, c = v.c, e = v.e, s = v.s;
476
+ out:
477
+ if ({}.toString.call(c) == "[object Array]") {
478
+ if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
479
+ if (c[0] === 0) {
480
+ if (e === 0 && c.length === 1)
481
+ return true;
482
+ break out;
483
+ }
484
+ i = (e + 1) % LOG_BASE;
485
+ if (i < 1)
486
+ i += LOG_BASE;
487
+ if (String(c[0]).length == i) {
488
+ for (i = 0; i < c.length; i++) {
489
+ n = c[i];
490
+ if (n < 0 || n >= BASE || n !== mathfloor(n))
491
+ break out;
492
+ }
493
+ if (n !== 0)
494
+ return true;
495
+ }
496
+ }
497
+ } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
498
+ return true;
499
+ }
500
+ throw Error(bignumberError + "Invalid BigNumber: " + v);
501
+ };
502
+ BigNumber2.maximum = BigNumber2.max = function() {
503
+ return maxOrMin(arguments, -1);
504
+ };
505
+ BigNumber2.minimum = BigNumber2.min = function() {
506
+ return maxOrMin(arguments, 1);
507
+ };
508
+ BigNumber2.random = function() {
509
+ var pow2_53 = 9007199254740992;
510
+ var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
511
+ return mathfloor(Math.random() * pow2_53);
512
+ } : function() {
513
+ return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
514
+ };
515
+ return function(dp) {
516
+ var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
517
+ if (dp == null)
518
+ dp = DECIMAL_PLACES;
519
+ else
520
+ intCheck(dp, 0, MAX);
521
+ k = mathceil(dp / LOG_BASE);
522
+ if (CRYPTO) {
523
+ if (crypto.getRandomValues) {
524
+ a = crypto.getRandomValues(new Uint32Array(k *= 2));
525
+ for (; i < k; ) {
526
+ v = a[i] * 131072 + (a[i + 1] >>> 11);
527
+ if (v >= 9e15) {
528
+ b = crypto.getRandomValues(new Uint32Array(2));
529
+ a[i] = b[0];
530
+ a[i + 1] = b[1];
531
+ } else {
532
+ c.push(v % 1e14);
533
+ i += 2;
534
+ }
535
+ }
536
+ i = k / 2;
537
+ } else if (crypto.randomBytes) {
538
+ a = crypto.randomBytes(k *= 7);
539
+ for (; i < k; ) {
540
+ v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
541
+ if (v >= 9e15) {
542
+ crypto.randomBytes(7).copy(a, i);
543
+ } else {
544
+ c.push(v % 1e14);
545
+ i += 7;
546
+ }
547
+ }
548
+ i = k / 7;
549
+ } else {
550
+ CRYPTO = false;
551
+ throw Error(bignumberError + "crypto unavailable");
552
+ }
553
+ }
554
+ if (!CRYPTO) {
555
+ for (; i < k; ) {
556
+ v = random53bitInt();
557
+ if (v < 9e15)
558
+ c[i++] = v % 1e14;
559
+ }
560
+ }
561
+ k = c[--i];
562
+ dp %= LOG_BASE;
563
+ if (k && dp) {
564
+ v = POWS_TEN[LOG_BASE - dp];
565
+ c[i] = mathfloor(k / v) * v;
566
+ }
567
+ for (; c[i] === 0; c.pop(), i--)
568
+ ;
569
+ if (i < 0) {
570
+ c = [e = 0];
571
+ } else {
572
+ for (e = -1; c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
573
+ ;
574
+ for (i = 1, v = c[0]; v >= 10; v /= 10, i++)
575
+ ;
576
+ if (i < LOG_BASE)
577
+ e -= LOG_BASE - i;
578
+ }
579
+ rand.e = e;
580
+ rand.c = c;
581
+ return rand;
582
+ };
583
+ }();
584
+ BigNumber2.sum = function() {
585
+ var i = 1, args = arguments, sum = new BigNumber2(args[0]);
586
+ for (; i < args.length; )
587
+ sum = sum.plus(args[i++]);
588
+ return sum;
589
+ };
590
+ convertBase = function() {
591
+ var decimal2 = "0123456789";
592
+ function toBaseOut(str, baseIn, baseOut, alphabet) {
593
+ var j, arr = [0], arrL, i = 0, len = str.length;
594
+ for (; i < len; ) {
595
+ for (arrL = arr.length; arrL--; arr[arrL] *= baseIn)
596
+ ;
597
+ arr[0] += alphabet.indexOf(str.charAt(i++));
598
+ for (j = 0; j < arr.length; j++) {
599
+ if (arr[j] > baseOut - 1) {
600
+ if (arr[j + 1] == null)
601
+ arr[j + 1] = 0;
602
+ arr[j + 1] += arr[j] / baseOut | 0;
603
+ arr[j] %= baseOut;
604
+ }
605
+ }
606
+ }
607
+ return arr.reverse();
608
+ }
609
+ return function(str, baseIn, baseOut, sign, callerIsToString) {
610
+ var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
611
+ if (i >= 0) {
612
+ k = POW_PRECISION;
613
+ POW_PRECISION = 0;
614
+ str = str.replace(".", "");
615
+ y = new BigNumber2(baseIn);
616
+ x = y.pow(str.length - i);
617
+ POW_PRECISION = k;
618
+ y.c = toBaseOut(
619
+ toFixedPoint(coeffToString(x.c), x.e, "0"),
620
+ 10,
621
+ baseOut,
622
+ decimal2
623
+ );
624
+ y.e = y.c.length;
625
+ }
626
+ xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal2) : (alphabet = decimal2, ALPHABET));
627
+ e = k = xc.length;
628
+ for (; xc[--k] == 0; xc.pop())
629
+ ;
630
+ if (!xc[0])
631
+ return alphabet.charAt(0);
632
+ if (i < 0) {
633
+ --e;
634
+ } else {
635
+ x.c = xc;
636
+ x.e = e;
637
+ x.s = sign;
638
+ x = div(x, y, dp, rm, baseOut);
639
+ xc = x.c;
640
+ r = x.r;
641
+ e = x.e;
642
+ }
643
+ d = e + dp + 1;
644
+ i = xc[d];
645
+ k = baseOut / 2;
646
+ r = r || d < 0 || xc[d + 1] != null;
647
+ r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
648
+ if (d < 1 || !xc[0]) {
649
+ str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
650
+ } else {
651
+ xc.length = d;
652
+ if (r) {
653
+ for (--baseOut; ++xc[--d] > baseOut; ) {
654
+ xc[d] = 0;
655
+ if (!d) {
656
+ ++e;
657
+ xc = [1].concat(xc);
658
+ }
659
+ }
660
+ }
661
+ for (k = xc.length; !xc[--k]; )
662
+ ;
663
+ for (i = 0, str = ""; i <= k; str += alphabet.charAt(xc[i++]))
664
+ ;
665
+ str = toFixedPoint(str, e, alphabet.charAt(0));
666
+ }
667
+ return str;
668
+ };
669
+ }();
670
+ div = function() {
671
+ function multiply(x, k, base) {
672
+ var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
673
+ for (x = x.slice(); i--; ) {
674
+ xlo = x[i] % SQRT_BASE;
675
+ xhi = x[i] / SQRT_BASE | 0;
676
+ m = khi * xlo + xhi * klo;
677
+ temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
678
+ carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
679
+ x[i] = temp % base;
680
+ }
681
+ if (carry)
682
+ x = [carry].concat(x);
683
+ return x;
684
+ }
685
+ function compare2(a, b, aL, bL) {
686
+ var i, cmp;
687
+ if (aL != bL) {
688
+ cmp = aL > bL ? 1 : -1;
689
+ } else {
690
+ for (i = cmp = 0; i < aL; i++) {
691
+ if (a[i] != b[i]) {
692
+ cmp = a[i] > b[i] ? 1 : -1;
693
+ break;
694
+ }
695
+ }
696
+ }
697
+ return cmp;
698
+ }
699
+ function subtract(a, b, aL, base) {
700
+ var i = 0;
701
+ for (; aL--; ) {
702
+ a[aL] -= i;
703
+ i = a[aL] < b[aL] ? 1 : 0;
704
+ a[aL] = i * base + a[aL] - b[aL];
705
+ }
706
+ for (; !a[0] && a.length > 1; a.splice(0, 1))
707
+ ;
708
+ }
709
+ return function(x, y, dp, rm, base) {
710
+ var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
711
+ if (!xc || !xc[0] || !yc || !yc[0]) {
712
+ return new BigNumber2(
713
+ // Return NaN if either NaN, or both Infinity or 0.
714
+ !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : (
715
+ // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
716
+ xc && xc[0] == 0 || !yc ? s * 0 : s / 0
717
+ )
718
+ );
719
+ }
720
+ q = new BigNumber2(s);
721
+ qc = q.c = [];
722
+ e = x.e - y.e;
723
+ s = dp + e + 1;
724
+ if (!base) {
725
+ base = BASE;
726
+ e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
727
+ s = s / LOG_BASE | 0;
728
+ }
729
+ for (i = 0; yc[i] == (xc[i] || 0); i++)
730
+ ;
731
+ if (yc[i] > (xc[i] || 0))
732
+ e--;
733
+ if (s < 0) {
734
+ qc.push(1);
735
+ more = true;
736
+ } else {
737
+ xL = xc.length;
738
+ yL = yc.length;
739
+ i = 0;
740
+ s += 2;
741
+ n = mathfloor(base / (yc[0] + 1));
742
+ if (n > 1) {
743
+ yc = multiply(yc, n, base);
744
+ xc = multiply(xc, n, base);
745
+ yL = yc.length;
746
+ xL = xc.length;
747
+ }
748
+ xi = yL;
749
+ rem = xc.slice(0, yL);
750
+ remL = rem.length;
751
+ for (; remL < yL; rem[remL++] = 0)
752
+ ;
753
+ yz = yc.slice();
754
+ yz = [0].concat(yz);
755
+ yc0 = yc[0];
756
+ if (yc[1] >= base / 2)
757
+ yc0++;
758
+ do {
759
+ n = 0;
760
+ cmp = compare2(yc, rem, yL, remL);
761
+ if (cmp < 0) {
762
+ rem0 = rem[0];
763
+ if (yL != remL)
764
+ rem0 = rem0 * base + (rem[1] || 0);
765
+ n = mathfloor(rem0 / yc0);
766
+ if (n > 1) {
767
+ if (n >= base)
768
+ n = base - 1;
769
+ prod = multiply(yc, n, base);
770
+ prodL = prod.length;
771
+ remL = rem.length;
772
+ while (compare2(prod, rem, prodL, remL) == 1) {
773
+ n--;
774
+ subtract(prod, yL < prodL ? yz : yc, prodL, base);
775
+ prodL = prod.length;
776
+ cmp = 1;
777
+ }
778
+ } else {
779
+ if (n == 0) {
780
+ cmp = n = 1;
781
+ }
782
+ prod = yc.slice();
783
+ prodL = prod.length;
784
+ }
785
+ if (prodL < remL)
786
+ prod = [0].concat(prod);
787
+ subtract(rem, prod, remL, base);
788
+ remL = rem.length;
789
+ if (cmp == -1) {
790
+ while (compare2(yc, rem, yL, remL) < 1) {
791
+ n++;
792
+ subtract(rem, yL < remL ? yz : yc, remL, base);
793
+ remL = rem.length;
794
+ }
795
+ }
796
+ } else if (cmp === 0) {
797
+ n++;
798
+ rem = [0];
799
+ }
800
+ qc[i++] = n;
801
+ if (rem[0]) {
802
+ rem[remL++] = xc[xi] || 0;
803
+ } else {
804
+ rem = [xc[xi]];
805
+ remL = 1;
806
+ }
807
+ } while ((xi++ < xL || rem[0] != null) && s--);
808
+ more = rem[0] != null;
809
+ if (!qc[0])
810
+ qc.splice(0, 1);
811
+ }
812
+ if (base == BASE) {
813
+ for (i = 1, s = qc[0]; s >= 10; s /= 10, i++)
814
+ ;
815
+ round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
816
+ } else {
817
+ q.e = e;
818
+ q.r = +more;
819
+ }
820
+ return q;
821
+ };
822
+ }();
823
+ function format(n, i, rm, id) {
824
+ var c0, e, ne, len, str;
825
+ if (rm == null)
826
+ rm = ROUNDING_MODE;
827
+ else
828
+ intCheck(rm, 0, 8);
829
+ if (!n.c)
830
+ return n.toString();
831
+ c0 = n.c[0];
832
+ ne = n.e;
833
+ if (i == null) {
834
+ str = coeffToString(n.c);
835
+ str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
836
+ } else {
837
+ n = round(new BigNumber2(n), i, rm);
838
+ e = n.e;
839
+ str = coeffToString(n.c);
840
+ len = str.length;
841
+ if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
842
+ for (; len < i; str += "0", len++)
843
+ ;
844
+ str = toExponential(str, e);
845
+ } else {
846
+ i -= ne;
847
+ str = toFixedPoint(str, e, "0");
848
+ if (e + 1 > len) {
849
+ if (--i > 0)
850
+ for (str += "."; i--; str += "0")
851
+ ;
852
+ } else {
853
+ i += e - len;
854
+ if (i > 0) {
855
+ if (e + 1 == len)
856
+ str += ".";
857
+ for (; i--; str += "0")
858
+ ;
859
+ }
860
+ }
861
+ }
862
+ }
863
+ return n.s < 0 && c0 ? "-" + str : str;
864
+ }
865
+ function maxOrMin(args, n) {
866
+ var k, y, i = 1, x = new BigNumber2(args[0]);
867
+ for (; i < args.length; i++) {
868
+ y = new BigNumber2(args[i]);
869
+ if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
870
+ x = y;
871
+ }
872
+ }
873
+ return x;
874
+ }
875
+ function normalise(n, c, e) {
876
+ var i = 1, j = c.length;
877
+ for (; !c[--j]; c.pop())
878
+ ;
879
+ for (j = c[0]; j >= 10; j /= 10, i++)
880
+ ;
881
+ if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
882
+ n.c = n.e = null;
883
+ } else if (e < MIN_EXP) {
884
+ n.c = [n.e = 0];
885
+ } else {
886
+ n.e = e;
887
+ n.c = c;
888
+ }
889
+ return n;
890
+ }
891
+ parseNumeric2 = function() {
892
+ var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
893
+ return function(x, str, isNum, b) {
894
+ var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
895
+ if (isInfinityOrNaN.test(s)) {
896
+ x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
897
+ } else {
898
+ if (!isNum) {
899
+ s = s.replace(basePrefix, function(m, p1, p2) {
900
+ base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
901
+ return !b || b == base ? p1 : m;
902
+ });
903
+ if (b) {
904
+ base = b;
905
+ s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
906
+ }
907
+ if (str != s)
908
+ return new BigNumber2(s, base);
909
+ }
910
+ if (BigNumber2.DEBUG) {
911
+ throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
912
+ }
913
+ x.s = null;
914
+ }
915
+ x.c = x.e = null;
916
+ };
917
+ }();
918
+ function round(x, sd, rm, r) {
919
+ var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
920
+ if (xc) {
921
+ out: {
922
+ for (d = 1, k = xc[0]; k >= 10; k /= 10, d++)
923
+ ;
924
+ i = sd - d;
925
+ if (i < 0) {
926
+ i += LOG_BASE;
927
+ j = sd;
928
+ n = xc[ni = 0];
929
+ rd = mathfloor(n / pows10[d - j - 1] % 10);
930
+ } else {
931
+ ni = mathceil((i + 1) / LOG_BASE);
932
+ if (ni >= xc.length) {
933
+ if (r) {
934
+ for (; xc.length <= ni; xc.push(0))
935
+ ;
936
+ n = rd = 0;
937
+ d = 1;
938
+ i %= LOG_BASE;
939
+ j = i - LOG_BASE + 1;
940
+ } else {
941
+ break out;
942
+ }
943
+ } else {
944
+ n = k = xc[ni];
945
+ for (d = 1; k >= 10; k /= 10, d++)
946
+ ;
947
+ i %= LOG_BASE;
948
+ j = i - LOG_BASE + d;
949
+ rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
950
+ }
951
+ }
952
+ r = r || sd < 0 || // Are there any non-zero digits after the rounding digit?
953
+ // The expression n % pows10[d - j - 1] returns all digits of n to the right
954
+ // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
955
+ xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
956
+ r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && // Check whether the digit to the left of the rounding digit is odd.
957
+ (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
958
+ if (sd < 1 || !xc[0]) {
959
+ xc.length = 0;
960
+ if (r) {
961
+ sd -= x.e + 1;
962
+ xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
963
+ x.e = -sd || 0;
964
+ } else {
965
+ xc[0] = x.e = 0;
966
+ }
967
+ return x;
968
+ }
969
+ if (i == 0) {
970
+ xc.length = ni;
971
+ k = 1;
972
+ ni--;
973
+ } else {
974
+ xc.length = ni + 1;
975
+ k = pows10[LOG_BASE - i];
976
+ xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
977
+ }
978
+ if (r) {
979
+ for (; ; ) {
980
+ if (ni == 0) {
981
+ for (i = 1, j = xc[0]; j >= 10; j /= 10, i++)
982
+ ;
983
+ j = xc[0] += k;
984
+ for (k = 1; j >= 10; j /= 10, k++)
985
+ ;
986
+ if (i != k) {
987
+ x.e++;
988
+ if (xc[0] == BASE)
989
+ xc[0] = 1;
990
+ }
991
+ break;
992
+ } else {
993
+ xc[ni] += k;
994
+ if (xc[ni] != BASE)
995
+ break;
996
+ xc[ni--] = 0;
997
+ k = 1;
998
+ }
999
+ }
1000
+ }
1001
+ for (i = xc.length; xc[--i] === 0; xc.pop())
1002
+ ;
1003
+ }
1004
+ if (x.e > MAX_EXP) {
1005
+ x.c = x.e = null;
1006
+ } else if (x.e < MIN_EXP) {
1007
+ x.c = [x.e = 0];
1008
+ }
1009
+ }
1010
+ return x;
1011
+ }
1012
+ function valueOf(n) {
1013
+ var str, e = n.e;
1014
+ if (e === null)
1015
+ return n.toString();
1016
+ str = coeffToString(n.c);
1017
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
1018
+ return n.s < 0 ? "-" + str : str;
1019
+ }
1020
+ P.absoluteValue = P.abs = function() {
1021
+ var x = new BigNumber2(this);
1022
+ if (x.s < 0)
1023
+ x.s = 1;
1024
+ return x;
1025
+ };
1026
+ P.comparedTo = function(y, b) {
1027
+ return compare(this, new BigNumber2(y, b));
1028
+ };
1029
+ P.decimalPlaces = P.dp = function(dp, rm) {
1030
+ var c, n, v, x = this;
1031
+ if (dp != null) {
1032
+ intCheck(dp, 0, MAX);
1033
+ if (rm == null)
1034
+ rm = ROUNDING_MODE;
1035
+ else
1036
+ intCheck(rm, 0, 8);
1037
+ return round(new BigNumber2(x), dp + x.e + 1, rm);
1038
+ }
1039
+ if (!(c = x.c))
1040
+ return null;
1041
+ n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
1042
+ if (v = c[v])
1043
+ for (; v % 10 == 0; v /= 10, n--)
1044
+ ;
1045
+ if (n < 0)
1046
+ n = 0;
1047
+ return n;
1048
+ };
1049
+ P.dividedBy = P.div = function(y, b) {
1050
+ return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
1051
+ };
1052
+ P.dividedToIntegerBy = P.idiv = function(y, b) {
1053
+ return div(this, new BigNumber2(y, b), 0, 1);
1054
+ };
1055
+ P.exponentiatedBy = P.pow = function(n, m) {
1056
+ var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
1057
+ n = new BigNumber2(n);
1058
+ if (n.c && !n.isInteger()) {
1059
+ throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
1060
+ }
1061
+ if (m != null)
1062
+ m = new BigNumber2(m);
1063
+ nIsBig = n.e > 14;
1064
+ if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
1065
+ y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
1066
+ return m ? y.mod(m) : y;
1067
+ }
1068
+ nIsNeg = n.s < 0;
1069
+ if (m) {
1070
+ if (m.c ? !m.c[0] : !m.s)
1071
+ return new BigNumber2(NaN);
1072
+ isModExp = !nIsNeg && x.isInteger() && m.isInteger();
1073
+ if (isModExp)
1074
+ x = x.mod(m);
1075
+ } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7 : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
1076
+ k = x.s < 0 && isOdd(n) ? -0 : 0;
1077
+ if (x.e > -1)
1078
+ k = 1 / k;
1079
+ return new BigNumber2(nIsNeg ? 1 / k : k);
1080
+ } else if (POW_PRECISION) {
1081
+ k = mathceil(POW_PRECISION / LOG_BASE + 2);
1082
+ }
1083
+ if (nIsBig) {
1084
+ half = new BigNumber2(0.5);
1085
+ if (nIsNeg)
1086
+ n.s = 1;
1087
+ nIsOdd = isOdd(n);
1088
+ } else {
1089
+ i = Math.abs(+valueOf(n));
1090
+ nIsOdd = i % 2;
1091
+ }
1092
+ y = new BigNumber2(ONE);
1093
+ for (; ; ) {
1094
+ if (nIsOdd) {
1095
+ y = y.times(x);
1096
+ if (!y.c)
1097
+ break;
1098
+ if (k) {
1099
+ if (y.c.length > k)
1100
+ y.c.length = k;
1101
+ } else if (isModExp) {
1102
+ y = y.mod(m);
1103
+ }
1104
+ }
1105
+ if (i) {
1106
+ i = mathfloor(i / 2);
1107
+ if (i === 0)
1108
+ break;
1109
+ nIsOdd = i % 2;
1110
+ } else {
1111
+ n = n.times(half);
1112
+ round(n, n.e + 1, 1);
1113
+ if (n.e > 14) {
1114
+ nIsOdd = isOdd(n);
1115
+ } else {
1116
+ i = +valueOf(n);
1117
+ if (i === 0)
1118
+ break;
1119
+ nIsOdd = i % 2;
1120
+ }
1121
+ }
1122
+ x = x.times(x);
1123
+ if (k) {
1124
+ if (x.c && x.c.length > k)
1125
+ x.c.length = k;
1126
+ } else if (isModExp) {
1127
+ x = x.mod(m);
1128
+ }
1129
+ }
1130
+ if (isModExp)
1131
+ return y;
1132
+ if (nIsNeg)
1133
+ y = ONE.div(y);
1134
+ return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
1135
+ };
1136
+ P.integerValue = function(rm) {
1137
+ var n = new BigNumber2(this);
1138
+ if (rm == null)
1139
+ rm = ROUNDING_MODE;
1140
+ else
1141
+ intCheck(rm, 0, 8);
1142
+ return round(n, n.e + 1, rm);
1143
+ };
1144
+ P.isEqualTo = P.eq = function(y, b) {
1145
+ return compare(this, new BigNumber2(y, b)) === 0;
1146
+ };
1147
+ P.isFinite = function() {
1148
+ return !!this.c;
1149
+ };
1150
+ P.isGreaterThan = P.gt = function(y, b) {
1151
+ return compare(this, new BigNumber2(y, b)) > 0;
1152
+ };
1153
+ P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
1154
+ return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
1155
+ };
1156
+ P.isInteger = function() {
1157
+ return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
1158
+ };
1159
+ P.isLessThan = P.lt = function(y, b) {
1160
+ return compare(this, new BigNumber2(y, b)) < 0;
1161
+ };
1162
+ P.isLessThanOrEqualTo = P.lte = function(y, b) {
1163
+ return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
1164
+ };
1165
+ P.isNaN = function() {
1166
+ return !this.s;
1167
+ };
1168
+ P.isNegative = function() {
1169
+ return this.s < 0;
1170
+ };
1171
+ P.isPositive = function() {
1172
+ return this.s > 0;
1173
+ };
1174
+ P.isZero = function() {
1175
+ return !!this.c && this.c[0] == 0;
1176
+ };
1177
+ P.minus = function(y, b) {
1178
+ var i, j, t, xLTy, x = this, a = x.s;
1179
+ y = new BigNumber2(y, b);
1180
+ b = y.s;
1181
+ if (!a || !b)
1182
+ return new BigNumber2(NaN);
1183
+ if (a != b) {
1184
+ y.s = -b;
1185
+ return x.plus(y);
1186
+ }
1187
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
1188
+ if (!xe || !ye) {
1189
+ if (!xc || !yc)
1190
+ return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
1191
+ if (!xc[0] || !yc[0]) {
1192
+ return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : (
1193
+ // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
1194
+ ROUNDING_MODE == 3 ? -0 : 0
1195
+ ));
1196
+ }
1197
+ }
1198
+ xe = bitFloor(xe);
1199
+ ye = bitFloor(ye);
1200
+ xc = xc.slice();
1201
+ if (a = xe - ye) {
1202
+ if (xLTy = a < 0) {
1203
+ a = -a;
1204
+ t = xc;
1205
+ } else {
1206
+ ye = xe;
1207
+ t = yc;
1208
+ }
1209
+ t.reverse();
1210
+ for (b = a; b--; t.push(0))
1211
+ ;
1212
+ t.reverse();
1213
+ } else {
1214
+ j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
1215
+ for (a = b = 0; b < j; b++) {
1216
+ if (xc[b] != yc[b]) {
1217
+ xLTy = xc[b] < yc[b];
1218
+ break;
1219
+ }
1220
+ }
1221
+ }
1222
+ if (xLTy) {
1223
+ t = xc;
1224
+ xc = yc;
1225
+ yc = t;
1226
+ y.s = -y.s;
1227
+ }
1228
+ b = (j = yc.length) - (i = xc.length);
1229
+ if (b > 0)
1230
+ for (; b--; xc[i++] = 0)
1231
+ ;
1232
+ b = BASE - 1;
1233
+ for (; j > a; ) {
1234
+ if (xc[--j] < yc[j]) {
1235
+ for (i = j; i && !xc[--i]; xc[i] = b)
1236
+ ;
1237
+ --xc[i];
1238
+ xc[j] += BASE;
1239
+ }
1240
+ xc[j] -= yc[j];
1241
+ }
1242
+ for (; xc[0] == 0; xc.splice(0, 1), --ye)
1243
+ ;
1244
+ if (!xc[0]) {
1245
+ y.s = ROUNDING_MODE == 3 ? -1 : 1;
1246
+ y.c = [y.e = 0];
1247
+ return y;
1248
+ }
1249
+ return normalise(y, xc, ye);
1250
+ };
1251
+ P.modulo = P.mod = function(y, b) {
1252
+ var q, s, x = this;
1253
+ y = new BigNumber2(y, b);
1254
+ if (!x.c || !y.s || y.c && !y.c[0]) {
1255
+ return new BigNumber2(NaN);
1256
+ } else if (!y.c || x.c && !x.c[0]) {
1257
+ return new BigNumber2(x);
1258
+ }
1259
+ if (MODULO_MODE == 9) {
1260
+ s = y.s;
1261
+ y.s = 1;
1262
+ q = div(x, y, 0, 3);
1263
+ y.s = s;
1264
+ q.s *= s;
1265
+ } else {
1266
+ q = div(x, y, 0, MODULO_MODE);
1267
+ }
1268
+ y = x.minus(q.times(y));
1269
+ if (!y.c[0] && MODULO_MODE == 1)
1270
+ y.s = x.s;
1271
+ return y;
1272
+ };
1273
+ P.multipliedBy = P.times = function(y, b) {
1274
+ var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
1275
+ if (!xc || !yc || !xc[0] || !yc[0]) {
1276
+ if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
1277
+ y.c = y.e = y.s = null;
1278
+ } else {
1279
+ y.s *= x.s;
1280
+ if (!xc || !yc) {
1281
+ y.c = y.e = null;
1282
+ } else {
1283
+ y.c = [0];
1284
+ y.e = 0;
1285
+ }
1286
+ }
1287
+ return y;
1288
+ }
1289
+ e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
1290
+ y.s *= x.s;
1291
+ xcL = xc.length;
1292
+ ycL = yc.length;
1293
+ if (xcL < ycL) {
1294
+ zc = xc;
1295
+ xc = yc;
1296
+ yc = zc;
1297
+ i = xcL;
1298
+ xcL = ycL;
1299
+ ycL = i;
1300
+ }
1301
+ for (i = xcL + ycL, zc = []; i--; zc.push(0))
1302
+ ;
1303
+ base = BASE;
1304
+ sqrtBase = SQRT_BASE;
1305
+ for (i = ycL; --i >= 0; ) {
1306
+ c = 0;
1307
+ ylo = yc[i] % sqrtBase;
1308
+ yhi = yc[i] / sqrtBase | 0;
1309
+ for (k = xcL, j = i + k; j > i; ) {
1310
+ xlo = xc[--k] % sqrtBase;
1311
+ xhi = xc[k] / sqrtBase | 0;
1312
+ m = yhi * xlo + xhi * ylo;
1313
+ xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
1314
+ c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
1315
+ zc[j--] = xlo % base;
1316
+ }
1317
+ zc[j] = c;
1318
+ }
1319
+ if (c) {
1320
+ ++e;
1321
+ } else {
1322
+ zc.splice(0, 1);
1323
+ }
1324
+ return normalise(y, zc, e);
1325
+ };
1326
+ P.negated = function() {
1327
+ var x = new BigNumber2(this);
1328
+ x.s = -x.s || null;
1329
+ return x;
1330
+ };
1331
+ P.plus = function(y, b) {
1332
+ var t, x = this, a = x.s;
1333
+ y = new BigNumber2(y, b);
1334
+ b = y.s;
1335
+ if (!a || !b)
1336
+ return new BigNumber2(NaN);
1337
+ if (a != b) {
1338
+ y.s = -b;
1339
+ return x.minus(y);
1340
+ }
1341
+ var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
1342
+ if (!xe || !ye) {
1343
+ if (!xc || !yc)
1344
+ return new BigNumber2(a / 0);
1345
+ if (!xc[0] || !yc[0])
1346
+ return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
1347
+ }
1348
+ xe = bitFloor(xe);
1349
+ ye = bitFloor(ye);
1350
+ xc = xc.slice();
1351
+ if (a = xe - ye) {
1352
+ if (a > 0) {
1353
+ ye = xe;
1354
+ t = yc;
1355
+ } else {
1356
+ a = -a;
1357
+ t = xc;
1358
+ }
1359
+ t.reverse();
1360
+ for (; a--; t.push(0))
1361
+ ;
1362
+ t.reverse();
1363
+ }
1364
+ a = xc.length;
1365
+ b = yc.length;
1366
+ if (a - b < 0) {
1367
+ t = yc;
1368
+ yc = xc;
1369
+ xc = t;
1370
+ b = a;
1371
+ }
1372
+ for (a = 0; b; ) {
1373
+ a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
1374
+ xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
1375
+ }
1376
+ if (a) {
1377
+ xc = [a].concat(xc);
1378
+ ++ye;
1379
+ }
1380
+ return normalise(y, xc, ye);
1381
+ };
1382
+ P.precision = P.sd = function(sd, rm) {
1383
+ var c, n, v, x = this;
1384
+ if (sd != null && sd !== !!sd) {
1385
+ intCheck(sd, 1, MAX);
1386
+ if (rm == null)
1387
+ rm = ROUNDING_MODE;
1388
+ else
1389
+ intCheck(rm, 0, 8);
1390
+ return round(new BigNumber2(x), sd, rm);
1391
+ }
1392
+ if (!(c = x.c))
1393
+ return null;
1394
+ v = c.length - 1;
1395
+ n = v * LOG_BASE + 1;
1396
+ if (v = c[v]) {
1397
+ for (; v % 10 == 0; v /= 10, n--)
1398
+ ;
1399
+ for (v = c[0]; v >= 10; v /= 10, n++)
1400
+ ;
1401
+ }
1402
+ if (sd && x.e + 1 > n)
1403
+ n = x.e + 1;
1404
+ return n;
1405
+ };
1406
+ P.shiftedBy = function(k) {
1407
+ intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
1408
+ return this.times("1e" + k);
1409
+ };
1410
+ P.squareRoot = P.sqrt = function() {
1411
+ var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
1412
+ if (s !== 1 || !c || !c[0]) {
1413
+ return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
1414
+ }
1415
+ s = Math.sqrt(+valueOf(x));
1416
+ if (s == 0 || s == 1 / 0) {
1417
+ n = coeffToString(c);
1418
+ if ((n.length + e) % 2 == 0)
1419
+ n += "0";
1420
+ s = Math.sqrt(+n);
1421
+ e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
1422
+ if (s == 1 / 0) {
1423
+ n = "5e" + e;
1424
+ } else {
1425
+ n = s.toExponential();
1426
+ n = n.slice(0, n.indexOf("e") + 1) + e;
1427
+ }
1428
+ r = new BigNumber2(n);
1429
+ } else {
1430
+ r = new BigNumber2(s + "");
1431
+ }
1432
+ if (r.c[0]) {
1433
+ e = r.e;
1434
+ s = e + dp;
1435
+ if (s < 3)
1436
+ s = 0;
1437
+ for (; ; ) {
1438
+ t = r;
1439
+ r = half.times(t.plus(div(x, t, dp, 1)));
1440
+ if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
1441
+ if (r.e < e)
1442
+ --s;
1443
+ n = n.slice(s - 3, s + 1);
1444
+ if (n == "9999" || !rep && n == "4999") {
1445
+ if (!rep) {
1446
+ round(t, t.e + DECIMAL_PLACES + 2, 0);
1447
+ if (t.times(t).eq(x)) {
1448
+ r = t;
1449
+ break;
1450
+ }
1451
+ }
1452
+ dp += 4;
1453
+ s += 4;
1454
+ rep = 1;
1455
+ } else {
1456
+ if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
1457
+ round(r, r.e + DECIMAL_PLACES + 2, 1);
1458
+ m = !r.times(r).eq(x);
1459
+ }
1460
+ break;
1461
+ }
1462
+ }
1463
+ }
1464
+ }
1465
+ return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
1466
+ };
1467
+ P.toExponential = function(dp, rm) {
1468
+ if (dp != null) {
1469
+ intCheck(dp, 0, MAX);
1470
+ dp++;
1471
+ }
1472
+ return format(this, dp, rm, 1);
1473
+ };
1474
+ P.toFixed = function(dp, rm) {
1475
+ if (dp != null) {
1476
+ intCheck(dp, 0, MAX);
1477
+ dp = dp + this.e + 1;
1478
+ }
1479
+ return format(this, dp, rm);
1480
+ };
1481
+ P.toFormat = function(dp, rm, format2) {
1482
+ var str, x = this;
1483
+ if (format2 == null) {
1484
+ if (dp != null && rm && typeof rm == "object") {
1485
+ format2 = rm;
1486
+ rm = null;
1487
+ } else if (dp && typeof dp == "object") {
1488
+ format2 = dp;
1489
+ dp = rm = null;
1490
+ } else {
1491
+ format2 = FORMAT;
1492
+ }
1493
+ } else if (typeof format2 != "object") {
1494
+ throw Error(bignumberError + "Argument not an object: " + format2);
1495
+ }
1496
+ str = x.toFixed(dp, rm);
1497
+ if (x.c) {
1498
+ var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
1499
+ if (g2) {
1500
+ i = g1;
1501
+ g1 = g2;
1502
+ g2 = i;
1503
+ len -= i;
1504
+ }
1505
+ if (g1 > 0 && len > 0) {
1506
+ i = len % g1 || g1;
1507
+ intPart = intDigits.substr(0, i);
1508
+ for (; i < len; i += g1)
1509
+ intPart += groupSeparator + intDigits.substr(i, g1);
1510
+ if (g2 > 0)
1511
+ intPart += groupSeparator + intDigits.slice(i);
1512
+ if (isNeg)
1513
+ intPart = "-" + intPart;
1514
+ }
1515
+ str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(
1516
+ new RegExp("\\d{" + g2 + "}\\B", "g"),
1517
+ "$&" + (format2.fractionGroupSeparator || "")
1518
+ ) : fractionPart) : intPart;
1519
+ }
1520
+ return (format2.prefix || "") + str + (format2.suffix || "");
1521
+ };
1522
+ P.toFraction = function(md) {
1523
+ var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
1524
+ if (md != null) {
1525
+ n = new BigNumber2(md);
1526
+ if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
1527
+ throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
1528
+ }
1529
+ }
1530
+ if (!xc)
1531
+ return new BigNumber2(x);
1532
+ d = new BigNumber2(ONE);
1533
+ n1 = d0 = new BigNumber2(ONE);
1534
+ d1 = n0 = new BigNumber2(ONE);
1535
+ s = coeffToString(xc);
1536
+ e = d.e = s.length - x.e - 1;
1537
+ d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
1538
+ md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
1539
+ exp = MAX_EXP;
1540
+ MAX_EXP = 1 / 0;
1541
+ n = new BigNumber2(s);
1542
+ n0.c[0] = 0;
1543
+ for (; ; ) {
1544
+ q = div(n, d, 0, 1);
1545
+ d2 = d0.plus(q.times(d1));
1546
+ if (d2.comparedTo(md) == 1)
1547
+ break;
1548
+ d0 = d1;
1549
+ d1 = d2;
1550
+ n1 = n0.plus(q.times(d2 = n1));
1551
+ n0 = d2;
1552
+ d = n.minus(q.times(d2 = d));
1553
+ n = d2;
1554
+ }
1555
+ d2 = div(md.minus(d0), d1, 0, 1);
1556
+ n0 = n0.plus(d2.times(n1));
1557
+ d0 = d0.plus(d2.times(d1));
1558
+ n0.s = n1.s = x.s;
1559
+ e = e * 2;
1560
+ r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
1561
+ div(n0, d0, e, ROUNDING_MODE).minus(x).abs()
1562
+ ) < 1 ? [n1, d1] : [n0, d0];
1563
+ MAX_EXP = exp;
1564
+ return r;
1565
+ };
1566
+ P.toNumber = function() {
1567
+ return +valueOf(this);
1568
+ };
1569
+ P.toPrecision = function(sd, rm) {
1570
+ if (sd != null)
1571
+ intCheck(sd, 1, MAX);
1572
+ return format(this, sd, rm, 2);
1573
+ };
1574
+ P.toString = function(b) {
1575
+ var str, n = this, s = n.s, e = n.e;
1576
+ if (e === null) {
1577
+ if (s) {
1578
+ str = "Infinity";
1579
+ if (s < 0)
1580
+ str = "-" + str;
1581
+ } else {
1582
+ str = "NaN";
1583
+ }
1584
+ } else {
1585
+ if (b == null) {
1586
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
1587
+ } else if (b === 10 && alphabetHasNormalDecimalDigits) {
1588
+ n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
1589
+ str = toFixedPoint(coeffToString(n.c), n.e, "0");
1590
+ } else {
1591
+ intCheck(b, 2, ALPHABET.length, "Base");
1592
+ str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
1593
+ }
1594
+ if (s < 0 && n.c[0])
1595
+ str = "-" + str;
1596
+ }
1597
+ return str;
1598
+ };
1599
+ P.valueOf = P.toJSON = function() {
1600
+ return valueOf(this);
1601
+ };
1602
+ P._isBigNumber = true;
1603
+ P[Symbol.toStringTag] = "BigNumber";
1604
+ P[Symbol.for("nodejs.util.inspect.custom")] = P.valueOf;
1605
+ if (configObject != null)
1606
+ BigNumber2.set(configObject);
1607
+ return BigNumber2;
1608
+ }
1609
+ function bitFloor(n) {
1610
+ var i = n | 0;
1611
+ return n > 0 || n === i ? i : i - 1;
1612
+ }
1613
+ function coeffToString(a) {
1614
+ var s, z, i = 1, j = a.length, r = a[0] + "";
1615
+ for (; i < j; ) {
1616
+ s = a[i++] + "";
1617
+ z = LOG_BASE - s.length;
1618
+ for (; z--; s = "0" + s)
1619
+ ;
1620
+ r += s;
1621
+ }
1622
+ for (j = r.length; r.charCodeAt(--j) === 48; )
1623
+ ;
1624
+ return r.slice(0, j + 1 || 1);
1625
+ }
1626
+ function compare(x, y) {
1627
+ var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
1628
+ if (!i || !j)
1629
+ return null;
1630
+ a = xc && !xc[0];
1631
+ b = yc && !yc[0];
1632
+ if (a || b)
1633
+ return a ? b ? 0 : -j : i;
1634
+ if (i != j)
1635
+ return i;
1636
+ a = i < 0;
1637
+ b = k == l;
1638
+ if (!xc || !yc)
1639
+ return b ? 0 : !xc ^ a ? 1 : -1;
1640
+ if (!b)
1641
+ return k > l ^ a ? 1 : -1;
1642
+ j = (k = xc.length) < (l = yc.length) ? k : l;
1643
+ for (i = 0; i < j; i++)
1644
+ if (xc[i] != yc[i])
1645
+ return xc[i] > yc[i] ^ a ? 1 : -1;
1646
+ return k == l ? 0 : k > l ^ a ? 1 : -1;
1647
+ }
1648
+ function intCheck(n, min, max, name) {
1649
+ if (n < min || n > max || n !== mathfloor(n)) {
1650
+ throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
1651
+ }
1652
+ }
1653
+ function isOdd(n) {
1654
+ var k = n.c.length - 1;
1655
+ return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
1656
+ }
1657
+ function toExponential(str, e) {
1658
+ return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
1659
+ }
1660
+ function toFixedPoint(str, e, z) {
1661
+ var len, zs;
1662
+ if (e < 0) {
1663
+ for (zs = z + "."; ++e; zs += z)
1664
+ ;
1665
+ str = zs + str;
1666
+ } else {
1667
+ len = str.length;
1668
+ if (++e > len) {
1669
+ for (zs = z, e -= len; --e; zs += z)
1670
+ ;
1671
+ str += zs;
1672
+ } else if (e < len) {
1673
+ str = str.slice(0, e) + "." + str.slice(e);
1674
+ }
1675
+ }
1676
+ return str;
1677
+ }
1678
+ var BigNumber = clone();
1679
+ var bignumber_default = BigNumber;
1680
+
1681
+ // src/number/index.ts
1682
+ var BIG_INTS = {
1683
+ t: { v: 10 ** 12, d: 13, n: "t" },
1684
+ b: { v: 10 ** 9, d: 10, n: "b" },
1685
+ m: { v: 10 ** 6, d: 7, n: "m" },
1686
+ k: { v: 10 ** 3, d: 4, n: "k" }
1687
+ };
1688
+ function unum(num = "0") {
1689
+ return new bignumber_default(numerfix(num));
1690
+ }
1691
+ function gte(num, n) {
1692
+ return unum(num).gte(unum(n));
1693
+ }
1694
+ function gt(num, n) {
1695
+ return unum(num).gt(unum(n));
1696
+ }
1697
+ function lte(num, n) {
1698
+ return unum(num).lte(unum(n));
1699
+ }
1700
+ function lt(num, n) {
1701
+ return unum(num).lt(unum(n));
1702
+ }
1703
+ function plus(array, options) {
1704
+ const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
1705
+ const decimal2 = (options == null ? void 0 : options.d) || 0;
1706
+ return array.filter((v) => unum(v).gt(0)).reduce((t, v) => t.plus(unum(v)), unum(0)).toFixed(decimal2, rounding);
1707
+ }
1708
+ function average(array, options) {
1709
+ const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
1710
+ const decimal2 = (options == null ? void 0 : options.d) || 0;
1711
+ if (array.length === 0)
1712
+ return "0";
1713
+ return unum(plus(array)).div(array.length).toFixed(decimal2, rounding);
1714
+ }
1715
+ function percentage(total, count, options) {
1716
+ options != null ? options : options = { d: 3, r: bignumber_default.ROUND_DOWN };
1717
+ const rounding = (options == null ? void 0 : options.r) || bignumber_default.ROUND_DOWN;
1718
+ const decimal2 = (options == null ? void 0 : options.d) || 3;
1719
+ if (unum(total).lte(0) || unum(count).lte(0))
1720
+ return "0";
1721
+ return unum(count).div(unum(total)).times(100).toFixed(decimal2, rounding);
1722
+ }
1723
+ function zerofill(value, n = 2, type = "positive") {
1724
+ const _value = integer(value);
1725
+ if (_value.length >= n)
1726
+ return value;
1727
+ const zero = "0".repeat(n - _value.length);
1728
+ if (type === "positive")
1729
+ return zero + value;
1730
+ if (type === "reverse")
1731
+ return zero + value;
1732
+ return "";
1733
+ }
1734
+ function numerfix(value) {
1735
+ const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
1736
+ if (_isNaN)
1737
+ console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
1738
+ return _isNaN ? "0" : String(value);
1739
+ }
1740
+ function integer(value) {
1741
+ return new bignumber_default(numerfix(value)).toFixed(0);
1742
+ }
1743
+ function decimal(value, n = 2) {
1744
+ let [integer2, decimal2] = numerfix(value).split(".");
1745
+ if (n <= 0)
1746
+ return integer2;
1747
+ if (!decimal2)
1748
+ decimal2 = "0";
1749
+ decimal2 = decimal2.slice(0, n);
1750
+ decimal2 = decimal2 + "0".repeat(n - decimal2.length);
1751
+ return `${integer2}.${decimal2}`;
1752
+ }
1753
+ function parseNumeric(num, delimiters = ["t", "b", "m"]) {
1754
+ const mappings = [
1755
+ delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
1756
+ delimiters.includes("b") && ((n) => gte(n, BIG_INTS.b.v) && lt(n, BIG_INTS.t.v) && BIG_INTS.b),
1757
+ delimiters.includes("m") && ((n) => gte(n, BIG_INTS.m.v) && lt(n, BIG_INTS.b.v) && BIG_INTS.m),
1758
+ delimiters.includes("k") && ((n) => gte(n, BIG_INTS.k.v) && lt(n, BIG_INTS.m.v) && BIG_INTS.k)
1759
+ ];
1760
+ let options;
1761
+ for (const analy of mappings) {
1762
+ const opts = analy && analy(unum(num).toFixed(0));
1763
+ opts && (options = opts);
1764
+ }
1765
+ return options || { v: 1, d: 0, n: "" };
1766
+ }
1767
+ function formatNumeric(value = "0", options) {
1768
+ const {
1769
+ rounding = bignumber_default.ROUND_DOWN,
1770
+ delimiters,
1771
+ format,
1772
+ decimals = 2
1773
+ } = options || {};
1774
+ const config = parseNumeric(value, delimiters || []);
1775
+ const number = unum(value).div(config.v).toFormat(decimals, rounding, format);
1776
+ return `${number}${config.n}`;
1777
+ }
1778
+
1779
+ // src/string/index.ts
1780
+ function cover(value, mode, symbol = "*") {
1781
+ return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
1782
+ }
185
1783
  // Annotate the CommonJS export names for ESM import in node:
186
1784
  0 && (module.exports = {
1785
+ BIG_INTS,
1786
+ Bignumber,
187
1787
  Deferred,
188
1788
  UA,
189
1789
  arange,
1790
+ average,
190
1791
  compose,
1792
+ cover,
1793
+ decimal,
191
1794
  delay,
192
1795
  formDataToObject,
1796
+ formatNumeric,
193
1797
  formatSize,
194
1798
  formatUnit,
195
1799
  getTypeof,
1800
+ gt,
1801
+ gte,
1802
+ integer,
196
1803
  isAndroid,
1804
+ isArray,
197
1805
  isBrowser,
198
1806
  isChrome,
199
1807
  isEdge,
@@ -204,6 +1812,7 @@ function riposte(...args) {
204
1812
  isIE9,
205
1813
  isIOS,
206
1814
  isMobile,
1815
+ isNull,
207
1816
  isNumber,
208
1817
  isObject,
209
1818
  isPhantomJS,
@@ -213,11 +1822,19 @@ function riposte(...args) {
213
1822
  isWeex,
214
1823
  isWindow,
215
1824
  loop,
1825
+ lt,
1826
+ lte,
216
1827
  noop,
1828
+ numerfix,
217
1829
  objectToFormData,
218
1830
  pPipe,
1831
+ parseNumeric,
1832
+ percentage,
219
1833
  pipe,
1834
+ plus,
220
1835
  riposte,
1836
+ unum,
221
1837
  weexPlatform,
222
- whenever
1838
+ whenever,
1839
+ zerofill
223
1840
  });