@wzyjs/utils 0.3.29 → 0.3.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.esm.js CHANGED
@@ -43,13 +43,13 @@ var __export = (target, all) => {
43
43
  });
44
44
  };
45
45
 
46
- // ../../node_modules/.bun/lodash@4.18.1/node_modules/lodash/lodash.js
46
+ // ../../node_modules/lodash/lodash.js
47
47
  var require_lodash = __commonJS((exports, module) => {
48
48
  (function() {
49
49
  var undefined2;
50
- var VERSION = "4.18.1";
50
+ var VERSION = "4.17.21";
51
51
  var LARGE_ARRAY_SIZE = 200;
52
- var CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill.", FUNC_ERROR_TEXT = "Expected a function", INVALID_TEMPL_VAR_ERROR_TEXT = "Invalid `variable` option passed into `_.template`", INVALID_TEMPL_IMPORTS_ERROR_TEXT = "Invalid `imports` option passed into `_.template`";
52
+ var CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill.", FUNC_ERROR_TEXT = "Expected a function", INVALID_TEMPL_VAR_ERROR_TEXT = "Invalid `variable` option passed into `_.template`";
53
53
  var HASH_UNDEFINED = "__lodash_hash_undefined__";
54
54
  var MAX_MEMOIZE_SIZE = 500;
55
55
  var PLACEHOLDER = "__lodash_placeholder__";
@@ -1924,21 +1924,8 @@ var require_lodash = __commonJS((exports, module) => {
1924
1924
  }
1925
1925
  function baseUnset(object, path) {
1926
1926
  path = castPath(path, object);
1927
- var index = -1, length = path.length;
1928
- if (!length) {
1929
- return true;
1930
- }
1931
- while (++index < length) {
1932
- var key = toKey(path[index]);
1933
- if (key === "__proto__" && !hasOwnProperty.call(object, "__proto__")) {
1934
- return false;
1935
- }
1936
- if ((key === "constructor" || key === "prototype") && index < length - 1) {
1937
- return false;
1938
- }
1939
- }
1940
- var obj = parent(object, path);
1941
- return obj == null || delete obj[toKey(last(path))];
1927
+ object = parent(object, path);
1928
+ return object == null || delete object[toKey(last(path))];
1942
1929
  }
1943
1930
  function baseUpdate(object, path, updater, customizer) {
1944
1931
  return baseSet(object, path, updater(baseGet(object, path)), customizer);
@@ -3241,7 +3228,7 @@ var require_lodash = __commonJS((exports, module) => {
3241
3228
  var index = -1, length = pairs == null ? 0 : pairs.length, result2 = {};
3242
3229
  while (++index < length) {
3243
3230
  var pair = pairs[index];
3244
- baseAssignValue(result2, pair[0], pair[1]);
3231
+ result2[pair[0]] = pair[1];
3245
3232
  }
3246
3233
  return result2;
3247
3234
  }
@@ -4078,7 +4065,7 @@ var require_lodash = __commonJS((exports, module) => {
4078
4065
  var tag = baseGetTag(value);
4079
4066
  return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
4080
4067
  }
4081
- function isFinite2(value) {
4068
+ function isFinite(value) {
4082
4069
  return typeof value == "number" && nativeIsFinite(value);
4083
4070
  }
4084
4071
  function isFunction(value) {
@@ -4109,7 +4096,7 @@ var require_lodash = __commonJS((exports, module) => {
4109
4096
  customizer = typeof customizer == "function" ? customizer : undefined2;
4110
4097
  return baseIsMatch(object, source, getMatchData(source), customizer);
4111
4098
  }
4112
- function isNaN2(value) {
4099
+ function isNaN(value) {
4113
4100
  return isNumber(value) && value != +value;
4114
4101
  }
4115
4102
  function isNative(value) {
@@ -4625,13 +4612,8 @@ var require_lodash = __commonJS((exports, module) => {
4625
4612
  options = undefined2;
4626
4613
  }
4627
4614
  string = toString(string);
4628
- options = assignWith({}, options, settings, customDefaultsAssignIn);
4629
- var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
4630
- arrayEach(importsKeys, function(key) {
4631
- if (reForbiddenIdentifierChars.test(key)) {
4632
- throw new Error2(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
4633
- }
4634
- });
4615
+ options = assignInWith({}, options, settings, customDefaultsAssignIn);
4616
+ var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
4635
4617
  var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '";
4636
4618
  var reDelimiters = RegExp2((options.escape || reNoMatch).source + "|" + interpolate.source + "|" + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + "|" + (options.evaluate || reNoMatch).source + "|$", "g");
4637
4619
  var sourceURL = "//# sourceURL=" + (hasOwnProperty.call(options, "sourceURL") ? (options.sourceURL + "").replace(/\s/g, " ") : "lodash.templateSources[" + ++templateCounter + "]") + `
@@ -4773,7 +4755,7 @@ __p += '`;
4773
4755
  }
4774
4756
  return result2 + omission;
4775
4757
  }
4776
- function unescape2(string) {
4758
+ function unescape(string) {
4777
4759
  string = toString(string);
4778
4760
  return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
4779
4761
  }
@@ -5197,14 +5179,14 @@ __p += '`;
5197
5179
  lodash.isEqual = isEqual;
5198
5180
  lodash.isEqualWith = isEqualWith;
5199
5181
  lodash.isError = isError;
5200
- lodash.isFinite = isFinite2;
5182
+ lodash.isFinite = isFinite;
5201
5183
  lodash.isFunction = isFunction;
5202
5184
  lodash.isInteger = isInteger;
5203
5185
  lodash.isLength = isLength;
5204
5186
  lodash.isMap = isMap;
5205
5187
  lodash.isMatch = isMatch;
5206
5188
  lodash.isMatchWith = isMatchWith;
5207
- lodash.isNaN = isNaN2;
5189
+ lodash.isNaN = isNaN;
5208
5190
  lodash.isNative = isNative;
5209
5191
  lodash.isNil = isNil;
5210
5192
  lodash.isNull = isNull;
@@ -5286,7 +5268,7 @@ __p += '`;
5286
5268
  lodash.trimEnd = trimEnd;
5287
5269
  lodash.trimStart = trimStart;
5288
5270
  lodash.truncate = truncate;
5289
- lodash.unescape = unescape2;
5271
+ lodash.unescape = unescape;
5290
5272
  lodash.uniqueId = uniqueId;
5291
5273
  lodash.upperCase = upperCase;
5292
5274
  lodash.upperFirst = upperFirst;
@@ -5477,7 +5459,7 @@ __p += '`;
5477
5459
  }).call(exports);
5478
5460
  });
5479
5461
 
5480
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
5462
+ // ../../node_modules/zod/v3/external.js
5481
5463
  var exports_external = {};
5482
5464
  __export(exports_external, {
5483
5465
  void: () => voidType,
@@ -5589,7 +5571,7 @@ __export(exports_external, {
5589
5571
  BRAND: () => BRAND
5590
5572
  });
5591
5573
 
5592
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
5574
+ // ../../node_modules/zod/v3/helpers/util.js
5593
5575
  var util;
5594
5576
  (function(util2) {
5595
5577
  util2.assertEqual = (_) => {};
@@ -5720,7 +5702,7 @@ var getParsedType = (data) => {
5720
5702
  }
5721
5703
  };
5722
5704
 
5723
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
5705
+ // ../../node_modules/zod/v3/ZodError.js
5724
5706
  var ZodIssueCode = util.arrayToEnum([
5725
5707
  "invalid_type",
5726
5708
  "invalid_literal",
@@ -5839,7 +5821,7 @@ ZodError.create = (issues) => {
5839
5821
  return error;
5840
5822
  };
5841
5823
 
5842
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
5824
+ // ../../node_modules/zod/v3/locales/en.js
5843
5825
  var errorMap = (issue, _ctx) => {
5844
5826
  let message;
5845
5827
  switch (issue.code) {
@@ -5942,7 +5924,7 @@ var errorMap = (issue, _ctx) => {
5942
5924
  };
5943
5925
  var en_default = errorMap;
5944
5926
 
5945
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
5927
+ // ../../node_modules/zod/v3/errors.js
5946
5928
  var overrideErrorMap = en_default;
5947
5929
  function setErrorMap(map) {
5948
5930
  overrideErrorMap = map;
@@ -5950,7 +5932,7 @@ function setErrorMap(map) {
5950
5932
  function getErrorMap() {
5951
5933
  return overrideErrorMap;
5952
5934
  }
5953
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
5935
+ // ../../node_modules/zod/v3/helpers/parseUtil.js
5954
5936
  var makeIssue = (params) => {
5955
5937
  const { data, path, errorMaps, issueData } = params;
5956
5938
  const fullPath = [...path, ...issueData.path || []];
@@ -6056,14 +6038,14 @@ var isAborted = (x) => x.status === "aborted";
6056
6038
  var isDirty = (x) => x.status === "dirty";
6057
6039
  var isValid = (x) => x.status === "valid";
6058
6040
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
6059
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
6041
+ // ../../node_modules/zod/v3/helpers/errorUtil.js
6060
6042
  var errorUtil;
6061
6043
  (function(errorUtil2) {
6062
6044
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6063
6045
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
6064
6046
  })(errorUtil || (errorUtil = {}));
6065
6047
 
6066
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
6048
+ // ../../node_modules/zod/v3/types.js
6067
6049
  class ParseInputLazyPath {
6068
6050
  constructor(parent, value, path, key) {
6069
6051
  this._cachedPath = [];
@@ -10243,16 +10225,6 @@ var getStrLength = (value) => {
10243
10225
  const chineseLength = getChineseByStr(value).length;
10244
10226
  return value.length - chineseLength + chineseLength * 2;
10245
10227
  };
10246
- var replaceAll = (str, searchValue, replaceValue) => {
10247
- if (!str || !searchValue || !replaceValue) {
10248
- return str || "";
10249
- }
10250
- str = str.replace(searchValue, replaceValue);
10251
- if (!str.includes(searchValue)) {
10252
- return str;
10253
- }
10254
- return replaceAll(str, searchValue, replaceValue);
10255
- };
10256
10228
  var replaceByRules = (str, rules) => {
10257
10229
  rules.forEach(([searchValue, replaceValue]) => {
10258
10230
  str = str.replaceAll(searchValue, replaceValue);
@@ -10271,67 +10243,46 @@ var replaceByVariables = (prompt, variables) => {
10271
10243
  var getType = (value) => {
10272
10244
  return Object.prototype.toString.call(value).slice(8, -1);
10273
10245
  };
10274
- var amount = (str) => {
10275
- const reg = /(?=(?!\b)(\d{3})+$)/g;
10276
- return str.replace(reg, ",");
10277
- };
10278
- var jsonParse = (value) => {
10279
- if (typeof value === "object") {
10280
- return value;
10246
+ var safeJsonParse = (value, fallback) => {
10247
+ if (typeof value !== "string") {
10248
+ return value ?? fallback;
10281
10249
  }
10282
10250
  try {
10283
10251
  return JSON.parse(value);
10284
- } catch (err) {
10285
- return {};
10252
+ } catch {
10253
+ return fallback;
10286
10254
  }
10287
10255
  };
10288
- var isJson = (str) => {
10256
+ var isJsonObject = (str) => {
10289
10257
  try {
10290
- if (getType(JSON.parse(str)) === "Object") {
10291
- return true;
10292
- }
10293
- } catch (e) {}
10294
- return false;
10295
- };
10296
- var toString = (value) => {
10297
- return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
10258
+ const val = JSON.parse(str);
10259
+ return typeof val === "object" && val !== null && !Array.isArray(val);
10260
+ } catch {
10261
+ return false;
10262
+ }
10298
10263
  };
10299
10264
  var getRandomColor = () => {
10300
- const color = Math.floor(Math.random() * 16777215).toString(16);
10301
- if (color.length === 6) {
10302
- return color;
10303
- } else {
10304
- return getRandomColor();
10305
- }
10265
+ const rand = () => Math.floor(Math.random() * 156 + 50);
10266
+ return `rgb(${rand()},${rand()},${rand()})`;
10306
10267
  };
10307
- var getRandomString = (length = 4) => {
10308
- return Math.random().toString(36).substr(2, length);
10268
+ var hexToRgba = (hexColor, a = 1) => {
10269
+ let red = parseInt(hexColor.substr(1, 2), 16);
10270
+ let green = parseInt(hexColor.substr(3, 2), 16);
10271
+ let blue = parseInt(hexColor.substr(5, 2), 16);
10272
+ return {
10273
+ nums: { red, green, blue },
10274
+ text: `rgba(${red}, ${green}, ${blue}, ${a})`
10275
+ };
10309
10276
  };
10310
- var getChinese = (str) => {
10311
- if (str == null || str === "") {
10312
- return "";
10313
- }
10314
- const res = str.match(/[\u4e00-\u9fa5]/g);
10315
- if (!res) {
10316
- return "";
10317
- }
10318
- return res.join("");
10277
+ var getRandomString = (length = 4) => {
10278
+ return Math.random().toString(36).substring(2, 2 + length);
10319
10279
  };
10320
10280
  var getSliceStr = (str, before, after) => {
10321
- return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
10322
- };
10323
- var getProxyUrl = (url2) => {
10324
- const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
10325
- return beforeUrl + url2;
10326
- };
10327
- var getLength = (value) => {
10328
- const chineseLength = getChinese(value).length;
10329
- return value.length - chineseLength + chineseLength * 2;
10330
- };
10331
- var getCookie = (name) => {
10332
- const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
10333
- const arr = document.cookie.match(reg);
10334
- return arr ? unescape(arr[2]) : null;
10281
+ const start = str.indexOf(before);
10282
+ const end = str.indexOf(after, start + before.length);
10283
+ if (start === -1 || end === -1)
10284
+ return "";
10285
+ return str.slice(start + before.length, end);
10335
10286
  };
10336
10287
  var generateAlphabetArray = (n) => {
10337
10288
  return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
@@ -10355,2400 +10306,8 @@ var levenshteinDistance = (a, b) => {
10355
10306
  }
10356
10307
  return matrix[b.length][a.length];
10357
10308
  };
10358
- var generateUniqueFileName = (name) => {
10359
- const match = name.match(/^(.*?)(\.[^.]*$|$)/);
10360
- if (match) {
10361
- const namePart = match[1];
10362
- const extensionPart = match[2];
10363
- if (extensionPart) {
10364
- return `${namePart}_${Date.now()}${extensionPart}`;
10365
- } else {
10366
- return `${namePart}_${Date.now()}.dat`;
10367
- }
10368
- }
10369
- throw new Error("Invalid filename format.");
10370
- };
10371
-
10372
- // ../../node_modules/.bun/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
10373
- /*!
10374
- * decimal.js v10.6.0
10375
- * An arbitrary-precision Decimal type for JavaScript.
10376
- * https://github.com/MikeMcl/decimal.js
10377
- * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
10378
- * MIT Licence
10379
- */
10380
- var EXP_LIMIT = 9000000000000000;
10381
- var MAX_DIGITS = 1e9;
10382
- var NUMERALS = "0123456789abcdef";
10383
- var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
10384
- var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
10385
- var DEFAULTS = {
10386
- precision: 20,
10387
- rounding: 4,
10388
- modulo: 1,
10389
- toExpNeg: -7,
10390
- toExpPos: 21,
10391
- minE: -EXP_LIMIT,
10392
- maxE: EXP_LIMIT,
10393
- crypto: false
10394
- };
10395
- var inexact;
10396
- var quadrant;
10397
- var external2 = true;
10398
- var decimalError = "[DecimalError] ";
10399
- var invalidArgument = decimalError + "Invalid argument: ";
10400
- var precisionLimitExceeded = decimalError + "Precision limit exceeded";
10401
- var cryptoUnavailable = decimalError + "crypto unavailable";
10402
- var tag = "[object Decimal]";
10403
- var mathfloor = Math.floor;
10404
- var mathpow = Math.pow;
10405
- var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
10406
- var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
10407
- var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
10408
- var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
10409
- var BASE = 1e7;
10410
- var LOG_BASE = 7;
10411
- var MAX_SAFE_INTEGER = 9007199254740991;
10412
- var LN10_PRECISION = LN10.length - 1;
10413
- var PI_PRECISION = PI.length - 1;
10414
- var P = { toStringTag: tag };
10415
- P.absoluteValue = P.abs = function() {
10416
- var x = new this.constructor(this);
10417
- if (x.s < 0)
10418
- x.s = 1;
10419
- return finalise(x);
10420
- };
10421
- P.ceil = function() {
10422
- return finalise(new this.constructor(this), this.e + 1, 2);
10423
- };
10424
- P.clampedTo = P.clamp = function(min, max) {
10425
- var k, x = this, Ctor = x.constructor;
10426
- min = new Ctor(min);
10427
- max = new Ctor(max);
10428
- if (!min.s || !max.s)
10429
- return new Ctor(NaN);
10430
- if (min.gt(max))
10431
- throw Error(invalidArgument + max);
10432
- k = x.cmp(min);
10433
- return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
10434
- };
10435
- P.comparedTo = P.cmp = function(y) {
10436
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
10437
- if (!xd || !yd) {
10438
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
10439
- }
10440
- if (!xd[0] || !yd[0])
10441
- return xd[0] ? xs : yd[0] ? -ys : 0;
10442
- if (xs !== ys)
10443
- return xs;
10444
- if (x.e !== y.e)
10445
- return x.e > y.e ^ xs < 0 ? 1 : -1;
10446
- xdL = xd.length;
10447
- ydL = yd.length;
10448
- for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
10449
- if (xd[i] !== yd[i])
10450
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
10451
- }
10452
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
10453
- };
10454
- P.cosine = P.cos = function() {
10455
- var pr, rm, x = this, Ctor = x.constructor;
10456
- if (!x.d)
10457
- return new Ctor(NaN);
10458
- if (!x.d[0])
10459
- return new Ctor(1);
10460
- pr = Ctor.precision;
10461
- rm = Ctor.rounding;
10462
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
10463
- Ctor.rounding = 1;
10464
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
10465
- Ctor.precision = pr;
10466
- Ctor.rounding = rm;
10467
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
10468
- };
10469
- P.cubeRoot = P.cbrt = function() {
10470
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
10471
- if (!x.isFinite() || x.isZero())
10472
- return new Ctor(x);
10473
- external2 = false;
10474
- s = x.s * mathpow(x.s * x, 1 / 3);
10475
- if (!s || Math.abs(s) == 1 / 0) {
10476
- n = digitsToString(x.d);
10477
- e = x.e;
10478
- if (s = (e - n.length + 1) % 3)
10479
- n += s == 1 || s == -2 ? "0" : "00";
10480
- s = mathpow(n, 1 / 3);
10481
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
10482
- if (s == 1 / 0) {
10483
- n = "5e" + e;
10484
- } else {
10485
- n = s.toExponential();
10486
- n = n.slice(0, n.indexOf("e") + 1) + e;
10487
- }
10488
- r = new Ctor(n);
10489
- r.s = x.s;
10490
- } else {
10491
- r = new Ctor(s.toString());
10492
- }
10493
- sd = (e = Ctor.precision) + 3;
10494
- for (;; ) {
10495
- t = r;
10496
- t3 = t.times(t).times(t);
10497
- t3plusx = t3.plus(x);
10498
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
10499
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
10500
- n = n.slice(sd - 3, sd + 1);
10501
- if (n == "9999" || !rep && n == "4999") {
10502
- if (!rep) {
10503
- finalise(t, e + 1, 0);
10504
- if (t.times(t).times(t).eq(x)) {
10505
- r = t;
10506
- break;
10507
- }
10508
- }
10509
- sd += 4;
10510
- rep = 1;
10511
- } else {
10512
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
10513
- finalise(r, e + 1, 1);
10514
- m = !r.times(r).times(r).eq(x);
10515
- }
10516
- break;
10517
- }
10518
- }
10519
- }
10520
- external2 = true;
10521
- return finalise(r, e, Ctor.rounding, m);
10522
- };
10523
- P.decimalPlaces = P.dp = function() {
10524
- var w, d = this.d, n = NaN;
10525
- if (d) {
10526
- w = d.length - 1;
10527
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
10528
- w = d[w];
10529
- if (w)
10530
- for (;w % 10 == 0; w /= 10)
10531
- n--;
10532
- if (n < 0)
10533
- n = 0;
10534
- }
10535
- return n;
10536
- };
10537
- P.dividedBy = P.div = function(y) {
10538
- return divide(this, new this.constructor(y));
10539
- };
10540
- P.dividedToIntegerBy = P.divToInt = function(y) {
10541
- var x = this, Ctor = x.constructor;
10542
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
10543
- };
10544
- P.equals = P.eq = function(y) {
10545
- return this.cmp(y) === 0;
10546
- };
10547
- P.floor = function() {
10548
- return finalise(new this.constructor(this), this.e + 1, 3);
10549
- };
10550
- P.greaterThan = P.gt = function(y) {
10551
- return this.cmp(y) > 0;
10552
- };
10553
- P.greaterThanOrEqualTo = P.gte = function(y) {
10554
- var k = this.cmp(y);
10555
- return k == 1 || k === 0;
10556
- };
10557
- P.hyperbolicCosine = P.cosh = function() {
10558
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
10559
- if (!x.isFinite())
10560
- return new Ctor(x.s ? 1 / 0 : NaN);
10561
- if (x.isZero())
10562
- return one;
10563
- pr = Ctor.precision;
10564
- rm = Ctor.rounding;
10565
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
10566
- Ctor.rounding = 1;
10567
- len = x.d.length;
10568
- if (len < 32) {
10569
- k = Math.ceil(len / 3);
10570
- n = (1 / tinyPow(4, k)).toString();
10571
- } else {
10572
- k = 16;
10573
- n = "2.3283064365386962890625e-10";
10574
- }
10575
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
10576
- var cosh2_x, i = k, d8 = new Ctor(8);
10577
- for (;i--; ) {
10578
- cosh2_x = x.times(x);
10579
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
10580
- }
10581
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
10582
- };
10583
- P.hyperbolicSine = P.sinh = function() {
10584
- var k, pr, rm, len, x = this, Ctor = x.constructor;
10585
- if (!x.isFinite() || x.isZero())
10586
- return new Ctor(x);
10587
- pr = Ctor.precision;
10588
- rm = Ctor.rounding;
10589
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
10590
- Ctor.rounding = 1;
10591
- len = x.d.length;
10592
- if (len < 3) {
10593
- x = taylorSeries(Ctor, 2, x, x, true);
10594
- } else {
10595
- k = 1.4 * Math.sqrt(len);
10596
- k = k > 16 ? 16 : k | 0;
10597
- x = x.times(1 / tinyPow(5, k));
10598
- x = taylorSeries(Ctor, 2, x, x, true);
10599
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
10600
- for (;k--; ) {
10601
- sinh2_x = x.times(x);
10602
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
10603
- }
10604
- }
10605
- Ctor.precision = pr;
10606
- Ctor.rounding = rm;
10607
- return finalise(x, pr, rm, true);
10608
- };
10609
- P.hyperbolicTangent = P.tanh = function() {
10610
- var pr, rm, x = this, Ctor = x.constructor;
10611
- if (!x.isFinite())
10612
- return new Ctor(x.s);
10613
- if (x.isZero())
10614
- return new Ctor(x);
10615
- pr = Ctor.precision;
10616
- rm = Ctor.rounding;
10617
- Ctor.precision = pr + 7;
10618
- Ctor.rounding = 1;
10619
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
10620
- };
10621
- P.inverseCosine = P.acos = function() {
10622
- var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
10623
- if (k !== -1) {
10624
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
10625
- }
10626
- if (x.isZero())
10627
- return getPi(Ctor, pr + 4, rm).times(0.5);
10628
- Ctor.precision = pr + 6;
10629
- Ctor.rounding = 1;
10630
- x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
10631
- Ctor.precision = pr;
10632
- Ctor.rounding = rm;
10633
- return x.times(2);
10634
- };
10635
- P.inverseHyperbolicCosine = P.acosh = function() {
10636
- var pr, rm, x = this, Ctor = x.constructor;
10637
- if (x.lte(1))
10638
- return new Ctor(x.eq(1) ? 0 : NaN);
10639
- if (!x.isFinite())
10640
- return new Ctor(x);
10641
- pr = Ctor.precision;
10642
- rm = Ctor.rounding;
10643
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
10644
- Ctor.rounding = 1;
10645
- external2 = false;
10646
- x = x.times(x).minus(1).sqrt().plus(x);
10647
- external2 = true;
10648
- Ctor.precision = pr;
10649
- Ctor.rounding = rm;
10650
- return x.ln();
10651
- };
10652
- P.inverseHyperbolicSine = P.asinh = function() {
10653
- var pr, rm, x = this, Ctor = x.constructor;
10654
- if (!x.isFinite() || x.isZero())
10655
- return new Ctor(x);
10656
- pr = Ctor.precision;
10657
- rm = Ctor.rounding;
10658
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
10659
- Ctor.rounding = 1;
10660
- external2 = false;
10661
- x = x.times(x).plus(1).sqrt().plus(x);
10662
- external2 = true;
10663
- Ctor.precision = pr;
10664
- Ctor.rounding = rm;
10665
- return x.ln();
10666
- };
10667
- P.inverseHyperbolicTangent = P.atanh = function() {
10668
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
10669
- if (!x.isFinite())
10670
- return new Ctor(NaN);
10671
- if (x.e >= 0)
10672
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
10673
- pr = Ctor.precision;
10674
- rm = Ctor.rounding;
10675
- xsd = x.sd();
10676
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
10677
- return finalise(new Ctor(x), pr, rm, true);
10678
- Ctor.precision = wpr = xsd - x.e;
10679
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
10680
- Ctor.precision = pr + 4;
10681
- Ctor.rounding = 1;
10682
- x = x.ln();
10683
- Ctor.precision = pr;
10684
- Ctor.rounding = rm;
10685
- return x.times(0.5);
10686
- };
10687
- P.inverseSine = P.asin = function() {
10688
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
10689
- if (x.isZero())
10690
- return new Ctor(x);
10691
- k = x.abs().cmp(1);
10692
- pr = Ctor.precision;
10693
- rm = Ctor.rounding;
10694
- if (k !== -1) {
10695
- if (k === 0) {
10696
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
10697
- halfPi.s = x.s;
10698
- return halfPi;
10699
- }
10700
- return new Ctor(NaN);
10701
- }
10702
- Ctor.precision = pr + 6;
10703
- Ctor.rounding = 1;
10704
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
10705
- Ctor.precision = pr;
10706
- Ctor.rounding = rm;
10707
- return x.times(2);
10708
- };
10709
- P.inverseTangent = P.atan = function() {
10710
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
10711
- if (!x.isFinite()) {
10712
- if (!x.s)
10713
- return new Ctor(NaN);
10714
- if (pr + 4 <= PI_PRECISION) {
10715
- r = getPi(Ctor, pr + 4, rm).times(0.5);
10716
- r.s = x.s;
10717
- return r;
10718
- }
10719
- } else if (x.isZero()) {
10720
- return new Ctor(x);
10721
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
10722
- r = getPi(Ctor, pr + 4, rm).times(0.25);
10723
- r.s = x.s;
10724
- return r;
10725
- }
10726
- Ctor.precision = wpr = pr + 10;
10727
- Ctor.rounding = 1;
10728
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
10729
- for (i = k;i; --i)
10730
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
10731
- external2 = false;
10732
- j = Math.ceil(wpr / LOG_BASE);
10733
- n = 1;
10734
- x2 = x.times(x);
10735
- r = new Ctor(x);
10736
- px = x;
10737
- for (;i !== -1; ) {
10738
- px = px.times(x2);
10739
- t = r.minus(px.div(n += 2));
10740
- px = px.times(x2);
10741
- r = t.plus(px.div(n += 2));
10742
- if (r.d[j] !== undefined)
10743
- for (i = j;r.d[i] === t.d[i] && i--; )
10744
- ;
10745
- }
10746
- if (k)
10747
- r = r.times(2 << k - 1);
10748
- external2 = true;
10749
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
10750
- };
10751
- P.isFinite = function() {
10752
- return !!this.d;
10753
- };
10754
- P.isInteger = P.isInt = function() {
10755
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
10756
- };
10757
- P.isNaN = function() {
10758
- return !this.s;
10759
- };
10760
- P.isNegative = P.isNeg = function() {
10761
- return this.s < 0;
10762
- };
10763
- P.isPositive = P.isPos = function() {
10764
- return this.s > 0;
10765
- };
10766
- P.isZero = function() {
10767
- return !!this.d && this.d[0] === 0;
10768
- };
10769
- P.lessThan = P.lt = function(y) {
10770
- return this.cmp(y) < 0;
10771
- };
10772
- P.lessThanOrEqualTo = P.lte = function(y) {
10773
- return this.cmp(y) < 1;
10774
- };
10775
- P.logarithm = P.log = function(base) {
10776
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
10777
- if (base == null) {
10778
- base = new Ctor(10);
10779
- isBase10 = true;
10780
- } else {
10781
- base = new Ctor(base);
10782
- d = base.d;
10783
- if (base.s < 0 || !d || !d[0] || base.eq(1))
10784
- return new Ctor(NaN);
10785
- isBase10 = base.eq(10);
10786
- }
10787
- d = arg.d;
10788
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
10789
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
10790
- }
10791
- if (isBase10) {
10792
- if (d.length > 1) {
10793
- inf = true;
10794
- } else {
10795
- for (k = d[0];k % 10 === 0; )
10796
- k /= 10;
10797
- inf = k !== 1;
10798
- }
10799
- }
10800
- external2 = false;
10801
- sd = pr + guard;
10802
- num = naturalLogarithm(arg, sd);
10803
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10804
- r = divide(num, denominator, sd, 1);
10805
- if (checkRoundingDigits(r.d, k = pr, rm)) {
10806
- do {
10807
- sd += 10;
10808
- num = naturalLogarithm(arg, sd);
10809
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10810
- r = divide(num, denominator, sd, 1);
10811
- if (!inf) {
10812
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
10813
- r = finalise(r, pr + 1, 0);
10814
- }
10815
- break;
10816
- }
10817
- } while (checkRoundingDigits(r.d, k += 10, rm));
10818
- }
10819
- external2 = true;
10820
- return finalise(r, pr, rm);
10821
- };
10822
- P.minus = P.sub = function(y) {
10823
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
10824
- y = new Ctor(y);
10825
- if (!x.d || !y.d) {
10826
- if (!x.s || !y.s)
10827
- y = new Ctor(NaN);
10828
- else if (x.d)
10829
- y.s = -y.s;
10830
- else
10831
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
10832
- return y;
10833
- }
10834
- if (x.s != y.s) {
10835
- y.s = -y.s;
10836
- return x.plus(y);
10837
- }
10838
- xd = x.d;
10839
- yd = y.d;
10840
- pr = Ctor.precision;
10841
- rm = Ctor.rounding;
10842
- if (!xd[0] || !yd[0]) {
10843
- if (yd[0])
10844
- y.s = -y.s;
10845
- else if (xd[0])
10846
- y = new Ctor(x);
10847
- else
10848
- return new Ctor(rm === 3 ? -0 : 0);
10849
- return external2 ? finalise(y, pr, rm) : y;
10850
- }
10851
- e = mathfloor(y.e / LOG_BASE);
10852
- xe = mathfloor(x.e / LOG_BASE);
10853
- xd = xd.slice();
10854
- k = xe - e;
10855
- if (k) {
10856
- xLTy = k < 0;
10857
- if (xLTy) {
10858
- d = xd;
10859
- k = -k;
10860
- len = yd.length;
10861
- } else {
10862
- d = yd;
10863
- e = xe;
10864
- len = xd.length;
10865
- }
10866
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
10867
- if (k > i) {
10868
- k = i;
10869
- d.length = 1;
10870
- }
10871
- d.reverse();
10872
- for (i = k;i--; )
10873
- d.push(0);
10874
- d.reverse();
10875
- } else {
10876
- i = xd.length;
10877
- len = yd.length;
10878
- xLTy = i < len;
10879
- if (xLTy)
10880
- len = i;
10881
- for (i = 0;i < len; i++) {
10882
- if (xd[i] != yd[i]) {
10883
- xLTy = xd[i] < yd[i];
10884
- break;
10885
- }
10886
- }
10887
- k = 0;
10888
- }
10889
- if (xLTy) {
10890
- d = xd;
10891
- xd = yd;
10892
- yd = d;
10893
- y.s = -y.s;
10894
- }
10895
- len = xd.length;
10896
- for (i = yd.length - len;i > 0; --i)
10897
- xd[len++] = 0;
10898
- for (i = yd.length;i > k; ) {
10899
- if (xd[--i] < yd[i]) {
10900
- for (j = i;j && xd[--j] === 0; )
10901
- xd[j] = BASE - 1;
10902
- --xd[j];
10903
- xd[i] += BASE;
10904
- }
10905
- xd[i] -= yd[i];
10906
- }
10907
- for (;xd[--len] === 0; )
10908
- xd.pop();
10909
- for (;xd[0] === 0; xd.shift())
10910
- --e;
10911
- if (!xd[0])
10912
- return new Ctor(rm === 3 ? -0 : 0);
10913
- y.d = xd;
10914
- y.e = getBase10Exponent(xd, e);
10915
- return external2 ? finalise(y, pr, rm) : y;
10916
- };
10917
- P.modulo = P.mod = function(y) {
10918
- var q, x = this, Ctor = x.constructor;
10919
- y = new Ctor(y);
10920
- if (!x.d || !y.s || y.d && !y.d[0])
10921
- return new Ctor(NaN);
10922
- if (!y.d || x.d && !x.d[0]) {
10923
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
10924
- }
10925
- external2 = false;
10926
- if (Ctor.modulo == 9) {
10927
- q = divide(x, y.abs(), 0, 3, 1);
10928
- q.s *= y.s;
10929
- } else {
10930
- q = divide(x, y, 0, Ctor.modulo, 1);
10931
- }
10932
- q = q.times(y);
10933
- external2 = true;
10934
- return x.minus(q);
10935
- };
10936
- P.naturalExponential = P.exp = function() {
10937
- return naturalExponential(this);
10938
- };
10939
- P.naturalLogarithm = P.ln = function() {
10940
- return naturalLogarithm(this);
10941
- };
10942
- P.negated = P.neg = function() {
10943
- var x = new this.constructor(this);
10944
- x.s = -x.s;
10945
- return finalise(x);
10946
- };
10947
- P.plus = P.add = function(y) {
10948
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
10949
- y = new Ctor(y);
10950
- if (!x.d || !y.d) {
10951
- if (!x.s || !y.s)
10952
- y = new Ctor(NaN);
10953
- else if (!x.d)
10954
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
10955
- return y;
10956
- }
10957
- if (x.s != y.s) {
10958
- y.s = -y.s;
10959
- return x.minus(y);
10960
- }
10961
- xd = x.d;
10962
- yd = y.d;
10963
- pr = Ctor.precision;
10964
- rm = Ctor.rounding;
10965
- if (!xd[0] || !yd[0]) {
10966
- if (!yd[0])
10967
- y = new Ctor(x);
10968
- return external2 ? finalise(y, pr, rm) : y;
10969
- }
10970
- k = mathfloor(x.e / LOG_BASE);
10971
- e = mathfloor(y.e / LOG_BASE);
10972
- xd = xd.slice();
10973
- i = k - e;
10974
- if (i) {
10975
- if (i < 0) {
10976
- d = xd;
10977
- i = -i;
10978
- len = yd.length;
10979
- } else {
10980
- d = yd;
10981
- e = k;
10982
- len = xd.length;
10983
- }
10984
- k = Math.ceil(pr / LOG_BASE);
10985
- len = k > len ? k + 1 : len + 1;
10986
- if (i > len) {
10987
- i = len;
10988
- d.length = 1;
10989
- }
10990
- d.reverse();
10991
- for (;i--; )
10992
- d.push(0);
10993
- d.reverse();
10994
- }
10995
- len = xd.length;
10996
- i = yd.length;
10997
- if (len - i < 0) {
10998
- i = len;
10999
- d = yd;
11000
- yd = xd;
11001
- xd = d;
11002
- }
11003
- for (carry = 0;i; ) {
11004
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
11005
- xd[i] %= BASE;
11006
- }
11007
- if (carry) {
11008
- xd.unshift(carry);
11009
- ++e;
11010
- }
11011
- for (len = xd.length;xd[--len] == 0; )
11012
- xd.pop();
11013
- y.d = xd;
11014
- y.e = getBase10Exponent(xd, e);
11015
- return external2 ? finalise(y, pr, rm) : y;
11016
- };
11017
- P.precision = P.sd = function(z) {
11018
- var k, x = this;
11019
- if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
11020
- throw Error(invalidArgument + z);
11021
- if (x.d) {
11022
- k = getPrecision(x.d);
11023
- if (z && x.e + 1 > k)
11024
- k = x.e + 1;
11025
- } else {
11026
- k = NaN;
11027
- }
11028
- return k;
11029
- };
11030
- P.round = function() {
11031
- var x = this, Ctor = x.constructor;
11032
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
11033
- };
11034
- P.sine = P.sin = function() {
11035
- var pr, rm, x = this, Ctor = x.constructor;
11036
- if (!x.isFinite())
11037
- return new Ctor(NaN);
11038
- if (x.isZero())
11039
- return new Ctor(x);
11040
- pr = Ctor.precision;
11041
- rm = Ctor.rounding;
11042
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
11043
- Ctor.rounding = 1;
11044
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
11045
- Ctor.precision = pr;
11046
- Ctor.rounding = rm;
11047
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
11048
- };
11049
- P.squareRoot = P.sqrt = function() {
11050
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
11051
- if (s !== 1 || !d || !d[0]) {
11052
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
11053
- }
11054
- external2 = false;
11055
- s = Math.sqrt(+x);
11056
- if (s == 0 || s == 1 / 0) {
11057
- n = digitsToString(d);
11058
- if ((n.length + e) % 2 == 0)
11059
- n += "0";
11060
- s = Math.sqrt(n);
11061
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
11062
- if (s == 1 / 0) {
11063
- n = "5e" + e;
11064
- } else {
11065
- n = s.toExponential();
11066
- n = n.slice(0, n.indexOf("e") + 1) + e;
11067
- }
11068
- r = new Ctor(n);
11069
- } else {
11070
- r = new Ctor(s.toString());
11071
- }
11072
- sd = (e = Ctor.precision) + 3;
11073
- for (;; ) {
11074
- t = r;
11075
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
11076
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
11077
- n = n.slice(sd - 3, sd + 1);
11078
- if (n == "9999" || !rep && n == "4999") {
11079
- if (!rep) {
11080
- finalise(t, e + 1, 0);
11081
- if (t.times(t).eq(x)) {
11082
- r = t;
11083
- break;
11084
- }
11085
- }
11086
- sd += 4;
11087
- rep = 1;
11088
- } else {
11089
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
11090
- finalise(r, e + 1, 1);
11091
- m = !r.times(r).eq(x);
11092
- }
11093
- break;
11094
- }
11095
- }
11096
- }
11097
- external2 = true;
11098
- return finalise(r, e, Ctor.rounding, m);
11099
- };
11100
- P.tangent = P.tan = function() {
11101
- var pr, rm, x = this, Ctor = x.constructor;
11102
- if (!x.isFinite())
11103
- return new Ctor(NaN);
11104
- if (x.isZero())
11105
- return new Ctor(x);
11106
- pr = Ctor.precision;
11107
- rm = Ctor.rounding;
11108
- Ctor.precision = pr + 10;
11109
- Ctor.rounding = 1;
11110
- x = x.sin();
11111
- x.s = 1;
11112
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
11113
- Ctor.precision = pr;
11114
- Ctor.rounding = rm;
11115
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
11116
- };
11117
- P.times = P.mul = function(y) {
11118
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
11119
- y.s *= x.s;
11120
- if (!xd || !xd[0] || !yd || !yd[0]) {
11121
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
11122
- }
11123
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
11124
- xdL = xd.length;
11125
- ydL = yd.length;
11126
- if (xdL < ydL) {
11127
- r = xd;
11128
- xd = yd;
11129
- yd = r;
11130
- rL = xdL;
11131
- xdL = ydL;
11132
- ydL = rL;
11133
- }
11134
- r = [];
11135
- rL = xdL + ydL;
11136
- for (i = rL;i--; )
11137
- r.push(0);
11138
- for (i = ydL;--i >= 0; ) {
11139
- carry = 0;
11140
- for (k = xdL + i;k > i; ) {
11141
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
11142
- r[k--] = t % BASE | 0;
11143
- carry = t / BASE | 0;
11144
- }
11145
- r[k] = (r[k] + carry) % BASE | 0;
11146
- }
11147
- for (;!r[--rL]; )
11148
- r.pop();
11149
- if (carry)
11150
- ++e;
11151
- else
11152
- r.shift();
11153
- y.d = r;
11154
- y.e = getBase10Exponent(r, e);
11155
- return external2 ? finalise(y, Ctor.precision, Ctor.rounding) : y;
11156
- };
11157
- P.toBinary = function(sd, rm) {
11158
- return toStringBinary(this, 2, sd, rm);
11159
- };
11160
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
11161
- var x = this, Ctor = x.constructor;
11162
- x = new Ctor(x);
11163
- if (dp === undefined)
11164
- return x;
11165
- checkInt32(dp, 0, MAX_DIGITS);
11166
- if (rm === undefined)
11167
- rm = Ctor.rounding;
11168
- else
11169
- checkInt32(rm, 0, 8);
11170
- return finalise(x, dp + x.e + 1, rm);
11171
- };
11172
- P.toExponential = function(dp, rm) {
11173
- var str, x = this, Ctor = x.constructor;
11174
- if (dp === undefined) {
11175
- str = finiteToString(x, true);
11176
- } else {
11177
- checkInt32(dp, 0, MAX_DIGITS);
11178
- if (rm === undefined)
11179
- rm = Ctor.rounding;
11180
- else
11181
- checkInt32(rm, 0, 8);
11182
- x = finalise(new Ctor(x), dp + 1, rm);
11183
- str = finiteToString(x, true, dp + 1);
11184
- }
11185
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11186
- };
11187
- P.toFixed = function(dp, rm) {
11188
- var str, y, x = this, Ctor = x.constructor;
11189
- if (dp === undefined) {
11190
- str = finiteToString(x);
11191
- } else {
11192
- checkInt32(dp, 0, MAX_DIGITS);
11193
- if (rm === undefined)
11194
- rm = Ctor.rounding;
11195
- else
11196
- checkInt32(rm, 0, 8);
11197
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
11198
- str = finiteToString(y, false, dp + y.e + 1);
11199
- }
11200
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11201
- };
11202
- P.toFraction = function(maxD) {
11203
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
11204
- if (!xd)
11205
- return new Ctor(x);
11206
- n1 = d0 = new Ctor(1);
11207
- d1 = n0 = new Ctor(0);
11208
- d = new Ctor(d1);
11209
- e = d.e = getPrecision(xd) - x.e - 1;
11210
- k = e % LOG_BASE;
11211
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
11212
- if (maxD == null) {
11213
- maxD = e > 0 ? d : n1;
11214
- } else {
11215
- n = new Ctor(maxD);
11216
- if (!n.isInt() || n.lt(n1))
11217
- throw Error(invalidArgument + n);
11218
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
11219
- }
11220
- external2 = false;
11221
- n = new Ctor(digitsToString(xd));
11222
- pr = Ctor.precision;
11223
- Ctor.precision = e = xd.length * LOG_BASE * 2;
11224
- for (;; ) {
11225
- q = divide(n, d, 0, 1, 1);
11226
- d2 = d0.plus(q.times(d1));
11227
- if (d2.cmp(maxD) == 1)
11228
- break;
11229
- d0 = d1;
11230
- d1 = d2;
11231
- d2 = n1;
11232
- n1 = n0.plus(q.times(d2));
11233
- n0 = d2;
11234
- d2 = d;
11235
- d = n.minus(q.times(d2));
11236
- n = d2;
11237
- }
11238
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
11239
- n0 = n0.plus(d2.times(n1));
11240
- d0 = d0.plus(d2.times(d1));
11241
- n0.s = n1.s = x.s;
11242
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
11243
- Ctor.precision = pr;
11244
- external2 = true;
11245
- return r;
11246
- };
11247
- P.toHexadecimal = P.toHex = function(sd, rm) {
11248
- return toStringBinary(this, 16, sd, rm);
11249
- };
11250
- P.toNearest = function(y, rm) {
11251
- var x = this, Ctor = x.constructor;
11252
- x = new Ctor(x);
11253
- if (y == null) {
11254
- if (!x.d)
11255
- return x;
11256
- y = new Ctor(1);
11257
- rm = Ctor.rounding;
11258
- } else {
11259
- y = new Ctor(y);
11260
- if (rm === undefined) {
11261
- rm = Ctor.rounding;
11262
- } else {
11263
- checkInt32(rm, 0, 8);
11264
- }
11265
- if (!x.d)
11266
- return y.s ? x : y;
11267
- if (!y.d) {
11268
- if (y.s)
11269
- y.s = x.s;
11270
- return y;
11271
- }
11272
- }
11273
- if (y.d[0]) {
11274
- external2 = false;
11275
- x = divide(x, y, 0, rm, 1).times(y);
11276
- external2 = true;
11277
- finalise(x);
11278
- } else {
11279
- y.s = x.s;
11280
- x = y;
11281
- }
11282
- return x;
11283
- };
11284
- P.toNumber = function() {
11285
- return +this;
11286
- };
11287
- P.toOctal = function(sd, rm) {
11288
- return toStringBinary(this, 8, sd, rm);
11289
- };
11290
- P.toPower = P.pow = function(y) {
11291
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
11292
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
11293
- return new Ctor(mathpow(+x, yn));
11294
- x = new Ctor(x);
11295
- if (x.eq(1))
11296
- return x;
11297
- pr = Ctor.precision;
11298
- rm = Ctor.rounding;
11299
- if (y.eq(1))
11300
- return finalise(x, pr, rm);
11301
- e = mathfloor(y.e / LOG_BASE);
11302
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
11303
- r = intPow(Ctor, x, k, pr);
11304
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
11305
- }
11306
- s = x.s;
11307
- if (s < 0) {
11308
- if (e < y.d.length - 1)
11309
- return new Ctor(NaN);
11310
- if ((y.d[e] & 1) == 0)
11311
- s = 1;
11312
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
11313
- x.s = s;
11314
- return x;
11315
- }
11316
- }
11317
- k = mathpow(+x, yn);
11318
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
11319
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
11320
- return new Ctor(e > 0 ? s / 0 : 0);
11321
- external2 = false;
11322
- Ctor.rounding = x.s = 1;
11323
- k = Math.min(12, (e + "").length);
11324
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
11325
- if (r.d) {
11326
- r = finalise(r, pr + 5, 1);
11327
- if (checkRoundingDigits(r.d, pr, rm)) {
11328
- e = pr + 10;
11329
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
11330
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
11331
- r = finalise(r, pr + 1, 0);
11332
- }
11333
- }
11334
- }
11335
- r.s = s;
11336
- external2 = true;
11337
- Ctor.rounding = rm;
11338
- return finalise(r, pr, rm);
11339
- };
11340
- P.toPrecision = function(sd, rm) {
11341
- var str, x = this, Ctor = x.constructor;
11342
- if (sd === undefined) {
11343
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11344
- } else {
11345
- checkInt32(sd, 1, MAX_DIGITS);
11346
- if (rm === undefined)
11347
- rm = Ctor.rounding;
11348
- else
11349
- checkInt32(rm, 0, 8);
11350
- x = finalise(new Ctor(x), sd, rm);
11351
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
11352
- }
11353
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11354
- };
11355
- P.toSignificantDigits = P.toSD = function(sd, rm) {
11356
- var x = this, Ctor = x.constructor;
11357
- if (sd === undefined) {
11358
- sd = Ctor.precision;
11359
- rm = Ctor.rounding;
11360
- } else {
11361
- checkInt32(sd, 1, MAX_DIGITS);
11362
- if (rm === undefined)
11363
- rm = Ctor.rounding;
11364
- else
11365
- checkInt32(rm, 0, 8);
11366
- }
11367
- return finalise(new Ctor(x), sd, rm);
11368
- };
11369
- P.toString = function() {
11370
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11371
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11372
- };
11373
- P.truncated = P.trunc = function() {
11374
- return finalise(new this.constructor(this), this.e + 1, 1);
11375
- };
11376
- P.valueOf = P.toJSON = function() {
11377
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11378
- return x.isNeg() ? "-" + str : str;
11379
- };
11380
- function digitsToString(d) {
11381
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
11382
- if (indexOfLastWord > 0) {
11383
- str += w;
11384
- for (i = 1;i < indexOfLastWord; i++) {
11385
- ws = d[i] + "";
11386
- k = LOG_BASE - ws.length;
11387
- if (k)
11388
- str += getZeroString(k);
11389
- str += ws;
11390
- }
11391
- w = d[i];
11392
- ws = w + "";
11393
- k = LOG_BASE - ws.length;
11394
- if (k)
11395
- str += getZeroString(k);
11396
- } else if (w === 0) {
11397
- return "0";
11398
- }
11399
- for (;w % 10 === 0; )
11400
- w /= 10;
11401
- return str + w;
11402
- }
11403
- function checkInt32(i, min, max) {
11404
- if (i !== ~~i || i < min || i > max) {
11405
- throw Error(invalidArgument + i);
11406
- }
11407
- }
11408
- function checkRoundingDigits(d, i, rm, repeating) {
11409
- var di, k, r, rd;
11410
- for (k = d[0];k >= 10; k /= 10)
11411
- --i;
11412
- if (--i < 0) {
11413
- i += LOG_BASE;
11414
- di = 0;
11415
- } else {
11416
- di = Math.ceil((i + 1) / LOG_BASE);
11417
- i %= LOG_BASE;
11418
- }
11419
- k = mathpow(10, LOG_BASE - i);
11420
- rd = d[di] % k | 0;
11421
- if (repeating == null) {
11422
- if (i < 3) {
11423
- if (i == 0)
11424
- rd = rd / 100 | 0;
11425
- else if (i == 1)
11426
- rd = rd / 10 | 0;
11427
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
11428
- } else {
11429
- r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
11430
- }
11431
- } else {
11432
- if (i < 4) {
11433
- if (i == 0)
11434
- rd = rd / 1000 | 0;
11435
- else if (i == 1)
11436
- rd = rd / 100 | 0;
11437
- else if (i == 2)
11438
- rd = rd / 10 | 0;
11439
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
11440
- } else {
11441
- r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
11442
- }
11443
- }
11444
- return r;
11445
- }
11446
- function convertBase(str, baseIn, baseOut) {
11447
- var j, arr = [0], arrL, i = 0, strL = str.length;
11448
- for (;i < strL; ) {
11449
- for (arrL = arr.length;arrL--; )
11450
- arr[arrL] *= baseIn;
11451
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
11452
- for (j = 0;j < arr.length; j++) {
11453
- if (arr[j] > baseOut - 1) {
11454
- if (arr[j + 1] === undefined)
11455
- arr[j + 1] = 0;
11456
- arr[j + 1] += arr[j] / baseOut | 0;
11457
- arr[j] %= baseOut;
11458
- }
11459
- }
11460
- }
11461
- return arr.reverse();
11462
- }
11463
- function cosine(Ctor, x) {
11464
- var k, len, y;
11465
- if (x.isZero())
11466
- return x;
11467
- len = x.d.length;
11468
- if (len < 32) {
11469
- k = Math.ceil(len / 3);
11470
- y = (1 / tinyPow(4, k)).toString();
11471
- } else {
11472
- k = 16;
11473
- y = "2.3283064365386962890625e-10";
11474
- }
11475
- Ctor.precision += k;
11476
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
11477
- for (var i = k;i--; ) {
11478
- var cos2x = x.times(x);
11479
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
11480
- }
11481
- Ctor.precision -= k;
11482
- return x;
11483
- }
11484
- var divide = function() {
11485
- function multiplyInteger(x, k, base) {
11486
- var temp, carry = 0, i = x.length;
11487
- for (x = x.slice();i--; ) {
11488
- temp = x[i] * k + carry;
11489
- x[i] = temp % base | 0;
11490
- carry = temp / base | 0;
11491
- }
11492
- if (carry)
11493
- x.unshift(carry);
11494
- return x;
11495
- }
11496
- function compare(a, b, aL, bL) {
11497
- var i, r;
11498
- if (aL != bL) {
11499
- r = aL > bL ? 1 : -1;
11500
- } else {
11501
- for (i = r = 0;i < aL; i++) {
11502
- if (a[i] != b[i]) {
11503
- r = a[i] > b[i] ? 1 : -1;
11504
- break;
11505
- }
11506
- }
11507
- }
11508
- return r;
11509
- }
11510
- function subtract(a, b, aL, base) {
11511
- var i = 0;
11512
- for (;aL--; ) {
11513
- a[aL] -= i;
11514
- i = a[aL] < b[aL] ? 1 : 0;
11515
- a[aL] = i * base + a[aL] - b[aL];
11516
- }
11517
- for (;!a[0] && a.length > 1; )
11518
- a.shift();
11519
- }
11520
- return function(x, y, pr, rm, dp, base) {
11521
- var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
11522
- if (!xd || !xd[0] || !yd || !yd[0]) {
11523
- return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
11524
- }
11525
- if (base) {
11526
- logBase = 1;
11527
- e = x.e - y.e;
11528
- } else {
11529
- base = BASE;
11530
- logBase = LOG_BASE;
11531
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
11532
- }
11533
- yL = yd.length;
11534
- xL = xd.length;
11535
- q = new Ctor(sign);
11536
- qd = q.d = [];
11537
- for (i = 0;yd[i] == (xd[i] || 0); i++)
11538
- ;
11539
- if (yd[i] > (xd[i] || 0))
11540
- e--;
11541
- if (pr == null) {
11542
- sd = pr = Ctor.precision;
11543
- rm = Ctor.rounding;
11544
- } else if (dp) {
11545
- sd = pr + (x.e - y.e) + 1;
11546
- } else {
11547
- sd = pr;
11548
- }
11549
- if (sd < 0) {
11550
- qd.push(1);
11551
- more = true;
11552
- } else {
11553
- sd = sd / logBase + 2 | 0;
11554
- i = 0;
11555
- if (yL == 1) {
11556
- k = 0;
11557
- yd = yd[0];
11558
- sd++;
11559
- for (;(i < xL || k) && sd--; i++) {
11560
- t = k * base + (xd[i] || 0);
11561
- qd[i] = t / yd | 0;
11562
- k = t % yd | 0;
11563
- }
11564
- more = k || i < xL;
11565
- } else {
11566
- k = base / (yd[0] + 1) | 0;
11567
- if (k > 1) {
11568
- yd = multiplyInteger(yd, k, base);
11569
- xd = multiplyInteger(xd, k, base);
11570
- yL = yd.length;
11571
- xL = xd.length;
11572
- }
11573
- xi = yL;
11574
- rem = xd.slice(0, yL);
11575
- remL = rem.length;
11576
- for (;remL < yL; )
11577
- rem[remL++] = 0;
11578
- yz = yd.slice();
11579
- yz.unshift(0);
11580
- yd0 = yd[0];
11581
- if (yd[1] >= base / 2)
11582
- ++yd0;
11583
- do {
11584
- k = 0;
11585
- cmp = compare(yd, rem, yL, remL);
11586
- if (cmp < 0) {
11587
- rem0 = rem[0];
11588
- if (yL != remL)
11589
- rem0 = rem0 * base + (rem[1] || 0);
11590
- k = rem0 / yd0 | 0;
11591
- if (k > 1) {
11592
- if (k >= base)
11593
- k = base - 1;
11594
- prod = multiplyInteger(yd, k, base);
11595
- prodL = prod.length;
11596
- remL = rem.length;
11597
- cmp = compare(prod, rem, prodL, remL);
11598
- if (cmp == 1) {
11599
- k--;
11600
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
11601
- }
11602
- } else {
11603
- if (k == 0)
11604
- cmp = k = 1;
11605
- prod = yd.slice();
11606
- }
11607
- prodL = prod.length;
11608
- if (prodL < remL)
11609
- prod.unshift(0);
11610
- subtract(rem, prod, remL, base);
11611
- if (cmp == -1) {
11612
- remL = rem.length;
11613
- cmp = compare(yd, rem, yL, remL);
11614
- if (cmp < 1) {
11615
- k++;
11616
- subtract(rem, yL < remL ? yz : yd, remL, base);
11617
- }
11618
- }
11619
- remL = rem.length;
11620
- } else if (cmp === 0) {
11621
- k++;
11622
- rem = [0];
11623
- }
11624
- qd[i++] = k;
11625
- if (cmp && rem[0]) {
11626
- rem[remL++] = xd[xi] || 0;
11627
- } else {
11628
- rem = [xd[xi]];
11629
- remL = 1;
11630
- }
11631
- } while ((xi++ < xL || rem[0] !== undefined) && sd--);
11632
- more = rem[0] !== undefined;
11633
- }
11634
- if (!qd[0])
11635
- qd.shift();
11636
- }
11637
- if (logBase == 1) {
11638
- q.e = e;
11639
- inexact = more;
11640
- } else {
11641
- for (i = 1, k = qd[0];k >= 10; k /= 10)
11642
- i++;
11643
- q.e = i + e * logBase - 1;
11644
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
11645
- }
11646
- return q;
11647
- };
11648
- }();
11649
- function finalise(x, sd, rm, isTruncated) {
11650
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
11651
- out:
11652
- if (sd != null) {
11653
- xd = x.d;
11654
- if (!xd)
11655
- return x;
11656
- for (digits = 1, k = xd[0];k >= 10; k /= 10)
11657
- digits++;
11658
- i = sd - digits;
11659
- if (i < 0) {
11660
- i += LOG_BASE;
11661
- j = sd;
11662
- w = xd[xdi = 0];
11663
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
11664
- } else {
11665
- xdi = Math.ceil((i + 1) / LOG_BASE);
11666
- k = xd.length;
11667
- if (xdi >= k) {
11668
- if (isTruncated) {
11669
- for (;k++ <= xdi; )
11670
- xd.push(0);
11671
- w = rd = 0;
11672
- digits = 1;
11673
- i %= LOG_BASE;
11674
- j = i - LOG_BASE + 1;
11675
- } else {
11676
- break out;
11677
- }
11678
- } else {
11679
- w = k = xd[xdi];
11680
- for (digits = 1;k >= 10; k /= 10)
11681
- digits++;
11682
- i %= LOG_BASE;
11683
- j = i - LOG_BASE + digits;
11684
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
11685
- }
11686
- }
11687
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
11688
- roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
11689
- if (sd < 1 || !xd[0]) {
11690
- xd.length = 0;
11691
- if (roundUp) {
11692
- sd -= x.e + 1;
11693
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
11694
- x.e = -sd || 0;
11695
- } else {
11696
- xd[0] = x.e = 0;
11697
- }
11698
- return x;
11699
- }
11700
- if (i == 0) {
11701
- xd.length = xdi;
11702
- k = 1;
11703
- xdi--;
11704
- } else {
11705
- xd.length = xdi + 1;
11706
- k = mathpow(10, LOG_BASE - i);
11707
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
11708
- }
11709
- if (roundUp) {
11710
- for (;; ) {
11711
- if (xdi == 0) {
11712
- for (i = 1, j = xd[0];j >= 10; j /= 10)
11713
- i++;
11714
- j = xd[0] += k;
11715
- for (k = 1;j >= 10; j /= 10)
11716
- k++;
11717
- if (i != k) {
11718
- x.e++;
11719
- if (xd[0] == BASE)
11720
- xd[0] = 1;
11721
- }
11722
- break;
11723
- } else {
11724
- xd[xdi] += k;
11725
- if (xd[xdi] != BASE)
11726
- break;
11727
- xd[xdi--] = 0;
11728
- k = 1;
11729
- }
11730
- }
11731
- }
11732
- for (i = xd.length;xd[--i] === 0; )
11733
- xd.pop();
11734
- }
11735
- if (external2) {
11736
- if (x.e > Ctor.maxE) {
11737
- x.d = null;
11738
- x.e = NaN;
11739
- } else if (x.e < Ctor.minE) {
11740
- x.e = 0;
11741
- x.d = [0];
11742
- }
11743
- }
11744
- return x;
11745
- }
11746
- function finiteToString(x, isExp, sd) {
11747
- if (!x.isFinite())
11748
- return nonFiniteToString(x);
11749
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
11750
- if (isExp) {
11751
- if (sd && (k = sd - len) > 0) {
11752
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
11753
- } else if (len > 1) {
11754
- str = str.charAt(0) + "." + str.slice(1);
11755
- }
11756
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
11757
- } else if (e < 0) {
11758
- str = "0." + getZeroString(-e - 1) + str;
11759
- if (sd && (k = sd - len) > 0)
11760
- str += getZeroString(k);
11761
- } else if (e >= len) {
11762
- str += getZeroString(e + 1 - len);
11763
- if (sd && (k = sd - e - 1) > 0)
11764
- str = str + "." + getZeroString(k);
11765
- } else {
11766
- if ((k = e + 1) < len)
11767
- str = str.slice(0, k) + "." + str.slice(k);
11768
- if (sd && (k = sd - len) > 0) {
11769
- if (e + 1 === len)
11770
- str += ".";
11771
- str += getZeroString(k);
11772
- }
11773
- }
11774
- return str;
11775
- }
11776
- function getBase10Exponent(digits, e) {
11777
- var w = digits[0];
11778
- for (e *= LOG_BASE;w >= 10; w /= 10)
11779
- e++;
11780
- return e;
11781
- }
11782
- function getLn10(Ctor, sd, pr) {
11783
- if (sd > LN10_PRECISION) {
11784
- external2 = true;
11785
- if (pr)
11786
- Ctor.precision = pr;
11787
- throw Error(precisionLimitExceeded);
11788
- }
11789
- return finalise(new Ctor(LN10), sd, 1, true);
11790
- }
11791
- function getPi(Ctor, sd, rm) {
11792
- if (sd > PI_PRECISION)
11793
- throw Error(precisionLimitExceeded);
11794
- return finalise(new Ctor(PI), sd, rm, true);
11795
- }
11796
- function getPrecision(digits) {
11797
- var w = digits.length - 1, len = w * LOG_BASE + 1;
11798
- w = digits[w];
11799
- if (w) {
11800
- for (;w % 10 == 0; w /= 10)
11801
- len--;
11802
- for (w = digits[0];w >= 10; w /= 10)
11803
- len++;
11804
- }
11805
- return len;
11806
- }
11807
- function getZeroString(k) {
11808
- var zs = "";
11809
- for (;k--; )
11810
- zs += "0";
11811
- return zs;
11812
- }
11813
- function intPow(Ctor, x, n, pr) {
11814
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
11815
- external2 = false;
11816
- for (;; ) {
11817
- if (n % 2) {
11818
- r = r.times(x);
11819
- if (truncate(r.d, k))
11820
- isTruncated = true;
11821
- }
11822
- n = mathfloor(n / 2);
11823
- if (n === 0) {
11824
- n = r.d.length - 1;
11825
- if (isTruncated && r.d[n] === 0)
11826
- ++r.d[n];
11827
- break;
11828
- }
11829
- x = x.times(x);
11830
- truncate(x.d, k);
11831
- }
11832
- external2 = true;
11833
- return r;
11834
- }
11835
- function isOdd(n) {
11836
- return n.d[n.d.length - 1] & 1;
11837
- }
11838
- function maxOrMin(Ctor, args, n) {
11839
- var k, y, x = new Ctor(args[0]), i = 0;
11840
- for (;++i < args.length; ) {
11841
- y = new Ctor(args[i]);
11842
- if (!y.s) {
11843
- x = y;
11844
- break;
11845
- }
11846
- k = x.cmp(y);
11847
- if (k === n || k === 0 && x.s === n) {
11848
- x = y;
11849
- }
11850
- }
11851
- return x;
11852
- }
11853
- function naturalExponential(x, sd) {
11854
- var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11855
- if (!x.d || !x.d[0] || x.e > 17) {
11856
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
11857
- }
11858
- if (sd == null) {
11859
- external2 = false;
11860
- wpr = pr;
11861
- } else {
11862
- wpr = sd;
11863
- }
11864
- t = new Ctor(0.03125);
11865
- while (x.e > -2) {
11866
- x = x.times(t);
11867
- k += 5;
11868
- }
11869
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
11870
- wpr += guard;
11871
- denominator = pow = sum = new Ctor(1);
11872
- Ctor.precision = wpr;
11873
- for (;; ) {
11874
- pow = finalise(pow.times(x), wpr, 1);
11875
- denominator = denominator.times(++i);
11876
- t = sum.plus(divide(pow, denominator, wpr, 1));
11877
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11878
- j = k;
11879
- while (j--)
11880
- sum = finalise(sum.times(sum), wpr, 1);
11881
- if (sd == null) {
11882
- if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11883
- Ctor.precision = wpr += 10;
11884
- denominator = pow = t = new Ctor(1);
11885
- i = 0;
11886
- rep++;
11887
- } else {
11888
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11889
- }
11890
- } else {
11891
- Ctor.precision = pr;
11892
- return sum;
11893
- }
11894
- }
11895
- sum = t;
11896
- }
11897
- }
11898
- function naturalLogarithm(y, sd) {
11899
- var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
11900
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
11901
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
11902
- }
11903
- if (sd == null) {
11904
- external2 = false;
11905
- wpr = pr;
11906
- } else {
11907
- wpr = sd;
11908
- }
11909
- Ctor.precision = wpr += guard;
11910
- c = digitsToString(xd);
11911
- c0 = c.charAt(0);
11912
- if (Math.abs(e = x.e) < 1500000000000000) {
11913
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
11914
- x = x.times(y);
11915
- c = digitsToString(x.d);
11916
- c0 = c.charAt(0);
11917
- n++;
11918
- }
11919
- e = x.e;
11920
- if (c0 > 1) {
11921
- x = new Ctor("0." + c);
11922
- e++;
11923
- } else {
11924
- x = new Ctor(c0 + "." + c.slice(1));
11925
- }
11926
- } else {
11927
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
11928
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
11929
- Ctor.precision = pr;
11930
- return sd == null ? finalise(x, pr, rm, external2 = true) : x;
11931
- }
11932
- x1 = x;
11933
- sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
11934
- x2 = finalise(x.times(x), wpr, 1);
11935
- denominator = 3;
11936
- for (;; ) {
11937
- numerator = finalise(numerator.times(x2), wpr, 1);
11938
- t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
11939
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
11940
- sum = sum.times(2);
11941
- if (e !== 0)
11942
- sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
11943
- sum = divide(sum, new Ctor(n), wpr, 1);
11944
- if (sd == null) {
11945
- if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
11946
- Ctor.precision = wpr += guard;
11947
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
11948
- x2 = finalise(x.times(x), wpr, 1);
11949
- denominator = rep = 1;
11950
- } else {
11951
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
11952
- }
11953
- } else {
11954
- Ctor.precision = pr;
11955
- return sum;
11956
- }
11957
- }
11958
- sum = t;
11959
- denominator += 2;
11960
- }
11961
- }
11962
- function nonFiniteToString(x) {
11963
- return String(x.s * x.s / 0);
11964
- }
11965
- function parseDecimal(x, str) {
11966
- var e, i, len;
11967
- if ((e = str.indexOf(".")) > -1)
11968
- str = str.replace(".", "");
11969
- if ((i = str.search(/e/i)) > 0) {
11970
- if (e < 0)
11971
- e = i;
11972
- e += +str.slice(i + 1);
11973
- str = str.substring(0, i);
11974
- } else if (e < 0) {
11975
- e = str.length;
11976
- }
11977
- for (i = 0;str.charCodeAt(i) === 48; i++)
11978
- ;
11979
- for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
11980
- ;
11981
- str = str.slice(i, len);
11982
- if (str) {
11983
- len -= i;
11984
- x.e = e = e - i - 1;
11985
- x.d = [];
11986
- i = (e + 1) % LOG_BASE;
11987
- if (e < 0)
11988
- i += LOG_BASE;
11989
- if (i < len) {
11990
- if (i)
11991
- x.d.push(+str.slice(0, i));
11992
- for (len -= LOG_BASE;i < len; )
11993
- x.d.push(+str.slice(i, i += LOG_BASE));
11994
- str = str.slice(i);
11995
- i = LOG_BASE - str.length;
11996
- } else {
11997
- i -= len;
11998
- }
11999
- for (;i--; )
12000
- str += "0";
12001
- x.d.push(+str);
12002
- if (external2) {
12003
- if (x.e > x.constructor.maxE) {
12004
- x.d = null;
12005
- x.e = NaN;
12006
- } else if (x.e < x.constructor.minE) {
12007
- x.e = 0;
12008
- x.d = [0];
12009
- }
12010
- }
12011
- } else {
12012
- x.e = 0;
12013
- x.d = [0];
12014
- }
12015
- return x;
12016
- }
12017
- function parseOther(x, str) {
12018
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
12019
- if (str.indexOf("_") > -1) {
12020
- str = str.replace(/(\d)_(?=\d)/g, "$1");
12021
- if (isDecimal.test(str))
12022
- return parseDecimal(x, str);
12023
- } else if (str === "Infinity" || str === "NaN") {
12024
- if (!+str)
12025
- x.s = NaN;
12026
- x.e = NaN;
12027
- x.d = null;
12028
- return x;
12029
- }
12030
- if (isHex.test(str)) {
12031
- base = 16;
12032
- str = str.toLowerCase();
12033
- } else if (isBinary.test(str)) {
12034
- base = 2;
12035
- } else if (isOctal.test(str)) {
12036
- base = 8;
12037
- } else {
12038
- throw Error(invalidArgument + str);
12039
- }
12040
- i = str.search(/p/i);
12041
- if (i > 0) {
12042
- p = +str.slice(i + 1);
12043
- str = str.substring(2, i);
12044
- } else {
12045
- str = str.slice(2);
12046
- }
12047
- i = str.indexOf(".");
12048
- isFloat = i >= 0;
12049
- Ctor = x.constructor;
12050
- if (isFloat) {
12051
- str = str.replace(".", "");
12052
- len = str.length;
12053
- i = len - i;
12054
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
12055
- }
12056
- xd = convertBase(str, base, BASE);
12057
- xe = xd.length - 1;
12058
- for (i = xe;xd[i] === 0; --i)
12059
- xd.pop();
12060
- if (i < 0)
12061
- return new Ctor(x.s * 0);
12062
- x.e = getBase10Exponent(xd, xe);
12063
- x.d = xd;
12064
- external2 = false;
12065
- if (isFloat)
12066
- x = divide(x, divisor, len * 4);
12067
- if (p)
12068
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
12069
- external2 = true;
12070
- return x;
12071
- }
12072
- function sine(Ctor, x) {
12073
- var k, len = x.d.length;
12074
- if (len < 3) {
12075
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
12076
- }
12077
- k = 1.4 * Math.sqrt(len);
12078
- k = k > 16 ? 16 : k | 0;
12079
- x = x.times(1 / tinyPow(5, k));
12080
- x = taylorSeries(Ctor, 2, x, x);
12081
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
12082
- for (;k--; ) {
12083
- sin2_x = x.times(x);
12084
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
12085
- }
12086
- return x;
12087
- }
12088
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
12089
- var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
12090
- external2 = false;
12091
- x2 = x.times(x);
12092
- u = new Ctor(y);
12093
- for (;; ) {
12094
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
12095
- u = isHyperbolic ? y.plus(t) : y.minus(t);
12096
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
12097
- t = u.plus(y);
12098
- if (t.d[k] !== undefined) {
12099
- for (j = k;t.d[j] === u.d[j] && j--; )
12100
- ;
12101
- if (j == -1)
12102
- break;
12103
- }
12104
- j = u;
12105
- u = y;
12106
- y = t;
12107
- t = j;
12108
- i++;
12109
- }
12110
- external2 = true;
12111
- t.d.length = k + 1;
12112
- return t;
12113
- }
12114
- function tinyPow(b, e) {
12115
- var n = b;
12116
- while (--e)
12117
- n *= b;
12118
- return n;
12119
- }
12120
- function toLessThanHalfPi(Ctor, x) {
12121
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
12122
- x = x.abs();
12123
- if (x.lte(halfPi)) {
12124
- quadrant = isNeg ? 4 : 1;
12125
- return x;
12126
- }
12127
- t = x.divToInt(pi);
12128
- if (t.isZero()) {
12129
- quadrant = isNeg ? 3 : 2;
12130
- } else {
12131
- x = x.minus(t.times(pi));
12132
- if (x.lte(halfPi)) {
12133
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
12134
- return x;
12135
- }
12136
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
12137
- }
12138
- return x.minus(pi).abs();
12139
- }
12140
- function toStringBinary(x, baseOut, sd, rm) {
12141
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
12142
- if (isExp) {
12143
- checkInt32(sd, 1, MAX_DIGITS);
12144
- if (rm === undefined)
12145
- rm = Ctor.rounding;
12146
- else
12147
- checkInt32(rm, 0, 8);
12148
- } else {
12149
- sd = Ctor.precision;
12150
- rm = Ctor.rounding;
12151
- }
12152
- if (!x.isFinite()) {
12153
- str = nonFiniteToString(x);
12154
- } else {
12155
- str = finiteToString(x);
12156
- i = str.indexOf(".");
12157
- if (isExp) {
12158
- base = 2;
12159
- if (baseOut == 16) {
12160
- sd = sd * 4 - 3;
12161
- } else if (baseOut == 8) {
12162
- sd = sd * 3 - 2;
12163
- }
12164
- } else {
12165
- base = baseOut;
12166
- }
12167
- if (i >= 0) {
12168
- str = str.replace(".", "");
12169
- y = new Ctor(1);
12170
- y.e = str.length - i;
12171
- y.d = convertBase(finiteToString(y), 10, base);
12172
- y.e = y.d.length;
12173
- }
12174
- xd = convertBase(str, 10, base);
12175
- e = len = xd.length;
12176
- for (;xd[--len] == 0; )
12177
- xd.pop();
12178
- if (!xd[0]) {
12179
- str = isExp ? "0p+0" : "0";
12180
- } else {
12181
- if (i < 0) {
12182
- e--;
12183
- } else {
12184
- x = new Ctor(x);
12185
- x.d = xd;
12186
- x.e = e;
12187
- x = divide(x, y, sd, rm, 0, base);
12188
- xd = x.d;
12189
- e = x.e;
12190
- roundUp = inexact;
12191
- }
12192
- i = xd[sd];
12193
- k = base / 2;
12194
- roundUp = roundUp || xd[sd + 1] !== undefined;
12195
- roundUp = rm < 4 ? (i !== undefined || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
12196
- xd.length = sd;
12197
- if (roundUp) {
12198
- for (;++xd[--sd] > base - 1; ) {
12199
- xd[sd] = 0;
12200
- if (!sd) {
12201
- ++e;
12202
- xd.unshift(1);
12203
- }
12204
- }
12205
- }
12206
- for (len = xd.length;!xd[len - 1]; --len)
12207
- ;
12208
- for (i = 0, str = "";i < len; i++)
12209
- str += NUMERALS.charAt(xd[i]);
12210
- if (isExp) {
12211
- if (len > 1) {
12212
- if (baseOut == 16 || baseOut == 8) {
12213
- i = baseOut == 16 ? 4 : 3;
12214
- for (--len;len % i; len++)
12215
- str += "0";
12216
- xd = convertBase(str, base, baseOut);
12217
- for (len = xd.length;!xd[len - 1]; --len)
12218
- ;
12219
- for (i = 1, str = "1.";i < len; i++)
12220
- str += NUMERALS.charAt(xd[i]);
12221
- } else {
12222
- str = str.charAt(0) + "." + str.slice(1);
12223
- }
12224
- }
12225
- str = str + (e < 0 ? "p" : "p+") + e;
12226
- } else if (e < 0) {
12227
- for (;++e; )
12228
- str = "0" + str;
12229
- str = "0." + str;
12230
- } else {
12231
- if (++e > len)
12232
- for (e -= len;e--; )
12233
- str += "0";
12234
- else if (e < len)
12235
- str = str.slice(0, e) + "." + str.slice(e);
12236
- }
12237
- }
12238
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
12239
- }
12240
- return x.s < 0 ? "-" + str : str;
12241
- }
12242
- function truncate(arr, len) {
12243
- if (arr.length > len) {
12244
- arr.length = len;
12245
- return true;
12246
- }
12247
- }
12248
- function abs(x) {
12249
- return new this(x).abs();
12250
- }
12251
- function acos(x) {
12252
- return new this(x).acos();
12253
- }
12254
- function acosh(x) {
12255
- return new this(x).acosh();
12256
- }
12257
- function add(x, y) {
12258
- return new this(x).plus(y);
12259
- }
12260
- function asin(x) {
12261
- return new this(x).asin();
12262
- }
12263
- function asinh(x) {
12264
- return new this(x).asinh();
12265
- }
12266
- function atan(x) {
12267
- return new this(x).atan();
12268
- }
12269
- function atanh(x) {
12270
- return new this(x).atanh();
12271
- }
12272
- function atan2(y, x) {
12273
- y = new this(y);
12274
- x = new this(x);
12275
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
12276
- if (!y.s || !x.s) {
12277
- r = new this(NaN);
12278
- } else if (!y.d && !x.d) {
12279
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
12280
- r.s = y.s;
12281
- } else if (!x.d || y.isZero()) {
12282
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
12283
- r.s = y.s;
12284
- } else if (!y.d || x.isZero()) {
12285
- r = getPi(this, wpr, 1).times(0.5);
12286
- r.s = y.s;
12287
- } else if (x.s < 0) {
12288
- this.precision = wpr;
12289
- this.rounding = 1;
12290
- r = this.atan(divide(y, x, wpr, 1));
12291
- x = getPi(this, wpr, 1);
12292
- this.precision = pr;
12293
- this.rounding = rm;
12294
- r = y.s < 0 ? r.minus(x) : r.plus(x);
12295
- } else {
12296
- r = this.atan(divide(y, x, wpr, 1));
12297
- }
12298
- return r;
12299
- }
12300
- function cbrt(x) {
12301
- return new this(x).cbrt();
12302
- }
12303
- function ceil(x) {
12304
- return finalise(x = new this(x), x.e + 1, 2);
12305
- }
12306
- function clamp(x, min, max) {
12307
- return new this(x).clamp(min, max);
12308
- }
12309
- function config(obj) {
12310
- if (!obj || typeof obj !== "object")
12311
- throw Error(decimalError + "Object expected");
12312
- var i, p, v, useDefaults = obj.defaults === true, ps = [
12313
- "precision",
12314
- 1,
12315
- MAX_DIGITS,
12316
- "rounding",
12317
- 0,
12318
- 8,
12319
- "toExpNeg",
12320
- -EXP_LIMIT,
12321
- 0,
12322
- "toExpPos",
12323
- 0,
12324
- EXP_LIMIT,
12325
- "maxE",
12326
- 0,
12327
- EXP_LIMIT,
12328
- "minE",
12329
- -EXP_LIMIT,
12330
- 0,
12331
- "modulo",
12332
- 0,
12333
- 9
12334
- ];
12335
- for (i = 0;i < ps.length; i += 3) {
12336
- if (p = ps[i], useDefaults)
12337
- this[p] = DEFAULTS[p];
12338
- if ((v = obj[p]) !== undefined) {
12339
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
12340
- this[p] = v;
12341
- else
12342
- throw Error(invalidArgument + p + ": " + v);
12343
- }
12344
- }
12345
- if (p = "crypto", useDefaults)
12346
- this[p] = DEFAULTS[p];
12347
- if ((v = obj[p]) !== undefined) {
12348
- if (v === true || v === false || v === 0 || v === 1) {
12349
- if (v) {
12350
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
12351
- this[p] = true;
12352
- } else {
12353
- throw Error(cryptoUnavailable);
12354
- }
12355
- } else {
12356
- this[p] = false;
12357
- }
12358
- } else {
12359
- throw Error(invalidArgument + p + ": " + v);
12360
- }
12361
- }
12362
- return this;
12363
- }
12364
- function cos(x) {
12365
- return new this(x).cos();
12366
- }
12367
- function cosh(x) {
12368
- return new this(x).cosh();
12369
- }
12370
- function clone(obj) {
12371
- var i, p, ps;
12372
- function Decimal(v) {
12373
- var e, i2, t, x = this;
12374
- if (!(x instanceof Decimal))
12375
- return new Decimal(v);
12376
- x.constructor = Decimal;
12377
- if (isDecimalInstance(v)) {
12378
- x.s = v.s;
12379
- if (external2) {
12380
- if (!v.d || v.e > Decimal.maxE) {
12381
- x.e = NaN;
12382
- x.d = null;
12383
- } else if (v.e < Decimal.minE) {
12384
- x.e = 0;
12385
- x.d = [0];
12386
- } else {
12387
- x.e = v.e;
12388
- x.d = v.d.slice();
12389
- }
12390
- } else {
12391
- x.e = v.e;
12392
- x.d = v.d ? v.d.slice() : v.d;
12393
- }
12394
- return;
12395
- }
12396
- t = typeof v;
12397
- if (t === "number") {
12398
- if (v === 0) {
12399
- x.s = 1 / v < 0 ? -1 : 1;
12400
- x.e = 0;
12401
- x.d = [0];
12402
- return;
12403
- }
12404
- if (v < 0) {
12405
- v = -v;
12406
- x.s = -1;
12407
- } else {
12408
- x.s = 1;
12409
- }
12410
- if (v === ~~v && v < 1e7) {
12411
- for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
12412
- e++;
12413
- if (external2) {
12414
- if (e > Decimal.maxE) {
12415
- x.e = NaN;
12416
- x.d = null;
12417
- } else if (e < Decimal.minE) {
12418
- x.e = 0;
12419
- x.d = [0];
12420
- } else {
12421
- x.e = e;
12422
- x.d = [v];
12423
- }
12424
- } else {
12425
- x.e = e;
12426
- x.d = [v];
12427
- }
12428
- return;
12429
- }
12430
- if (v * 0 !== 0) {
12431
- if (!v)
12432
- x.s = NaN;
12433
- x.e = NaN;
12434
- x.d = null;
12435
- return;
12436
- }
12437
- return parseDecimal(x, v.toString());
12438
- }
12439
- if (t === "string") {
12440
- if ((i2 = v.charCodeAt(0)) === 45) {
12441
- v = v.slice(1);
12442
- x.s = -1;
12443
- } else {
12444
- if (i2 === 43)
12445
- v = v.slice(1);
12446
- x.s = 1;
12447
- }
12448
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
12449
- }
12450
- if (t === "bigint") {
12451
- if (v < 0) {
12452
- v = -v;
12453
- x.s = -1;
12454
- } else {
12455
- x.s = 1;
12456
- }
12457
- return parseDecimal(x, v.toString());
12458
- }
12459
- throw Error(invalidArgument + v);
12460
- }
12461
- Decimal.prototype = P;
12462
- Decimal.ROUND_UP = 0;
12463
- Decimal.ROUND_DOWN = 1;
12464
- Decimal.ROUND_CEIL = 2;
12465
- Decimal.ROUND_FLOOR = 3;
12466
- Decimal.ROUND_HALF_UP = 4;
12467
- Decimal.ROUND_HALF_DOWN = 5;
12468
- Decimal.ROUND_HALF_EVEN = 6;
12469
- Decimal.ROUND_HALF_CEIL = 7;
12470
- Decimal.ROUND_HALF_FLOOR = 8;
12471
- Decimal.EUCLID = 9;
12472
- Decimal.config = Decimal.set = config;
12473
- Decimal.clone = clone;
12474
- Decimal.isDecimal = isDecimalInstance;
12475
- Decimal.abs = abs;
12476
- Decimal.acos = acos;
12477
- Decimal.acosh = acosh;
12478
- Decimal.add = add;
12479
- Decimal.asin = asin;
12480
- Decimal.asinh = asinh;
12481
- Decimal.atan = atan;
12482
- Decimal.atanh = atanh;
12483
- Decimal.atan2 = atan2;
12484
- Decimal.cbrt = cbrt;
12485
- Decimal.ceil = ceil;
12486
- Decimal.clamp = clamp;
12487
- Decimal.cos = cos;
12488
- Decimal.cosh = cosh;
12489
- Decimal.div = div;
12490
- Decimal.exp = exp;
12491
- Decimal.floor = floor;
12492
- Decimal.hypot = hypot;
12493
- Decimal.ln = ln;
12494
- Decimal.log = log;
12495
- Decimal.log10 = log10;
12496
- Decimal.log2 = log2;
12497
- Decimal.max = max;
12498
- Decimal.min = min;
12499
- Decimal.mod = mod;
12500
- Decimal.mul = mul;
12501
- Decimal.pow = pow;
12502
- Decimal.random = random;
12503
- Decimal.round = round;
12504
- Decimal.sign = sign;
12505
- Decimal.sin = sin;
12506
- Decimal.sinh = sinh;
12507
- Decimal.sqrt = sqrt;
12508
- Decimal.sub = sub;
12509
- Decimal.sum = sum;
12510
- Decimal.tan = tan;
12511
- Decimal.tanh = tanh;
12512
- Decimal.trunc = trunc;
12513
- if (obj === undefined)
12514
- obj = {};
12515
- if (obj) {
12516
- if (obj.defaults !== true) {
12517
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
12518
- for (i = 0;i < ps.length; )
12519
- if (!obj.hasOwnProperty(p = ps[i++]))
12520
- obj[p] = this[p];
12521
- }
12522
- }
12523
- Decimal.config(obj);
12524
- return Decimal;
12525
- }
12526
- function div(x, y) {
12527
- return new this(x).div(y);
12528
- }
12529
- function exp(x) {
12530
- return new this(x).exp();
12531
- }
12532
- function floor(x) {
12533
- return finalise(x = new this(x), x.e + 1, 3);
12534
- }
12535
- function hypot() {
12536
- var i, n, t = new this(0);
12537
- external2 = false;
12538
- for (i = 0;i < arguments.length; ) {
12539
- n = new this(arguments[i++]);
12540
- if (!n.d) {
12541
- if (n.s) {
12542
- external2 = true;
12543
- return new this(1 / 0);
12544
- }
12545
- t = n;
12546
- } else if (t.d) {
12547
- t = t.plus(n.times(n));
12548
- }
12549
- }
12550
- external2 = true;
12551
- return t.sqrt();
12552
- }
12553
- function isDecimalInstance(obj) {
12554
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
12555
- }
12556
- function ln(x) {
12557
- return new this(x).ln();
12558
- }
12559
- function log(x, y) {
12560
- return new this(x).log(y);
12561
- }
12562
- function log2(x) {
12563
- return new this(x).log(2);
12564
- }
12565
- function log10(x) {
12566
- return new this(x).log(10);
12567
- }
12568
- function max() {
12569
- return maxOrMin(this, arguments, -1);
12570
- }
12571
- function min() {
12572
- return maxOrMin(this, arguments, 1);
12573
- }
12574
- function mod(x, y) {
12575
- return new this(x).mod(y);
12576
- }
12577
- function mul(x, y) {
12578
- return new this(x).mul(y);
12579
- }
12580
- function pow(x, y) {
12581
- return new this(x).pow(y);
12582
- }
12583
- function random(sd) {
12584
- var d, e, k, n, i = 0, r = new this(1), rd = [];
12585
- if (sd === undefined)
12586
- sd = this.precision;
12587
- else
12588
- checkInt32(sd, 1, MAX_DIGITS);
12589
- k = Math.ceil(sd / LOG_BASE);
12590
- if (!this.crypto) {
12591
- for (;i < k; )
12592
- rd[i++] = Math.random() * 1e7 | 0;
12593
- } else if (crypto.getRandomValues) {
12594
- d = crypto.getRandomValues(new Uint32Array(k));
12595
- for (;i < k; ) {
12596
- n = d[i];
12597
- if (n >= 4290000000) {
12598
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
12599
- } else {
12600
- rd[i++] = n % 1e7;
12601
- }
12602
- }
12603
- } else if (crypto.randomBytes) {
12604
- d = crypto.randomBytes(k *= 4);
12605
- for (;i < k; ) {
12606
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
12607
- if (n >= 2140000000) {
12608
- crypto.randomBytes(4).copy(d, i);
12609
- } else {
12610
- rd.push(n % 1e7);
12611
- i += 4;
12612
- }
12613
- }
12614
- i = k / 4;
12615
- } else {
12616
- throw Error(cryptoUnavailable);
12617
- }
12618
- k = rd[--i];
12619
- sd %= LOG_BASE;
12620
- if (k && sd) {
12621
- n = mathpow(10, LOG_BASE - sd);
12622
- rd[i] = (k / n | 0) * n;
12623
- }
12624
- for (;rd[i] === 0; i--)
12625
- rd.pop();
12626
- if (i < 0) {
12627
- e = 0;
12628
- rd = [0];
12629
- } else {
12630
- e = -1;
12631
- for (;rd[0] === 0; e -= LOG_BASE)
12632
- rd.shift();
12633
- for (k = 1, n = rd[0];n >= 10; n /= 10)
12634
- k++;
12635
- if (k < LOG_BASE)
12636
- e -= LOG_BASE - k;
12637
- }
12638
- r.e = e;
12639
- r.d = rd;
12640
- return r;
12641
- }
12642
- function round(x) {
12643
- return finalise(x = new this(x), x.e + 1, this.rounding);
12644
- }
12645
- function sign(x) {
12646
- x = new this(x);
12647
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
12648
- }
12649
- function sin(x) {
12650
- return new this(x).sin();
12651
- }
12652
- function sinh(x) {
12653
- return new this(x).sinh();
12654
- }
12655
- function sqrt(x) {
12656
- return new this(x).sqrt();
12657
- }
12658
- function sub(x, y) {
12659
- return new this(x).sub(y);
12660
- }
12661
- function sum() {
12662
- var i = 0, args = arguments, x = new this(args[i]);
12663
- external2 = false;
12664
- for (;x.s && ++i < args.length; )
12665
- x = x.plus(args[i]);
12666
- external2 = true;
12667
- return finalise(x, this.precision, this.rounding);
12668
- }
12669
- function tan(x) {
12670
- return new this(x).tan();
12671
- }
12672
- function tanh(x) {
12673
- return new this(x).tanh();
12674
- }
12675
- function trunc(x) {
12676
- return finalise(x = new this(x), x.e + 1, 1);
12677
- }
12678
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
12679
- P[Symbol.toStringTag] = "Decimal";
12680
- var Decimal = P.constructor = clone(DEFAULTS);
12681
- LN10 = new Decimal(LN10);
12682
- PI = new Decimal(PI);
12683
- var decimal_default = Decimal;
12684
-
12685
- // src/common/base/other.ts
12686
- var delay = (time = 1000) => {
12687
- return new Promise((resolve) => setTimeout(resolve, time));
12688
- };
12689
- var calcJsText = (expr, context) => {
12690
- const keys = Object.keys(context);
12691
- const values = keys.map((key2) => context[key2]);
12692
- return Function(...keys, `return (${expr})`)(...values);
12693
- };
12694
- var optionsToEnum = (options, text, key2) => {
12695
- return options.reduce((acc, cur) => {
12696
- acc[cur[key2]] = {
12697
- text: cur[text]
12698
- };
12699
- return acc;
12700
- }, {});
12701
- };
12702
- var performDecimalOperation = (num1, num2, operator) => {
12703
- if (num1 === undefined || num2 === undefined || !operator) {
12704
- return;
12705
- }
12706
- const decimalNum1 = new decimal_default(Number(num1));
12707
- const decimalNum2 = new decimal_default(Number(num2));
12708
- switch (operator) {
12709
- case "+":
12710
- return decimalNum1.plus(decimalNum2).toNumber();
12711
- case "-":
12712
- return decimalNum1.minus(decimalNum2).toNumber();
12713
- case "*":
12714
- return decimalNum1.times(decimalNum2).toNumber();
12715
- case "/":
12716
- if (num2 !== 0) {
12717
- return decimalNum1.dividedBy(decimalNum2).toNumber();
12718
- } else {
12719
- console.error("Division by zero is not allowed.");
12720
- return NaN;
12721
- }
12722
- default:
12723
- console.error("Invalid operator:", operator);
12724
- return NaN;
12725
- }
12726
- };
12727
- var printConsoleLog = (type, path2, params, response) => {
12728
- const styles = {
12729
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
12730
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
12731
- separator: "color: #409EFF; margin: 0 4px;"
12732
- };
12733
- console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
12734
- if (params) {
12735
- console.table(params);
12736
- }
12737
- if (response) {
12738
- console.table(response);
12739
- }
12740
- console.groupEnd();
12741
- };
12742
10309
 
12743
10310
  // src/common/base/array.ts
12744
- var shuffleArray = (array) => {
12745
- const shuffledArray = [...array];
12746
- for (let i = shuffledArray.length - 1;i > 0; i--) {
12747
- const j = Math.floor(Math.random() * (i + 1));
12748
- [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
12749
- }
12750
- return shuffledArray;
12751
- };
12752
10311
  var removeSimilarDuplicates = (arr, threshold, isLog) => {
12753
10312
  const uniqueArray = [];
12754
10313
  const similarPairs = [];
@@ -12778,65 +10337,26 @@ var removeSimilarDuplicates = (arr, threshold, isLog) => {
12778
10337
  }
12779
10338
  return uniqueArray;
12780
10339
  };
12781
- var getTotal = (arr, key2) => {
12782
- if (!Array.isArray(arr) || !key2) {
12783
- return 0;
12784
- }
12785
- return arr.reduce((total, item) => {
12786
- const itemValue = Number(item[key2]);
12787
- if (!isNaN(itemValue)) {
12788
- return performDecimalOperation(total, itemValue, "+");
12789
- }
12790
- return total;
12791
- }, 0);
12792
- };
12793
10340
 
12794
- // src/common/base/number.ts
12795
- var getRandomNum = (min2, max2) => {
12796
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
12797
- };
12798
- var limitDecimals = (v, num = 2, isForce) => {
12799
- let value = parseFloat(v);
12800
- if (isNaN(value)) {
12801
- if (isForce) {
12802
- value = 0;
12803
- } else {
12804
- return "";
10341
+ // src/common/base/object.ts
10342
+ var findAttr = (data, target, path2 = "data") => {
10343
+ if (Array.isArray(data)) {
10344
+ for (let i = 0;i < data.length; i++) {
10345
+ const res = findAttr(data[i], target, `${path2}[${i}]`);
10346
+ if (res)
10347
+ return res;
12805
10348
  }
12806
10349
  }
12807
- return value.toFixed(num).toString();
12808
- };
12809
- var formatFileSize = (bytes) => {
12810
- if (!bytes || bytes === 0) {
12811
- return "0 B";
12812
- }
12813
- const base = 1024;
12814
- const sizes = ["B", "KB", "MB", "GB"];
12815
- const index = Math.floor(Math.log(bytes) / Math.log(base));
12816
- return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
12817
- };
12818
- var isValidNumber = (value) => {
12819
- if (typeof value !== "number") {
12820
- return false;
12821
- }
12822
- if (isNaN(value)) {
12823
- return false;
12824
- }
12825
- if (value === Infinity || value === -Infinity) {
12826
- return false;
12827
- }
12828
- return true;
12829
- };
12830
- var numberWithCommas = (x) => {
12831
- if (x === undefined || x === null) {
12832
- return "";
10350
+ if (data && typeof data === "object") {
10351
+ if (target in data)
10352
+ return `${path2}.${target}`;
10353
+ for (const key2 in data) {
10354
+ const res = findAttr(data[key2], target, `${path2}.${key2}`);
10355
+ if (res)
10356
+ return res;
10357
+ }
12833
10358
  }
12834
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
12835
- };
12836
-
12837
- // src/common/base/object.ts
12838
- var findItem = (list, attr, value) => {
12839
- return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
10359
+ return null;
12840
10360
  };
12841
10361
  var filterParams = (params, deep = false) => {
12842
10362
  const clean = (value) => {
@@ -12861,26 +10381,30 @@ var filterParams = (params, deep = false) => {
12861
10381
  };
12862
10382
  return clean(params);
12863
10383
  };
12864
- var watch = {
12865
- observe(obj, key2, watchFun) {
12866
- const val = obj[key2];
12867
- Object.defineProperty(obj, key2, {
12868
- configurable: true,
12869
- enumerable: true,
12870
- set(value) {
12871
- obj[key2] = value;
12872
- watchFun(value, val);
12873
- },
12874
- get() {
12875
- return val;
12876
- }
12877
- });
12878
- },
12879
- setWatcher(data = {}, watch2 = {}) {
12880
- Object.keys(watch2).forEach((v) => {
12881
- this.observe(data, v, watch2[v]);
12882
- });
10384
+
10385
+ // src/common/base/other.ts
10386
+ var delay = (time = 1000) => {
10387
+ return new Promise((resolve) => setTimeout(resolve, time));
10388
+ };
10389
+ var calcJsText = (expr, context) => {
10390
+ const keys = Object.keys(context);
10391
+ const values = keys.map((key2) => context[key2]);
10392
+ return Function(...keys, `return (${expr})`)(...values);
10393
+ };
10394
+ var logNetwork = (type, path2, params, response) => {
10395
+ const styles = {
10396
+ header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
10397
+ value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
10398
+ separator: "color: #409EFF; margin: 0 4px;"
10399
+ };
10400
+ console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
10401
+ if (params) {
10402
+ console.table(params);
12883
10403
  }
10404
+ if (response) {
10405
+ console.table(response);
10406
+ }
10407
+ console.groupEnd();
12884
10408
  };
12885
10409
 
12886
10410
  // src/common/base/promise.ts
@@ -12893,7 +10417,7 @@ var executePromise = async (promise) => {
12893
10417
  time
12894
10418
  };
12895
10419
  };
12896
- var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
10420
+ var retryPromise = async (promiseFn, retryCount = 3, retryInterval = 1000) => {
12897
10421
  try {
12898
10422
  return await promiseFn();
12899
10423
  } catch (error) {
@@ -12909,10 +10433,10 @@ class EnumItem {
12909
10433
  label;
12910
10434
  value;
12911
10435
  extra;
12912
- constructor(config2) {
12913
- this.value = config2.value;
12914
- this.label = config2.label;
12915
- this.extra = config2.extra;
10436
+ constructor(config) {
10437
+ this.value = config.value;
10438
+ this.label = config.label;
10439
+ this.extra = config.extra;
12916
10440
  }
12917
10441
  }
12918
10442
  var Enum = {
@@ -12951,20 +10475,6 @@ var Enum = {
12951
10475
  return enumObj;
12952
10476
  }
12953
10477
  };
12954
- // src/common/image/index.ts
12955
- import axios6 from "axios";
12956
- async function imageToBase64(url2) {
12957
- try {
12958
- const response = await axios6.get(url2, {
12959
- responseType: "arraybuffer"
12960
- });
12961
- const base64String = Buffer.from(response.data).toString("base64");
12962
- return `data:image/*;base64,${base64String}`;
12963
- } catch (error) {
12964
- console.error("Failed to fetch the image:", error);
12965
- throw error;
12966
- }
12967
- }
12968
10478
  // src/common/other/index.ts
12969
10479
  function getPublicUrl(objectKey) {
12970
10480
  if (!objectKey) {
@@ -12978,6 +10488,41 @@ function getPublicUrl(objectKey) {
12978
10488
  const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
12979
10489
  return `${baseUrl}${key2}`;
12980
10490
  }
10491
+ // src/common/antd/index.ts
10492
+ var options2valueEnum = (options) => {
10493
+ return (options || []).reduce((acc, cur) => {
10494
+ acc[cur] = { text: cur };
10495
+ return acc;
10496
+ }, {});
10497
+ };
10498
+ var optionsToEnum = (options, text, key2) => {
10499
+ return options.reduce((acc, cur) => {
10500
+ acc[cur[key2]] = {
10501
+ text: cur[text]
10502
+ };
10503
+ return acc;
10504
+ }, {});
10505
+ };
10506
+ var transformOptions = (inputArray) => {
10507
+ if (!inputArray?.length) {
10508
+ return [];
10509
+ }
10510
+ return inputArray.map((item) => {
10511
+ if (typeof item === "string") {
10512
+ return { label: item, value: item };
10513
+ }
10514
+ return item;
10515
+ });
10516
+ };
10517
+ var getColumns = (dataSource) => {
10518
+ if (!Array.isArray(dataSource)) {
10519
+ return [];
10520
+ }
10521
+ return Object.keys(dataSource?.[0] || {}).map((item) => ({
10522
+ title: item,
10523
+ dataIndex: item
10524
+ }));
10525
+ };
12981
10526
  // src/common/dayjs/index.ts
12982
10527
  import dayjs from "dayjs";
12983
10528
  import isBetween from "dayjs/plugin/isBetween";
@@ -13007,15 +10552,6 @@ var Timezone;
13007
10552
  Timezone2["EuropeLondon"] = "Europe/London";
13008
10553
  Timezone2["EuropeBerlin"] = "Europe/Berlin";
13009
10554
  })(Timezone ||= {});
13010
- var initChinaDayjs = () => {
13011
- dayjs.locale("zh-cn");
13012
- dayjs.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
13013
- dayjs.updateLocale("zh-cn", {
13014
- weekStart: 1
13015
- });
13016
- return dayjs;
13017
- };
13018
- var chinaDayjs = initChinaDayjs();
13019
10555
  var dayjs_default = dayjs;
13020
10556
  // src/node/oss/index.ts
13021
10557
  var exports_oss = {};
@@ -13174,10 +10710,10 @@ var transporter = nodemailer.createTransport({
13174
10710
  secure: true,
13175
10711
  auth: authMap.gmail
13176
10712
  });
13177
- var send = (config2) => {
10713
+ var send = (config) => {
13178
10714
  return transporter.sendMail({
13179
10715
  from: authMap.gmail.user,
13180
- ...config2
10716
+ ...config
13181
10717
  });
13182
10718
  };
13183
10719
  // src/node/file/index.ts
@@ -13189,7 +10725,7 @@ __export(exports_file, {
13189
10725
  downloadFile: () => downloadFile
13190
10726
  });
13191
10727
  import fs from "fs-extra";
13192
- import axios7 from "axios";
10728
+ import axios6 from "axios";
13193
10729
  import url2 from "url";
13194
10730
  import * as path2 from "path";
13195
10731
  import crypto2 from "crypto";
@@ -13242,23 +10778,14 @@ var getMimeType = (fileName) => {
13242
10778
  }
13243
10779
  };
13244
10780
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
13245
- try {
13246
- const data = await fs.readFile(filePath, "utf8");
13247
- if (replacement && data.includes(replacement)) {
13248
- console.error(`已替换过:${filePath}`);
13249
- return;
13250
- }
13251
- if (!data.includes(targetContent)) {
13252
- console.error(`不包含目标内容:${targetContent}`);
13253
- throw new Error(`不包含目标内容:${targetContent}`);
13254
- }
13255
- const updatedData = data.replace(new RegExp(targetContent, "g"), replacement);
13256
- await fs.writeFile(filePath, updatedData, "utf8");
13257
- console.log(`成功替换文件中的内容!`);
13258
- } catch (err) {
13259
- console.error(`处理文件时发生错误:${err}`);
13260
- throw err;
10781
+ const data = await fs.readFile(filePath, "utf8");
10782
+ if (!data.includes(targetContent)) {
10783
+ throw new Error(`未找到目标内容:${targetContent}`);
13261
10784
  }
10785
+ const updatedData = data.replaceAll(targetContent, replacement);
10786
+ if (updatedData === data)
10787
+ return;
10788
+ await fs.writeFile(filePath, updatedData, "utf8");
13262
10789
  };
13263
10790
  var downloadFile = async (httpUrl, outputPath) => {
13264
10791
  try {
@@ -13270,7 +10797,7 @@ var downloadFile = async (httpUrl, outputPath) => {
13270
10797
  }
13271
10798
  outputPath = ".tmp/" + decodeURIComponent(fileName);
13272
10799
  }
13273
- const response = await axios7({
10800
+ const response = await axios6({
13274
10801
  url: httpUrl,
13275
10802
  method: "get",
13276
10803
  responseType: "stream"
@@ -13287,7 +10814,7 @@ var downloadFile = async (httpUrl, outputPath) => {
13287
10814
  throw error;
13288
10815
  }
13289
10816
  };
13290
- var generateUniqueFileName2 = (originalName = "") => {
10817
+ var generateUniqueFileName = (originalName = "") => {
13291
10818
  const ext = path2.extname(originalName);
13292
10819
  const nameWithoutExt = path2.basename(originalName, ext);
13293
10820
  const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
@@ -13307,7 +10834,7 @@ var processFile = async (params) => {
13307
10834
  throw new Error("当类型为 url 时,file 必须是字符串");
13308
10835
  }
13309
10836
  try {
13310
- const response = await axios7.get(file, { responseType: "arraybuffer" });
10837
+ const response = await axios6.get(file, { responseType: "arraybuffer" });
13311
10838
  buffer = Buffer.from(response.data);
13312
10839
  } catch (error) {
13313
10840
  throw new Error(`无法从 URL 下载文件: ${error}`);
@@ -13344,7 +10871,7 @@ var processFile = async (params) => {
13344
10871
  }
13345
10872
  const size = buffer.length;
13346
10873
  const hash = crypto2.createHash("md5").update(buffer).digest("hex");
13347
- const { finalFileName, ext } = generateUniqueFileName2(originalName);
10874
+ const { finalFileName, ext } = generateUniqueFileName(originalName);
13348
10875
  if (!mimeType) {
13349
10876
  mimeType = getMimeType(finalFileName);
13350
10877
  }
@@ -13363,7 +10890,6 @@ var processFile = async (params) => {
13363
10890
  var _ = import_lodash.default;
13364
10891
  export {
13365
10892
  exports_external as z,
13366
- watch,
13367
10893
  voidType as void,
13368
10894
  util,
13369
10895
  unknownType as unknown,
@@ -13371,34 +10897,31 @@ export {
13371
10897
  undefinedType as undefined,
13372
10898
  tupleType as tuple,
13373
10899
  effectsType as transformer,
13374
- toString,
10900
+ transformOptions,
13375
10901
  symbolType as symbol,
13376
10902
  stringType as string,
13377
10903
  strictObjectType as strictObject,
13378
- shuffleArray,
13379
10904
  setErrorMap,
13380
10905
  setType as set,
10906
+ safeJsonParse,
13381
10907
  retryPromise,
13382
10908
  replaceByVariables,
13383
10909
  replaceByRules,
13384
- replaceAll,
13385
10910
  removeSimilarDuplicates,
13386
10911
  recordType as record,
13387
10912
  quotelessJson,
13388
10913
  promiseType as promise,
13389
- printConsoleLog,
13390
10914
  preprocessType as preprocess,
13391
10915
  pipelineType as pipeline,
13392
- performDecimalOperation,
13393
10916
  ostring,
13394
10917
  exports_oss as oss,
13395
10918
  optionsToEnum,
10919
+ options2valueEnum,
13396
10920
  optionalType as optional,
13397
10921
  onumber,
13398
10922
  oboolean,
13399
10923
  objectUtil,
13400
10924
  objectType as object,
13401
- numberWithCommas,
13402
10925
  numberType as number,
13403
10926
  nullableType as nullable,
13404
10927
  nullType as null,
@@ -13408,44 +10931,34 @@ export {
13408
10931
  mapType as map,
13409
10932
  makeIssue,
13410
10933
  exports_mail as mail,
10934
+ logNetwork,
13411
10935
  literalType as literal,
13412
- limitDecimals,
13413
10936
  levenshteinDistance,
13414
10937
  lazyType as lazy,
13415
10938
  late,
13416
- jsonParse,
13417
10939
  default3 as json5,
13418
- isValidNumber,
13419
10940
  isValid,
13420
- isJson,
10941
+ isJsonObject,
13421
10942
  isDirty,
13422
10943
  isAsync,
13423
10944
  isAborted,
13424
10945
  intersectionType as intersection,
13425
10946
  instanceOfType as instanceof,
13426
- initChinaDayjs,
13427
- imageToBase64,
10947
+ hexToRgba,
13428
10948
  getType,
13429
- getTotal,
13430
10949
  getStrLength,
13431
10950
  getSliceStr,
13432
10951
  getRandomString,
13433
- getRandomNum,
13434
10952
  getRandomColor,
13435
10953
  getPublicUrl,
13436
- getProxyUrl,
13437
10954
  getParsedType,
13438
- getLength,
13439
10955
  getErrorMap,
13440
- getCookie,
10956
+ getColumns,
13441
10957
  getChineseByStr,
13442
- getChinese,
13443
- generateUniqueFileName,
13444
10958
  generateAlphabetArray,
13445
10959
  functionType as function,
13446
10960
  default5 as fs,
13447
- formatFileSize,
13448
- findItem,
10961
+ findAttr,
13449
10962
  filterParams,
13450
10963
  exports_file as file,
13451
10964
  executePromise,
@@ -13461,7 +10974,6 @@ export {
13461
10974
  exports_cron as cron,
13462
10975
  default4 as consola,
13463
10976
  coerce,
13464
- chinaDayjs,
13465
10977
  cheerio,
13466
10978
  calcJsText,
13467
10979
  booleanType as boolean,
@@ -13469,7 +10981,6 @@ export {
13469
10981
  default2 as axios,
13470
10982
  arrayType as array,
13471
10983
  anyType as any,
13472
- amount,
13473
10984
  exports_ai as ai,
13474
10985
  addIssueToContext,
13475
10986
  _,