@appwrite.io/console 2.1.0 → 2.1.2

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 (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/sdk.js +153 -22
  4. package/dist/cjs/sdk.js.map +1 -1
  5. package/dist/esm/sdk.js +150 -23
  6. package/dist/esm/sdk.js.map +1 -1
  7. package/dist/iife/sdk.js +3910 -22
  8. package/docs/examples/domains/list-suggestions.md +18 -0
  9. package/docs/examples/health/get-queue-audits.md +13 -0
  10. package/docs/examples/organizations/create.md +2 -2
  11. package/docs/examples/organizations/estimation-create-organization.md +2 -2
  12. package/docs/examples/organizations/estimation-update-plan.md +2 -2
  13. package/docs/examples/organizations/update-plan.md +2 -2
  14. package/docs/examples/projects/update-labels.md +14 -0
  15. package/package.json +7 -1
  16. package/rollup.config.js +40 -24
  17. package/src/client.ts +20 -10
  18. package/src/enums/billing-plan.ts +17 -0
  19. package/src/enums/filter-type.ts +4 -0
  20. package/src/enums/name.ts +1 -0
  21. package/src/enums/o-auth-provider.ts +0 -2
  22. package/src/index.ts +2 -0
  23. package/src/models.ts +129 -59
  24. package/src/query.ts +14 -11
  25. package/src/services/databases.ts +30 -30
  26. package/src/services/domains.ts +91 -0
  27. package/src/services/health.ts +55 -6
  28. package/src/services/organizations.ts +37 -36
  29. package/src/services/projects.ts +65 -2
  30. package/src/services/storage.ts +4 -4
  31. package/src/services/tables-db.ts +30 -30
  32. package/types/client.d.ts +8 -1
  33. package/types/enums/billing-plan.d.ts +17 -0
  34. package/types/enums/filter-type.d.ts +4 -0
  35. package/types/enums/name.d.ts +1 -0
  36. package/types/enums/o-auth-provider.d.ts +0 -2
  37. package/types/index.d.ts +2 -0
  38. package/types/models.d.ts +126 -59
  39. package/types/query.d.ts +8 -8
  40. package/types/services/databases.d.ts +20 -20
  41. package/types/services/domains.d.ts +35 -0
  42. package/types/services/health.d.ts +23 -6
  43. package/types/services/organizations.d.ts +17 -16
  44. package/types/services/projects.d.ts +24 -2
  45. package/types/services/storage.d.ts +4 -4
  46. package/types/services/tables-db.d.ts +20 -20
package/dist/iife/sdk.js CHANGED
@@ -32,6 +32,3770 @@
32
32
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
33
33
  }
34
34
 
35
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
36
+
37
+ var jsonBigint = {exports: {}};
38
+
39
+ var stringify = {exports: {}};
40
+
41
+ var bignumber = {exports: {}};
42
+
43
+ (function (module) {
44
+ (function (globalObject) {
45
+
46
+ /*
47
+ * bignumber.js v9.3.1
48
+ * A JavaScript library for arbitrary-precision arithmetic.
49
+ * https://github.com/MikeMcl/bignumber.js
50
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
51
+ * MIT Licensed.
52
+ *
53
+ * BigNumber.prototype methods | BigNumber methods
54
+ * |
55
+ * absoluteValue abs | clone
56
+ * comparedTo | config set
57
+ * decimalPlaces dp | DECIMAL_PLACES
58
+ * dividedBy div | ROUNDING_MODE
59
+ * dividedToIntegerBy idiv | EXPONENTIAL_AT
60
+ * exponentiatedBy pow | RANGE
61
+ * integerValue | CRYPTO
62
+ * isEqualTo eq | MODULO_MODE
63
+ * isFinite | POW_PRECISION
64
+ * isGreaterThan gt | FORMAT
65
+ * isGreaterThanOrEqualTo gte | ALPHABET
66
+ * isInteger | isBigNumber
67
+ * isLessThan lt | maximum max
68
+ * isLessThanOrEqualTo lte | minimum min
69
+ * isNaN | random
70
+ * isNegative | sum
71
+ * isPositive |
72
+ * isZero |
73
+ * minus |
74
+ * modulo mod |
75
+ * multipliedBy times |
76
+ * negated |
77
+ * plus |
78
+ * precision sd |
79
+ * shiftedBy |
80
+ * squareRoot sqrt |
81
+ * toExponential |
82
+ * toFixed |
83
+ * toFormat |
84
+ * toFraction |
85
+ * toJSON |
86
+ * toNumber |
87
+ * toPrecision |
88
+ * toString |
89
+ * valueOf |
90
+ *
91
+ */
92
+
93
+
94
+ var BigNumber,
95
+ isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,
96
+ mathceil = Math.ceil,
97
+ mathfloor = Math.floor,
98
+
99
+ bignumberError = '[BigNumber Error] ',
100
+ tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',
101
+
102
+ BASE = 1e14,
103
+ LOG_BASE = 14,
104
+ MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1
105
+ // MAX_INT32 = 0x7fffffff, // 2^31 - 1
106
+ POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],
107
+ SQRT_BASE = 1e7,
108
+
109
+ // EDITABLE
110
+ // The limit on the value of DECIMAL_PLACES, TO_EXP_NEG, TO_EXP_POS, MIN_EXP, MAX_EXP, and
111
+ // the arguments to toExponential, toFixed, toFormat, and toPrecision.
112
+ MAX = 1E9; // 0 to MAX_INT32
113
+
114
+
115
+ /*
116
+ * Create and return a BigNumber constructor.
117
+ */
118
+ function clone(configObject) {
119
+ var div, convertBase, parseNumeric,
120
+ P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
121
+ ONE = new BigNumber(1),
122
+
123
+
124
+ //----------------------------- EDITABLE CONFIG DEFAULTS -------------------------------
125
+
126
+
127
+ // The default values below must be integers within the inclusive ranges stated.
128
+ // The values can also be changed at run-time using BigNumber.set.
129
+
130
+ // The maximum number of decimal places for operations involving division.
131
+ DECIMAL_PLACES = 20, // 0 to MAX
132
+
133
+ // The rounding mode used when rounding to the above decimal places, and when using
134
+ // toExponential, toFixed, toFormat and toPrecision, and round (default value).
135
+ // UP 0 Away from zero.
136
+ // DOWN 1 Towards zero.
137
+ // CEIL 2 Towards +Infinity.
138
+ // FLOOR 3 Towards -Infinity.
139
+ // HALF_UP 4 Towards nearest neighbour. If equidistant, up.
140
+ // HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
141
+ // HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
142
+ // HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
143
+ // HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
144
+ ROUNDING_MODE = 4, // 0 to 8
145
+
146
+ // EXPONENTIAL_AT : [TO_EXP_NEG , TO_EXP_POS]
147
+
148
+ // The exponent value at and beneath which toString returns exponential notation.
149
+ // Number type: -7
150
+ TO_EXP_NEG = -7, // 0 to -MAX
151
+
152
+ // The exponent value at and above which toString returns exponential notation.
153
+ // Number type: 21
154
+ TO_EXP_POS = 21, // 0 to MAX
155
+
156
+ // RANGE : [MIN_EXP, MAX_EXP]
157
+
158
+ // The minimum exponent value, beneath which underflow to zero occurs.
159
+ // Number type: -324 (5e-324)
160
+ MIN_EXP = -1e7, // -1 to -MAX
161
+
162
+ // The maximum exponent value, above which overflow to Infinity occurs.
163
+ // Number type: 308 (1.7976931348623157e+308)
164
+ // For MAX_EXP > 1e7, e.g. new BigNumber('1e100000000').plus(1) may be slow.
165
+ MAX_EXP = 1e7, // 1 to MAX
166
+
167
+ // Whether to use cryptographically-secure random number generation, if available.
168
+ CRYPTO = false, // true or false
169
+
170
+ // The modulo mode used when calculating the modulus: a mod n.
171
+ // The quotient (q = a / n) is calculated according to the corresponding rounding mode.
172
+ // The remainder (r) is calculated as: r = a - n * q.
173
+ //
174
+ // UP 0 The remainder is positive if the dividend is negative, else is negative.
175
+ // DOWN 1 The remainder has the same sign as the dividend.
176
+ // This modulo mode is commonly known as 'truncated division' and is
177
+ // equivalent to (a % n) in JavaScript.
178
+ // FLOOR 3 The remainder has the same sign as the divisor (Python %).
179
+ // HALF_EVEN 6 This modulo mode implements the IEEE 754 remainder function.
180
+ // EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)).
181
+ // The remainder is always positive.
182
+ //
183
+ // The truncated division, floored division, Euclidian division and IEEE 754 remainder
184
+ // modes are commonly used for the modulus operation.
185
+ // Although the other rounding modes can also be used, they may not give useful results.
186
+ MODULO_MODE = 1, // 0 to 9
187
+
188
+ // The maximum number of significant digits of the result of the exponentiatedBy operation.
189
+ // If POW_PRECISION is 0, there will be unlimited significant digits.
190
+ POW_PRECISION = 0, // 0 to MAX
191
+
192
+ // The format specification used by the BigNumber.prototype.toFormat method.
193
+ FORMAT = {
194
+ prefix: '',
195
+ groupSize: 3,
196
+ secondaryGroupSize: 0,
197
+ groupSeparator: ',',
198
+ decimalSeparator: '.',
199
+ fractionGroupSize: 0,
200
+ fractionGroupSeparator: '\xA0', // non-breaking space
201
+ suffix: ''
202
+ },
203
+
204
+ // The alphabet used for base conversion. It must be at least 2 characters long, with no '+',
205
+ // '-', '.', whitespace, or repeated character.
206
+ // '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
207
+ ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz',
208
+ alphabetHasNormalDecimalDigits = true;
209
+
210
+
211
+ //------------------------------------------------------------------------------------------
212
+
213
+
214
+ // CONSTRUCTOR
215
+
216
+
217
+ /*
218
+ * The BigNumber constructor and exported function.
219
+ * Create and return a new instance of a BigNumber object.
220
+ *
221
+ * v {number|string|BigNumber} A numeric value.
222
+ * [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
223
+ */
224
+ function BigNumber(v, b) {
225
+ var alphabet, c, caseChanged, e, i, isNum, len, str,
226
+ x = this;
227
+
228
+ // Enable constructor call without `new`.
229
+ if (!(x instanceof BigNumber)) return new BigNumber(v, b);
230
+
231
+ if (b == null) {
232
+
233
+ if (v && v._isBigNumber === true) {
234
+ x.s = v.s;
235
+
236
+ if (!v.c || v.e > MAX_EXP) {
237
+ x.c = x.e = null;
238
+ } else if (v.e < MIN_EXP) {
239
+ x.c = [x.e = 0];
240
+ } else {
241
+ x.e = v.e;
242
+ x.c = v.c.slice();
243
+ }
244
+
245
+ return;
246
+ }
247
+
248
+ if ((isNum = typeof v == 'number') && v * 0 == 0) {
249
+
250
+ // Use `1 / n` to handle minus zero also.
251
+ x.s = 1 / v < 0 ? (v = -v, -1) : 1;
252
+
253
+ // Fast path for integers, where n < 2147483648 (2**31).
254
+ if (v === ~~v) {
255
+ for (e = 0, i = v; i >= 10; i /= 10, e++);
256
+
257
+ if (e > MAX_EXP) {
258
+ x.c = x.e = null;
259
+ } else {
260
+ x.e = e;
261
+ x.c = [v];
262
+ }
263
+
264
+ return;
265
+ }
266
+
267
+ str = String(v);
268
+ } else {
269
+
270
+ if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
271
+
272
+ x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
273
+ }
274
+
275
+ // Decimal point?
276
+ if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
277
+
278
+ // Exponential form?
279
+ if ((i = str.search(/e/i)) > 0) {
280
+
281
+ // Determine exponent.
282
+ if (e < 0) e = i;
283
+ e += +str.slice(i + 1);
284
+ str = str.substring(0, i);
285
+ } else if (e < 0) {
286
+
287
+ // Integer.
288
+ e = str.length;
289
+ }
290
+
291
+ } else {
292
+
293
+ // '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
294
+ intCheck(b, 2, ALPHABET.length, 'Base');
295
+
296
+ // Allow exponential notation to be used with base 10 argument, while
297
+ // also rounding to DECIMAL_PLACES as with other bases.
298
+ if (b == 10 && alphabetHasNormalDecimalDigits) {
299
+ x = new BigNumber(v);
300
+ return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
301
+ }
302
+
303
+ str = String(v);
304
+
305
+ if (isNum = typeof v == 'number') {
306
+
307
+ // Avoid potential interpretation of Infinity and NaN as base 44+ values.
308
+ if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
309
+
310
+ x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
311
+
312
+ // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
313
+ if (BigNumber.DEBUG && str.replace(/^0\.0*|\./, '').length > 15) {
314
+ throw Error
315
+ (tooManyDigits + v);
316
+ }
317
+ } else {
318
+ x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
319
+ }
320
+
321
+ alphabet = ALPHABET.slice(0, b);
322
+ e = i = 0;
323
+
324
+ // Check that str is a valid base b number.
325
+ // Don't use RegExp, so alphabet can contain special characters.
326
+ for (len = str.length; i < len; i++) {
327
+ if (alphabet.indexOf(c = str.charAt(i)) < 0) {
328
+ if (c == '.') {
329
+
330
+ // If '.' is not the first character and it has not be found before.
331
+ if (i > e) {
332
+ e = len;
333
+ continue;
334
+ }
335
+ } else if (!caseChanged) {
336
+
337
+ // Allow e.g. hexadecimal 'FF' as well as 'ff'.
338
+ if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
339
+ str == str.toLowerCase() && (str = str.toUpperCase())) {
340
+ caseChanged = true;
341
+ i = -1;
342
+ e = 0;
343
+ continue;
344
+ }
345
+ }
346
+
347
+ return parseNumeric(x, String(v), isNum, b);
348
+ }
349
+ }
350
+
351
+ // Prevent later check for length on converted number.
352
+ isNum = false;
353
+ str = convertBase(str, b, 10, x.s);
354
+
355
+ // Decimal point?
356
+ if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
357
+ else e = str.length;
358
+ }
359
+
360
+ // Determine leading zeros.
361
+ for (i = 0; str.charCodeAt(i) === 48; i++);
362
+
363
+ // Determine trailing zeros.
364
+ for (len = str.length; str.charCodeAt(--len) === 48;);
365
+
366
+ if (str = str.slice(i, ++len)) {
367
+ len -= i;
368
+
369
+ // '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
370
+ if (isNum && BigNumber.DEBUG &&
371
+ len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
372
+ throw Error
373
+ (tooManyDigits + (x.s * v));
374
+ }
375
+
376
+ // Overflow?
377
+ if ((e = e - i - 1) > MAX_EXP) {
378
+
379
+ // Infinity.
380
+ x.c = x.e = null;
381
+
382
+ // Underflow?
383
+ } else if (e < MIN_EXP) {
384
+
385
+ // Zero.
386
+ x.c = [x.e = 0];
387
+ } else {
388
+ x.e = e;
389
+ x.c = [];
390
+
391
+ // Transform base
392
+
393
+ // e is the base 10 exponent.
394
+ // i is where to slice str to get the first element of the coefficient array.
395
+ i = (e + 1) % LOG_BASE;
396
+ if (e < 0) i += LOG_BASE; // i < 1
397
+
398
+ if (i < len) {
399
+ if (i) x.c.push(+str.slice(0, i));
400
+
401
+ for (len -= LOG_BASE; i < len;) {
402
+ x.c.push(+str.slice(i, i += LOG_BASE));
403
+ }
404
+
405
+ i = LOG_BASE - (str = str.slice(i)).length;
406
+ } else {
407
+ i -= len;
408
+ }
409
+
410
+ for (; i--; str += '0');
411
+ x.c.push(+str);
412
+ }
413
+ } else {
414
+
415
+ // Zero.
416
+ x.c = [x.e = 0];
417
+ }
418
+ }
419
+
420
+
421
+ // CONSTRUCTOR PROPERTIES
422
+
423
+
424
+ BigNumber.clone = clone;
425
+
426
+ BigNumber.ROUND_UP = 0;
427
+ BigNumber.ROUND_DOWN = 1;
428
+ BigNumber.ROUND_CEIL = 2;
429
+ BigNumber.ROUND_FLOOR = 3;
430
+ BigNumber.ROUND_HALF_UP = 4;
431
+ BigNumber.ROUND_HALF_DOWN = 5;
432
+ BigNumber.ROUND_HALF_EVEN = 6;
433
+ BigNumber.ROUND_HALF_CEIL = 7;
434
+ BigNumber.ROUND_HALF_FLOOR = 8;
435
+ BigNumber.EUCLID = 9;
436
+
437
+
438
+ /*
439
+ * Configure infrequently-changing library-wide settings.
440
+ *
441
+ * Accept an object with the following optional properties (if the value of a property is
442
+ * a number, it must be an integer within the inclusive range stated):
443
+ *
444
+ * DECIMAL_PLACES {number} 0 to MAX
445
+ * ROUNDING_MODE {number} 0 to 8
446
+ * EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
447
+ * RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
448
+ * CRYPTO {boolean} true or false
449
+ * MODULO_MODE {number} 0 to 9
450
+ * POW_PRECISION {number} 0 to MAX
451
+ * ALPHABET {string} A string of two or more unique characters which does
452
+ * not contain '.'.
453
+ * FORMAT {object} An object with some of the following properties:
454
+ * prefix {string}
455
+ * groupSize {number}
456
+ * secondaryGroupSize {number}
457
+ * groupSeparator {string}
458
+ * decimalSeparator {string}
459
+ * fractionGroupSize {number}
460
+ * fractionGroupSeparator {string}
461
+ * suffix {string}
462
+ *
463
+ * (The values assigned to the above FORMAT object properties are not checked for validity.)
464
+ *
465
+ * E.g.
466
+ * BigNumber.config({ DECIMAL_PLACES : 20, ROUNDING_MODE : 4 })
467
+ *
468
+ * Ignore properties/parameters set to null or undefined, except for ALPHABET.
469
+ *
470
+ * Return an object with the properties current values.
471
+ */
472
+ BigNumber.config = BigNumber.set = function (obj) {
473
+ var p, v;
474
+
475
+ if (obj != null) {
476
+
477
+ if (typeof obj == 'object') {
478
+
479
+ // DECIMAL_PLACES {number} Integer, 0 to MAX inclusive.
480
+ // '[BigNumber Error] DECIMAL_PLACES {not a primitive number|not an integer|out of range}: {v}'
481
+ if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {
482
+ v = obj[p];
483
+ intCheck(v, 0, MAX, p);
484
+ DECIMAL_PLACES = v;
485
+ }
486
+
487
+ // ROUNDING_MODE {number} Integer, 0 to 8 inclusive.
488
+ // '[BigNumber Error] ROUNDING_MODE {not a primitive number|not an integer|out of range}: {v}'
489
+ if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {
490
+ v = obj[p];
491
+ intCheck(v, 0, 8, p);
492
+ ROUNDING_MODE = v;
493
+ }
494
+
495
+ // EXPONENTIAL_AT {number|number[]}
496
+ // Integer, -MAX to MAX inclusive or
497
+ // [integer -MAX to 0 inclusive, 0 to MAX inclusive].
498
+ // '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
499
+ if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
500
+ v = obj[p];
501
+ if (v && v.pop) {
502
+ intCheck(v[0], -MAX, 0, p);
503
+ intCheck(v[1], 0, MAX, p);
504
+ TO_EXP_NEG = v[0];
505
+ TO_EXP_POS = v[1];
506
+ } else {
507
+ intCheck(v, -MAX, MAX, p);
508
+ TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
509
+ }
510
+ }
511
+
512
+ // RANGE {number|number[]} Non-zero integer, -MAX to MAX inclusive or
513
+ // [integer -MAX to -1 inclusive, integer 1 to MAX inclusive].
514
+ // '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
515
+ if (obj.hasOwnProperty(p = 'RANGE')) {
516
+ v = obj[p];
517
+ if (v && v.pop) {
518
+ intCheck(v[0], -MAX, -1, p);
519
+ intCheck(v[1], 1, MAX, p);
520
+ MIN_EXP = v[0];
521
+ MAX_EXP = v[1];
522
+ } else {
523
+ intCheck(v, -MAX, MAX, p);
524
+ if (v) {
525
+ MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
526
+ } else {
527
+ throw Error
528
+ (bignumberError + p + ' cannot be zero: ' + v);
529
+ }
530
+ }
531
+ }
532
+
533
+ // CRYPTO {boolean} true or false.
534
+ // '[BigNumber Error] CRYPTO not true or false: {v}'
535
+ // '[BigNumber Error] crypto unavailable'
536
+ if (obj.hasOwnProperty(p = 'CRYPTO')) {
537
+ v = obj[p];
538
+ if (v === !!v) {
539
+ if (v) {
540
+ if (typeof crypto != 'undefined' && crypto &&
541
+ (crypto.getRandomValues || crypto.randomBytes)) {
542
+ CRYPTO = v;
543
+ } else {
544
+ CRYPTO = !v;
545
+ throw Error
546
+ (bignumberError + 'crypto unavailable');
547
+ }
548
+ } else {
549
+ CRYPTO = v;
550
+ }
551
+ } else {
552
+ throw Error
553
+ (bignumberError + p + ' not true or false: ' + v);
554
+ }
555
+ }
556
+
557
+ // MODULO_MODE {number} Integer, 0 to 9 inclusive.
558
+ // '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
559
+ if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
560
+ v = obj[p];
561
+ intCheck(v, 0, 9, p);
562
+ MODULO_MODE = v;
563
+ }
564
+
565
+ // POW_PRECISION {number} Integer, 0 to MAX inclusive.
566
+ // '[BigNumber Error] POW_PRECISION {not a primitive number|not an integer|out of range}: {v}'
567
+ if (obj.hasOwnProperty(p = 'POW_PRECISION')) {
568
+ v = obj[p];
569
+ intCheck(v, 0, MAX, p);
570
+ POW_PRECISION = v;
571
+ }
572
+
573
+ // FORMAT {object}
574
+ // '[BigNumber Error] FORMAT not an object: {v}'
575
+ if (obj.hasOwnProperty(p = 'FORMAT')) {
576
+ v = obj[p];
577
+ if (typeof v == 'object') FORMAT = v;
578
+ else throw Error
579
+ (bignumberError + p + ' not an object: ' + v);
580
+ }
581
+
582
+ // ALPHABET {string}
583
+ // '[BigNumber Error] ALPHABET invalid: {v}'
584
+ if (obj.hasOwnProperty(p = 'ALPHABET')) {
585
+ v = obj[p];
586
+
587
+ // Disallow if less than two characters,
588
+ // or if it contains '+', '-', '.', whitespace, or a repeated character.
589
+ if (typeof v == 'string' && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
590
+ alphabetHasNormalDecimalDigits = v.slice(0, 10) == '0123456789';
591
+ ALPHABET = v;
592
+ } else {
593
+ throw Error
594
+ (bignumberError + p + ' invalid: ' + v);
595
+ }
596
+ }
597
+
598
+ } else {
599
+
600
+ // '[BigNumber Error] Object expected: {v}'
601
+ throw Error
602
+ (bignumberError + 'Object expected: ' + obj);
603
+ }
604
+ }
605
+
606
+ return {
607
+ DECIMAL_PLACES: DECIMAL_PLACES,
608
+ ROUNDING_MODE: ROUNDING_MODE,
609
+ EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
610
+ RANGE: [MIN_EXP, MAX_EXP],
611
+ CRYPTO: CRYPTO,
612
+ MODULO_MODE: MODULO_MODE,
613
+ POW_PRECISION: POW_PRECISION,
614
+ FORMAT: FORMAT,
615
+ ALPHABET: ALPHABET
616
+ };
617
+ };
618
+
619
+
620
+ /*
621
+ * Return true if v is a BigNumber instance, otherwise return false.
622
+ *
623
+ * If BigNumber.DEBUG is true, throw if a BigNumber instance is not well-formed.
624
+ *
625
+ * v {any}
626
+ *
627
+ * '[BigNumber Error] Invalid BigNumber: {v}'
628
+ */
629
+ BigNumber.isBigNumber = function (v) {
630
+ if (!v || v._isBigNumber !== true) return false;
631
+ if (!BigNumber.DEBUG) return true;
632
+
633
+ var i, n,
634
+ c = v.c,
635
+ e = v.e,
636
+ s = v.s;
637
+
638
+ out: if ({}.toString.call(c) == '[object Array]') {
639
+
640
+ if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
641
+
642
+ // If the first element is zero, the BigNumber value must be zero.
643
+ if (c[0] === 0) {
644
+ if (e === 0 && c.length === 1) return true;
645
+ break out;
646
+ }
647
+
648
+ // Calculate number of digits that c[0] should have, based on the exponent.
649
+ i = (e + 1) % LOG_BASE;
650
+ if (i < 1) i += LOG_BASE;
651
+
652
+ // Calculate number of digits of c[0].
653
+ //if (Math.ceil(Math.log(c[0] + 1) / Math.LN10) == i) {
654
+ if (String(c[0]).length == i) {
655
+
656
+ for (i = 0; i < c.length; i++) {
657
+ n = c[i];
658
+ if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
659
+ }
660
+
661
+ // Last element cannot be zero, unless it is the only element.
662
+ if (n !== 0) return true;
663
+ }
664
+ }
665
+
666
+ // Infinity/NaN
667
+ } else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
668
+ return true;
669
+ }
670
+
671
+ throw Error
672
+ (bignumberError + 'Invalid BigNumber: ' + v);
673
+ };
674
+
675
+
676
+ /*
677
+ * Return a new BigNumber whose value is the maximum of the arguments.
678
+ *
679
+ * arguments {number|string|BigNumber}
680
+ */
681
+ BigNumber.maximum = BigNumber.max = function () {
682
+ return maxOrMin(arguments, -1);
683
+ };
684
+
685
+
686
+ /*
687
+ * Return a new BigNumber whose value is the minimum of the arguments.
688
+ *
689
+ * arguments {number|string|BigNumber}
690
+ */
691
+ BigNumber.minimum = BigNumber.min = function () {
692
+ return maxOrMin(arguments, 1);
693
+ };
694
+
695
+
696
+ /*
697
+ * Return a new BigNumber with a random value equal to or greater than 0 and less than 1,
698
+ * and with dp, or DECIMAL_PLACES if dp is omitted, decimal places (or less if trailing
699
+ * zeros are produced).
700
+ *
701
+ * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
702
+ *
703
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp}'
704
+ * '[BigNumber Error] crypto unavailable'
705
+ */
706
+ BigNumber.random = (function () {
707
+ var pow2_53 = 0x20000000000000;
708
+
709
+ // Return a 53 bit integer n, where 0 <= n < 9007199254740992.
710
+ // Check if Math.random() produces more than 32 bits of randomness.
711
+ // If it does, assume at least 53 bits are produced, otherwise assume at least 30 bits.
712
+ // 0x40000000 is 2^30, 0x800000 is 2^23, 0x1fffff is 2^21 - 1.
713
+ var random53bitInt = (Math.random() * pow2_53) & 0x1fffff
714
+ ? function () { return mathfloor(Math.random() * pow2_53); }
715
+ : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +
716
+ (Math.random() * 0x800000 | 0); };
717
+
718
+ return function (dp) {
719
+ var a, b, e, k, v,
720
+ i = 0,
721
+ c = [],
722
+ rand = new BigNumber(ONE);
723
+
724
+ if (dp == null) dp = DECIMAL_PLACES;
725
+ else intCheck(dp, 0, MAX);
726
+
727
+ k = mathceil(dp / LOG_BASE);
728
+
729
+ if (CRYPTO) {
730
+
731
+ // Browsers supporting crypto.getRandomValues.
732
+ if (crypto.getRandomValues) {
733
+
734
+ a = crypto.getRandomValues(new Uint32Array(k *= 2));
735
+
736
+ for (; i < k;) {
737
+
738
+ // 53 bits:
739
+ // ((Math.pow(2, 32) - 1) * Math.pow(2, 21)).toString(2)
740
+ // 11111 11111111 11111111 11111111 11100000 00000000 00000000
741
+ // ((Math.pow(2, 32) - 1) >>> 11).toString(2)
742
+ // 11111 11111111 11111111
743
+ // 0x20000 is 2^21.
744
+ v = a[i] * 0x20000 + (a[i + 1] >>> 11);
745
+
746
+ // Rejection sampling:
747
+ // 0 <= v < 9007199254740992
748
+ // Probability that v >= 9e15, is
749
+ // 7199254740992 / 9007199254740992 ~= 0.0008, i.e. 1 in 1251
750
+ if (v >= 9e15) {
751
+ b = crypto.getRandomValues(new Uint32Array(2));
752
+ a[i] = b[0];
753
+ a[i + 1] = b[1];
754
+ } else {
755
+
756
+ // 0 <= v <= 8999999999999999
757
+ // 0 <= (v % 1e14) <= 99999999999999
758
+ c.push(v % 1e14);
759
+ i += 2;
760
+ }
761
+ }
762
+ i = k / 2;
763
+
764
+ // Node.js supporting crypto.randomBytes.
765
+ } else if (crypto.randomBytes) {
766
+
767
+ // buffer
768
+ a = crypto.randomBytes(k *= 7);
769
+
770
+ for (; i < k;) {
771
+
772
+ // 0x1000000000000 is 2^48, 0x10000000000 is 2^40
773
+ // 0x100000000 is 2^32, 0x1000000 is 2^24
774
+ // 11111 11111111 11111111 11111111 11111111 11111111 11111111
775
+ // 0 <= v < 9007199254740992
776
+ v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +
777
+ (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +
778
+ (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
779
+
780
+ if (v >= 9e15) {
781
+ crypto.randomBytes(7).copy(a, i);
782
+ } else {
783
+
784
+ // 0 <= (v % 1e14) <= 99999999999999
785
+ c.push(v % 1e14);
786
+ i += 7;
787
+ }
788
+ }
789
+ i = k / 7;
790
+ } else {
791
+ CRYPTO = false;
792
+ throw Error
793
+ (bignumberError + 'crypto unavailable');
794
+ }
795
+ }
796
+
797
+ // Use Math.random.
798
+ if (!CRYPTO) {
799
+
800
+ for (; i < k;) {
801
+ v = random53bitInt();
802
+ if (v < 9e15) c[i++] = v % 1e14;
803
+ }
804
+ }
805
+
806
+ k = c[--i];
807
+ dp %= LOG_BASE;
808
+
809
+ // Convert trailing digits to zeros according to dp.
810
+ if (k && dp) {
811
+ v = POWS_TEN[LOG_BASE - dp];
812
+ c[i] = mathfloor(k / v) * v;
813
+ }
814
+
815
+ // Remove trailing elements which are zero.
816
+ for (; c[i] === 0; c.pop(), i--);
817
+
818
+ // Zero?
819
+ if (i < 0) {
820
+ c = [e = 0];
821
+ } else {
822
+
823
+ // Remove leading elements which are zero and adjust exponent accordingly.
824
+ for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
825
+
826
+ // Count the digits of the first element of c to determine leading zeros, and...
827
+ for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
828
+
829
+ // adjust the exponent accordingly.
830
+ if (i < LOG_BASE) e -= LOG_BASE - i;
831
+ }
832
+
833
+ rand.e = e;
834
+ rand.c = c;
835
+ return rand;
836
+ };
837
+ })();
838
+
839
+
840
+ /*
841
+ * Return a BigNumber whose value is the sum of the arguments.
842
+ *
843
+ * arguments {number|string|BigNumber}
844
+ */
845
+ BigNumber.sum = function () {
846
+ var i = 1,
847
+ args = arguments,
848
+ sum = new BigNumber(args[0]);
849
+ for (; i < args.length;) sum = sum.plus(args[i++]);
850
+ return sum;
851
+ };
852
+
853
+
854
+ // PRIVATE FUNCTIONS
855
+
856
+
857
+ // Called by BigNumber and BigNumber.prototype.toString.
858
+ convertBase = (function () {
859
+ var decimal = '0123456789';
860
+
861
+ /*
862
+ * Convert string of baseIn to an array of numbers of baseOut.
863
+ * Eg. toBaseOut('255', 10, 16) returns [15, 15].
864
+ * Eg. toBaseOut('ff', 16, 10) returns [2, 5, 5].
865
+ */
866
+ function toBaseOut(str, baseIn, baseOut, alphabet) {
867
+ var j,
868
+ arr = [0],
869
+ arrL,
870
+ i = 0,
871
+ len = str.length;
872
+
873
+ for (; i < len;) {
874
+ for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
875
+
876
+ arr[0] += alphabet.indexOf(str.charAt(i++));
877
+
878
+ for (j = 0; j < arr.length; j++) {
879
+
880
+ if (arr[j] > baseOut - 1) {
881
+ if (arr[j + 1] == null) arr[j + 1] = 0;
882
+ arr[j + 1] += arr[j] / baseOut | 0;
883
+ arr[j] %= baseOut;
884
+ }
885
+ }
886
+ }
887
+
888
+ return arr.reverse();
889
+ }
890
+
891
+ // Convert a numeric string of baseIn to a numeric string of baseOut.
892
+ // If the caller is toString, we are converting from base 10 to baseOut.
893
+ // If the caller is BigNumber, we are converting from baseIn to base 10.
894
+ return function (str, baseIn, baseOut, sign, callerIsToString) {
895
+ var alphabet, d, e, k, r, x, xc, y,
896
+ i = str.indexOf('.'),
897
+ dp = DECIMAL_PLACES,
898
+ rm = ROUNDING_MODE;
899
+
900
+ // Non-integer.
901
+ if (i >= 0) {
902
+ k = POW_PRECISION;
903
+
904
+ // Unlimited precision.
905
+ POW_PRECISION = 0;
906
+ str = str.replace('.', '');
907
+ y = new BigNumber(baseIn);
908
+ x = y.pow(str.length - i);
909
+ POW_PRECISION = k;
910
+
911
+ // Convert str as if an integer, then restore the fraction part by dividing the
912
+ // result by its base raised to a power.
913
+
914
+ y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),
915
+ 10, baseOut, decimal);
916
+ y.e = y.c.length;
917
+ }
918
+
919
+ // Convert the number as integer.
920
+
921
+ xc = toBaseOut(str, baseIn, baseOut, callerIsToString
922
+ ? (alphabet = ALPHABET, decimal)
923
+ : (alphabet = decimal, ALPHABET));
924
+
925
+ // xc now represents str as an integer and converted to baseOut. e is the exponent.
926
+ e = k = xc.length;
927
+
928
+ // Remove trailing zeros.
929
+ for (; xc[--k] == 0; xc.pop());
930
+
931
+ // Zero?
932
+ if (!xc[0]) return alphabet.charAt(0);
933
+
934
+ // Does str represent an integer? If so, no need for the division.
935
+ if (i < 0) {
936
+ --e;
937
+ } else {
938
+ x.c = xc;
939
+ x.e = e;
940
+
941
+ // The sign is needed for correct rounding.
942
+ x.s = sign;
943
+ x = div(x, y, dp, rm, baseOut);
944
+ xc = x.c;
945
+ r = x.r;
946
+ e = x.e;
947
+ }
948
+
949
+ // xc now represents str converted to baseOut.
950
+
951
+ // The index of the rounding digit.
952
+ d = e + dp + 1;
953
+
954
+ // The rounding digit: the digit to the right of the digit that may be rounded up.
955
+ i = xc[d];
956
+
957
+ // Look at the rounding digits and mode to determine whether to round up.
958
+
959
+ k = baseOut / 2;
960
+ r = r || d < 0 || xc[d + 1] != null;
961
+
962
+ r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
963
+ : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||
964
+ rm == (x.s < 0 ? 8 : 7));
965
+
966
+ // If the index of the rounding digit is not greater than zero, or xc represents
967
+ // zero, then the result of the base conversion is zero or, if rounding up, a value
968
+ // such as 0.00001.
969
+ if (d < 1 || !xc[0]) {
970
+
971
+ // 1^-dp or 0
972
+ str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
973
+ } else {
974
+
975
+ // Truncate xc to the required number of decimal places.
976
+ xc.length = d;
977
+
978
+ // Round up?
979
+ if (r) {
980
+
981
+ // Rounding up may mean the previous digit has to be rounded up and so on.
982
+ for (--baseOut; ++xc[--d] > baseOut;) {
983
+ xc[d] = 0;
984
+
985
+ if (!d) {
986
+ ++e;
987
+ xc = [1].concat(xc);
988
+ }
989
+ }
990
+ }
991
+
992
+ // Determine trailing zeros.
993
+ for (k = xc.length; !xc[--k];);
994
+
995
+ // E.g. [4, 11, 15] becomes 4bf.
996
+ for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));
997
+
998
+ // Add leading zeros, decimal point and trailing zeros as required.
999
+ str = toFixedPoint(str, e, alphabet.charAt(0));
1000
+ }
1001
+
1002
+ // The caller will add the sign.
1003
+ return str;
1004
+ };
1005
+ })();
1006
+
1007
+
1008
+ // Perform division in the specified base. Called by div and convertBase.
1009
+ div = (function () {
1010
+
1011
+ // Assume non-zero x and k.
1012
+ function multiply(x, k, base) {
1013
+ var m, temp, xlo, xhi,
1014
+ carry = 0,
1015
+ i = x.length,
1016
+ klo = k % SQRT_BASE,
1017
+ khi = k / SQRT_BASE | 0;
1018
+
1019
+ for (x = x.slice(); i--;) {
1020
+ xlo = x[i] % SQRT_BASE;
1021
+ xhi = x[i] / SQRT_BASE | 0;
1022
+ m = khi * xlo + xhi * klo;
1023
+ temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;
1024
+ carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
1025
+ x[i] = temp % base;
1026
+ }
1027
+
1028
+ if (carry) x = [carry].concat(x);
1029
+
1030
+ return x;
1031
+ }
1032
+
1033
+ function compare(a, b, aL, bL) {
1034
+ var i, cmp;
1035
+
1036
+ if (aL != bL) {
1037
+ cmp = aL > bL ? 1 : -1;
1038
+ } else {
1039
+
1040
+ for (i = cmp = 0; i < aL; i++) {
1041
+
1042
+ if (a[i] != b[i]) {
1043
+ cmp = a[i] > b[i] ? 1 : -1;
1044
+ break;
1045
+ }
1046
+ }
1047
+ }
1048
+
1049
+ return cmp;
1050
+ }
1051
+
1052
+ function subtract(a, b, aL, base) {
1053
+ var i = 0;
1054
+
1055
+ // Subtract b from a.
1056
+ for (; aL--;) {
1057
+ a[aL] -= i;
1058
+ i = a[aL] < b[aL] ? 1 : 0;
1059
+ a[aL] = i * base + a[aL] - b[aL];
1060
+ }
1061
+
1062
+ // Remove leading zeros.
1063
+ for (; !a[0] && a.length > 1; a.splice(0, 1));
1064
+ }
1065
+
1066
+ // x: dividend, y: divisor.
1067
+ return function (x, y, dp, rm, base) {
1068
+ var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,
1069
+ yL, yz,
1070
+ s = x.s == y.s ? 1 : -1,
1071
+ xc = x.c,
1072
+ yc = y.c;
1073
+
1074
+ // Either NaN, Infinity or 0?
1075
+ if (!xc || !xc[0] || !yc || !yc[0]) {
1076
+
1077
+ return new BigNumber(
1078
+
1079
+ // Return NaN if either NaN, or both Infinity or 0.
1080
+ !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :
1081
+
1082
+ // Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
1083
+ xc && xc[0] == 0 || !yc ? s * 0 : s / 0
1084
+ );
1085
+ }
1086
+
1087
+ q = new BigNumber(s);
1088
+ qc = q.c = [];
1089
+ e = x.e - y.e;
1090
+ s = dp + e + 1;
1091
+
1092
+ if (!base) {
1093
+ base = BASE;
1094
+ e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
1095
+ s = s / LOG_BASE | 0;
1096
+ }
1097
+
1098
+ // Result exponent may be one less then the current value of e.
1099
+ // The coefficients of the BigNumbers from convertBase may have trailing zeros.
1100
+ for (i = 0; yc[i] == (xc[i] || 0); i++);
1101
+
1102
+ if (yc[i] > (xc[i] || 0)) e--;
1103
+
1104
+ if (s < 0) {
1105
+ qc.push(1);
1106
+ more = true;
1107
+ } else {
1108
+ xL = xc.length;
1109
+ yL = yc.length;
1110
+ i = 0;
1111
+ s += 2;
1112
+
1113
+ // Normalise xc and yc so highest order digit of yc is >= base / 2.
1114
+
1115
+ n = mathfloor(base / (yc[0] + 1));
1116
+
1117
+ // Not necessary, but to handle odd bases where yc[0] == (base / 2) - 1.
1118
+ // if (n > 1 || n++ == 1 && yc[0] < base / 2) {
1119
+ if (n > 1) {
1120
+ yc = multiply(yc, n, base);
1121
+ xc = multiply(xc, n, base);
1122
+ yL = yc.length;
1123
+ xL = xc.length;
1124
+ }
1125
+
1126
+ xi = yL;
1127
+ rem = xc.slice(0, yL);
1128
+ remL = rem.length;
1129
+
1130
+ // Add zeros to make remainder as long as divisor.
1131
+ for (; remL < yL; rem[remL++] = 0);
1132
+ yz = yc.slice();
1133
+ yz = [0].concat(yz);
1134
+ yc0 = yc[0];
1135
+ if (yc[1] >= base / 2) yc0++;
1136
+ // Not necessary, but to prevent trial digit n > base, when using base 3.
1137
+ // else if (base == 3 && yc0 == 1) yc0 = 1 + 1e-15;
1138
+
1139
+ do {
1140
+ n = 0;
1141
+
1142
+ // Compare divisor and remainder.
1143
+ cmp = compare(yc, rem, yL, remL);
1144
+
1145
+ // If divisor < remainder.
1146
+ if (cmp < 0) {
1147
+
1148
+ // Calculate trial digit, n.
1149
+
1150
+ rem0 = rem[0];
1151
+ if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
1152
+
1153
+ // n is how many times the divisor goes into the current remainder.
1154
+ n = mathfloor(rem0 / yc0);
1155
+
1156
+ // Algorithm:
1157
+ // product = divisor multiplied by trial digit (n).
1158
+ // Compare product and remainder.
1159
+ // If product is greater than remainder:
1160
+ // Subtract divisor from product, decrement trial digit.
1161
+ // Subtract product from remainder.
1162
+ // If product was less than remainder at the last compare:
1163
+ // Compare new remainder and divisor.
1164
+ // If remainder is greater than divisor:
1165
+ // Subtract divisor from remainder, increment trial digit.
1166
+
1167
+ if (n > 1) {
1168
+
1169
+ // n may be > base only when base is 3.
1170
+ if (n >= base) n = base - 1;
1171
+
1172
+ // product = divisor * trial digit.
1173
+ prod = multiply(yc, n, base);
1174
+ prodL = prod.length;
1175
+ remL = rem.length;
1176
+
1177
+ // Compare product and remainder.
1178
+ // If product > remainder then trial digit n too high.
1179
+ // n is 1 too high about 5% of the time, and is not known to have
1180
+ // ever been more than 1 too high.
1181
+ while (compare(prod, rem, prodL, remL) == 1) {
1182
+ n--;
1183
+
1184
+ // Subtract divisor from product.
1185
+ subtract(prod, yL < prodL ? yz : yc, prodL, base);
1186
+ prodL = prod.length;
1187
+ cmp = 1;
1188
+ }
1189
+ } else {
1190
+
1191
+ // n is 0 or 1, cmp is -1.
1192
+ // If n is 0, there is no need to compare yc and rem again below,
1193
+ // so change cmp to 1 to avoid it.
1194
+ // If n is 1, leave cmp as -1, so yc and rem are compared again.
1195
+ if (n == 0) {
1196
+
1197
+ // divisor < remainder, so n must be at least 1.
1198
+ cmp = n = 1;
1199
+ }
1200
+
1201
+ // product = divisor
1202
+ prod = yc.slice();
1203
+ prodL = prod.length;
1204
+ }
1205
+
1206
+ if (prodL < remL) prod = [0].concat(prod);
1207
+
1208
+ // Subtract product from remainder.
1209
+ subtract(rem, prod, remL, base);
1210
+ remL = rem.length;
1211
+
1212
+ // If product was < remainder.
1213
+ if (cmp == -1) {
1214
+
1215
+ // Compare divisor and new remainder.
1216
+ // If divisor < new remainder, subtract divisor from remainder.
1217
+ // Trial digit n too low.
1218
+ // n is 1 too low about 5% of the time, and very rarely 2 too low.
1219
+ while (compare(yc, rem, yL, remL) < 1) {
1220
+ n++;
1221
+
1222
+ // Subtract divisor from remainder.
1223
+ subtract(rem, yL < remL ? yz : yc, remL, base);
1224
+ remL = rem.length;
1225
+ }
1226
+ }
1227
+ } else if (cmp === 0) {
1228
+ n++;
1229
+ rem = [0];
1230
+ } // else cmp === 1 and n will be 0
1231
+
1232
+ // Add the next digit, n, to the result array.
1233
+ qc[i++] = n;
1234
+
1235
+ // Update the remainder.
1236
+ if (rem[0]) {
1237
+ rem[remL++] = xc[xi] || 0;
1238
+ } else {
1239
+ rem = [xc[xi]];
1240
+ remL = 1;
1241
+ }
1242
+ } while ((xi++ < xL || rem[0] != null) && s--);
1243
+
1244
+ more = rem[0] != null;
1245
+
1246
+ // Leading zero?
1247
+ if (!qc[0]) qc.splice(0, 1);
1248
+ }
1249
+
1250
+ if (base == BASE) {
1251
+
1252
+ // To calculate q.e, first get the number of digits of qc[0].
1253
+ for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
1254
+
1255
+ round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
1256
+
1257
+ // Caller is convertBase.
1258
+ } else {
1259
+ q.e = e;
1260
+ q.r = +more;
1261
+ }
1262
+
1263
+ return q;
1264
+ };
1265
+ })();
1266
+
1267
+
1268
+ /*
1269
+ * Return a string representing the value of BigNumber n in fixed-point or exponential
1270
+ * notation rounded to the specified decimal places or significant digits.
1271
+ *
1272
+ * n: a BigNumber.
1273
+ * i: the index of the last digit required (i.e. the digit that may be rounded up).
1274
+ * rm: the rounding mode.
1275
+ * id: 1 (toExponential) or 2 (toPrecision).
1276
+ */
1277
+ function format(n, i, rm, id) {
1278
+ var c0, e, ne, len, str;
1279
+
1280
+ if (rm == null) rm = ROUNDING_MODE;
1281
+ else intCheck(rm, 0, 8);
1282
+
1283
+ if (!n.c) return n.toString();
1284
+
1285
+ c0 = n.c[0];
1286
+ ne = n.e;
1287
+
1288
+ if (i == null) {
1289
+ str = coeffToString(n.c);
1290
+ str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)
1291
+ ? toExponential(str, ne)
1292
+ : toFixedPoint(str, ne, '0');
1293
+ } else {
1294
+ n = round(new BigNumber(n), i, rm);
1295
+
1296
+ // n.e may have changed if the value was rounded up.
1297
+ e = n.e;
1298
+
1299
+ str = coeffToString(n.c);
1300
+ len = str.length;
1301
+
1302
+ // toPrecision returns exponential notation if the number of significant digits
1303
+ // specified is less than the number of digits necessary to represent the integer
1304
+ // part of the value in fixed-point notation.
1305
+
1306
+ // Exponential notation.
1307
+ if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
1308
+
1309
+ // Append zeros?
1310
+ for (; len < i; str += '0', len++);
1311
+ str = toExponential(str, e);
1312
+
1313
+ // Fixed-point notation.
1314
+ } else {
1315
+ i -= ne + (id === 2 && e > ne);
1316
+ str = toFixedPoint(str, e, '0');
1317
+
1318
+ // Append zeros?
1319
+ if (e + 1 > len) {
1320
+ if (--i > 0) for (str += '.'; i--; str += '0');
1321
+ } else {
1322
+ i += e - len;
1323
+ if (i > 0) {
1324
+ if (e + 1 == len) str += '.';
1325
+ for (; i--; str += '0');
1326
+ }
1327
+ }
1328
+ }
1329
+ }
1330
+
1331
+ return n.s < 0 && c0 ? '-' + str : str;
1332
+ }
1333
+
1334
+
1335
+ // Handle BigNumber.max and BigNumber.min.
1336
+ // If any number is NaN, return NaN.
1337
+ function maxOrMin(args, n) {
1338
+ var k, y,
1339
+ i = 1,
1340
+ x = new BigNumber(args[0]);
1341
+
1342
+ for (; i < args.length; i++) {
1343
+ y = new BigNumber(args[i]);
1344
+ if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
1345
+ x = y;
1346
+ }
1347
+ }
1348
+
1349
+ return x;
1350
+ }
1351
+
1352
+
1353
+ /*
1354
+ * Strip trailing zeros, calculate base 10 exponent and check against MIN_EXP and MAX_EXP.
1355
+ * Called by minus, plus and times.
1356
+ */
1357
+ function normalise(n, c, e) {
1358
+ var i = 1,
1359
+ j = c.length;
1360
+
1361
+ // Remove trailing zeros.
1362
+ for (; !c[--j]; c.pop());
1363
+
1364
+ // Calculate the base 10 exponent. First get the number of digits of c[0].
1365
+ for (j = c[0]; j >= 10; j /= 10, i++);
1366
+
1367
+ // Overflow?
1368
+ if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
1369
+
1370
+ // Infinity.
1371
+ n.c = n.e = null;
1372
+
1373
+ // Underflow?
1374
+ } else if (e < MIN_EXP) {
1375
+
1376
+ // Zero.
1377
+ n.c = [n.e = 0];
1378
+ } else {
1379
+ n.e = e;
1380
+ n.c = c;
1381
+ }
1382
+
1383
+ return n;
1384
+ }
1385
+
1386
+
1387
+ // Handle values that fail the validity test in BigNumber.
1388
+ parseNumeric = (function () {
1389
+ var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
1390
+ dotAfter = /^([^.]+)\.$/,
1391
+ dotBefore = /^\.([^.]+)$/,
1392
+ isInfinityOrNaN = /^-?(Infinity|NaN)$/,
1393
+ whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
1394
+
1395
+ return function (x, str, isNum, b) {
1396
+ var base,
1397
+ s = isNum ? str : str.replace(whitespaceOrPlus, '');
1398
+
1399
+ // No exception on ±Infinity or NaN.
1400
+ if (isInfinityOrNaN.test(s)) {
1401
+ x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
1402
+ } else {
1403
+ if (!isNum) {
1404
+
1405
+ // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
1406
+ s = s.replace(basePrefix, function (m, p1, p2) {
1407
+ base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
1408
+ return !b || b == base ? p1 : m;
1409
+ });
1410
+
1411
+ if (b) {
1412
+ base = b;
1413
+
1414
+ // E.g. '1.' to '1', '.1' to '0.1'
1415
+ s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
1416
+ }
1417
+
1418
+ if (str != s) return new BigNumber(s, base);
1419
+ }
1420
+
1421
+ // '[BigNumber Error] Not a number: {n}'
1422
+ // '[BigNumber Error] Not a base {b} number: {n}'
1423
+ if (BigNumber.DEBUG) {
1424
+ throw Error
1425
+ (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
1426
+ }
1427
+
1428
+ // NaN
1429
+ x.s = null;
1430
+ }
1431
+
1432
+ x.c = x.e = null;
1433
+ }
1434
+ })();
1435
+
1436
+
1437
+ /*
1438
+ * Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
1439
+ * If r is truthy, it is known that there are more digits after the rounding digit.
1440
+ */
1441
+ function round(x, sd, rm, r) {
1442
+ var d, i, j, k, n, ni, rd,
1443
+ xc = x.c,
1444
+ pows10 = POWS_TEN;
1445
+
1446
+ // if x is not Infinity or NaN...
1447
+ if (xc) {
1448
+
1449
+ // rd is the rounding digit, i.e. the digit after the digit that may be rounded up.
1450
+ // n is a base 1e14 number, the value of the element of array x.c containing rd.
1451
+ // ni is the index of n within x.c.
1452
+ // d is the number of digits of n.
1453
+ // i is the index of rd within n including leading zeros.
1454
+ // j is the actual index of rd within n (if < 0, rd is a leading zero).
1455
+ out: {
1456
+
1457
+ // Get the number of digits of the first element of xc.
1458
+ for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
1459
+ i = sd - d;
1460
+
1461
+ // If the rounding digit is in the first element of xc...
1462
+ if (i < 0) {
1463
+ i += LOG_BASE;
1464
+ j = sd;
1465
+ n = xc[ni = 0];
1466
+
1467
+ // Get the rounding digit at index j of n.
1468
+ rd = mathfloor(n / pows10[d - j - 1] % 10);
1469
+ } else {
1470
+ ni = mathceil((i + 1) / LOG_BASE);
1471
+
1472
+ if (ni >= xc.length) {
1473
+
1474
+ if (r) {
1475
+
1476
+ // Needed by sqrt.
1477
+ for (; xc.length <= ni; xc.push(0));
1478
+ n = rd = 0;
1479
+ d = 1;
1480
+ i %= LOG_BASE;
1481
+ j = i - LOG_BASE + 1;
1482
+ } else {
1483
+ break out;
1484
+ }
1485
+ } else {
1486
+ n = k = xc[ni];
1487
+
1488
+ // Get the number of digits of n.
1489
+ for (d = 1; k >= 10; k /= 10, d++);
1490
+
1491
+ // Get the index of rd within n.
1492
+ i %= LOG_BASE;
1493
+
1494
+ // Get the index of rd within n, adjusted for leading zeros.
1495
+ // The number of leading zeros of n is given by LOG_BASE - d.
1496
+ j = i - LOG_BASE + d;
1497
+
1498
+ // Get the rounding digit at index j of n.
1499
+ rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
1500
+ }
1501
+ }
1502
+
1503
+ r = r || sd < 0 ||
1504
+
1505
+ // Are there any non-zero digits after the rounding digit?
1506
+ // The expression n % pows10[d - j - 1] returns all digits of n to the right
1507
+ // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
1508
+ xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
1509
+
1510
+ r = rm < 4
1511
+ ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
1512
+ : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&
1513
+
1514
+ // Check whether the digit to the left of the rounding digit is odd.
1515
+ ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||
1516
+ rm == (x.s < 0 ? 8 : 7));
1517
+
1518
+ if (sd < 1 || !xc[0]) {
1519
+ xc.length = 0;
1520
+
1521
+ if (r) {
1522
+
1523
+ // Convert sd to decimal places.
1524
+ sd -= x.e + 1;
1525
+
1526
+ // 1, 0.1, 0.01, 0.001, 0.0001 etc.
1527
+ xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
1528
+ x.e = -sd || 0;
1529
+ } else {
1530
+
1531
+ // Zero.
1532
+ xc[0] = x.e = 0;
1533
+ }
1534
+
1535
+ return x;
1536
+ }
1537
+
1538
+ // Remove excess digits.
1539
+ if (i == 0) {
1540
+ xc.length = ni;
1541
+ k = 1;
1542
+ ni--;
1543
+ } else {
1544
+ xc.length = ni + 1;
1545
+ k = pows10[LOG_BASE - i];
1546
+
1547
+ // E.g. 56700 becomes 56000 if 7 is the rounding digit.
1548
+ // j > 0 means i > number of leading zeros of n.
1549
+ xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
1550
+ }
1551
+
1552
+ // Round up?
1553
+ if (r) {
1554
+
1555
+ for (; ;) {
1556
+
1557
+ // If the digit to be rounded up is in the first element of xc...
1558
+ if (ni == 0) {
1559
+
1560
+ // i will be the length of xc[0] before k is added.
1561
+ for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
1562
+ j = xc[0] += k;
1563
+ for (k = 1; j >= 10; j /= 10, k++);
1564
+
1565
+ // if i != k the length has increased.
1566
+ if (i != k) {
1567
+ x.e++;
1568
+ if (xc[0] == BASE) xc[0] = 1;
1569
+ }
1570
+
1571
+ break;
1572
+ } else {
1573
+ xc[ni] += k;
1574
+ if (xc[ni] != BASE) break;
1575
+ xc[ni--] = 0;
1576
+ k = 1;
1577
+ }
1578
+ }
1579
+ }
1580
+
1581
+ // Remove trailing zeros.
1582
+ for (i = xc.length; xc[--i] === 0; xc.pop());
1583
+ }
1584
+
1585
+ // Overflow? Infinity.
1586
+ if (x.e > MAX_EXP) {
1587
+ x.c = x.e = null;
1588
+
1589
+ // Underflow? Zero.
1590
+ } else if (x.e < MIN_EXP) {
1591
+ x.c = [x.e = 0];
1592
+ }
1593
+ }
1594
+
1595
+ return x;
1596
+ }
1597
+
1598
+
1599
+ function valueOf(n) {
1600
+ var str,
1601
+ e = n.e;
1602
+
1603
+ if (e === null) return n.toString();
1604
+
1605
+ str = coeffToString(n.c);
1606
+
1607
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS
1608
+ ? toExponential(str, e)
1609
+ : toFixedPoint(str, e, '0');
1610
+
1611
+ return n.s < 0 ? '-' + str : str;
1612
+ }
1613
+
1614
+
1615
+ // PROTOTYPE/INSTANCE METHODS
1616
+
1617
+
1618
+ /*
1619
+ * Return a new BigNumber whose value is the absolute value of this BigNumber.
1620
+ */
1621
+ P.absoluteValue = P.abs = function () {
1622
+ var x = new BigNumber(this);
1623
+ if (x.s < 0) x.s = 1;
1624
+ return x;
1625
+ };
1626
+
1627
+
1628
+ /*
1629
+ * Return
1630
+ * 1 if the value of this BigNumber is greater than the value of BigNumber(y, b),
1631
+ * -1 if the value of this BigNumber is less than the value of BigNumber(y, b),
1632
+ * 0 if they have the same value,
1633
+ * or null if the value of either is NaN.
1634
+ */
1635
+ P.comparedTo = function (y, b) {
1636
+ return compare(this, new BigNumber(y, b));
1637
+ };
1638
+
1639
+
1640
+ /*
1641
+ * If dp is undefined or null or true or false, return the number of decimal places of the
1642
+ * value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
1643
+ *
1644
+ * Otherwise, if dp is a number, return a new BigNumber whose value is the value of this
1645
+ * BigNumber rounded to a maximum of dp decimal places using rounding mode rm, or
1646
+ * ROUNDING_MODE if rm is omitted.
1647
+ *
1648
+ * [dp] {number} Decimal places: integer, 0 to MAX inclusive.
1649
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1650
+ *
1651
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
1652
+ */
1653
+ P.decimalPlaces = P.dp = function (dp, rm) {
1654
+ var c, n, v,
1655
+ x = this;
1656
+
1657
+ if (dp != null) {
1658
+ intCheck(dp, 0, MAX);
1659
+ if (rm == null) rm = ROUNDING_MODE;
1660
+ else intCheck(rm, 0, 8);
1661
+
1662
+ return round(new BigNumber(x), dp + x.e + 1, rm);
1663
+ }
1664
+
1665
+ if (!(c = x.c)) return null;
1666
+ n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
1667
+
1668
+ // Subtract the number of trailing zeros of the last number.
1669
+ if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
1670
+ if (n < 0) n = 0;
1671
+
1672
+ return n;
1673
+ };
1674
+
1675
+
1676
+ /*
1677
+ * n / 0 = I
1678
+ * n / N = N
1679
+ * n / I = 0
1680
+ * 0 / n = 0
1681
+ * 0 / 0 = N
1682
+ * 0 / N = N
1683
+ * 0 / I = 0
1684
+ * N / n = N
1685
+ * N / 0 = N
1686
+ * N / N = N
1687
+ * N / I = N
1688
+ * I / n = I
1689
+ * I / 0 = I
1690
+ * I / N = N
1691
+ * I / I = N
1692
+ *
1693
+ * Return a new BigNumber whose value is the value of this BigNumber divided by the value of
1694
+ * BigNumber(y, b), rounded according to DECIMAL_PLACES and ROUNDING_MODE.
1695
+ */
1696
+ P.dividedBy = P.div = function (y, b) {
1697
+ return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);
1698
+ };
1699
+
1700
+
1701
+ /*
1702
+ * Return a new BigNumber whose value is the integer part of dividing the value of this
1703
+ * BigNumber by the value of BigNumber(y, b).
1704
+ */
1705
+ P.dividedToIntegerBy = P.idiv = function (y, b) {
1706
+ return div(this, new BigNumber(y, b), 0, 1);
1707
+ };
1708
+
1709
+
1710
+ /*
1711
+ * Return a BigNumber whose value is the value of this BigNumber exponentiated by n.
1712
+ *
1713
+ * If m is present, return the result modulo m.
1714
+ * If n is negative round according to DECIMAL_PLACES and ROUNDING_MODE.
1715
+ * If POW_PRECISION is non-zero and m is not present, round to POW_PRECISION using ROUNDING_MODE.
1716
+ *
1717
+ * The modular power operation works efficiently when x, n, and m are integers, otherwise it
1718
+ * is equivalent to calculating x.exponentiatedBy(n).modulo(m) with a POW_PRECISION of 0.
1719
+ *
1720
+ * n {number|string|BigNumber} The exponent. An integer.
1721
+ * [m] {number|string|BigNumber} The modulus.
1722
+ *
1723
+ * '[BigNumber Error] Exponent not an integer: {n}'
1724
+ */
1725
+ P.exponentiatedBy = P.pow = function (n, m) {
1726
+ var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,
1727
+ x = this;
1728
+
1729
+ n = new BigNumber(n);
1730
+
1731
+ // Allow NaN and ±Infinity, but not other non-integers.
1732
+ if (n.c && !n.isInteger()) {
1733
+ throw Error
1734
+ (bignumberError + 'Exponent not an integer: ' + valueOf(n));
1735
+ }
1736
+
1737
+ if (m != null) m = new BigNumber(m);
1738
+
1739
+ // Exponent of MAX_SAFE_INTEGER is 15.
1740
+ nIsBig = n.e > 14;
1741
+
1742
+ // If x is NaN, ±Infinity, ±0 or ±1, or n is ±Infinity, NaN or ±0.
1743
+ if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
1744
+
1745
+ // The sign of the result of pow when x is negative depends on the evenness of n.
1746
+ // If +n overflows to ±Infinity, the evenness of n would be not be known.
1747
+ y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
1748
+ return m ? y.mod(m) : y;
1749
+ }
1750
+
1751
+ nIsNeg = n.s < 0;
1752
+
1753
+ if (m) {
1754
+
1755
+ // x % m returns NaN if abs(m) is zero, or m is NaN.
1756
+ if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
1757
+
1758
+ isModExp = !nIsNeg && x.isInteger() && m.isInteger();
1759
+
1760
+ if (isModExp) x = x.mod(m);
1761
+
1762
+ // Overflow to ±Infinity: >=2**1e10 or >=1.0000024**1e15.
1763
+ // Underflow to ±0: <=0.79**1e10 or <=0.9999975**1e15.
1764
+ } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0
1765
+ // [1, 240000000]
1766
+ ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7
1767
+ // [80000000000000] [99999750000000]
1768
+ : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
1769
+
1770
+ // If x is negative and n is odd, k = -0, else k = 0.
1771
+ k = x.s < 0 && isOdd(n) ? -0 : 0;
1772
+
1773
+ // If x >= 1, k = ±Infinity.
1774
+ if (x.e > -1) k = 1 / k;
1775
+
1776
+ // If n is negative return ±0, else return ±Infinity.
1777
+ return new BigNumber(nIsNeg ? 1 / k : k);
1778
+
1779
+ } else if (POW_PRECISION) {
1780
+
1781
+ // Truncating each coefficient array to a length of k after each multiplication
1782
+ // equates to truncating significant digits to POW_PRECISION + [28, 41],
1783
+ // i.e. there will be a minimum of 28 guard digits retained.
1784
+ k = mathceil(POW_PRECISION / LOG_BASE + 2);
1785
+ }
1786
+
1787
+ if (nIsBig) {
1788
+ half = new BigNumber(0.5);
1789
+ if (nIsNeg) n.s = 1;
1790
+ nIsOdd = isOdd(n);
1791
+ } else {
1792
+ i = Math.abs(+valueOf(n));
1793
+ nIsOdd = i % 2;
1794
+ }
1795
+
1796
+ y = new BigNumber(ONE);
1797
+
1798
+ // Performs 54 loop iterations for n of 9007199254740991.
1799
+ for (; ;) {
1800
+
1801
+ if (nIsOdd) {
1802
+ y = y.times(x);
1803
+ if (!y.c) break;
1804
+
1805
+ if (k) {
1806
+ if (y.c.length > k) y.c.length = k;
1807
+ } else if (isModExp) {
1808
+ y = y.mod(m); //y = y.minus(div(y, m, 0, MODULO_MODE).times(m));
1809
+ }
1810
+ }
1811
+
1812
+ if (i) {
1813
+ i = mathfloor(i / 2);
1814
+ if (i === 0) break;
1815
+ nIsOdd = i % 2;
1816
+ } else {
1817
+ n = n.times(half);
1818
+ round(n, n.e + 1, 1);
1819
+
1820
+ if (n.e > 14) {
1821
+ nIsOdd = isOdd(n);
1822
+ } else {
1823
+ i = +valueOf(n);
1824
+ if (i === 0) break;
1825
+ nIsOdd = i % 2;
1826
+ }
1827
+ }
1828
+
1829
+ x = x.times(x);
1830
+
1831
+ if (k) {
1832
+ if (x.c && x.c.length > k) x.c.length = k;
1833
+ } else if (isModExp) {
1834
+ x = x.mod(m); //x = x.minus(div(x, m, 0, MODULO_MODE).times(m));
1835
+ }
1836
+ }
1837
+
1838
+ if (isModExp) return y;
1839
+ if (nIsNeg) y = ONE.div(y);
1840
+
1841
+ return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
1842
+ };
1843
+
1844
+
1845
+ /*
1846
+ * Return a new BigNumber whose value is the value of this BigNumber rounded to an integer
1847
+ * using rounding mode rm, or ROUNDING_MODE if rm is omitted.
1848
+ *
1849
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
1850
+ *
1851
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {rm}'
1852
+ */
1853
+ P.integerValue = function (rm) {
1854
+ var n = new BigNumber(this);
1855
+ if (rm == null) rm = ROUNDING_MODE;
1856
+ else intCheck(rm, 0, 8);
1857
+ return round(n, n.e + 1, rm);
1858
+ };
1859
+
1860
+
1861
+ /*
1862
+ * Return true if the value of this BigNumber is equal to the value of BigNumber(y, b),
1863
+ * otherwise return false.
1864
+ */
1865
+ P.isEqualTo = P.eq = function (y, b) {
1866
+ return compare(this, new BigNumber(y, b)) === 0;
1867
+ };
1868
+
1869
+
1870
+ /*
1871
+ * Return true if the value of this BigNumber is a finite number, otherwise return false.
1872
+ */
1873
+ P.isFinite = function () {
1874
+ return !!this.c;
1875
+ };
1876
+
1877
+
1878
+ /*
1879
+ * Return true if the value of this BigNumber is greater than the value of BigNumber(y, b),
1880
+ * otherwise return false.
1881
+ */
1882
+ P.isGreaterThan = P.gt = function (y, b) {
1883
+ return compare(this, new BigNumber(y, b)) > 0;
1884
+ };
1885
+
1886
+
1887
+ /*
1888
+ * Return true if the value of this BigNumber is greater than or equal to the value of
1889
+ * BigNumber(y, b), otherwise return false.
1890
+ */
1891
+ P.isGreaterThanOrEqualTo = P.gte = function (y, b) {
1892
+ return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;
1893
+
1894
+ };
1895
+
1896
+
1897
+ /*
1898
+ * Return true if the value of this BigNumber is an integer, otherwise return false.
1899
+ */
1900
+ P.isInteger = function () {
1901
+ return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
1902
+ };
1903
+
1904
+
1905
+ /*
1906
+ * Return true if the value of this BigNumber is less than the value of BigNumber(y, b),
1907
+ * otherwise return false.
1908
+ */
1909
+ P.isLessThan = P.lt = function (y, b) {
1910
+ return compare(this, new BigNumber(y, b)) < 0;
1911
+ };
1912
+
1913
+
1914
+ /*
1915
+ * Return true if the value of this BigNumber is less than or equal to the value of
1916
+ * BigNumber(y, b), otherwise return false.
1917
+ */
1918
+ P.isLessThanOrEqualTo = P.lte = function (y, b) {
1919
+ return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;
1920
+ };
1921
+
1922
+
1923
+ /*
1924
+ * Return true if the value of this BigNumber is NaN, otherwise return false.
1925
+ */
1926
+ P.isNaN = function () {
1927
+ return !this.s;
1928
+ };
1929
+
1930
+
1931
+ /*
1932
+ * Return true if the value of this BigNumber is negative, otherwise return false.
1933
+ */
1934
+ P.isNegative = function () {
1935
+ return this.s < 0;
1936
+ };
1937
+
1938
+
1939
+ /*
1940
+ * Return true if the value of this BigNumber is positive, otherwise return false.
1941
+ */
1942
+ P.isPositive = function () {
1943
+ return this.s > 0;
1944
+ };
1945
+
1946
+
1947
+ /*
1948
+ * Return true if the value of this BigNumber is 0 or -0, otherwise return false.
1949
+ */
1950
+ P.isZero = function () {
1951
+ return !!this.c && this.c[0] == 0;
1952
+ };
1953
+
1954
+
1955
+ /*
1956
+ * n - 0 = n
1957
+ * n - N = N
1958
+ * n - I = -I
1959
+ * 0 - n = -n
1960
+ * 0 - 0 = 0
1961
+ * 0 - N = N
1962
+ * 0 - I = -I
1963
+ * N - n = N
1964
+ * N - 0 = N
1965
+ * N - N = N
1966
+ * N - I = N
1967
+ * I - n = I
1968
+ * I - 0 = I
1969
+ * I - N = N
1970
+ * I - I = N
1971
+ *
1972
+ * Return a new BigNumber whose value is the value of this BigNumber minus the value of
1973
+ * BigNumber(y, b).
1974
+ */
1975
+ P.minus = function (y, b) {
1976
+ var i, j, t, xLTy,
1977
+ x = this,
1978
+ a = x.s;
1979
+
1980
+ y = new BigNumber(y, b);
1981
+ b = y.s;
1982
+
1983
+ // Either NaN?
1984
+ if (!a || !b) return new BigNumber(NaN);
1985
+
1986
+ // Signs differ?
1987
+ if (a != b) {
1988
+ y.s = -b;
1989
+ return x.plus(y);
1990
+ }
1991
+
1992
+ var xe = x.e / LOG_BASE,
1993
+ ye = y.e / LOG_BASE,
1994
+ xc = x.c,
1995
+ yc = y.c;
1996
+
1997
+ if (!xe || !ye) {
1998
+
1999
+ // Either Infinity?
2000
+ if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
2001
+
2002
+ // Either zero?
2003
+ if (!xc[0] || !yc[0]) {
2004
+
2005
+ // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
2006
+ return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :
2007
+
2008
+ // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
2009
+ ROUNDING_MODE == 3 ? -0 : 0);
2010
+ }
2011
+ }
2012
+
2013
+ xe = bitFloor(xe);
2014
+ ye = bitFloor(ye);
2015
+ xc = xc.slice();
2016
+
2017
+ // Determine which is the bigger number.
2018
+ if (a = xe - ye) {
2019
+
2020
+ if (xLTy = a < 0) {
2021
+ a = -a;
2022
+ t = xc;
2023
+ } else {
2024
+ ye = xe;
2025
+ t = yc;
2026
+ }
2027
+
2028
+ t.reverse();
2029
+
2030
+ // Prepend zeros to equalise exponents.
2031
+ for (b = a; b--; t.push(0));
2032
+ t.reverse();
2033
+ } else {
2034
+
2035
+ // Exponents equal. Check digit by digit.
2036
+ j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
2037
+
2038
+ for (a = b = 0; b < j; b++) {
2039
+
2040
+ if (xc[b] != yc[b]) {
2041
+ xLTy = xc[b] < yc[b];
2042
+ break;
2043
+ }
2044
+ }
2045
+ }
2046
+
2047
+ // x < y? Point xc to the array of the bigger number.
2048
+ if (xLTy) {
2049
+ t = xc;
2050
+ xc = yc;
2051
+ yc = t;
2052
+ y.s = -y.s;
2053
+ }
2054
+
2055
+ b = (j = yc.length) - (i = xc.length);
2056
+
2057
+ // Append zeros to xc if shorter.
2058
+ // No need to add zeros to yc if shorter as subtract only needs to start at yc.length.
2059
+ if (b > 0) for (; b--; xc[i++] = 0);
2060
+ b = BASE - 1;
2061
+
2062
+ // Subtract yc from xc.
2063
+ for (; j > a;) {
2064
+
2065
+ if (xc[--j] < yc[j]) {
2066
+ for (i = j; i && !xc[--i]; xc[i] = b);
2067
+ --xc[i];
2068
+ xc[j] += BASE;
2069
+ }
2070
+
2071
+ xc[j] -= yc[j];
2072
+ }
2073
+
2074
+ // Remove leading zeros and adjust exponent accordingly.
2075
+ for (; xc[0] == 0; xc.splice(0, 1), --ye);
2076
+
2077
+ // Zero?
2078
+ if (!xc[0]) {
2079
+
2080
+ // Following IEEE 754 (2008) 6.3,
2081
+ // n - n = +0 but n - n = -0 when rounding towards -Infinity.
2082
+ y.s = ROUNDING_MODE == 3 ? -1 : 1;
2083
+ y.c = [y.e = 0];
2084
+ return y;
2085
+ }
2086
+
2087
+ // No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
2088
+ // for finite x and y.
2089
+ return normalise(y, xc, ye);
2090
+ };
2091
+
2092
+
2093
+ /*
2094
+ * n % 0 = N
2095
+ * n % N = N
2096
+ * n % I = n
2097
+ * 0 % n = 0
2098
+ * -0 % n = -0
2099
+ * 0 % 0 = N
2100
+ * 0 % N = N
2101
+ * 0 % I = 0
2102
+ * N % n = N
2103
+ * N % 0 = N
2104
+ * N % N = N
2105
+ * N % I = N
2106
+ * I % n = N
2107
+ * I % 0 = N
2108
+ * I % N = N
2109
+ * I % I = N
2110
+ *
2111
+ * Return a new BigNumber whose value is the value of this BigNumber modulo the value of
2112
+ * BigNumber(y, b). The result depends on the value of MODULO_MODE.
2113
+ */
2114
+ P.modulo = P.mod = function (y, b) {
2115
+ var q, s,
2116
+ x = this;
2117
+
2118
+ y = new BigNumber(y, b);
2119
+
2120
+ // Return NaN if x is Infinity or NaN, or y is NaN or zero.
2121
+ if (!x.c || !y.s || y.c && !y.c[0]) {
2122
+ return new BigNumber(NaN);
2123
+
2124
+ // Return x if y is Infinity or x is zero.
2125
+ } else if (!y.c || x.c && !x.c[0]) {
2126
+ return new BigNumber(x);
2127
+ }
2128
+
2129
+ if (MODULO_MODE == 9) {
2130
+
2131
+ // Euclidian division: q = sign(y) * floor(x / abs(y))
2132
+ // r = x - qy where 0 <= r < abs(y)
2133
+ s = y.s;
2134
+ y.s = 1;
2135
+ q = div(x, y, 0, 3);
2136
+ y.s = s;
2137
+ q.s *= s;
2138
+ } else {
2139
+ q = div(x, y, 0, MODULO_MODE);
2140
+ }
2141
+
2142
+ y = x.minus(q.times(y));
2143
+
2144
+ // To match JavaScript %, ensure sign of zero is sign of dividend.
2145
+ if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
2146
+
2147
+ return y;
2148
+ };
2149
+
2150
+
2151
+ /*
2152
+ * n * 0 = 0
2153
+ * n * N = N
2154
+ * n * I = I
2155
+ * 0 * n = 0
2156
+ * 0 * 0 = 0
2157
+ * 0 * N = N
2158
+ * 0 * I = N
2159
+ * N * n = N
2160
+ * N * 0 = N
2161
+ * N * N = N
2162
+ * N * I = N
2163
+ * I * n = I
2164
+ * I * 0 = N
2165
+ * I * N = N
2166
+ * I * I = I
2167
+ *
2168
+ * Return a new BigNumber whose value is the value of this BigNumber multiplied by the value
2169
+ * of BigNumber(y, b).
2170
+ */
2171
+ P.multipliedBy = P.times = function (y, b) {
2172
+ var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,
2173
+ base, sqrtBase,
2174
+ x = this,
2175
+ xc = x.c,
2176
+ yc = (y = new BigNumber(y, b)).c;
2177
+
2178
+ // Either NaN, ±Infinity or ±0?
2179
+ if (!xc || !yc || !xc[0] || !yc[0]) {
2180
+
2181
+ // Return NaN if either is NaN, or one is 0 and the other is Infinity.
2182
+ if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
2183
+ y.c = y.e = y.s = null;
2184
+ } else {
2185
+ y.s *= x.s;
2186
+
2187
+ // Return ±Infinity if either is ±Infinity.
2188
+ if (!xc || !yc) {
2189
+ y.c = y.e = null;
2190
+
2191
+ // Return ±0 if either is ±0.
2192
+ } else {
2193
+ y.c = [0];
2194
+ y.e = 0;
2195
+ }
2196
+ }
2197
+
2198
+ return y;
2199
+ }
2200
+
2201
+ e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
2202
+ y.s *= x.s;
2203
+ xcL = xc.length;
2204
+ ycL = yc.length;
2205
+
2206
+ // Ensure xc points to longer array and xcL to its length.
2207
+ if (xcL < ycL) {
2208
+ zc = xc;
2209
+ xc = yc;
2210
+ yc = zc;
2211
+ i = xcL;
2212
+ xcL = ycL;
2213
+ ycL = i;
2214
+ }
2215
+
2216
+ // Initialise the result array with zeros.
2217
+ for (i = xcL + ycL, zc = []; i--; zc.push(0));
2218
+
2219
+ base = BASE;
2220
+ sqrtBase = SQRT_BASE;
2221
+
2222
+ for (i = ycL; --i >= 0;) {
2223
+ c = 0;
2224
+ ylo = yc[i] % sqrtBase;
2225
+ yhi = yc[i] / sqrtBase | 0;
2226
+
2227
+ for (k = xcL, j = i + k; j > i;) {
2228
+ xlo = xc[--k] % sqrtBase;
2229
+ xhi = xc[k] / sqrtBase | 0;
2230
+ m = yhi * xlo + xhi * ylo;
2231
+ xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;
2232
+ c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
2233
+ zc[j--] = xlo % base;
2234
+ }
2235
+
2236
+ zc[j] = c;
2237
+ }
2238
+
2239
+ if (c) {
2240
+ ++e;
2241
+ } else {
2242
+ zc.splice(0, 1);
2243
+ }
2244
+
2245
+ return normalise(y, zc, e);
2246
+ };
2247
+
2248
+
2249
+ /*
2250
+ * Return a new BigNumber whose value is the value of this BigNumber negated,
2251
+ * i.e. multiplied by -1.
2252
+ */
2253
+ P.negated = function () {
2254
+ var x = new BigNumber(this);
2255
+ x.s = -x.s || null;
2256
+ return x;
2257
+ };
2258
+
2259
+
2260
+ /*
2261
+ * n + 0 = n
2262
+ * n + N = N
2263
+ * n + I = I
2264
+ * 0 + n = n
2265
+ * 0 + 0 = 0
2266
+ * 0 + N = N
2267
+ * 0 + I = I
2268
+ * N + n = N
2269
+ * N + 0 = N
2270
+ * N + N = N
2271
+ * N + I = N
2272
+ * I + n = I
2273
+ * I + 0 = I
2274
+ * I + N = N
2275
+ * I + I = I
2276
+ *
2277
+ * Return a new BigNumber whose value is the value of this BigNumber plus the value of
2278
+ * BigNumber(y, b).
2279
+ */
2280
+ P.plus = function (y, b) {
2281
+ var t,
2282
+ x = this,
2283
+ a = x.s;
2284
+
2285
+ y = new BigNumber(y, b);
2286
+ b = y.s;
2287
+
2288
+ // Either NaN?
2289
+ if (!a || !b) return new BigNumber(NaN);
2290
+
2291
+ // Signs differ?
2292
+ if (a != b) {
2293
+ y.s = -b;
2294
+ return x.minus(y);
2295
+ }
2296
+
2297
+ var xe = x.e / LOG_BASE,
2298
+ ye = y.e / LOG_BASE,
2299
+ xc = x.c,
2300
+ yc = y.c;
2301
+
2302
+ if (!xe || !ye) {
2303
+
2304
+ // Return ±Infinity if either ±Infinity.
2305
+ if (!xc || !yc) return new BigNumber(a / 0);
2306
+
2307
+ // Either zero?
2308
+ // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
2309
+ if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);
2310
+ }
2311
+
2312
+ xe = bitFloor(xe);
2313
+ ye = bitFloor(ye);
2314
+ xc = xc.slice();
2315
+
2316
+ // Prepend zeros to equalise exponents. Faster to use reverse then do unshifts.
2317
+ if (a = xe - ye) {
2318
+ if (a > 0) {
2319
+ ye = xe;
2320
+ t = yc;
2321
+ } else {
2322
+ a = -a;
2323
+ t = xc;
2324
+ }
2325
+
2326
+ t.reverse();
2327
+ for (; a--; t.push(0));
2328
+ t.reverse();
2329
+ }
2330
+
2331
+ a = xc.length;
2332
+ b = yc.length;
2333
+
2334
+ // Point xc to the longer array, and b to the shorter length.
2335
+ if (a - b < 0) {
2336
+ t = yc;
2337
+ yc = xc;
2338
+ xc = t;
2339
+ b = a;
2340
+ }
2341
+
2342
+ // Only start adding at yc.length - 1 as the further digits of xc can be ignored.
2343
+ for (a = 0; b;) {
2344
+ a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
2345
+ xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
2346
+ }
2347
+
2348
+ if (a) {
2349
+ xc = [a].concat(xc);
2350
+ ++ye;
2351
+ }
2352
+
2353
+ // No need to check for zero, as +x + +y != 0 && -x + -y != 0
2354
+ // ye = MAX_EXP + 1 possible
2355
+ return normalise(y, xc, ye);
2356
+ };
2357
+
2358
+
2359
+ /*
2360
+ * If sd is undefined or null or true or false, return the number of significant digits of
2361
+ * the value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
2362
+ * If sd is true include integer-part trailing zeros in the count.
2363
+ *
2364
+ * Otherwise, if sd is a number, return a new BigNumber whose value is the value of this
2365
+ * BigNumber rounded to a maximum of sd significant digits using rounding mode rm, or
2366
+ * ROUNDING_MODE if rm is omitted.
2367
+ *
2368
+ * sd {number|boolean} number: significant digits: integer, 1 to MAX inclusive.
2369
+ * boolean: whether to count integer-part trailing zeros: true or false.
2370
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2371
+ *
2372
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2373
+ */
2374
+ P.precision = P.sd = function (sd, rm) {
2375
+ var c, n, v,
2376
+ x = this;
2377
+
2378
+ if (sd != null && sd !== !!sd) {
2379
+ intCheck(sd, 1, MAX);
2380
+ if (rm == null) rm = ROUNDING_MODE;
2381
+ else intCheck(rm, 0, 8);
2382
+
2383
+ return round(new BigNumber(x), sd, rm);
2384
+ }
2385
+
2386
+ if (!(c = x.c)) return null;
2387
+ v = c.length - 1;
2388
+ n = v * LOG_BASE + 1;
2389
+
2390
+ if (v = c[v]) {
2391
+
2392
+ // Subtract the number of trailing zeros of the last element.
2393
+ for (; v % 10 == 0; v /= 10, n--);
2394
+
2395
+ // Add the number of digits of the first element.
2396
+ for (v = c[0]; v >= 10; v /= 10, n++);
2397
+ }
2398
+
2399
+ if (sd && x.e + 1 > n) n = x.e + 1;
2400
+
2401
+ return n;
2402
+ };
2403
+
2404
+
2405
+ /*
2406
+ * Return a new BigNumber whose value is the value of this BigNumber shifted by k places
2407
+ * (powers of 10). Shift to the right if n > 0, and to the left if n < 0.
2408
+ *
2409
+ * k {number} Integer, -MAX_SAFE_INTEGER to MAX_SAFE_INTEGER inclusive.
2410
+ *
2411
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {k}'
2412
+ */
2413
+ P.shiftedBy = function (k) {
2414
+ intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
2415
+ return this.times('1e' + k);
2416
+ };
2417
+
2418
+
2419
+ /*
2420
+ * sqrt(-n) = N
2421
+ * sqrt(N) = N
2422
+ * sqrt(-I) = N
2423
+ * sqrt(I) = I
2424
+ * sqrt(0) = 0
2425
+ * sqrt(-0) = -0
2426
+ *
2427
+ * Return a new BigNumber whose value is the square root of the value of this BigNumber,
2428
+ * rounded according to DECIMAL_PLACES and ROUNDING_MODE.
2429
+ */
2430
+ P.squareRoot = P.sqrt = function () {
2431
+ var m, n, r, rep, t,
2432
+ x = this,
2433
+ c = x.c,
2434
+ s = x.s,
2435
+ e = x.e,
2436
+ dp = DECIMAL_PLACES + 4,
2437
+ half = new BigNumber('0.5');
2438
+
2439
+ // Negative/NaN/Infinity/zero?
2440
+ if (s !== 1 || !c || !c[0]) {
2441
+ return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
2442
+ }
2443
+
2444
+ // Initial estimate.
2445
+ s = Math.sqrt(+valueOf(x));
2446
+
2447
+ // Math.sqrt underflow/overflow?
2448
+ // Pass x to Math.sqrt as integer, then adjust the exponent of the result.
2449
+ if (s == 0 || s == 1 / 0) {
2450
+ n = coeffToString(c);
2451
+ if ((n.length + e) % 2 == 0) n += '0';
2452
+ s = Math.sqrt(+n);
2453
+ e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
2454
+
2455
+ if (s == 1 / 0) {
2456
+ n = '5e' + e;
2457
+ } else {
2458
+ n = s.toExponential();
2459
+ n = n.slice(0, n.indexOf('e') + 1) + e;
2460
+ }
2461
+
2462
+ r = new BigNumber(n);
2463
+ } else {
2464
+ r = new BigNumber(s + '');
2465
+ }
2466
+
2467
+ // Check for zero.
2468
+ // r could be zero if MIN_EXP is changed after the this value was created.
2469
+ // This would cause a division by zero (x/t) and hence Infinity below, which would cause
2470
+ // coeffToString to throw.
2471
+ if (r.c[0]) {
2472
+ e = r.e;
2473
+ s = e + dp;
2474
+ if (s < 3) s = 0;
2475
+
2476
+ // Newton-Raphson iteration.
2477
+ for (; ;) {
2478
+ t = r;
2479
+ r = half.times(t.plus(div(x, t, dp, 1)));
2480
+
2481
+ if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
2482
+
2483
+ // The exponent of r may here be one less than the final result exponent,
2484
+ // e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust s so the rounding digits
2485
+ // are indexed correctly.
2486
+ if (r.e < e) --s;
2487
+ n = n.slice(s - 3, s + 1);
2488
+
2489
+ // The 4th rounding digit may be in error by -1 so if the 4 rounding digits
2490
+ // are 9999 or 4999 (i.e. approaching a rounding boundary) continue the
2491
+ // iteration.
2492
+ if (n == '9999' || !rep && n == '4999') {
2493
+
2494
+ // On the first iteration only, check to see if rounding up gives the
2495
+ // exact result as the nines may infinitely repeat.
2496
+ if (!rep) {
2497
+ round(t, t.e + DECIMAL_PLACES + 2, 0);
2498
+
2499
+ if (t.times(t).eq(x)) {
2500
+ r = t;
2501
+ break;
2502
+ }
2503
+ }
2504
+
2505
+ dp += 4;
2506
+ s += 4;
2507
+ rep = 1;
2508
+ } else {
2509
+
2510
+ // If rounding digits are null, 0{0,4} or 50{0,3}, check for exact
2511
+ // result. If not, then there are further digits and m will be truthy.
2512
+ if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
2513
+
2514
+ // Truncate to the first rounding digit.
2515
+ round(r, r.e + DECIMAL_PLACES + 2, 1);
2516
+ m = !r.times(r).eq(x);
2517
+ }
2518
+
2519
+ break;
2520
+ }
2521
+ }
2522
+ }
2523
+ }
2524
+
2525
+ return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
2526
+ };
2527
+
2528
+
2529
+ /*
2530
+ * Return a string representing the value of this BigNumber in exponential notation and
2531
+ * rounded using ROUNDING_MODE to dp fixed decimal places.
2532
+ *
2533
+ * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2534
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2535
+ *
2536
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2537
+ */
2538
+ P.toExponential = function (dp, rm) {
2539
+ if (dp != null) {
2540
+ intCheck(dp, 0, MAX);
2541
+ dp++;
2542
+ }
2543
+ return format(this, dp, rm, 1);
2544
+ };
2545
+
2546
+
2547
+ /*
2548
+ * Return a string representing the value of this BigNumber in fixed-point notation rounding
2549
+ * to dp fixed decimal places using rounding mode rm, or ROUNDING_MODE if rm is omitted.
2550
+ *
2551
+ * Note: as with JavaScript's number type, (-0).toFixed(0) is '0',
2552
+ * but e.g. (-0.00001).toFixed(0) is '-0'.
2553
+ *
2554
+ * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2555
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2556
+ *
2557
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2558
+ */
2559
+ P.toFixed = function (dp, rm) {
2560
+ if (dp != null) {
2561
+ intCheck(dp, 0, MAX);
2562
+ dp = dp + this.e + 1;
2563
+ }
2564
+ return format(this, dp, rm);
2565
+ };
2566
+
2567
+
2568
+ /*
2569
+ * Return a string representing the value of this BigNumber in fixed-point notation rounded
2570
+ * using rm or ROUNDING_MODE to dp decimal places, and formatted according to the properties
2571
+ * of the format or FORMAT object (see BigNumber.set).
2572
+ *
2573
+ * The formatting object may contain some or all of the properties shown below.
2574
+ *
2575
+ * FORMAT = {
2576
+ * prefix: '',
2577
+ * groupSize: 3,
2578
+ * secondaryGroupSize: 0,
2579
+ * groupSeparator: ',',
2580
+ * decimalSeparator: '.',
2581
+ * fractionGroupSize: 0,
2582
+ * fractionGroupSeparator: '\xA0', // non-breaking space
2583
+ * suffix: ''
2584
+ * };
2585
+ *
2586
+ * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
2587
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2588
+ * [format] {object} Formatting options. See FORMAT pbject above.
2589
+ *
2590
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
2591
+ * '[BigNumber Error] Argument not an object: {format}'
2592
+ */
2593
+ P.toFormat = function (dp, rm, format) {
2594
+ var str,
2595
+ x = this;
2596
+
2597
+ if (format == null) {
2598
+ if (dp != null && rm && typeof rm == 'object') {
2599
+ format = rm;
2600
+ rm = null;
2601
+ } else if (dp && typeof dp == 'object') {
2602
+ format = dp;
2603
+ dp = rm = null;
2604
+ } else {
2605
+ format = FORMAT;
2606
+ }
2607
+ } else if (typeof format != 'object') {
2608
+ throw Error
2609
+ (bignumberError + 'Argument not an object: ' + format);
2610
+ }
2611
+
2612
+ str = x.toFixed(dp, rm);
2613
+
2614
+ if (x.c) {
2615
+ var i,
2616
+ arr = str.split('.'),
2617
+ g1 = +format.groupSize,
2618
+ g2 = +format.secondaryGroupSize,
2619
+ groupSeparator = format.groupSeparator || '',
2620
+ intPart = arr[0],
2621
+ fractionPart = arr[1],
2622
+ isNeg = x.s < 0,
2623
+ intDigits = isNeg ? intPart.slice(1) : intPart,
2624
+ len = intDigits.length;
2625
+
2626
+ if (g2) {
2627
+ i = g1;
2628
+ g1 = g2;
2629
+ g2 = i;
2630
+ len -= i;
2631
+ }
2632
+
2633
+ if (g1 > 0 && len > 0) {
2634
+ i = len % g1 || g1;
2635
+ intPart = intDigits.substr(0, i);
2636
+ for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
2637
+ if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
2638
+ if (isNeg) intPart = '-' + intPart;
2639
+ }
2640
+
2641
+ str = fractionPart
2642
+ ? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)
2643
+ ? fractionPart.replace(new RegExp('\\d{' + g2 + '}\\B', 'g'),
2644
+ '$&' + (format.fractionGroupSeparator || ''))
2645
+ : fractionPart)
2646
+ : intPart;
2647
+ }
2648
+
2649
+ return (format.prefix || '') + str + (format.suffix || '');
2650
+ };
2651
+
2652
+
2653
+ /*
2654
+ * Return an array of two BigNumbers representing the value of this BigNumber as a simple
2655
+ * fraction with an integer numerator and an integer denominator.
2656
+ * The denominator will be a positive non-zero value less than or equal to the specified
2657
+ * maximum denominator. If a maximum denominator is not specified, the denominator will be
2658
+ * the lowest value necessary to represent the number exactly.
2659
+ *
2660
+ * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
2661
+ *
2662
+ * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
2663
+ */
2664
+ P.toFraction = function (md) {
2665
+ var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,
2666
+ x = this,
2667
+ xc = x.c;
2668
+
2669
+ if (md != null) {
2670
+ n = new BigNumber(md);
2671
+
2672
+ // Throw if md is less than one or is not an integer, unless it is Infinity.
2673
+ if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
2674
+ throw Error
2675
+ (bignumberError + 'Argument ' +
2676
+ (n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));
2677
+ }
2678
+ }
2679
+
2680
+ if (!xc) return new BigNumber(x);
2681
+
2682
+ d = new BigNumber(ONE);
2683
+ n1 = d0 = new BigNumber(ONE);
2684
+ d1 = n0 = new BigNumber(ONE);
2685
+ s = coeffToString(xc);
2686
+
2687
+ // Determine initial denominator.
2688
+ // d is a power of 10 and the minimum max denominator that specifies the value exactly.
2689
+ e = d.e = s.length - x.e - 1;
2690
+ d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
2691
+ md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;
2692
+
2693
+ exp = MAX_EXP;
2694
+ MAX_EXP = 1 / 0;
2695
+ n = new BigNumber(s);
2696
+
2697
+ // n0 = d1 = 0
2698
+ n0.c[0] = 0;
2699
+
2700
+ for (; ;) {
2701
+ q = div(n, d, 0, 1);
2702
+ d2 = d0.plus(q.times(d1));
2703
+ if (d2.comparedTo(md) == 1) break;
2704
+ d0 = d1;
2705
+ d1 = d2;
2706
+ n1 = n0.plus(q.times(d2 = n1));
2707
+ n0 = d2;
2708
+ d = n.minus(q.times(d2 = d));
2709
+ n = d2;
2710
+ }
2711
+
2712
+ d2 = div(md.minus(d0), d1, 0, 1);
2713
+ n0 = n0.plus(d2.times(n1));
2714
+ d0 = d0.plus(d2.times(d1));
2715
+ n0.s = n1.s = x.s;
2716
+ e = e * 2;
2717
+
2718
+ // Determine which fraction is closer to x, n0/d0 or n1/d1
2719
+ r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
2720
+ div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
2721
+
2722
+ MAX_EXP = exp;
2723
+
2724
+ return r;
2725
+ };
2726
+
2727
+
2728
+ /*
2729
+ * Return the value of this BigNumber converted to a number primitive.
2730
+ */
2731
+ P.toNumber = function () {
2732
+ return +valueOf(this);
2733
+ };
2734
+
2735
+
2736
+ /*
2737
+ * Return a string representing the value of this BigNumber rounded to sd significant digits
2738
+ * using rounding mode rm or ROUNDING_MODE. If sd is less than the number of digits
2739
+ * necessary to represent the integer part of the value in fixed-point notation, then use
2740
+ * exponential notation.
2741
+ *
2742
+ * [sd] {number} Significant digits. Integer, 1 to MAX inclusive.
2743
+ * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
2744
+ *
2745
+ * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
2746
+ */
2747
+ P.toPrecision = function (sd, rm) {
2748
+ if (sd != null) intCheck(sd, 1, MAX);
2749
+ return format(this, sd, rm, 2);
2750
+ };
2751
+
2752
+
2753
+ /*
2754
+ * Return a string representing the value of this BigNumber in base b, or base 10 if b is
2755
+ * omitted. If a base is specified, including base 10, round according to DECIMAL_PLACES and
2756
+ * ROUNDING_MODE. If a base is not specified, and this BigNumber has a positive exponent
2757
+ * that is equal to or greater than TO_EXP_POS, or a negative exponent equal to or less than
2758
+ * TO_EXP_NEG, return exponential notation.
2759
+ *
2760
+ * [b] {number} Integer, 2 to ALPHABET.length inclusive.
2761
+ *
2762
+ * '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
2763
+ */
2764
+ P.toString = function (b) {
2765
+ var str,
2766
+ n = this,
2767
+ s = n.s,
2768
+ e = n.e;
2769
+
2770
+ // Infinity or NaN?
2771
+ if (e === null) {
2772
+ if (s) {
2773
+ str = 'Infinity';
2774
+ if (s < 0) str = '-' + str;
2775
+ } else {
2776
+ str = 'NaN';
2777
+ }
2778
+ } else {
2779
+ if (b == null) {
2780
+ str = e <= TO_EXP_NEG || e >= TO_EXP_POS
2781
+ ? toExponential(coeffToString(n.c), e)
2782
+ : toFixedPoint(coeffToString(n.c), e, '0');
2783
+ } else if (b === 10 && alphabetHasNormalDecimalDigits) {
2784
+ n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
2785
+ str = toFixedPoint(coeffToString(n.c), n.e, '0');
2786
+ } else {
2787
+ intCheck(b, 2, ALPHABET.length, 'Base');
2788
+ str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
2789
+ }
2790
+
2791
+ if (s < 0 && n.c[0]) str = '-' + str;
2792
+ }
2793
+
2794
+ return str;
2795
+ };
2796
+
2797
+
2798
+ /*
2799
+ * Return as toString, but do not accept a base argument, and include the minus sign for
2800
+ * negative zero.
2801
+ */
2802
+ P.valueOf = P.toJSON = function () {
2803
+ return valueOf(this);
2804
+ };
2805
+
2806
+
2807
+ P._isBigNumber = true;
2808
+
2809
+ if (configObject != null) BigNumber.set(configObject);
2810
+
2811
+ return BigNumber;
2812
+ }
2813
+
2814
+
2815
+ // PRIVATE HELPER FUNCTIONS
2816
+
2817
+ // These functions don't need access to variables,
2818
+ // e.g. DECIMAL_PLACES, in the scope of the `clone` function above.
2819
+
2820
+
2821
+ function bitFloor(n) {
2822
+ var i = n | 0;
2823
+ return n > 0 || n === i ? i : i - 1;
2824
+ }
2825
+
2826
+
2827
+ // Return a coefficient array as a string of base 10 digits.
2828
+ function coeffToString(a) {
2829
+ var s, z,
2830
+ i = 1,
2831
+ j = a.length,
2832
+ r = a[0] + '';
2833
+
2834
+ for (; i < j;) {
2835
+ s = a[i++] + '';
2836
+ z = LOG_BASE - s.length;
2837
+ for (; z--; s = '0' + s);
2838
+ r += s;
2839
+ }
2840
+
2841
+ // Determine trailing zeros.
2842
+ for (j = r.length; r.charCodeAt(--j) === 48;);
2843
+
2844
+ return r.slice(0, j + 1 || 1);
2845
+ }
2846
+
2847
+
2848
+ // Compare the value of BigNumbers x and y.
2849
+ function compare(x, y) {
2850
+ var a, b,
2851
+ xc = x.c,
2852
+ yc = y.c,
2853
+ i = x.s,
2854
+ j = y.s,
2855
+ k = x.e,
2856
+ l = y.e;
2857
+
2858
+ // Either NaN?
2859
+ if (!i || !j) return null;
2860
+
2861
+ a = xc && !xc[0];
2862
+ b = yc && !yc[0];
2863
+
2864
+ // Either zero?
2865
+ if (a || b) return a ? b ? 0 : -j : i;
2866
+
2867
+ // Signs differ?
2868
+ if (i != j) return i;
2869
+
2870
+ a = i < 0;
2871
+ b = k == l;
2872
+
2873
+ // Either Infinity?
2874
+ if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
2875
+
2876
+ // Compare exponents.
2877
+ if (!b) return k > l ^ a ? 1 : -1;
2878
+
2879
+ j = (k = xc.length) < (l = yc.length) ? k : l;
2880
+
2881
+ // Compare digit by digit.
2882
+ for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
2883
+
2884
+ // Compare lengths.
2885
+ return k == l ? 0 : k > l ^ a ? 1 : -1;
2886
+ }
2887
+
2888
+
2889
+ /*
2890
+ * Check that n is a primitive number, an integer, and in range, otherwise throw.
2891
+ */
2892
+ function intCheck(n, min, max, name) {
2893
+ if (n < min || n > max || n !== mathfloor(n)) {
2894
+ throw Error
2895
+ (bignumberError + (name || 'Argument') + (typeof n == 'number'
2896
+ ? n < min || n > max ? ' out of range: ' : ' not an integer: '
2897
+ : ' not a primitive number: ') + String(n));
2898
+ }
2899
+ }
2900
+
2901
+
2902
+ // Assumes finite n.
2903
+ function isOdd(n) {
2904
+ var k = n.c.length - 1;
2905
+ return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
2906
+ }
2907
+
2908
+
2909
+ function toExponential(str, e) {
2910
+ return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +
2911
+ (e < 0 ? 'e' : 'e+') + e;
2912
+ }
2913
+
2914
+
2915
+ function toFixedPoint(str, e, z) {
2916
+ var len, zs;
2917
+
2918
+ // Negative exponent?
2919
+ if (e < 0) {
2920
+
2921
+ // Prepend zeros.
2922
+ for (zs = z + '.'; ++e; zs += z);
2923
+ str = zs + str;
2924
+
2925
+ // Positive exponent
2926
+ } else {
2927
+ len = str.length;
2928
+
2929
+ // Append zeros.
2930
+ if (++e > len) {
2931
+ for (zs = z, e -= len; --e; zs += z);
2932
+ str += zs;
2933
+ } else if (e < len) {
2934
+ str = str.slice(0, e) + '.' + str.slice(e);
2935
+ }
2936
+ }
2937
+
2938
+ return str;
2939
+ }
2940
+
2941
+
2942
+ // EXPORT
2943
+
2944
+
2945
+ BigNumber = clone();
2946
+ BigNumber['default'] = BigNumber.BigNumber = BigNumber;
2947
+
2948
+ // AMD.
2949
+ if (module.exports) {
2950
+ module.exports = BigNumber;
2951
+
2952
+ // Browser.
2953
+ } else {
2954
+ if (!globalObject) {
2955
+ globalObject = typeof self != 'undefined' && self ? self : window;
2956
+ }
2957
+
2958
+ globalObject.BigNumber = BigNumber;
2959
+ }
2960
+ })(commonjsGlobal);
2961
+ } (bignumber));
2962
+
2963
+ (function (module) {
2964
+ var BigNumber = bignumber.exports;
2965
+
2966
+ /*
2967
+ json2.js
2968
+ 2013-05-26
2969
+
2970
+ Public Domain.
2971
+
2972
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
2973
+
2974
+ See http://www.JSON.org/js.html
2975
+
2976
+
2977
+ This code should be minified before deployment.
2978
+ See http://javascript.crockford.com/jsmin.html
2979
+
2980
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
2981
+ NOT CONTROL.
2982
+
2983
+
2984
+ This file creates a global JSON object containing two methods: stringify
2985
+ and parse.
2986
+
2987
+ JSON.stringify(value, replacer, space)
2988
+ value any JavaScript value, usually an object or array.
2989
+
2990
+ replacer an optional parameter that determines how object
2991
+ values are stringified for objects. It can be a
2992
+ function or an array of strings.
2993
+
2994
+ space an optional parameter that specifies the indentation
2995
+ of nested structures. If it is omitted, the text will
2996
+ be packed without extra whitespace. If it is a number,
2997
+ it will specify the number of spaces to indent at each
2998
+ level. If it is a string (such as '\t' or '&nbsp;'),
2999
+ it contains the characters used to indent at each level.
3000
+
3001
+ This method produces a JSON text from a JavaScript value.
3002
+
3003
+ When an object value is found, if the object contains a toJSON
3004
+ method, its toJSON method will be called and the result will be
3005
+ stringified. A toJSON method does not serialize: it returns the
3006
+ value represented by the name/value pair that should be serialized,
3007
+ or undefined if nothing should be serialized. The toJSON method
3008
+ will be passed the key associated with the value, and this will be
3009
+ bound to the value
3010
+
3011
+ For example, this would serialize Dates as ISO strings.
3012
+
3013
+ Date.prototype.toJSON = function (key) {
3014
+ function f(n) {
3015
+ // Format integers to have at least two digits.
3016
+ return n < 10 ? '0' + n : n;
3017
+ }
3018
+
3019
+ return this.getUTCFullYear() + '-' +
3020
+ f(this.getUTCMonth() + 1) + '-' +
3021
+ f(this.getUTCDate()) + 'T' +
3022
+ f(this.getUTCHours()) + ':' +
3023
+ f(this.getUTCMinutes()) + ':' +
3024
+ f(this.getUTCSeconds()) + 'Z';
3025
+ };
3026
+
3027
+ You can provide an optional replacer method. It will be passed the
3028
+ key and value of each member, with this bound to the containing
3029
+ object. The value that is returned from your method will be
3030
+ serialized. If your method returns undefined, then the member will
3031
+ be excluded from the serialization.
3032
+
3033
+ If the replacer parameter is an array of strings, then it will be
3034
+ used to select the members to be serialized. It filters the results
3035
+ such that only members with keys listed in the replacer array are
3036
+ stringified.
3037
+
3038
+ Values that do not have JSON representations, such as undefined or
3039
+ functions, will not be serialized. Such values in objects will be
3040
+ dropped; in arrays they will be replaced with null. You can use
3041
+ a replacer function to replace those with JSON values.
3042
+ JSON.stringify(undefined) returns undefined.
3043
+
3044
+ The optional space parameter produces a stringification of the
3045
+ value that is filled with line breaks and indentation to make it
3046
+ easier to read.
3047
+
3048
+ If the space parameter is a non-empty string, then that string will
3049
+ be used for indentation. If the space parameter is a number, then
3050
+ the indentation will be that many spaces.
3051
+
3052
+ Example:
3053
+
3054
+ text = JSON.stringify(['e', {pluribus: 'unum'}]);
3055
+ // text is '["e",{"pluribus":"unum"}]'
3056
+
3057
+
3058
+ text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
3059
+ // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
3060
+
3061
+ text = JSON.stringify([new Date()], function (key, value) {
3062
+ return this[key] instanceof Date ?
3063
+ 'Date(' + this[key] + ')' : value;
3064
+ });
3065
+ // text is '["Date(---current time---)"]'
3066
+
3067
+
3068
+ JSON.parse(text, reviver)
3069
+ This method parses a JSON text to produce an object or array.
3070
+ It can throw a SyntaxError exception.
3071
+
3072
+ The optional reviver parameter is a function that can filter and
3073
+ transform the results. It receives each of the keys and values,
3074
+ and its return value is used instead of the original value.
3075
+ If it returns what it received, then the structure is not modified.
3076
+ If it returns undefined then the member is deleted.
3077
+
3078
+ Example:
3079
+
3080
+ // Parse the text. Values that look like ISO date strings will
3081
+ // be converted to Date objects.
3082
+
3083
+ myData = JSON.parse(text, function (key, value) {
3084
+ var a;
3085
+ if (typeof value === 'string') {
3086
+ a =
3087
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
3088
+ if (a) {
3089
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
3090
+ +a[5], +a[6]));
3091
+ }
3092
+ }
3093
+ return value;
3094
+ });
3095
+
3096
+ myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
3097
+ var d;
3098
+ if (typeof value === 'string' &&
3099
+ value.slice(0, 5) === 'Date(' &&
3100
+ value.slice(-1) === ')') {
3101
+ d = new Date(value.slice(5, -1));
3102
+ if (d) {
3103
+ return d;
3104
+ }
3105
+ }
3106
+ return value;
3107
+ });
3108
+
3109
+
3110
+ This is a reference implementation. You are free to copy, modify, or
3111
+ redistribute.
3112
+ */
3113
+
3114
+ /*jslint evil: true, regexp: true */
3115
+
3116
+ /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
3117
+ call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
3118
+ getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
3119
+ lastIndex, length, parse, prototype, push, replace, slice, stringify,
3120
+ test, toJSON, toString, valueOf
3121
+ */
3122
+
3123
+
3124
+ // Create a JSON object only if one does not already exist. We create the
3125
+ // methods in a closure to avoid creating global variables.
3126
+
3127
+ var JSON = module.exports;
3128
+
3129
+ (function () {
3130
+
3131
+ var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
3132
+ gap,
3133
+ indent,
3134
+ meta = { // table of character substitutions
3135
+ '\b': '\\b',
3136
+ '\t': '\\t',
3137
+ '\n': '\\n',
3138
+ '\f': '\\f',
3139
+ '\r': '\\r',
3140
+ '"' : '\\"',
3141
+ '\\': '\\\\'
3142
+ },
3143
+ rep;
3144
+
3145
+
3146
+ function quote(string) {
3147
+
3148
+ // If the string contains no control characters, no quote characters, and no
3149
+ // backslash characters, then we can safely slap some quotes around it.
3150
+ // Otherwise we must also replace the offending characters with safe escape
3151
+ // sequences.
3152
+
3153
+ escapable.lastIndex = 0;
3154
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
3155
+ var c = meta[a];
3156
+ return typeof c === 'string'
3157
+ ? c
3158
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
3159
+ }) + '"' : '"' + string + '"';
3160
+ }
3161
+
3162
+
3163
+ function str(key, holder) {
3164
+
3165
+ // Produce a string from holder[key].
3166
+
3167
+ var i, // The loop counter.
3168
+ k, // The member key.
3169
+ v, // The member value.
3170
+ length,
3171
+ mind = gap,
3172
+ partial,
3173
+ value = holder[key],
3174
+ isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));
3175
+
3176
+ // If the value has a toJSON method, call it to obtain a replacement value.
3177
+
3178
+ if (value && typeof value === 'object' &&
3179
+ typeof value.toJSON === 'function') {
3180
+ value = value.toJSON(key);
3181
+ }
3182
+
3183
+ // If we were called with a replacer function, then call the replacer to
3184
+ // obtain a replacement value.
3185
+
3186
+ if (typeof rep === 'function') {
3187
+ value = rep.call(holder, key, value);
3188
+ }
3189
+
3190
+ // What happens next depends on the value's type.
3191
+
3192
+ switch (typeof value) {
3193
+ case 'string':
3194
+ if (isBigNumber) {
3195
+ return value;
3196
+ } else {
3197
+ return quote(value);
3198
+ }
3199
+
3200
+ case 'number':
3201
+
3202
+ // JSON numbers must be finite. Encode non-finite numbers as null.
3203
+
3204
+ return isFinite(value) ? String(value) : 'null';
3205
+
3206
+ case 'boolean':
3207
+ case 'null':
3208
+ case 'bigint':
3209
+
3210
+ // If the value is a boolean or null, convert it to a string. Note:
3211
+ // typeof null does not produce 'null'. The case is included here in
3212
+ // the remote chance that this gets fixed someday.
3213
+
3214
+ return String(value);
3215
+
3216
+ // If the type is 'object', we might be dealing with an object or an array or
3217
+ // null.
3218
+
3219
+ case 'object':
3220
+
3221
+ // Due to a specification blunder in ECMAScript, typeof null is 'object',
3222
+ // so watch out for that case.
3223
+
3224
+ if (!value) {
3225
+ return 'null';
3226
+ }
3227
+
3228
+ // Make an array to hold the partial results of stringifying this object value.
3229
+
3230
+ gap += indent;
3231
+ partial = [];
3232
+
3233
+ // Is the value an array?
3234
+
3235
+ if (Object.prototype.toString.apply(value) === '[object Array]') {
3236
+
3237
+ // The value is an array. Stringify every element. Use null as a placeholder
3238
+ // for non-JSON values.
3239
+
3240
+ length = value.length;
3241
+ for (i = 0; i < length; i += 1) {
3242
+ partial[i] = str(i, value) || 'null';
3243
+ }
3244
+
3245
+ // Join all of the elements together, separated with commas, and wrap them in
3246
+ // brackets.
3247
+
3248
+ v = partial.length === 0
3249
+ ? '[]'
3250
+ : gap
3251
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
3252
+ : '[' + partial.join(',') + ']';
3253
+ gap = mind;
3254
+ return v;
3255
+ }
3256
+
3257
+ // If the replacer is an array, use it to select the members to be stringified.
3258
+
3259
+ if (rep && typeof rep === 'object') {
3260
+ length = rep.length;
3261
+ for (i = 0; i < length; i += 1) {
3262
+ if (typeof rep[i] === 'string') {
3263
+ k = rep[i];
3264
+ v = str(k, value);
3265
+ if (v) {
3266
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
3267
+ }
3268
+ }
3269
+ }
3270
+ } else {
3271
+
3272
+ // Otherwise, iterate through all of the keys in the object.
3273
+
3274
+ Object.keys(value).forEach(function(k) {
3275
+ var v = str(k, value);
3276
+ if (v) {
3277
+ partial.push(quote(k) + (gap ? ': ' : ':') + v);
3278
+ }
3279
+ });
3280
+ }
3281
+
3282
+ // Join all of the member texts together, separated with commas,
3283
+ // and wrap them in braces.
3284
+
3285
+ v = partial.length === 0
3286
+ ? '{}'
3287
+ : gap
3288
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
3289
+ : '{' + partial.join(',') + '}';
3290
+ gap = mind;
3291
+ return v;
3292
+ }
3293
+ }
3294
+
3295
+ // If the JSON object does not yet have a stringify method, give it one.
3296
+
3297
+ if (typeof JSON.stringify !== 'function') {
3298
+ JSON.stringify = function (value, replacer, space) {
3299
+
3300
+ // The stringify method takes a value and an optional replacer, and an optional
3301
+ // space parameter, and returns a JSON text. The replacer can be a function
3302
+ // that can replace values, or an array of strings that will select the keys.
3303
+ // A default replacer method can be provided. Use of the space parameter can
3304
+ // produce text that is more easily readable.
3305
+
3306
+ var i;
3307
+ gap = '';
3308
+ indent = '';
3309
+
3310
+ // If the space parameter is a number, make an indent string containing that
3311
+ // many spaces.
3312
+
3313
+ if (typeof space === 'number') {
3314
+ for (i = 0; i < space; i += 1) {
3315
+ indent += ' ';
3316
+ }
3317
+
3318
+ // If the space parameter is a string, it will be used as the indent string.
3319
+
3320
+ } else if (typeof space === 'string') {
3321
+ indent = space;
3322
+ }
3323
+
3324
+ // If there is a replacer, it must be a function or an array.
3325
+ // Otherwise, throw an error.
3326
+
3327
+ rep = replacer;
3328
+ if (replacer && typeof replacer !== 'function' &&
3329
+ (typeof replacer !== 'object' ||
3330
+ typeof replacer.length !== 'number')) {
3331
+ throw new Error('JSON.stringify');
3332
+ }
3333
+
3334
+ // Make a fake root object containing our value under the key of ''.
3335
+ // Return the result of stringifying the value.
3336
+
3337
+ return str('', {'': value});
3338
+ };
3339
+ }
3340
+ }());
3341
+ } (stringify));
3342
+
3343
+ var BigNumber = null;
3344
+
3345
+ // regexpxs extracted from
3346
+ // (c) BSD-3-Clause
3347
+ // https://github.com/fastify/secure-json-parse/graphs/contributors and https://github.com/hapijs/bourne/graphs/contributors
3348
+
3349
+ const suspectProtoRx = /(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/;
3350
+ const suspectConstructorRx = /(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/;
3351
+
3352
+ /*
3353
+ json_parse.js
3354
+ 2012-06-20
3355
+
3356
+ Public Domain.
3357
+
3358
+ NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
3359
+
3360
+ This file creates a json_parse function.
3361
+ During create you can (optionally) specify some behavioural switches
3362
+
3363
+ require('json-bigint')(options)
3364
+
3365
+ The optional options parameter holds switches that drive certain
3366
+ aspects of the parsing process:
3367
+ * options.strict = true will warn about duplicate-key usage in the json.
3368
+ The default (strict = false) will silently ignore those and overwrite
3369
+ values for keys that are in duplicate use.
3370
+
3371
+ The resulting function follows this signature:
3372
+ json_parse(text, reviver)
3373
+ This method parses a JSON text to produce an object or array.
3374
+ It can throw a SyntaxError exception.
3375
+
3376
+ The optional reviver parameter is a function that can filter and
3377
+ transform the results. It receives each of the keys and values,
3378
+ and its return value is used instead of the original value.
3379
+ If it returns what it received, then the structure is not modified.
3380
+ If it returns undefined then the member is deleted.
3381
+
3382
+ Example:
3383
+
3384
+ // Parse the text. Values that look like ISO date strings will
3385
+ // be converted to Date objects.
3386
+
3387
+ myData = json_parse(text, function (key, value) {
3388
+ var a;
3389
+ if (typeof value === 'string') {
3390
+ a =
3391
+ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
3392
+ if (a) {
3393
+ return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
3394
+ +a[5], +a[6]));
3395
+ }
3396
+ }
3397
+ return value;
3398
+ });
3399
+
3400
+ This is a reference implementation. You are free to copy, modify, or
3401
+ redistribute.
3402
+
3403
+ This code should be minified before deployment.
3404
+ See http://javascript.crockford.com/jsmin.html
3405
+
3406
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
3407
+ NOT CONTROL.
3408
+ */
3409
+
3410
+ /*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode,
3411
+ hasOwnProperty, message, n, name, prototype, push, r, t, text
3412
+ */
3413
+
3414
+ var json_parse$1 = function (options) {
3415
+
3416
+ // This is a function that can parse a JSON text, producing a JavaScript
3417
+ // data structure. It is a simple, recursive descent parser. It does not use
3418
+ // eval or regular expressions, so it can be used as a model for implementing
3419
+ // a JSON parser in other languages.
3420
+
3421
+ // We are defining the function inside of another function to avoid creating
3422
+ // global variables.
3423
+
3424
+ // Default options one can override by passing options to the parse()
3425
+ var _options = {
3426
+ strict: false, // not being strict means do not generate syntax errors for "duplicate key"
3427
+ storeAsString: false, // toggles whether the values should be stored as BigNumber (default) or a string
3428
+ alwaysParseAsBig: false, // toggles whether all numbers should be Big
3429
+ useNativeBigInt: false, // toggles whether to use native BigInt instead of bignumber.js
3430
+ protoAction: 'error',
3431
+ constructorAction: 'error',
3432
+ };
3433
+
3434
+ // If there are options, then use them to override the default _options
3435
+ if (options !== undefined && options !== null) {
3436
+ if (options.strict === true) {
3437
+ _options.strict = true;
3438
+ }
3439
+ if (options.storeAsString === true) {
3440
+ _options.storeAsString = true;
3441
+ }
3442
+ _options.alwaysParseAsBig =
3443
+ options.alwaysParseAsBig === true ? options.alwaysParseAsBig : false;
3444
+ _options.useNativeBigInt =
3445
+ options.useNativeBigInt === true ? options.useNativeBigInt : false;
3446
+
3447
+ if (typeof options.constructorAction !== 'undefined') {
3448
+ if (
3449
+ options.constructorAction === 'error' ||
3450
+ options.constructorAction === 'ignore' ||
3451
+ options.constructorAction === 'preserve'
3452
+ ) {
3453
+ _options.constructorAction = options.constructorAction;
3454
+ } else {
3455
+ throw new Error(
3456
+ `Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${options.constructorAction}`
3457
+ );
3458
+ }
3459
+ }
3460
+
3461
+ if (typeof options.protoAction !== 'undefined') {
3462
+ if (
3463
+ options.protoAction === 'error' ||
3464
+ options.protoAction === 'ignore' ||
3465
+ options.protoAction === 'preserve'
3466
+ ) {
3467
+ _options.protoAction = options.protoAction;
3468
+ } else {
3469
+ throw new Error(
3470
+ `Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${options.protoAction}`
3471
+ );
3472
+ }
3473
+ }
3474
+ }
3475
+
3476
+ var at, // The index of the current character
3477
+ ch, // The current character
3478
+ escapee = {
3479
+ '"': '"',
3480
+ '\\': '\\',
3481
+ '/': '/',
3482
+ b: '\b',
3483
+ f: '\f',
3484
+ n: '\n',
3485
+ r: '\r',
3486
+ t: '\t',
3487
+ },
3488
+ text,
3489
+ error = function (m) {
3490
+ // Call error when something is wrong.
3491
+
3492
+ throw {
3493
+ name: 'SyntaxError',
3494
+ message: m,
3495
+ at: at,
3496
+ text: text,
3497
+ };
3498
+ },
3499
+ next = function (c) {
3500
+ // If a c parameter is provided, verify that it matches the current character.
3501
+
3502
+ if (c && c !== ch) {
3503
+ error("Expected '" + c + "' instead of '" + ch + "'");
3504
+ }
3505
+
3506
+ // Get the next character. When there are no more characters,
3507
+ // return the empty string.
3508
+
3509
+ ch = text.charAt(at);
3510
+ at += 1;
3511
+ return ch;
3512
+ },
3513
+ number = function () {
3514
+ // Parse a number value.
3515
+
3516
+ var number,
3517
+ string = '';
3518
+
3519
+ if (ch === '-') {
3520
+ string = '-';
3521
+ next('-');
3522
+ }
3523
+ while (ch >= '0' && ch <= '9') {
3524
+ string += ch;
3525
+ next();
3526
+ }
3527
+ if (ch === '.') {
3528
+ string += '.';
3529
+ while (next() && ch >= '0' && ch <= '9') {
3530
+ string += ch;
3531
+ }
3532
+ }
3533
+ if (ch === 'e' || ch === 'E') {
3534
+ string += ch;
3535
+ next();
3536
+ if (ch === '-' || ch === '+') {
3537
+ string += ch;
3538
+ next();
3539
+ }
3540
+ while (ch >= '0' && ch <= '9') {
3541
+ string += ch;
3542
+ next();
3543
+ }
3544
+ }
3545
+ number = +string;
3546
+ if (!isFinite(number)) {
3547
+ error('Bad number');
3548
+ } else {
3549
+ if (BigNumber == null) BigNumber = bignumber.exports;
3550
+ //if (number > 9007199254740992 || number < -9007199254740992)
3551
+ // Bignumber has stricter check: everything with length > 15 digits disallowed
3552
+ if (string.length > 15)
3553
+ return _options.storeAsString
3554
+ ? string
3555
+ : _options.useNativeBigInt
3556
+ ? BigInt(string)
3557
+ : new BigNumber(string);
3558
+ else
3559
+ return !_options.alwaysParseAsBig
3560
+ ? number
3561
+ : _options.useNativeBigInt
3562
+ ? BigInt(number)
3563
+ : new BigNumber(number);
3564
+ }
3565
+ },
3566
+ string = function () {
3567
+ // Parse a string value.
3568
+
3569
+ var hex,
3570
+ i,
3571
+ string = '',
3572
+ uffff;
3573
+
3574
+ // When parsing for string values, we must look for " and \ characters.
3575
+
3576
+ if (ch === '"') {
3577
+ var startAt = at;
3578
+ while (next()) {
3579
+ if (ch === '"') {
3580
+ if (at - 1 > startAt) string += text.substring(startAt, at - 1);
3581
+ next();
3582
+ return string;
3583
+ }
3584
+ if (ch === '\\') {
3585
+ if (at - 1 > startAt) string += text.substring(startAt, at - 1);
3586
+ next();
3587
+ if (ch === 'u') {
3588
+ uffff = 0;
3589
+ for (i = 0; i < 4; i += 1) {
3590
+ hex = parseInt(next(), 16);
3591
+ if (!isFinite(hex)) {
3592
+ break;
3593
+ }
3594
+ uffff = uffff * 16 + hex;
3595
+ }
3596
+ string += String.fromCharCode(uffff);
3597
+ } else if (typeof escapee[ch] === 'string') {
3598
+ string += escapee[ch];
3599
+ } else {
3600
+ break;
3601
+ }
3602
+ startAt = at;
3603
+ }
3604
+ }
3605
+ }
3606
+ error('Bad string');
3607
+ },
3608
+ white = function () {
3609
+ // Skip whitespace.
3610
+
3611
+ while (ch && ch <= ' ') {
3612
+ next();
3613
+ }
3614
+ },
3615
+ word = function () {
3616
+ // true, false, or null.
3617
+
3618
+ switch (ch) {
3619
+ case 't':
3620
+ next('t');
3621
+ next('r');
3622
+ next('u');
3623
+ next('e');
3624
+ return true;
3625
+ case 'f':
3626
+ next('f');
3627
+ next('a');
3628
+ next('l');
3629
+ next('s');
3630
+ next('e');
3631
+ return false;
3632
+ case 'n':
3633
+ next('n');
3634
+ next('u');
3635
+ next('l');
3636
+ next('l');
3637
+ return null;
3638
+ }
3639
+ error("Unexpected '" + ch + "'");
3640
+ },
3641
+ value, // Place holder for the value function.
3642
+ array = function () {
3643
+ // Parse an array value.
3644
+
3645
+ var array = [];
3646
+
3647
+ if (ch === '[') {
3648
+ next('[');
3649
+ white();
3650
+ if (ch === ']') {
3651
+ next(']');
3652
+ return array; // empty array
3653
+ }
3654
+ while (ch) {
3655
+ array.push(value());
3656
+ white();
3657
+ if (ch === ']') {
3658
+ next(']');
3659
+ return array;
3660
+ }
3661
+ next(',');
3662
+ white();
3663
+ }
3664
+ }
3665
+ error('Bad array');
3666
+ },
3667
+ object = function () {
3668
+ // Parse an object value.
3669
+
3670
+ var key,
3671
+ object = Object.create(null);
3672
+
3673
+ if (ch === '{') {
3674
+ next('{');
3675
+ white();
3676
+ if (ch === '}') {
3677
+ next('}');
3678
+ return object; // empty object
3679
+ }
3680
+ while (ch) {
3681
+ key = string();
3682
+ white();
3683
+ next(':');
3684
+ if (
3685
+ _options.strict === true &&
3686
+ Object.hasOwnProperty.call(object, key)
3687
+ ) {
3688
+ error('Duplicate key "' + key + '"');
3689
+ }
3690
+
3691
+ if (suspectProtoRx.test(key) === true) {
3692
+ if (_options.protoAction === 'error') {
3693
+ error('Object contains forbidden prototype property');
3694
+ } else if (_options.protoAction === 'ignore') {
3695
+ value();
3696
+ } else {
3697
+ object[key] = value();
3698
+ }
3699
+ } else if (suspectConstructorRx.test(key) === true) {
3700
+ if (_options.constructorAction === 'error') {
3701
+ error('Object contains forbidden constructor property');
3702
+ } else if (_options.constructorAction === 'ignore') {
3703
+ value();
3704
+ } else {
3705
+ object[key] = value();
3706
+ }
3707
+ } else {
3708
+ object[key] = value();
3709
+ }
3710
+
3711
+ white();
3712
+ if (ch === '}') {
3713
+ next('}');
3714
+ return object;
3715
+ }
3716
+ next(',');
3717
+ white();
3718
+ }
3719
+ }
3720
+ error('Bad object');
3721
+ };
3722
+
3723
+ value = function () {
3724
+ // Parse a JSON value. It could be an object, an array, a string, a number,
3725
+ // or a word.
3726
+
3727
+ white();
3728
+ switch (ch) {
3729
+ case '{':
3730
+ return object();
3731
+ case '[':
3732
+ return array();
3733
+ case '"':
3734
+ return string();
3735
+ case '-':
3736
+ return number();
3737
+ default:
3738
+ return ch >= '0' && ch <= '9' ? number() : word();
3739
+ }
3740
+ };
3741
+
3742
+ // Return the json_parse function. It will have access to all of the above
3743
+ // functions and variables.
3744
+
3745
+ return function (source, reviver) {
3746
+ var result;
3747
+
3748
+ text = source + '';
3749
+ at = 0;
3750
+ ch = ' ';
3751
+ result = value();
3752
+ white();
3753
+ if (ch) {
3754
+ error('Syntax error');
3755
+ }
3756
+
3757
+ // If there is a reviver function, we recursively walk the new structure,
3758
+ // passing each name/value pair to the reviver function for possible
3759
+ // transformation, starting with a temporary root object that holds the result
3760
+ // in an empty key. If there is not a reviver function, we simply return the
3761
+ // result.
3762
+
3763
+ return typeof reviver === 'function'
3764
+ ? (function walk(holder, key) {
3765
+ var v,
3766
+ value = holder[key];
3767
+ if (value && typeof value === 'object') {
3768
+ Object.keys(value).forEach(function (k) {
3769
+ v = walk(value, k);
3770
+ if (v !== undefined) {
3771
+ value[k] = v;
3772
+ } else {
3773
+ delete value[k];
3774
+ }
3775
+ });
3776
+ }
3777
+ return reviver.call(holder, key, value);
3778
+ })({ '': result }, '')
3779
+ : result;
3780
+ };
3781
+ };
3782
+
3783
+ var parse = json_parse$1;
3784
+
3785
+ var json_stringify = stringify.exports.stringify;
3786
+ var json_parse = parse;
3787
+
3788
+ jsonBigint.exports = function(options) {
3789
+ return {
3790
+ parse: json_parse(options),
3791
+ stringify: json_stringify
3792
+ }
3793
+ };
3794
+ //create the default method members with no options applied for backwards compatibility
3795
+ jsonBigint.exports.parse = json_parse();
3796
+ jsonBigint.exports.stringify = json_stringify;
3797
+
3798
+ const JSONbig$1 = jsonBigint.exports({ useNativeBigInt: true });
35
3799
  /**
36
3800
  * Helper class to generate query strings.
37
3801
  */
@@ -61,7 +3825,7 @@
61
3825
  * @returns {string}
62
3826
  */
63
3827
  toString() {
64
- return JSON.stringify({
3828
+ return JSONbig$1.stringify({
65
3829
  method: this.method,
66
3830
  attribute: this.attribute,
67
3831
  values: this.values,
@@ -134,8 +3898,8 @@
134
3898
  * Filter resources where attribute is between start and end (inclusive).
135
3899
  *
136
3900
  * @param {string} attribute
137
- * @param {string | number} start
138
- * @param {string | number} end
3901
+ * @param {string | number | bigint} start
3902
+ * @param {string | number | bigint} end
139
3903
  * @returns {string}
140
3904
  */
141
3905
  Query.between = (attribute, start, end) => new Query("between", attribute, [start, end]).toString();
@@ -248,8 +4012,8 @@
248
4012
  * Filter resources where attribute is not between start and end (exclusive).
249
4013
  *
250
4014
  * @param {string} attribute
251
- * @param {string | number} start
252
- * @param {string | number} end
4015
+ * @param {string | number | bigint} start
4016
+ * @param {string | number | bigint} end
253
4017
  * @returns {string}
254
4018
  */
255
4019
  Query.notBetween = (attribute, start, end) => new Query("notBetween", attribute, [start, end]).toString();
@@ -319,14 +4083,14 @@
319
4083
  * @param {string[]} queries
320
4084
  * @returns {string}
321
4085
  */
322
- Query.or = (queries) => new Query("or", undefined, queries.map((query) => JSON.parse(query))).toString();
4086
+ Query.or = (queries) => new Query("or", undefined, queries.map((query) => JSONbig$1.parse(query))).toString();
323
4087
  /**
324
4088
  * Combine multiple queries using logical AND operator.
325
4089
  *
326
4090
  * @param {string[]} queries
327
4091
  * @returns {string}
328
4092
  */
329
- Query.and = (queries) => new Query("and", undefined, queries.map((query) => JSON.parse(query))).toString();
4093
+ Query.and = (queries) => new Query("and", undefined, queries.map((query) => JSONbig$1.parse(query))).toString();
330
4094
  /**
331
4095
  * Filter resources where attribute is at a specific distance from the given coordinates.
332
4096
  *
@@ -432,6 +4196,7 @@
432
4196
  */
433
4197
  Query.notTouches = (attribute, values) => new Query("notTouches", attribute, [values]).toString();
434
4198
 
4199
+ const JSONbig = jsonBigint.exports({ useNativeBigInt: true });
435
4200
  /**
436
4201
  * Exception thrown by the package
437
4202
  */
@@ -464,7 +4229,6 @@
464
4229
  this.config = {
465
4230
  endpoint: 'https://cloud.appwrite.io/v1',
466
4231
  endpointRealtime: '',
467
- selfSigned: false,
468
4232
  project: '',
469
4233
  key: '',
470
4234
  jwt: '',
@@ -472,6 +4236,8 @@
472
4236
  mode: '',
473
4237
  cookie: '',
474
4238
  platform: '',
4239
+ selfSigned: false,
4240
+ session: undefined,
475
4241
  };
476
4242
  /**
477
4243
  * Custom headers for API requests.
@@ -480,7 +4246,7 @@
480
4246
  'x-sdk-name': 'Console',
481
4247
  'x-sdk-platform': 'console',
482
4248
  'x-sdk-language': 'web',
483
- 'x-sdk-version': '2.1.0',
4249
+ 'x-sdk-version': '2.1.2',
484
4250
  'X-Appwrite-Response-Format': '1.8.0',
485
4251
  };
486
4252
  this.realtime = {
@@ -518,7 +4284,7 @@
518
4284
  }
519
4285
  this.realtime.heartbeat = window === null || window === void 0 ? void 0 : window.setInterval(() => {
520
4286
  var _a;
521
- (_a = this.realtime.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({
4287
+ (_a = this.realtime.socket) === null || _a === void 0 ? void 0 : _a.send(JSONbig.stringify({
522
4288
  type: 'ping'
523
4289
  }));
524
4290
  }, 20000);
@@ -576,18 +4342,18 @@
576
4342
  onMessage: (event) => {
577
4343
  var _a, _b;
578
4344
  try {
579
- const message = JSON.parse(event.data);
4345
+ const message = JSONbig.parse(event.data);
580
4346
  this.realtime.lastMessage = message;
581
4347
  switch (message.type) {
582
4348
  case 'connected':
583
4349
  let session = this.config.session;
584
4350
  if (!session) {
585
- const cookie = JSON.parse((_a = window.localStorage.getItem('cookieFallback')) !== null && _a !== void 0 ? _a : '{}');
4351
+ const cookie = JSONbig.parse((_a = window.localStorage.getItem('cookieFallback')) !== null && _a !== void 0 ? _a : '{}');
586
4352
  session = cookie === null || cookie === void 0 ? void 0 : cookie[`a_session_${this.config.project}`];
587
4353
  }
588
4354
  const messageData = message.data;
589
4355
  if (session && !messageData.user) {
590
- (_b = this.realtime.socket) === null || _b === void 0 ? void 0 : _b.send(JSON.stringify({
4356
+ (_b = this.realtime.socket) === null || _b === void 0 ? void 0 : _b.send(JSONbig.stringify({
591
4357
  type: 'authentication',
592
4358
  data: {
593
4359
  session
@@ -843,7 +4609,7 @@
843
4609
  else {
844
4610
  switch (headers['content-type']) {
845
4611
  case 'application/json':
846
- options.body = JSON.stringify(params);
4612
+ options.body = JSONbig.stringify(params);
847
4613
  break;
848
4614
  case 'multipart/form-data':
849
4615
  const formData = new FormData();
@@ -926,7 +4692,7 @@
926
4692
  warnings.split(';').forEach((warning) => console.warn('Warning: ' + warning));
927
4693
  }
928
4694
  if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
929
- data = yield response.json();
4695
+ data = JSONbig.parse(yield response.text());
930
4696
  }
931
4697
  else if (responseType === 'arrayBuffer') {
932
4698
  data = yield response.arrayBuffer();
@@ -939,7 +4705,7 @@
939
4705
  if (400 <= response.status) {
940
4706
  let responseText = '';
941
4707
  if (((_b = response.headers.get('content-type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) || responseType === 'arrayBuffer') {
942
- responseText = JSON.stringify(data);
4708
+ responseText = JSONbig.stringify(data);
943
4709
  }
944
4710
  else {
945
4711
  responseText = data === null || data === void 0 ? void 0 : data.message;
@@ -6935,6 +10701,54 @@
6935
10701
  };
6936
10702
  return this.client.call('post', uri, apiHeaders, payload);
6937
10703
  }
10704
+ listSuggestions(paramsOrFirst, ...rest) {
10705
+ let params;
10706
+ if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
10707
+ params = (paramsOrFirst || {});
10708
+ }
10709
+ else {
10710
+ params = {
10711
+ query: paramsOrFirst,
10712
+ tlds: rest[0],
10713
+ limit: rest[1],
10714
+ filterType: rest[2],
10715
+ priceMax: rest[3],
10716
+ priceMin: rest[4]
10717
+ };
10718
+ }
10719
+ const query = params.query;
10720
+ const tlds = params.tlds;
10721
+ const limit = params.limit;
10722
+ const filterType = params.filterType;
10723
+ const priceMax = params.priceMax;
10724
+ const priceMin = params.priceMin;
10725
+ if (typeof query === 'undefined') {
10726
+ throw new AppwriteException('Missing required parameter: "query"');
10727
+ }
10728
+ const apiPath = '/domains/suggestions';
10729
+ const payload = {};
10730
+ if (typeof query !== 'undefined') {
10731
+ payload['query'] = query;
10732
+ }
10733
+ if (typeof tlds !== 'undefined') {
10734
+ payload['tlds'] = tlds;
10735
+ }
10736
+ if (typeof limit !== 'undefined') {
10737
+ payload['limit'] = limit;
10738
+ }
10739
+ if (typeof filterType !== 'undefined') {
10740
+ payload['filterType'] = filterType;
10741
+ }
10742
+ if (typeof priceMax !== 'undefined') {
10743
+ payload['priceMax'] = priceMax;
10744
+ }
10745
+ if (typeof priceMin !== 'undefined') {
10746
+ payload['priceMin'] = priceMin;
10747
+ }
10748
+ const uri = new URL(this.client.config.endpoint + apiPath);
10749
+ const apiHeaders = {};
10750
+ return this.client.call('get', uri, apiHeaders, payload);
10751
+ }
6938
10752
  get(paramsOrFirst) {
6939
10753
  let params;
6940
10754
  if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
@@ -9735,7 +13549,7 @@
9735
13549
  * Check the Appwrite in-memory cache servers are up and connection is successful.
9736
13550
  *
9737
13551
  * @throws {AppwriteException}
9738
- * @returns {Promise<Models.HealthStatus>}
13552
+ * @returns {Promise<Models.HealthStatusList>}
9739
13553
  */
9740
13554
  getCache() {
9741
13555
  const apiPath = '/health/cache';
@@ -9768,7 +13582,7 @@
9768
13582
  * Check the Appwrite database servers are up and connection is successful.
9769
13583
  *
9770
13584
  * @throws {AppwriteException}
9771
- * @returns {Promise<Models.HealthStatus>}
13585
+ * @returns {Promise<Models.HealthStatusList>}
9772
13586
  */
9773
13587
  getDB() {
9774
13588
  const apiPath = '/health/db';
@@ -9781,7 +13595,7 @@
9781
13595
  * Check the Appwrite pub-sub servers are up and connection is successful.
9782
13596
  *
9783
13597
  * @throws {AppwriteException}
9784
- * @returns {Promise<Models.HealthStatus>}
13598
+ * @returns {Promise<Models.HealthStatusList>}
9785
13599
  */
9786
13600
  getPubSub() {
9787
13601
  const apiPath = '/health/pubsub';
@@ -9790,6 +13604,26 @@
9790
13604
  const apiHeaders = {};
9791
13605
  return this.client.call('get', uri, apiHeaders, payload);
9792
13606
  }
13607
+ getQueueAudits(paramsOrFirst) {
13608
+ let params;
13609
+ if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
13610
+ params = (paramsOrFirst || {});
13611
+ }
13612
+ else {
13613
+ params = {
13614
+ threshold: paramsOrFirst
13615
+ };
13616
+ }
13617
+ const threshold = params.threshold;
13618
+ const apiPath = '/health/queue/audits';
13619
+ const payload = {};
13620
+ if (typeof threshold !== 'undefined') {
13621
+ payload['threshold'] = threshold;
13622
+ }
13623
+ const uri = new URL(this.client.config.endpoint + apiPath);
13624
+ const apiHeaders = {};
13625
+ return this.client.call('get', uri, apiHeaders, payload);
13626
+ }
9793
13627
  getQueueBillingProjectAggregation(paramsOrFirst) {
9794
13628
  let params;
9795
13629
  if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
@@ -13909,7 +17743,7 @@
13909
17743
  }
13910
17744
  estimationCreateOrganization(paramsOrFirst, ...rest) {
13911
17745
  let params;
13912
- if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
17746
+ if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst) && 'billingPlan' in paramsOrFirst)) {
13913
17747
  params = (paramsOrFirst || {});
13914
17748
  }
13915
17749
  else {
@@ -16186,6 +20020,36 @@
16186
20020
  };
16187
20021
  return this.client.call('delete', uri, apiHeaders, payload);
16188
20022
  }
20023
+ updateLabels(paramsOrFirst, ...rest) {
20024
+ let params;
20025
+ if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
20026
+ params = (paramsOrFirst || {});
20027
+ }
20028
+ else {
20029
+ params = {
20030
+ projectId: paramsOrFirst,
20031
+ labels: rest[0]
20032
+ };
20033
+ }
20034
+ const projectId = params.projectId;
20035
+ const labels = params.labels;
20036
+ if (typeof projectId === 'undefined') {
20037
+ throw new AppwriteException('Missing required parameter: "projectId"');
20038
+ }
20039
+ if (typeof labels === 'undefined') {
20040
+ throw new AppwriteException('Missing required parameter: "labels"');
20041
+ }
20042
+ const apiPath = '/projects/{projectId}/labels'.replace('{projectId}', projectId);
20043
+ const payload = {};
20044
+ if (typeof labels !== 'undefined') {
20045
+ payload['labels'] = labels;
20046
+ }
20047
+ const uri = new URL(this.client.config.endpoint + apiPath);
20048
+ const apiHeaders = {
20049
+ 'content-type': 'application/json',
20050
+ };
20051
+ return this.client.call('put', uri, apiHeaders, payload);
20052
+ }
16189
20053
  updateOAuth2(paramsOrFirst, ...rest) {
16190
20054
  let params;
16191
20055
  if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
@@ -25444,8 +29308,6 @@
25444
29308
  OAuthProvider["Yandex"] = "yandex";
25445
29309
  OAuthProvider["Zoho"] = "zoho";
25446
29310
  OAuthProvider["Zoom"] = "zoom";
25447
- OAuthProvider["Mock"] = "mock";
25448
- OAuthProvider["Mockunverified"] = "mock-unverified";
25449
29311
  OAuthProvider["GithubImagine"] = "githubImagine";
25450
29312
  OAuthProvider["GoogleImagine"] = "googleImagine";
25451
29313
  })(exports.OAuthProvider || (exports.OAuthProvider = {}));
@@ -26169,6 +30031,12 @@
26169
30031
  IndexType["Spatial"] = "spatial";
26170
30032
  })(exports.IndexType || (exports.IndexType = {}));
26171
30033
 
30034
+ exports.FilterType = void 0;
30035
+ (function (FilterType) {
30036
+ FilterType["Premium"] = "premium";
30037
+ FilterType["Suggestion"] = "suggestion";
30038
+ })(exports.FilterType || (exports.FilterType = {}));
30039
+
26172
30040
  exports.Runtime = void 0;
26173
30041
  (function (Runtime) {
26174
30042
  Runtime["Node145"] = "node-14.5";
@@ -26280,6 +30148,7 @@
26280
30148
  Name["V1webhooks"] = "v1-webhooks";
26281
30149
  Name["V1certificates"] = "v1-certificates";
26282
30150
  Name["V1builds"] = "v1-builds";
30151
+ Name["V1screenshots"] = "v1-screenshots";
26283
30152
  Name["V1messaging"] = "v1-messaging";
26284
30153
  Name["V1migrations"] = "v1-migrations";
26285
30154
  })(exports.Name || (exports.Name = {}));
@@ -26297,6 +30166,25 @@
26297
30166
  SmtpEncryption["Tls"] = "tls";
26298
30167
  })(exports.SmtpEncryption || (exports.SmtpEncryption = {}));
26299
30168
 
30169
+ exports.BillingPlan = void 0;
30170
+ (function (BillingPlan) {
30171
+ BillingPlan["Tier0"] = "tier-0";
30172
+ BillingPlan["Tier1"] = "tier-1";
30173
+ BillingPlan["Tier2"] = "tier-2";
30174
+ BillingPlan["Imaginetier0"] = "imagine-tier-0";
30175
+ BillingPlan["Imaginetier1"] = "imagine-tier-1";
30176
+ BillingPlan["Imaginetier150"] = "imagine-tier-1-50";
30177
+ BillingPlan["Imaginetier1100"] = "imagine-tier-1-100";
30178
+ BillingPlan["Imaginetier1200"] = "imagine-tier-1-200";
30179
+ BillingPlan["Imaginetier1290"] = "imagine-tier-1-290";
30180
+ BillingPlan["Imaginetier1480"] = "imagine-tier-1-480";
30181
+ BillingPlan["Imaginetier1700"] = "imagine-tier-1-700";
30182
+ BillingPlan["Imaginetier1900"] = "imagine-tier-1-900";
30183
+ BillingPlan["Imaginetier11100"] = "imagine-tier-1-1100";
30184
+ BillingPlan["Imaginetier11650"] = "imagine-tier-1-1650";
30185
+ BillingPlan["Imaginetier12200"] = "imagine-tier-1-2200";
30186
+ })(exports.BillingPlan || (exports.BillingPlan = {}));
30187
+
26300
30188
  exports.ProjectUsageRange = void 0;
26301
30189
  (function (ProjectUsageRange) {
26302
30190
  ProjectUsageRange["OneHour"] = "1h";