@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.cjs.js CHANGED
@@ -61,13 +61,13 @@ var __export = (target, all) => {
61
61
  });
62
62
  };
63
63
 
64
- // ../../node_modules/.bun/lodash@4.18.1/node_modules/lodash/lodash.js
64
+ // ../../node_modules/lodash/lodash.js
65
65
  var require_lodash = __commonJS((exports2, module2) => {
66
66
  (function() {
67
67
  var undefined2;
68
- var VERSION = "4.18.1";
68
+ var VERSION = "4.17.21";
69
69
  var LARGE_ARRAY_SIZE = 200;
70
- 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`";
70
+ 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`";
71
71
  var HASH_UNDEFINED = "__lodash_hash_undefined__";
72
72
  var MAX_MEMOIZE_SIZE = 500;
73
73
  var PLACEHOLDER = "__lodash_placeholder__";
@@ -1942,21 +1942,8 @@ var require_lodash = __commonJS((exports2, module2) => {
1942
1942
  }
1943
1943
  function baseUnset(object, path) {
1944
1944
  path = castPath(path, object);
1945
- var index = -1, length = path.length;
1946
- if (!length) {
1947
- return true;
1948
- }
1949
- while (++index < length) {
1950
- var key = toKey(path[index]);
1951
- if (key === "__proto__" && !hasOwnProperty.call(object, "__proto__")) {
1952
- return false;
1953
- }
1954
- if ((key === "constructor" || key === "prototype") && index < length - 1) {
1955
- return false;
1956
- }
1957
- }
1958
- var obj = parent(object, path);
1959
- return obj == null || delete obj[toKey(last(path))];
1945
+ object = parent(object, path);
1946
+ return object == null || delete object[toKey(last(path))];
1960
1947
  }
1961
1948
  function baseUpdate(object, path, updater, customizer) {
1962
1949
  return baseSet(object, path, updater(baseGet(object, path)), customizer);
@@ -3259,7 +3246,7 @@ var require_lodash = __commonJS((exports2, module2) => {
3259
3246
  var index = -1, length = pairs == null ? 0 : pairs.length, result2 = {};
3260
3247
  while (++index < length) {
3261
3248
  var pair = pairs[index];
3262
- baseAssignValue(result2, pair[0], pair[1]);
3249
+ result2[pair[0]] = pair[1];
3263
3250
  }
3264
3251
  return result2;
3265
3252
  }
@@ -4096,7 +4083,7 @@ var require_lodash = __commonJS((exports2, module2) => {
4096
4083
  var tag = baseGetTag(value);
4097
4084
  return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject(value);
4098
4085
  }
4099
- function isFinite2(value) {
4086
+ function isFinite(value) {
4100
4087
  return typeof value == "number" && nativeIsFinite(value);
4101
4088
  }
4102
4089
  function isFunction(value) {
@@ -4127,7 +4114,7 @@ var require_lodash = __commonJS((exports2, module2) => {
4127
4114
  customizer = typeof customizer == "function" ? customizer : undefined2;
4128
4115
  return baseIsMatch(object, source, getMatchData(source), customizer);
4129
4116
  }
4130
- function isNaN2(value) {
4117
+ function isNaN(value) {
4131
4118
  return isNumber(value) && value != +value;
4132
4119
  }
4133
4120
  function isNative(value) {
@@ -4643,13 +4630,8 @@ var require_lodash = __commonJS((exports2, module2) => {
4643
4630
  options = undefined2;
4644
4631
  }
4645
4632
  string = toString(string);
4646
- options = assignWith({}, options, settings, customDefaultsAssignIn);
4647
- var imports = assignWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
4648
- arrayEach(importsKeys, function(key) {
4649
- if (reForbiddenIdentifierChars.test(key)) {
4650
- throw new Error2(INVALID_TEMPL_IMPORTS_ERROR_TEXT);
4651
- }
4652
- });
4633
+ options = assignInWith({}, options, settings, customDefaultsAssignIn);
4634
+ var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = keys(imports), importsValues = baseValues(imports, importsKeys);
4653
4635
  var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '";
4654
4636
  var reDelimiters = RegExp2((options.escape || reNoMatch).source + "|" + interpolate.source + "|" + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + "|" + (options.evaluate || reNoMatch).source + "|$", "g");
4655
4637
  var sourceURL = "//# sourceURL=" + (hasOwnProperty.call(options, "sourceURL") ? (options.sourceURL + "").replace(/\s/g, " ") : "lodash.templateSources[" + ++templateCounter + "]") + `
@@ -4791,7 +4773,7 @@ __p += '`;
4791
4773
  }
4792
4774
  return result2 + omission;
4793
4775
  }
4794
- function unescape2(string) {
4776
+ function unescape(string) {
4795
4777
  string = toString(string);
4796
4778
  return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, unescapeHtmlChar) : string;
4797
4779
  }
@@ -5215,14 +5197,14 @@ __p += '`;
5215
5197
  lodash.isEqual = isEqual;
5216
5198
  lodash.isEqualWith = isEqualWith;
5217
5199
  lodash.isError = isError;
5218
- lodash.isFinite = isFinite2;
5200
+ lodash.isFinite = isFinite;
5219
5201
  lodash.isFunction = isFunction;
5220
5202
  lodash.isInteger = isInteger;
5221
5203
  lodash.isLength = isLength;
5222
5204
  lodash.isMap = isMap;
5223
5205
  lodash.isMatch = isMatch;
5224
5206
  lodash.isMatchWith = isMatchWith;
5225
- lodash.isNaN = isNaN2;
5207
+ lodash.isNaN = isNaN;
5226
5208
  lodash.isNative = isNative;
5227
5209
  lodash.isNil = isNil;
5228
5210
  lodash.isNull = isNull;
@@ -5304,7 +5286,7 @@ __p += '`;
5304
5286
  lodash.trimEnd = trimEnd;
5305
5287
  lodash.trimStart = trimStart;
5306
5288
  lodash.truncate = truncate;
5307
- lodash.unescape = unescape2;
5289
+ lodash.unescape = unescape;
5308
5290
  lodash.uniqueId = uniqueId;
5309
5291
  lodash.upperCase = upperCase;
5310
5292
  lodash.upperFirst = upperFirst;
@@ -5499,7 +5481,6 @@ __p += '`;
5499
5481
  var exports_node = {};
5500
5482
  __export(exports_node, {
5501
5483
  z: () => exports_external,
5502
- watch: () => watch,
5503
5484
  void: () => voidType,
5504
5485
  util: () => util,
5505
5486
  unknown: () => unknownType,
@@ -5507,34 +5488,31 @@ __export(exports_node, {
5507
5488
  undefined: () => undefinedType,
5508
5489
  tuple: () => tupleType,
5509
5490
  transformer: () => effectsType,
5510
- toString: () => toString,
5491
+ transformOptions: () => transformOptions,
5511
5492
  symbol: () => symbolType,
5512
5493
  string: () => stringType,
5513
5494
  strictObject: () => strictObjectType,
5514
- shuffleArray: () => shuffleArray,
5515
5495
  setErrorMap: () => setErrorMap,
5516
5496
  set: () => setType,
5497
+ safeJsonParse: () => safeJsonParse,
5517
5498
  retryPromise: () => retryPromise,
5518
5499
  replaceByVariables: () => replaceByVariables,
5519
5500
  replaceByRules: () => replaceByRules,
5520
- replaceAll: () => replaceAll,
5521
5501
  removeSimilarDuplicates: () => removeSimilarDuplicates,
5522
5502
  record: () => recordType,
5523
5503
  quotelessJson: () => quotelessJson,
5524
5504
  promise: () => promiseType,
5525
- printConsoleLog: () => printConsoleLog,
5526
5505
  preprocess: () => preprocessType,
5527
5506
  pipeline: () => pipelineType,
5528
- performDecimalOperation: () => performDecimalOperation,
5529
5507
  ostring: () => ostring,
5530
5508
  oss: () => exports_oss,
5531
5509
  optionsToEnum: () => optionsToEnum,
5510
+ options2valueEnum: () => options2valueEnum,
5532
5511
  optional: () => optionalType,
5533
5512
  onumber: () => onumber,
5534
5513
  oboolean: () => oboolean,
5535
5514
  objectUtil: () => objectUtil,
5536
5515
  object: () => objectType,
5537
- numberWithCommas: () => numberWithCommas,
5538
5516
  number: () => numberType,
5539
5517
  nullable: () => nullableType,
5540
5518
  null: () => nullType,
@@ -5544,44 +5522,34 @@ __export(exports_node, {
5544
5522
  map: () => mapType,
5545
5523
  makeIssue: () => makeIssue,
5546
5524
  mail: () => exports_mail,
5525
+ logNetwork: () => logNetwork,
5547
5526
  literal: () => literalType,
5548
- limitDecimals: () => limitDecimals,
5549
5527
  levenshteinDistance: () => levenshteinDistance,
5550
5528
  lazy: () => lazyType,
5551
5529
  late: () => late,
5552
- jsonParse: () => jsonParse,
5553
5530
  json5: () => import_json53.default,
5554
- isValidNumber: () => isValidNumber,
5555
5531
  isValid: () => isValid,
5556
- isJson: () => isJson,
5532
+ isJsonObject: () => isJsonObject,
5557
5533
  isDirty: () => isDirty,
5558
5534
  isAsync: () => isAsync,
5559
5535
  isAborted: () => isAborted,
5560
5536
  intersection: () => intersectionType,
5561
5537
  instanceof: () => instanceOfType,
5562
- initChinaDayjs: () => initChinaDayjs,
5563
- imageToBase64: () => imageToBase64,
5538
+ hexToRgba: () => hexToRgba,
5564
5539
  getType: () => getType,
5565
- getTotal: () => getTotal,
5566
5540
  getStrLength: () => getStrLength,
5567
5541
  getSliceStr: () => getSliceStr,
5568
5542
  getRandomString: () => getRandomString,
5569
- getRandomNum: () => getRandomNum,
5570
5543
  getRandomColor: () => getRandomColor,
5571
5544
  getPublicUrl: () => getPublicUrl,
5572
- getProxyUrl: () => getProxyUrl,
5573
5545
  getParsedType: () => getParsedType,
5574
- getLength: () => getLength,
5575
5546
  getErrorMap: () => getErrorMap,
5576
- getCookie: () => getCookie,
5547
+ getColumns: () => getColumns,
5577
5548
  getChineseByStr: () => getChineseByStr,
5578
- getChinese: () => getChinese,
5579
- generateUniqueFileName: () => generateUniqueFileName,
5580
5549
  generateAlphabetArray: () => generateAlphabetArray,
5581
5550
  function: () => functionType,
5582
5551
  fs: () => import_fs_extra2.default,
5583
- formatFileSize: () => formatFileSize,
5584
- findItem: () => findItem,
5552
+ findAttr: () => findAttr,
5585
5553
  filterParams: () => filterParams,
5586
5554
  file: () => exports_file,
5587
5555
  executePromise: () => executePromise,
@@ -5597,15 +5565,13 @@ __export(exports_node, {
5597
5565
  cron: () => exports_cron,
5598
5566
  consola: () => import_consola.default,
5599
5567
  coerce: () => coerce,
5600
- chinaDayjs: () => chinaDayjs,
5601
5568
  cheerio: () => cheerio,
5602
5569
  calcJsText: () => calcJsText,
5603
5570
  boolean: () => booleanType,
5604
5571
  bigint: () => bigIntType,
5605
- axios: () => import_axios11.default,
5572
+ axios: () => import_axios10.default,
5606
5573
  array: () => arrayType,
5607
5574
  any: () => anyType,
5608
- amount: () => amount,
5609
5575
  ai: () => exports_ai,
5610
5576
  addIssueToContext: () => addIssueToContext,
5611
5577
  _: () => _,
@@ -5665,7 +5631,7 @@ __export(exports_node, {
5665
5631
  });
5666
5632
  module.exports = __toCommonJS(exports_node);
5667
5633
 
5668
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
5634
+ // ../../node_modules/zod/v3/external.js
5669
5635
  var exports_external = {};
5670
5636
  __export(exports_external, {
5671
5637
  void: () => voidType,
@@ -5777,7 +5743,7 @@ __export(exports_external, {
5777
5743
  BRAND: () => BRAND
5778
5744
  });
5779
5745
 
5780
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
5746
+ // ../../node_modules/zod/v3/helpers/util.js
5781
5747
  var util;
5782
5748
  (function(util2) {
5783
5749
  util2.assertEqual = (_) => {};
@@ -5908,7 +5874,7 @@ var getParsedType = (data) => {
5908
5874
  }
5909
5875
  };
5910
5876
 
5911
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
5877
+ // ../../node_modules/zod/v3/ZodError.js
5912
5878
  var ZodIssueCode = util.arrayToEnum([
5913
5879
  "invalid_type",
5914
5880
  "invalid_literal",
@@ -6027,7 +5993,7 @@ ZodError.create = (issues) => {
6027
5993
  return error;
6028
5994
  };
6029
5995
 
6030
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
5996
+ // ../../node_modules/zod/v3/locales/en.js
6031
5997
  var errorMap = (issue, _ctx) => {
6032
5998
  let message;
6033
5999
  switch (issue.code) {
@@ -6130,7 +6096,7 @@ var errorMap = (issue, _ctx) => {
6130
6096
  };
6131
6097
  var en_default = errorMap;
6132
6098
 
6133
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
6099
+ // ../../node_modules/zod/v3/errors.js
6134
6100
  var overrideErrorMap = en_default;
6135
6101
  function setErrorMap(map) {
6136
6102
  overrideErrorMap = map;
@@ -6138,7 +6104,7 @@ function setErrorMap(map) {
6138
6104
  function getErrorMap() {
6139
6105
  return overrideErrorMap;
6140
6106
  }
6141
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
6107
+ // ../../node_modules/zod/v3/helpers/parseUtil.js
6142
6108
  var makeIssue = (params) => {
6143
6109
  const { data, path, errorMaps, issueData } = params;
6144
6110
  const fullPath = [...path, ...issueData.path || []];
@@ -6244,14 +6210,14 @@ var isAborted = (x) => x.status === "aborted";
6244
6210
  var isDirty = (x) => x.status === "dirty";
6245
6211
  var isValid = (x) => x.status === "valid";
6246
6212
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
6247
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
6213
+ // ../../node_modules/zod/v3/helpers/errorUtil.js
6248
6214
  var errorUtil;
6249
6215
  (function(errorUtil2) {
6250
6216
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
6251
6217
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
6252
6218
  })(errorUtil || (errorUtil = {}));
6253
6219
 
6254
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
6220
+ // ../../node_modules/zod/v3/types.js
6255
6221
  class ParseInputLazyPath {
6256
6222
  constructor(parent, value, path, key) {
6257
6223
  this._cachedPath = [];
@@ -9640,7 +9606,7 @@ var coerce = {
9640
9606
  var NEVER = INVALID;
9641
9607
  // src/node.ts
9642
9608
  var cheerio = __toESM(require("cheerio"));
9643
- var import_axios11 = __toESM(require("axios"));
9609
+ var import_axios10 = __toESM(require("axios"));
9644
9610
  var import_json53 = __toESM(require("json5"));
9645
9611
  var import_consola = __toESM(require("consola"));
9646
9612
  var import_fs_extra2 = __toESM(require("fs-extra"));
@@ -10431,16 +10397,6 @@ var getStrLength = (value) => {
10431
10397
  const chineseLength = getChineseByStr(value).length;
10432
10398
  return value.length - chineseLength + chineseLength * 2;
10433
10399
  };
10434
- var replaceAll = (str, searchValue, replaceValue) => {
10435
- if (!str || !searchValue || !replaceValue) {
10436
- return str || "";
10437
- }
10438
- str = str.replace(searchValue, replaceValue);
10439
- if (!str.includes(searchValue)) {
10440
- return str;
10441
- }
10442
- return replaceAll(str, searchValue, replaceValue);
10443
- };
10444
10400
  var replaceByRules = (str, rules) => {
10445
10401
  rules.forEach(([searchValue, replaceValue]) => {
10446
10402
  str = str.replaceAll(searchValue, replaceValue);
@@ -10459,67 +10415,46 @@ var replaceByVariables = (prompt, variables) => {
10459
10415
  var getType = (value) => {
10460
10416
  return Object.prototype.toString.call(value).slice(8, -1);
10461
10417
  };
10462
- var amount = (str) => {
10463
- const reg = /(?=(?!\b)(\d{3})+$)/g;
10464
- return str.replace(reg, ",");
10465
- };
10466
- var jsonParse = (value) => {
10467
- if (typeof value === "object") {
10468
- return value;
10418
+ var safeJsonParse = (value, fallback) => {
10419
+ if (typeof value !== "string") {
10420
+ return value ?? fallback;
10469
10421
  }
10470
10422
  try {
10471
10423
  return JSON.parse(value);
10472
- } catch (err) {
10473
- return {};
10424
+ } catch {
10425
+ return fallback;
10474
10426
  }
10475
10427
  };
10476
- var isJson = (str) => {
10428
+ var isJsonObject = (str) => {
10477
10429
  try {
10478
- if (getType(JSON.parse(str)) === "Object") {
10479
- return true;
10480
- }
10481
- } catch (e) {}
10482
- return false;
10483
- };
10484
- var toString = (value) => {
10485
- return Object.prototype.toString.call(value).slice(8, -1) === "object" ? JSON.stringify(value) : String(value);
10430
+ const val = JSON.parse(str);
10431
+ return typeof val === "object" && val !== null && !Array.isArray(val);
10432
+ } catch {
10433
+ return false;
10434
+ }
10486
10435
  };
10487
10436
  var getRandomColor = () => {
10488
- const color = Math.floor(Math.random() * 16777215).toString(16);
10489
- if (color.length === 6) {
10490
- return color;
10491
- } else {
10492
- return getRandomColor();
10493
- }
10437
+ const rand = () => Math.floor(Math.random() * 156 + 50);
10438
+ return `rgb(${rand()},${rand()},${rand()})`;
10494
10439
  };
10495
- var getRandomString = (length = 4) => {
10496
- return Math.random().toString(36).substr(2, length);
10440
+ var hexToRgba = (hexColor, a = 1) => {
10441
+ let red = parseInt(hexColor.substr(1, 2), 16);
10442
+ let green = parseInt(hexColor.substr(3, 2), 16);
10443
+ let blue = parseInt(hexColor.substr(5, 2), 16);
10444
+ return {
10445
+ nums: { red, green, blue },
10446
+ text: `rgba(${red}, ${green}, ${blue}, ${a})`
10447
+ };
10497
10448
  };
10498
- var getChinese = (str) => {
10499
- if (str == null || str === "") {
10500
- return "";
10501
- }
10502
- const res = str.match(/[\u4e00-\u9fa5]/g);
10503
- if (!res) {
10504
- return "";
10505
- }
10506
- return res.join("");
10449
+ var getRandomString = (length = 4) => {
10450
+ return Math.random().toString(36).substring(2, 2 + length);
10507
10451
  };
10508
10452
  var getSliceStr = (str, before, after) => {
10509
- return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
10510
- };
10511
- var getProxyUrl = (url2) => {
10512
- const beforeUrl = "https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=";
10513
- return beforeUrl + url2;
10514
- };
10515
- var getLength = (value) => {
10516
- const chineseLength = getChinese(value).length;
10517
- return value.length - chineseLength + chineseLength * 2;
10518
- };
10519
- var getCookie = (name) => {
10520
- const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
10521
- const arr = document.cookie.match(reg);
10522
- return arr ? unescape(arr[2]) : null;
10453
+ const start = str.indexOf(before);
10454
+ const end = str.indexOf(after, start + before.length);
10455
+ if (start === -1 || end === -1)
10456
+ return "";
10457
+ return str.slice(start + before.length, end);
10523
10458
  };
10524
10459
  var generateAlphabetArray = (n) => {
10525
10460
  return Array.from({ length: n }, (_, i) => String.fromCharCode(97 + i));
@@ -10543,2400 +10478,8 @@ var levenshteinDistance = (a, b) => {
10543
10478
  }
10544
10479
  return matrix[b.length][a.length];
10545
10480
  };
10546
- var generateUniqueFileName = (name) => {
10547
- const match = name.match(/^(.*?)(\.[^.]*$|$)/);
10548
- if (match) {
10549
- const namePart = match[1];
10550
- const extensionPart = match[2];
10551
- if (extensionPart) {
10552
- return `${namePart}_${Date.now()}${extensionPart}`;
10553
- } else {
10554
- return `${namePart}_${Date.now()}.dat`;
10555
- }
10556
- }
10557
- throw new Error("Invalid filename format.");
10558
- };
10559
-
10560
- // ../../node_modules/.bun/decimal.js@10.6.0/node_modules/decimal.js/decimal.mjs
10561
- /*!
10562
- * decimal.js v10.6.0
10563
- * An arbitrary-precision Decimal type for JavaScript.
10564
- * https://github.com/MikeMcl/decimal.js
10565
- * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
10566
- * MIT Licence
10567
- */
10568
- var EXP_LIMIT = 9000000000000000;
10569
- var MAX_DIGITS = 1e9;
10570
- var NUMERALS = "0123456789abcdef";
10571
- var LN10 = "2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058";
10572
- var PI = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789";
10573
- var DEFAULTS = {
10574
- precision: 20,
10575
- rounding: 4,
10576
- modulo: 1,
10577
- toExpNeg: -7,
10578
- toExpPos: 21,
10579
- minE: -EXP_LIMIT,
10580
- maxE: EXP_LIMIT,
10581
- crypto: false
10582
- };
10583
- var inexact;
10584
- var quadrant;
10585
- var external2 = true;
10586
- var decimalError = "[DecimalError] ";
10587
- var invalidArgument = decimalError + "Invalid argument: ";
10588
- var precisionLimitExceeded = decimalError + "Precision limit exceeded";
10589
- var cryptoUnavailable = decimalError + "crypto unavailable";
10590
- var tag = "[object Decimal]";
10591
- var mathfloor = Math.floor;
10592
- var mathpow = Math.pow;
10593
- var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
10594
- var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
10595
- var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
10596
- var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
10597
- var BASE = 1e7;
10598
- var LOG_BASE = 7;
10599
- var MAX_SAFE_INTEGER = 9007199254740991;
10600
- var LN10_PRECISION = LN10.length - 1;
10601
- var PI_PRECISION = PI.length - 1;
10602
- var P = { toStringTag: tag };
10603
- P.absoluteValue = P.abs = function() {
10604
- var x = new this.constructor(this);
10605
- if (x.s < 0)
10606
- x.s = 1;
10607
- return finalise(x);
10608
- };
10609
- P.ceil = function() {
10610
- return finalise(new this.constructor(this), this.e + 1, 2);
10611
- };
10612
- P.clampedTo = P.clamp = function(min, max) {
10613
- var k, x = this, Ctor = x.constructor;
10614
- min = new Ctor(min);
10615
- max = new Ctor(max);
10616
- if (!min.s || !max.s)
10617
- return new Ctor(NaN);
10618
- if (min.gt(max))
10619
- throw Error(invalidArgument + max);
10620
- k = x.cmp(min);
10621
- return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
10622
- };
10623
- P.comparedTo = P.cmp = function(y) {
10624
- var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
10625
- if (!xd || !yd) {
10626
- return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
10627
- }
10628
- if (!xd[0] || !yd[0])
10629
- return xd[0] ? xs : yd[0] ? -ys : 0;
10630
- if (xs !== ys)
10631
- return xs;
10632
- if (x.e !== y.e)
10633
- return x.e > y.e ^ xs < 0 ? 1 : -1;
10634
- xdL = xd.length;
10635
- ydL = yd.length;
10636
- for (i = 0, j = xdL < ydL ? xdL : ydL;i < j; ++i) {
10637
- if (xd[i] !== yd[i])
10638
- return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
10639
- }
10640
- return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
10641
- };
10642
- P.cosine = P.cos = function() {
10643
- var pr, rm, x = this, Ctor = x.constructor;
10644
- if (!x.d)
10645
- return new Ctor(NaN);
10646
- if (!x.d[0])
10647
- return new Ctor(1);
10648
- pr = Ctor.precision;
10649
- rm = Ctor.rounding;
10650
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
10651
- Ctor.rounding = 1;
10652
- x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
10653
- Ctor.precision = pr;
10654
- Ctor.rounding = rm;
10655
- return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
10656
- };
10657
- P.cubeRoot = P.cbrt = function() {
10658
- var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
10659
- if (!x.isFinite() || x.isZero())
10660
- return new Ctor(x);
10661
- external2 = false;
10662
- s = x.s * mathpow(x.s * x, 1 / 3);
10663
- if (!s || Math.abs(s) == 1 / 0) {
10664
- n = digitsToString(x.d);
10665
- e = x.e;
10666
- if (s = (e - n.length + 1) % 3)
10667
- n += s == 1 || s == -2 ? "0" : "00";
10668
- s = mathpow(n, 1 / 3);
10669
- e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
10670
- if (s == 1 / 0) {
10671
- n = "5e" + e;
10672
- } else {
10673
- n = s.toExponential();
10674
- n = n.slice(0, n.indexOf("e") + 1) + e;
10675
- }
10676
- r = new Ctor(n);
10677
- r.s = x.s;
10678
- } else {
10679
- r = new Ctor(s.toString());
10680
- }
10681
- sd = (e = Ctor.precision) + 3;
10682
- for (;; ) {
10683
- t = r;
10684
- t3 = t.times(t).times(t);
10685
- t3plusx = t3.plus(x);
10686
- r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
10687
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
10688
- n = n.slice(sd - 3, sd + 1);
10689
- if (n == "9999" || !rep && n == "4999") {
10690
- if (!rep) {
10691
- finalise(t, e + 1, 0);
10692
- if (t.times(t).times(t).eq(x)) {
10693
- r = t;
10694
- break;
10695
- }
10696
- }
10697
- sd += 4;
10698
- rep = 1;
10699
- } else {
10700
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
10701
- finalise(r, e + 1, 1);
10702
- m = !r.times(r).times(r).eq(x);
10703
- }
10704
- break;
10705
- }
10706
- }
10707
- }
10708
- external2 = true;
10709
- return finalise(r, e, Ctor.rounding, m);
10710
- };
10711
- P.decimalPlaces = P.dp = function() {
10712
- var w, d = this.d, n = NaN;
10713
- if (d) {
10714
- w = d.length - 1;
10715
- n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
10716
- w = d[w];
10717
- if (w)
10718
- for (;w % 10 == 0; w /= 10)
10719
- n--;
10720
- if (n < 0)
10721
- n = 0;
10722
- }
10723
- return n;
10724
- };
10725
- P.dividedBy = P.div = function(y) {
10726
- return divide(this, new this.constructor(y));
10727
- };
10728
- P.dividedToIntegerBy = P.divToInt = function(y) {
10729
- var x = this, Ctor = x.constructor;
10730
- return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
10731
- };
10732
- P.equals = P.eq = function(y) {
10733
- return this.cmp(y) === 0;
10734
- };
10735
- P.floor = function() {
10736
- return finalise(new this.constructor(this), this.e + 1, 3);
10737
- };
10738
- P.greaterThan = P.gt = function(y) {
10739
- return this.cmp(y) > 0;
10740
- };
10741
- P.greaterThanOrEqualTo = P.gte = function(y) {
10742
- var k = this.cmp(y);
10743
- return k == 1 || k === 0;
10744
- };
10745
- P.hyperbolicCosine = P.cosh = function() {
10746
- var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
10747
- if (!x.isFinite())
10748
- return new Ctor(x.s ? 1 / 0 : NaN);
10749
- if (x.isZero())
10750
- return one;
10751
- pr = Ctor.precision;
10752
- rm = Ctor.rounding;
10753
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
10754
- Ctor.rounding = 1;
10755
- len = x.d.length;
10756
- if (len < 32) {
10757
- k = Math.ceil(len / 3);
10758
- n = (1 / tinyPow(4, k)).toString();
10759
- } else {
10760
- k = 16;
10761
- n = "2.3283064365386962890625e-10";
10762
- }
10763
- x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
10764
- var cosh2_x, i = k, d8 = new Ctor(8);
10765
- for (;i--; ) {
10766
- cosh2_x = x.times(x);
10767
- x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
10768
- }
10769
- return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
10770
- };
10771
- P.hyperbolicSine = P.sinh = function() {
10772
- var k, pr, rm, len, x = this, Ctor = x.constructor;
10773
- if (!x.isFinite() || x.isZero())
10774
- return new Ctor(x);
10775
- pr = Ctor.precision;
10776
- rm = Ctor.rounding;
10777
- Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
10778
- Ctor.rounding = 1;
10779
- len = x.d.length;
10780
- if (len < 3) {
10781
- x = taylorSeries(Ctor, 2, x, x, true);
10782
- } else {
10783
- k = 1.4 * Math.sqrt(len);
10784
- k = k > 16 ? 16 : k | 0;
10785
- x = x.times(1 / tinyPow(5, k));
10786
- x = taylorSeries(Ctor, 2, x, x, true);
10787
- var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
10788
- for (;k--; ) {
10789
- sinh2_x = x.times(x);
10790
- x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
10791
- }
10792
- }
10793
- Ctor.precision = pr;
10794
- Ctor.rounding = rm;
10795
- return finalise(x, pr, rm, true);
10796
- };
10797
- P.hyperbolicTangent = P.tanh = function() {
10798
- var pr, rm, x = this, Ctor = x.constructor;
10799
- if (!x.isFinite())
10800
- return new Ctor(x.s);
10801
- if (x.isZero())
10802
- return new Ctor(x);
10803
- pr = Ctor.precision;
10804
- rm = Ctor.rounding;
10805
- Ctor.precision = pr + 7;
10806
- Ctor.rounding = 1;
10807
- return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
10808
- };
10809
- P.inverseCosine = P.acos = function() {
10810
- var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
10811
- if (k !== -1) {
10812
- return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
10813
- }
10814
- if (x.isZero())
10815
- return getPi(Ctor, pr + 4, rm).times(0.5);
10816
- Ctor.precision = pr + 6;
10817
- Ctor.rounding = 1;
10818
- x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
10819
- Ctor.precision = pr;
10820
- Ctor.rounding = rm;
10821
- return x.times(2);
10822
- };
10823
- P.inverseHyperbolicCosine = P.acosh = function() {
10824
- var pr, rm, x = this, Ctor = x.constructor;
10825
- if (x.lte(1))
10826
- return new Ctor(x.eq(1) ? 0 : NaN);
10827
- if (!x.isFinite())
10828
- return new Ctor(x);
10829
- pr = Ctor.precision;
10830
- rm = Ctor.rounding;
10831
- Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
10832
- Ctor.rounding = 1;
10833
- external2 = false;
10834
- x = x.times(x).minus(1).sqrt().plus(x);
10835
- external2 = true;
10836
- Ctor.precision = pr;
10837
- Ctor.rounding = rm;
10838
- return x.ln();
10839
- };
10840
- P.inverseHyperbolicSine = P.asinh = function() {
10841
- var pr, rm, x = this, Ctor = x.constructor;
10842
- if (!x.isFinite() || x.isZero())
10843
- return new Ctor(x);
10844
- pr = Ctor.precision;
10845
- rm = Ctor.rounding;
10846
- Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
10847
- Ctor.rounding = 1;
10848
- external2 = false;
10849
- x = x.times(x).plus(1).sqrt().plus(x);
10850
- external2 = true;
10851
- Ctor.precision = pr;
10852
- Ctor.rounding = rm;
10853
- return x.ln();
10854
- };
10855
- P.inverseHyperbolicTangent = P.atanh = function() {
10856
- var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
10857
- if (!x.isFinite())
10858
- return new Ctor(NaN);
10859
- if (x.e >= 0)
10860
- return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
10861
- pr = Ctor.precision;
10862
- rm = Ctor.rounding;
10863
- xsd = x.sd();
10864
- if (Math.max(xsd, pr) < 2 * -x.e - 1)
10865
- return finalise(new Ctor(x), pr, rm, true);
10866
- Ctor.precision = wpr = xsd - x.e;
10867
- x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
10868
- Ctor.precision = pr + 4;
10869
- Ctor.rounding = 1;
10870
- x = x.ln();
10871
- Ctor.precision = pr;
10872
- Ctor.rounding = rm;
10873
- return x.times(0.5);
10874
- };
10875
- P.inverseSine = P.asin = function() {
10876
- var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
10877
- if (x.isZero())
10878
- return new Ctor(x);
10879
- k = x.abs().cmp(1);
10880
- pr = Ctor.precision;
10881
- rm = Ctor.rounding;
10882
- if (k !== -1) {
10883
- if (k === 0) {
10884
- halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
10885
- halfPi.s = x.s;
10886
- return halfPi;
10887
- }
10888
- return new Ctor(NaN);
10889
- }
10890
- Ctor.precision = pr + 6;
10891
- Ctor.rounding = 1;
10892
- x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
10893
- Ctor.precision = pr;
10894
- Ctor.rounding = rm;
10895
- return x.times(2);
10896
- };
10897
- P.inverseTangent = P.atan = function() {
10898
- var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
10899
- if (!x.isFinite()) {
10900
- if (!x.s)
10901
- return new Ctor(NaN);
10902
- if (pr + 4 <= PI_PRECISION) {
10903
- r = getPi(Ctor, pr + 4, rm).times(0.5);
10904
- r.s = x.s;
10905
- return r;
10906
- }
10907
- } else if (x.isZero()) {
10908
- return new Ctor(x);
10909
- } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
10910
- r = getPi(Ctor, pr + 4, rm).times(0.25);
10911
- r.s = x.s;
10912
- return r;
10913
- }
10914
- Ctor.precision = wpr = pr + 10;
10915
- Ctor.rounding = 1;
10916
- k = Math.min(28, wpr / LOG_BASE + 2 | 0);
10917
- for (i = k;i; --i)
10918
- x = x.div(x.times(x).plus(1).sqrt().plus(1));
10919
- external2 = false;
10920
- j = Math.ceil(wpr / LOG_BASE);
10921
- n = 1;
10922
- x2 = x.times(x);
10923
- r = new Ctor(x);
10924
- px = x;
10925
- for (;i !== -1; ) {
10926
- px = px.times(x2);
10927
- t = r.minus(px.div(n += 2));
10928
- px = px.times(x2);
10929
- r = t.plus(px.div(n += 2));
10930
- if (r.d[j] !== undefined)
10931
- for (i = j;r.d[i] === t.d[i] && i--; )
10932
- ;
10933
- }
10934
- if (k)
10935
- r = r.times(2 << k - 1);
10936
- external2 = true;
10937
- return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
10938
- };
10939
- P.isFinite = function() {
10940
- return !!this.d;
10941
- };
10942
- P.isInteger = P.isInt = function() {
10943
- return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
10944
- };
10945
- P.isNaN = function() {
10946
- return !this.s;
10947
- };
10948
- P.isNegative = P.isNeg = function() {
10949
- return this.s < 0;
10950
- };
10951
- P.isPositive = P.isPos = function() {
10952
- return this.s > 0;
10953
- };
10954
- P.isZero = function() {
10955
- return !!this.d && this.d[0] === 0;
10956
- };
10957
- P.lessThan = P.lt = function(y) {
10958
- return this.cmp(y) < 0;
10959
- };
10960
- P.lessThanOrEqualTo = P.lte = function(y) {
10961
- return this.cmp(y) < 1;
10962
- };
10963
- P.logarithm = P.log = function(base) {
10964
- var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
10965
- if (base == null) {
10966
- base = new Ctor(10);
10967
- isBase10 = true;
10968
- } else {
10969
- base = new Ctor(base);
10970
- d = base.d;
10971
- if (base.s < 0 || !d || !d[0] || base.eq(1))
10972
- return new Ctor(NaN);
10973
- isBase10 = base.eq(10);
10974
- }
10975
- d = arg.d;
10976
- if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
10977
- return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
10978
- }
10979
- if (isBase10) {
10980
- if (d.length > 1) {
10981
- inf = true;
10982
- } else {
10983
- for (k = d[0];k % 10 === 0; )
10984
- k /= 10;
10985
- inf = k !== 1;
10986
- }
10987
- }
10988
- external2 = false;
10989
- sd = pr + guard;
10990
- num = naturalLogarithm(arg, sd);
10991
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10992
- r = divide(num, denominator, sd, 1);
10993
- if (checkRoundingDigits(r.d, k = pr, rm)) {
10994
- do {
10995
- sd += 10;
10996
- num = naturalLogarithm(arg, sd);
10997
- denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
10998
- r = divide(num, denominator, sd, 1);
10999
- if (!inf) {
11000
- if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 100000000000000) {
11001
- r = finalise(r, pr + 1, 0);
11002
- }
11003
- break;
11004
- }
11005
- } while (checkRoundingDigits(r.d, k += 10, rm));
11006
- }
11007
- external2 = true;
11008
- return finalise(r, pr, rm);
11009
- };
11010
- P.minus = P.sub = function(y) {
11011
- var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
11012
- y = new Ctor(y);
11013
- if (!x.d || !y.d) {
11014
- if (!x.s || !y.s)
11015
- y = new Ctor(NaN);
11016
- else if (x.d)
11017
- y.s = -y.s;
11018
- else
11019
- y = new Ctor(y.d || x.s !== y.s ? x : NaN);
11020
- return y;
11021
- }
11022
- if (x.s != y.s) {
11023
- y.s = -y.s;
11024
- return x.plus(y);
11025
- }
11026
- xd = x.d;
11027
- yd = y.d;
11028
- pr = Ctor.precision;
11029
- rm = Ctor.rounding;
11030
- if (!xd[0] || !yd[0]) {
11031
- if (yd[0])
11032
- y.s = -y.s;
11033
- else if (xd[0])
11034
- y = new Ctor(x);
11035
- else
11036
- return new Ctor(rm === 3 ? -0 : 0);
11037
- return external2 ? finalise(y, pr, rm) : y;
11038
- }
11039
- e = mathfloor(y.e / LOG_BASE);
11040
- xe = mathfloor(x.e / LOG_BASE);
11041
- xd = xd.slice();
11042
- k = xe - e;
11043
- if (k) {
11044
- xLTy = k < 0;
11045
- if (xLTy) {
11046
- d = xd;
11047
- k = -k;
11048
- len = yd.length;
11049
- } else {
11050
- d = yd;
11051
- e = xe;
11052
- len = xd.length;
11053
- }
11054
- i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
11055
- if (k > i) {
11056
- k = i;
11057
- d.length = 1;
11058
- }
11059
- d.reverse();
11060
- for (i = k;i--; )
11061
- d.push(0);
11062
- d.reverse();
11063
- } else {
11064
- i = xd.length;
11065
- len = yd.length;
11066
- xLTy = i < len;
11067
- if (xLTy)
11068
- len = i;
11069
- for (i = 0;i < len; i++) {
11070
- if (xd[i] != yd[i]) {
11071
- xLTy = xd[i] < yd[i];
11072
- break;
11073
- }
11074
- }
11075
- k = 0;
11076
- }
11077
- if (xLTy) {
11078
- d = xd;
11079
- xd = yd;
11080
- yd = d;
11081
- y.s = -y.s;
11082
- }
11083
- len = xd.length;
11084
- for (i = yd.length - len;i > 0; --i)
11085
- xd[len++] = 0;
11086
- for (i = yd.length;i > k; ) {
11087
- if (xd[--i] < yd[i]) {
11088
- for (j = i;j && xd[--j] === 0; )
11089
- xd[j] = BASE - 1;
11090
- --xd[j];
11091
- xd[i] += BASE;
11092
- }
11093
- xd[i] -= yd[i];
11094
- }
11095
- for (;xd[--len] === 0; )
11096
- xd.pop();
11097
- for (;xd[0] === 0; xd.shift())
11098
- --e;
11099
- if (!xd[0])
11100
- return new Ctor(rm === 3 ? -0 : 0);
11101
- y.d = xd;
11102
- y.e = getBase10Exponent(xd, e);
11103
- return external2 ? finalise(y, pr, rm) : y;
11104
- };
11105
- P.modulo = P.mod = function(y) {
11106
- var q, x = this, Ctor = x.constructor;
11107
- y = new Ctor(y);
11108
- if (!x.d || !y.s || y.d && !y.d[0])
11109
- return new Ctor(NaN);
11110
- if (!y.d || x.d && !x.d[0]) {
11111
- return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
11112
- }
11113
- external2 = false;
11114
- if (Ctor.modulo == 9) {
11115
- q = divide(x, y.abs(), 0, 3, 1);
11116
- q.s *= y.s;
11117
- } else {
11118
- q = divide(x, y, 0, Ctor.modulo, 1);
11119
- }
11120
- q = q.times(y);
11121
- external2 = true;
11122
- return x.minus(q);
11123
- };
11124
- P.naturalExponential = P.exp = function() {
11125
- return naturalExponential(this);
11126
- };
11127
- P.naturalLogarithm = P.ln = function() {
11128
- return naturalLogarithm(this);
11129
- };
11130
- P.negated = P.neg = function() {
11131
- var x = new this.constructor(this);
11132
- x.s = -x.s;
11133
- return finalise(x);
11134
- };
11135
- P.plus = P.add = function(y) {
11136
- var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
11137
- y = new Ctor(y);
11138
- if (!x.d || !y.d) {
11139
- if (!x.s || !y.s)
11140
- y = new Ctor(NaN);
11141
- else if (!x.d)
11142
- y = new Ctor(y.d || x.s === y.s ? x : NaN);
11143
- return y;
11144
- }
11145
- if (x.s != y.s) {
11146
- y.s = -y.s;
11147
- return x.minus(y);
11148
- }
11149
- xd = x.d;
11150
- yd = y.d;
11151
- pr = Ctor.precision;
11152
- rm = Ctor.rounding;
11153
- if (!xd[0] || !yd[0]) {
11154
- if (!yd[0])
11155
- y = new Ctor(x);
11156
- return external2 ? finalise(y, pr, rm) : y;
11157
- }
11158
- k = mathfloor(x.e / LOG_BASE);
11159
- e = mathfloor(y.e / LOG_BASE);
11160
- xd = xd.slice();
11161
- i = k - e;
11162
- if (i) {
11163
- if (i < 0) {
11164
- d = xd;
11165
- i = -i;
11166
- len = yd.length;
11167
- } else {
11168
- d = yd;
11169
- e = k;
11170
- len = xd.length;
11171
- }
11172
- k = Math.ceil(pr / LOG_BASE);
11173
- len = k > len ? k + 1 : len + 1;
11174
- if (i > len) {
11175
- i = len;
11176
- d.length = 1;
11177
- }
11178
- d.reverse();
11179
- for (;i--; )
11180
- d.push(0);
11181
- d.reverse();
11182
- }
11183
- len = xd.length;
11184
- i = yd.length;
11185
- if (len - i < 0) {
11186
- i = len;
11187
- d = yd;
11188
- yd = xd;
11189
- xd = d;
11190
- }
11191
- for (carry = 0;i; ) {
11192
- carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
11193
- xd[i] %= BASE;
11194
- }
11195
- if (carry) {
11196
- xd.unshift(carry);
11197
- ++e;
11198
- }
11199
- for (len = xd.length;xd[--len] == 0; )
11200
- xd.pop();
11201
- y.d = xd;
11202
- y.e = getBase10Exponent(xd, e);
11203
- return external2 ? finalise(y, pr, rm) : y;
11204
- };
11205
- P.precision = P.sd = function(z) {
11206
- var k, x = this;
11207
- if (z !== undefined && z !== !!z && z !== 1 && z !== 0)
11208
- throw Error(invalidArgument + z);
11209
- if (x.d) {
11210
- k = getPrecision(x.d);
11211
- if (z && x.e + 1 > k)
11212
- k = x.e + 1;
11213
- } else {
11214
- k = NaN;
11215
- }
11216
- return k;
11217
- };
11218
- P.round = function() {
11219
- var x = this, Ctor = x.constructor;
11220
- return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
11221
- };
11222
- P.sine = P.sin = function() {
11223
- var pr, rm, x = this, Ctor = x.constructor;
11224
- if (!x.isFinite())
11225
- return new Ctor(NaN);
11226
- if (x.isZero())
11227
- return new Ctor(x);
11228
- pr = Ctor.precision;
11229
- rm = Ctor.rounding;
11230
- Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
11231
- Ctor.rounding = 1;
11232
- x = sine(Ctor, toLessThanHalfPi(Ctor, x));
11233
- Ctor.precision = pr;
11234
- Ctor.rounding = rm;
11235
- return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
11236
- };
11237
- P.squareRoot = P.sqrt = function() {
11238
- var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
11239
- if (s !== 1 || !d || !d[0]) {
11240
- return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
11241
- }
11242
- external2 = false;
11243
- s = Math.sqrt(+x);
11244
- if (s == 0 || s == 1 / 0) {
11245
- n = digitsToString(d);
11246
- if ((n.length + e) % 2 == 0)
11247
- n += "0";
11248
- s = Math.sqrt(n);
11249
- e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
11250
- if (s == 1 / 0) {
11251
- n = "5e" + e;
11252
- } else {
11253
- n = s.toExponential();
11254
- n = n.slice(0, n.indexOf("e") + 1) + e;
11255
- }
11256
- r = new Ctor(n);
11257
- } else {
11258
- r = new Ctor(s.toString());
11259
- }
11260
- sd = (e = Ctor.precision) + 3;
11261
- for (;; ) {
11262
- t = r;
11263
- r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
11264
- if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
11265
- n = n.slice(sd - 3, sd + 1);
11266
- if (n == "9999" || !rep && n == "4999") {
11267
- if (!rep) {
11268
- finalise(t, e + 1, 0);
11269
- if (t.times(t).eq(x)) {
11270
- r = t;
11271
- break;
11272
- }
11273
- }
11274
- sd += 4;
11275
- rep = 1;
11276
- } else {
11277
- if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
11278
- finalise(r, e + 1, 1);
11279
- m = !r.times(r).eq(x);
11280
- }
11281
- break;
11282
- }
11283
- }
11284
- }
11285
- external2 = true;
11286
- return finalise(r, e, Ctor.rounding, m);
11287
- };
11288
- P.tangent = P.tan = function() {
11289
- var pr, rm, x = this, Ctor = x.constructor;
11290
- if (!x.isFinite())
11291
- return new Ctor(NaN);
11292
- if (x.isZero())
11293
- return new Ctor(x);
11294
- pr = Ctor.precision;
11295
- rm = Ctor.rounding;
11296
- Ctor.precision = pr + 10;
11297
- Ctor.rounding = 1;
11298
- x = x.sin();
11299
- x.s = 1;
11300
- x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
11301
- Ctor.precision = pr;
11302
- Ctor.rounding = rm;
11303
- return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
11304
- };
11305
- P.times = P.mul = function(y) {
11306
- var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
11307
- y.s *= x.s;
11308
- if (!xd || !xd[0] || !yd || !yd[0]) {
11309
- return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
11310
- }
11311
- e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
11312
- xdL = xd.length;
11313
- ydL = yd.length;
11314
- if (xdL < ydL) {
11315
- r = xd;
11316
- xd = yd;
11317
- yd = r;
11318
- rL = xdL;
11319
- xdL = ydL;
11320
- ydL = rL;
11321
- }
11322
- r = [];
11323
- rL = xdL + ydL;
11324
- for (i = rL;i--; )
11325
- r.push(0);
11326
- for (i = ydL;--i >= 0; ) {
11327
- carry = 0;
11328
- for (k = xdL + i;k > i; ) {
11329
- t = r[k] + yd[i] * xd[k - i - 1] + carry;
11330
- r[k--] = t % BASE | 0;
11331
- carry = t / BASE | 0;
11332
- }
11333
- r[k] = (r[k] + carry) % BASE | 0;
11334
- }
11335
- for (;!r[--rL]; )
11336
- r.pop();
11337
- if (carry)
11338
- ++e;
11339
- else
11340
- r.shift();
11341
- y.d = r;
11342
- y.e = getBase10Exponent(r, e);
11343
- return external2 ? finalise(y, Ctor.precision, Ctor.rounding) : y;
11344
- };
11345
- P.toBinary = function(sd, rm) {
11346
- return toStringBinary(this, 2, sd, rm);
11347
- };
11348
- P.toDecimalPlaces = P.toDP = function(dp, rm) {
11349
- var x = this, Ctor = x.constructor;
11350
- x = new Ctor(x);
11351
- if (dp === undefined)
11352
- return x;
11353
- checkInt32(dp, 0, MAX_DIGITS);
11354
- if (rm === undefined)
11355
- rm = Ctor.rounding;
11356
- else
11357
- checkInt32(rm, 0, 8);
11358
- return finalise(x, dp + x.e + 1, rm);
11359
- };
11360
- P.toExponential = function(dp, rm) {
11361
- var str, x = this, Ctor = x.constructor;
11362
- if (dp === undefined) {
11363
- str = finiteToString(x, true);
11364
- } else {
11365
- checkInt32(dp, 0, MAX_DIGITS);
11366
- if (rm === undefined)
11367
- rm = Ctor.rounding;
11368
- else
11369
- checkInt32(rm, 0, 8);
11370
- x = finalise(new Ctor(x), dp + 1, rm);
11371
- str = finiteToString(x, true, dp + 1);
11372
- }
11373
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11374
- };
11375
- P.toFixed = function(dp, rm) {
11376
- var str, y, x = this, Ctor = x.constructor;
11377
- if (dp === undefined) {
11378
- str = finiteToString(x);
11379
- } else {
11380
- checkInt32(dp, 0, MAX_DIGITS);
11381
- if (rm === undefined)
11382
- rm = Ctor.rounding;
11383
- else
11384
- checkInt32(rm, 0, 8);
11385
- y = finalise(new Ctor(x), dp + x.e + 1, rm);
11386
- str = finiteToString(y, false, dp + y.e + 1);
11387
- }
11388
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11389
- };
11390
- P.toFraction = function(maxD) {
11391
- var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
11392
- if (!xd)
11393
- return new Ctor(x);
11394
- n1 = d0 = new Ctor(1);
11395
- d1 = n0 = new Ctor(0);
11396
- d = new Ctor(d1);
11397
- e = d.e = getPrecision(xd) - x.e - 1;
11398
- k = e % LOG_BASE;
11399
- d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
11400
- if (maxD == null) {
11401
- maxD = e > 0 ? d : n1;
11402
- } else {
11403
- n = new Ctor(maxD);
11404
- if (!n.isInt() || n.lt(n1))
11405
- throw Error(invalidArgument + n);
11406
- maxD = n.gt(d) ? e > 0 ? d : n1 : n;
11407
- }
11408
- external2 = false;
11409
- n = new Ctor(digitsToString(xd));
11410
- pr = Ctor.precision;
11411
- Ctor.precision = e = xd.length * LOG_BASE * 2;
11412
- for (;; ) {
11413
- q = divide(n, d, 0, 1, 1);
11414
- d2 = d0.plus(q.times(d1));
11415
- if (d2.cmp(maxD) == 1)
11416
- break;
11417
- d0 = d1;
11418
- d1 = d2;
11419
- d2 = n1;
11420
- n1 = n0.plus(q.times(d2));
11421
- n0 = d2;
11422
- d2 = d;
11423
- d = n.minus(q.times(d2));
11424
- n = d2;
11425
- }
11426
- d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
11427
- n0 = n0.plus(d2.times(n1));
11428
- d0 = d0.plus(d2.times(d1));
11429
- n0.s = n1.s = x.s;
11430
- r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
11431
- Ctor.precision = pr;
11432
- external2 = true;
11433
- return r;
11434
- };
11435
- P.toHexadecimal = P.toHex = function(sd, rm) {
11436
- return toStringBinary(this, 16, sd, rm);
11437
- };
11438
- P.toNearest = function(y, rm) {
11439
- var x = this, Ctor = x.constructor;
11440
- x = new Ctor(x);
11441
- if (y == null) {
11442
- if (!x.d)
11443
- return x;
11444
- y = new Ctor(1);
11445
- rm = Ctor.rounding;
11446
- } else {
11447
- y = new Ctor(y);
11448
- if (rm === undefined) {
11449
- rm = Ctor.rounding;
11450
- } else {
11451
- checkInt32(rm, 0, 8);
11452
- }
11453
- if (!x.d)
11454
- return y.s ? x : y;
11455
- if (!y.d) {
11456
- if (y.s)
11457
- y.s = x.s;
11458
- return y;
11459
- }
11460
- }
11461
- if (y.d[0]) {
11462
- external2 = false;
11463
- x = divide(x, y, 0, rm, 1).times(y);
11464
- external2 = true;
11465
- finalise(x);
11466
- } else {
11467
- y.s = x.s;
11468
- x = y;
11469
- }
11470
- return x;
11471
- };
11472
- P.toNumber = function() {
11473
- return +this;
11474
- };
11475
- P.toOctal = function(sd, rm) {
11476
- return toStringBinary(this, 8, sd, rm);
11477
- };
11478
- P.toPower = P.pow = function(y) {
11479
- var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
11480
- if (!x.d || !y.d || !x.d[0] || !y.d[0])
11481
- return new Ctor(mathpow(+x, yn));
11482
- x = new Ctor(x);
11483
- if (x.eq(1))
11484
- return x;
11485
- pr = Ctor.precision;
11486
- rm = Ctor.rounding;
11487
- if (y.eq(1))
11488
- return finalise(x, pr, rm);
11489
- e = mathfloor(y.e / LOG_BASE);
11490
- if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
11491
- r = intPow(Ctor, x, k, pr);
11492
- return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
11493
- }
11494
- s = x.s;
11495
- if (s < 0) {
11496
- if (e < y.d.length - 1)
11497
- return new Ctor(NaN);
11498
- if ((y.d[e] & 1) == 0)
11499
- s = 1;
11500
- if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
11501
- x.s = s;
11502
- return x;
11503
- }
11504
- }
11505
- k = mathpow(+x, yn);
11506
- e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
11507
- if (e > Ctor.maxE + 1 || e < Ctor.minE - 1)
11508
- return new Ctor(e > 0 ? s / 0 : 0);
11509
- external2 = false;
11510
- Ctor.rounding = x.s = 1;
11511
- k = Math.min(12, (e + "").length);
11512
- r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
11513
- if (r.d) {
11514
- r = finalise(r, pr + 5, 1);
11515
- if (checkRoundingDigits(r.d, pr, rm)) {
11516
- e = pr + 10;
11517
- r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
11518
- if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 100000000000000) {
11519
- r = finalise(r, pr + 1, 0);
11520
- }
11521
- }
11522
- }
11523
- r.s = s;
11524
- external2 = true;
11525
- Ctor.rounding = rm;
11526
- return finalise(r, pr, rm);
11527
- };
11528
- P.toPrecision = function(sd, rm) {
11529
- var str, x = this, Ctor = x.constructor;
11530
- if (sd === undefined) {
11531
- str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11532
- } else {
11533
- checkInt32(sd, 1, MAX_DIGITS);
11534
- if (rm === undefined)
11535
- rm = Ctor.rounding;
11536
- else
11537
- checkInt32(rm, 0, 8);
11538
- x = finalise(new Ctor(x), sd, rm);
11539
- str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
11540
- }
11541
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11542
- };
11543
- P.toSignificantDigits = P.toSD = function(sd, rm) {
11544
- var x = this, Ctor = x.constructor;
11545
- if (sd === undefined) {
11546
- sd = Ctor.precision;
11547
- rm = Ctor.rounding;
11548
- } else {
11549
- checkInt32(sd, 1, MAX_DIGITS);
11550
- if (rm === undefined)
11551
- rm = Ctor.rounding;
11552
- else
11553
- checkInt32(rm, 0, 8);
11554
- }
11555
- return finalise(new Ctor(x), sd, rm);
11556
- };
11557
- P.toString = function() {
11558
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11559
- return x.isNeg() && !x.isZero() ? "-" + str : str;
11560
- };
11561
- P.truncated = P.trunc = function() {
11562
- return finalise(new this.constructor(this), this.e + 1, 1);
11563
- };
11564
- P.valueOf = P.toJSON = function() {
11565
- var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
11566
- return x.isNeg() ? "-" + str : str;
11567
- };
11568
- function digitsToString(d) {
11569
- var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
11570
- if (indexOfLastWord > 0) {
11571
- str += w;
11572
- for (i = 1;i < indexOfLastWord; i++) {
11573
- ws = d[i] + "";
11574
- k = LOG_BASE - ws.length;
11575
- if (k)
11576
- str += getZeroString(k);
11577
- str += ws;
11578
- }
11579
- w = d[i];
11580
- ws = w + "";
11581
- k = LOG_BASE - ws.length;
11582
- if (k)
11583
- str += getZeroString(k);
11584
- } else if (w === 0) {
11585
- return "0";
11586
- }
11587
- for (;w % 10 === 0; )
11588
- w /= 10;
11589
- return str + w;
11590
- }
11591
- function checkInt32(i, min, max) {
11592
- if (i !== ~~i || i < min || i > max) {
11593
- throw Error(invalidArgument + i);
11594
- }
11595
- }
11596
- function checkRoundingDigits(d, i, rm, repeating) {
11597
- var di, k, r, rd;
11598
- for (k = d[0];k >= 10; k /= 10)
11599
- --i;
11600
- if (--i < 0) {
11601
- i += LOG_BASE;
11602
- di = 0;
11603
- } else {
11604
- di = Math.ceil((i + 1) / LOG_BASE);
11605
- i %= LOG_BASE;
11606
- }
11607
- k = mathpow(10, LOG_BASE - i);
11608
- rd = d[di] % k | 0;
11609
- if (repeating == null) {
11610
- if (i < 3) {
11611
- if (i == 0)
11612
- rd = rd / 100 | 0;
11613
- else if (i == 1)
11614
- rd = rd / 10 | 0;
11615
- r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
11616
- } else {
11617
- 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;
11618
- }
11619
- } else {
11620
- if (i < 4) {
11621
- if (i == 0)
11622
- rd = rd / 1000 | 0;
11623
- else if (i == 1)
11624
- rd = rd / 100 | 0;
11625
- else if (i == 2)
11626
- rd = rd / 10 | 0;
11627
- r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
11628
- } else {
11629
- 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;
11630
- }
11631
- }
11632
- return r;
11633
- }
11634
- function convertBase(str, baseIn, baseOut) {
11635
- var j, arr = [0], arrL, i = 0, strL = str.length;
11636
- for (;i < strL; ) {
11637
- for (arrL = arr.length;arrL--; )
11638
- arr[arrL] *= baseIn;
11639
- arr[0] += NUMERALS.indexOf(str.charAt(i++));
11640
- for (j = 0;j < arr.length; j++) {
11641
- if (arr[j] > baseOut - 1) {
11642
- if (arr[j + 1] === undefined)
11643
- arr[j + 1] = 0;
11644
- arr[j + 1] += arr[j] / baseOut | 0;
11645
- arr[j] %= baseOut;
11646
- }
11647
- }
11648
- }
11649
- return arr.reverse();
11650
- }
11651
- function cosine(Ctor, x) {
11652
- var k, len, y;
11653
- if (x.isZero())
11654
- return x;
11655
- len = x.d.length;
11656
- if (len < 32) {
11657
- k = Math.ceil(len / 3);
11658
- y = (1 / tinyPow(4, k)).toString();
11659
- } else {
11660
- k = 16;
11661
- y = "2.3283064365386962890625e-10";
11662
- }
11663
- Ctor.precision += k;
11664
- x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
11665
- for (var i = k;i--; ) {
11666
- var cos2x = x.times(x);
11667
- x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
11668
- }
11669
- Ctor.precision -= k;
11670
- return x;
11671
- }
11672
- var divide = function() {
11673
- function multiplyInteger(x, k, base) {
11674
- var temp, carry = 0, i = x.length;
11675
- for (x = x.slice();i--; ) {
11676
- temp = x[i] * k + carry;
11677
- x[i] = temp % base | 0;
11678
- carry = temp / base | 0;
11679
- }
11680
- if (carry)
11681
- x.unshift(carry);
11682
- return x;
11683
- }
11684
- function compare(a, b, aL, bL) {
11685
- var i, r;
11686
- if (aL != bL) {
11687
- r = aL > bL ? 1 : -1;
11688
- } else {
11689
- for (i = r = 0;i < aL; i++) {
11690
- if (a[i] != b[i]) {
11691
- r = a[i] > b[i] ? 1 : -1;
11692
- break;
11693
- }
11694
- }
11695
- }
11696
- return r;
11697
- }
11698
- function subtract(a, b, aL, base) {
11699
- var i = 0;
11700
- for (;aL--; ) {
11701
- a[aL] -= i;
11702
- i = a[aL] < b[aL] ? 1 : 0;
11703
- a[aL] = i * base + a[aL] - b[aL];
11704
- }
11705
- for (;!a[0] && a.length > 1; )
11706
- a.shift();
11707
- }
11708
- return function(x, y, pr, rm, dp, base) {
11709
- 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;
11710
- if (!xd || !xd[0] || !yd || !yd[0]) {
11711
- return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
11712
- }
11713
- if (base) {
11714
- logBase = 1;
11715
- e = x.e - y.e;
11716
- } else {
11717
- base = BASE;
11718
- logBase = LOG_BASE;
11719
- e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
11720
- }
11721
- yL = yd.length;
11722
- xL = xd.length;
11723
- q = new Ctor(sign);
11724
- qd = q.d = [];
11725
- for (i = 0;yd[i] == (xd[i] || 0); i++)
11726
- ;
11727
- if (yd[i] > (xd[i] || 0))
11728
- e--;
11729
- if (pr == null) {
11730
- sd = pr = Ctor.precision;
11731
- rm = Ctor.rounding;
11732
- } else if (dp) {
11733
- sd = pr + (x.e - y.e) + 1;
11734
- } else {
11735
- sd = pr;
11736
- }
11737
- if (sd < 0) {
11738
- qd.push(1);
11739
- more = true;
11740
- } else {
11741
- sd = sd / logBase + 2 | 0;
11742
- i = 0;
11743
- if (yL == 1) {
11744
- k = 0;
11745
- yd = yd[0];
11746
- sd++;
11747
- for (;(i < xL || k) && sd--; i++) {
11748
- t = k * base + (xd[i] || 0);
11749
- qd[i] = t / yd | 0;
11750
- k = t % yd | 0;
11751
- }
11752
- more = k || i < xL;
11753
- } else {
11754
- k = base / (yd[0] + 1) | 0;
11755
- if (k > 1) {
11756
- yd = multiplyInteger(yd, k, base);
11757
- xd = multiplyInteger(xd, k, base);
11758
- yL = yd.length;
11759
- xL = xd.length;
11760
- }
11761
- xi = yL;
11762
- rem = xd.slice(0, yL);
11763
- remL = rem.length;
11764
- for (;remL < yL; )
11765
- rem[remL++] = 0;
11766
- yz = yd.slice();
11767
- yz.unshift(0);
11768
- yd0 = yd[0];
11769
- if (yd[1] >= base / 2)
11770
- ++yd0;
11771
- do {
11772
- k = 0;
11773
- cmp = compare(yd, rem, yL, remL);
11774
- if (cmp < 0) {
11775
- rem0 = rem[0];
11776
- if (yL != remL)
11777
- rem0 = rem0 * base + (rem[1] || 0);
11778
- k = rem0 / yd0 | 0;
11779
- if (k > 1) {
11780
- if (k >= base)
11781
- k = base - 1;
11782
- prod = multiplyInteger(yd, k, base);
11783
- prodL = prod.length;
11784
- remL = rem.length;
11785
- cmp = compare(prod, rem, prodL, remL);
11786
- if (cmp == 1) {
11787
- k--;
11788
- subtract(prod, yL < prodL ? yz : yd, prodL, base);
11789
- }
11790
- } else {
11791
- if (k == 0)
11792
- cmp = k = 1;
11793
- prod = yd.slice();
11794
- }
11795
- prodL = prod.length;
11796
- if (prodL < remL)
11797
- prod.unshift(0);
11798
- subtract(rem, prod, remL, base);
11799
- if (cmp == -1) {
11800
- remL = rem.length;
11801
- cmp = compare(yd, rem, yL, remL);
11802
- if (cmp < 1) {
11803
- k++;
11804
- subtract(rem, yL < remL ? yz : yd, remL, base);
11805
- }
11806
- }
11807
- remL = rem.length;
11808
- } else if (cmp === 0) {
11809
- k++;
11810
- rem = [0];
11811
- }
11812
- qd[i++] = k;
11813
- if (cmp && rem[0]) {
11814
- rem[remL++] = xd[xi] || 0;
11815
- } else {
11816
- rem = [xd[xi]];
11817
- remL = 1;
11818
- }
11819
- } while ((xi++ < xL || rem[0] !== undefined) && sd--);
11820
- more = rem[0] !== undefined;
11821
- }
11822
- if (!qd[0])
11823
- qd.shift();
11824
- }
11825
- if (logBase == 1) {
11826
- q.e = e;
11827
- inexact = more;
11828
- } else {
11829
- for (i = 1, k = qd[0];k >= 10; k /= 10)
11830
- i++;
11831
- q.e = i + e * logBase - 1;
11832
- finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
11833
- }
11834
- return q;
11835
- };
11836
- }();
11837
- function finalise(x, sd, rm, isTruncated) {
11838
- var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
11839
- out:
11840
- if (sd != null) {
11841
- xd = x.d;
11842
- if (!xd)
11843
- return x;
11844
- for (digits = 1, k = xd[0];k >= 10; k /= 10)
11845
- digits++;
11846
- i = sd - digits;
11847
- if (i < 0) {
11848
- i += LOG_BASE;
11849
- j = sd;
11850
- w = xd[xdi = 0];
11851
- rd = w / mathpow(10, digits - j - 1) % 10 | 0;
11852
- } else {
11853
- xdi = Math.ceil((i + 1) / LOG_BASE);
11854
- k = xd.length;
11855
- if (xdi >= k) {
11856
- if (isTruncated) {
11857
- for (;k++ <= xdi; )
11858
- xd.push(0);
11859
- w = rd = 0;
11860
- digits = 1;
11861
- i %= LOG_BASE;
11862
- j = i - LOG_BASE + 1;
11863
- } else {
11864
- break out;
11865
- }
11866
- } else {
11867
- w = k = xd[xdi];
11868
- for (digits = 1;k >= 10; k /= 10)
11869
- digits++;
11870
- i %= LOG_BASE;
11871
- j = i - LOG_BASE + digits;
11872
- rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
11873
- }
11874
- }
11875
- isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== undefined || (j < 0 ? w : w % mathpow(10, digits - j - 1));
11876
- 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));
11877
- if (sd < 1 || !xd[0]) {
11878
- xd.length = 0;
11879
- if (roundUp) {
11880
- sd -= x.e + 1;
11881
- xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
11882
- x.e = -sd || 0;
11883
- } else {
11884
- xd[0] = x.e = 0;
11885
- }
11886
- return x;
11887
- }
11888
- if (i == 0) {
11889
- xd.length = xdi;
11890
- k = 1;
11891
- xdi--;
11892
- } else {
11893
- xd.length = xdi + 1;
11894
- k = mathpow(10, LOG_BASE - i);
11895
- xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
11896
- }
11897
- if (roundUp) {
11898
- for (;; ) {
11899
- if (xdi == 0) {
11900
- for (i = 1, j = xd[0];j >= 10; j /= 10)
11901
- i++;
11902
- j = xd[0] += k;
11903
- for (k = 1;j >= 10; j /= 10)
11904
- k++;
11905
- if (i != k) {
11906
- x.e++;
11907
- if (xd[0] == BASE)
11908
- xd[0] = 1;
11909
- }
11910
- break;
11911
- } else {
11912
- xd[xdi] += k;
11913
- if (xd[xdi] != BASE)
11914
- break;
11915
- xd[xdi--] = 0;
11916
- k = 1;
11917
- }
11918
- }
11919
- }
11920
- for (i = xd.length;xd[--i] === 0; )
11921
- xd.pop();
11922
- }
11923
- if (external2) {
11924
- if (x.e > Ctor.maxE) {
11925
- x.d = null;
11926
- x.e = NaN;
11927
- } else if (x.e < Ctor.minE) {
11928
- x.e = 0;
11929
- x.d = [0];
11930
- }
11931
- }
11932
- return x;
11933
- }
11934
- function finiteToString(x, isExp, sd) {
11935
- if (!x.isFinite())
11936
- return nonFiniteToString(x);
11937
- var k, e = x.e, str = digitsToString(x.d), len = str.length;
11938
- if (isExp) {
11939
- if (sd && (k = sd - len) > 0) {
11940
- str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
11941
- } else if (len > 1) {
11942
- str = str.charAt(0) + "." + str.slice(1);
11943
- }
11944
- str = str + (x.e < 0 ? "e" : "e+") + x.e;
11945
- } else if (e < 0) {
11946
- str = "0." + getZeroString(-e - 1) + str;
11947
- if (sd && (k = sd - len) > 0)
11948
- str += getZeroString(k);
11949
- } else if (e >= len) {
11950
- str += getZeroString(e + 1 - len);
11951
- if (sd && (k = sd - e - 1) > 0)
11952
- str = str + "." + getZeroString(k);
11953
- } else {
11954
- if ((k = e + 1) < len)
11955
- str = str.slice(0, k) + "." + str.slice(k);
11956
- if (sd && (k = sd - len) > 0) {
11957
- if (e + 1 === len)
11958
- str += ".";
11959
- str += getZeroString(k);
11960
- }
11961
- }
11962
- return str;
11963
- }
11964
- function getBase10Exponent(digits, e) {
11965
- var w = digits[0];
11966
- for (e *= LOG_BASE;w >= 10; w /= 10)
11967
- e++;
11968
- return e;
11969
- }
11970
- function getLn10(Ctor, sd, pr) {
11971
- if (sd > LN10_PRECISION) {
11972
- external2 = true;
11973
- if (pr)
11974
- Ctor.precision = pr;
11975
- throw Error(precisionLimitExceeded);
11976
- }
11977
- return finalise(new Ctor(LN10), sd, 1, true);
11978
- }
11979
- function getPi(Ctor, sd, rm) {
11980
- if (sd > PI_PRECISION)
11981
- throw Error(precisionLimitExceeded);
11982
- return finalise(new Ctor(PI), sd, rm, true);
11983
- }
11984
- function getPrecision(digits) {
11985
- var w = digits.length - 1, len = w * LOG_BASE + 1;
11986
- w = digits[w];
11987
- if (w) {
11988
- for (;w % 10 == 0; w /= 10)
11989
- len--;
11990
- for (w = digits[0];w >= 10; w /= 10)
11991
- len++;
11992
- }
11993
- return len;
11994
- }
11995
- function getZeroString(k) {
11996
- var zs = "";
11997
- for (;k--; )
11998
- zs += "0";
11999
- return zs;
12000
- }
12001
- function intPow(Ctor, x, n, pr) {
12002
- var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
12003
- external2 = false;
12004
- for (;; ) {
12005
- if (n % 2) {
12006
- r = r.times(x);
12007
- if (truncate(r.d, k))
12008
- isTruncated = true;
12009
- }
12010
- n = mathfloor(n / 2);
12011
- if (n === 0) {
12012
- n = r.d.length - 1;
12013
- if (isTruncated && r.d[n] === 0)
12014
- ++r.d[n];
12015
- break;
12016
- }
12017
- x = x.times(x);
12018
- truncate(x.d, k);
12019
- }
12020
- external2 = true;
12021
- return r;
12022
- }
12023
- function isOdd(n) {
12024
- return n.d[n.d.length - 1] & 1;
12025
- }
12026
- function maxOrMin(Ctor, args, n) {
12027
- var k, y, x = new Ctor(args[0]), i = 0;
12028
- for (;++i < args.length; ) {
12029
- y = new Ctor(args[i]);
12030
- if (!y.s) {
12031
- x = y;
12032
- break;
12033
- }
12034
- k = x.cmp(y);
12035
- if (k === n || k === 0 && x.s === n) {
12036
- x = y;
12037
- }
12038
- }
12039
- return x;
12040
- }
12041
- function naturalExponential(x, sd) {
12042
- var denominator, guard, j, pow, sum, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
12043
- if (!x.d || !x.d[0] || x.e > 17) {
12044
- return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
12045
- }
12046
- if (sd == null) {
12047
- external2 = false;
12048
- wpr = pr;
12049
- } else {
12050
- wpr = sd;
12051
- }
12052
- t = new Ctor(0.03125);
12053
- while (x.e > -2) {
12054
- x = x.times(t);
12055
- k += 5;
12056
- }
12057
- guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
12058
- wpr += guard;
12059
- denominator = pow = sum = new Ctor(1);
12060
- Ctor.precision = wpr;
12061
- for (;; ) {
12062
- pow = finalise(pow.times(x), wpr, 1);
12063
- denominator = denominator.times(++i);
12064
- t = sum.plus(divide(pow, denominator, wpr, 1));
12065
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
12066
- j = k;
12067
- while (j--)
12068
- sum = finalise(sum.times(sum), wpr, 1);
12069
- if (sd == null) {
12070
- if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
12071
- Ctor.precision = wpr += 10;
12072
- denominator = pow = t = new Ctor(1);
12073
- i = 0;
12074
- rep++;
12075
- } else {
12076
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
12077
- }
12078
- } else {
12079
- Ctor.precision = pr;
12080
- return sum;
12081
- }
12082
- }
12083
- sum = t;
12084
- }
12085
- }
12086
- function naturalLogarithm(y, sd) {
12087
- 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;
12088
- if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
12089
- return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
12090
- }
12091
- if (sd == null) {
12092
- external2 = false;
12093
- wpr = pr;
12094
- } else {
12095
- wpr = sd;
12096
- }
12097
- Ctor.precision = wpr += guard;
12098
- c = digitsToString(xd);
12099
- c0 = c.charAt(0);
12100
- if (Math.abs(e = x.e) < 1500000000000000) {
12101
- while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
12102
- x = x.times(y);
12103
- c = digitsToString(x.d);
12104
- c0 = c.charAt(0);
12105
- n++;
12106
- }
12107
- e = x.e;
12108
- if (c0 > 1) {
12109
- x = new Ctor("0." + c);
12110
- e++;
12111
- } else {
12112
- x = new Ctor(c0 + "." + c.slice(1));
12113
- }
12114
- } else {
12115
- t = getLn10(Ctor, wpr + 2, pr).times(e + "");
12116
- x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
12117
- Ctor.precision = pr;
12118
- return sd == null ? finalise(x, pr, rm, external2 = true) : x;
12119
- }
12120
- x1 = x;
12121
- sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
12122
- x2 = finalise(x.times(x), wpr, 1);
12123
- denominator = 3;
12124
- for (;; ) {
12125
- numerator = finalise(numerator.times(x2), wpr, 1);
12126
- t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
12127
- if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
12128
- sum = sum.times(2);
12129
- if (e !== 0)
12130
- sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
12131
- sum = divide(sum, new Ctor(n), wpr, 1);
12132
- if (sd == null) {
12133
- if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
12134
- Ctor.precision = wpr += guard;
12135
- t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
12136
- x2 = finalise(x.times(x), wpr, 1);
12137
- denominator = rep = 1;
12138
- } else {
12139
- return finalise(sum, Ctor.precision = pr, rm, external2 = true);
12140
- }
12141
- } else {
12142
- Ctor.precision = pr;
12143
- return sum;
12144
- }
12145
- }
12146
- sum = t;
12147
- denominator += 2;
12148
- }
12149
- }
12150
- function nonFiniteToString(x) {
12151
- return String(x.s * x.s / 0);
12152
- }
12153
- function parseDecimal(x, str) {
12154
- var e, i, len;
12155
- if ((e = str.indexOf(".")) > -1)
12156
- str = str.replace(".", "");
12157
- if ((i = str.search(/e/i)) > 0) {
12158
- if (e < 0)
12159
- e = i;
12160
- e += +str.slice(i + 1);
12161
- str = str.substring(0, i);
12162
- } else if (e < 0) {
12163
- e = str.length;
12164
- }
12165
- for (i = 0;str.charCodeAt(i) === 48; i++)
12166
- ;
12167
- for (len = str.length;str.charCodeAt(len - 1) === 48; --len)
12168
- ;
12169
- str = str.slice(i, len);
12170
- if (str) {
12171
- len -= i;
12172
- x.e = e = e - i - 1;
12173
- x.d = [];
12174
- i = (e + 1) % LOG_BASE;
12175
- if (e < 0)
12176
- i += LOG_BASE;
12177
- if (i < len) {
12178
- if (i)
12179
- x.d.push(+str.slice(0, i));
12180
- for (len -= LOG_BASE;i < len; )
12181
- x.d.push(+str.slice(i, i += LOG_BASE));
12182
- str = str.slice(i);
12183
- i = LOG_BASE - str.length;
12184
- } else {
12185
- i -= len;
12186
- }
12187
- for (;i--; )
12188
- str += "0";
12189
- x.d.push(+str);
12190
- if (external2) {
12191
- if (x.e > x.constructor.maxE) {
12192
- x.d = null;
12193
- x.e = NaN;
12194
- } else if (x.e < x.constructor.minE) {
12195
- x.e = 0;
12196
- x.d = [0];
12197
- }
12198
- }
12199
- } else {
12200
- x.e = 0;
12201
- x.d = [0];
12202
- }
12203
- return x;
12204
- }
12205
- function parseOther(x, str) {
12206
- var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
12207
- if (str.indexOf("_") > -1) {
12208
- str = str.replace(/(\d)_(?=\d)/g, "$1");
12209
- if (isDecimal.test(str))
12210
- return parseDecimal(x, str);
12211
- } else if (str === "Infinity" || str === "NaN") {
12212
- if (!+str)
12213
- x.s = NaN;
12214
- x.e = NaN;
12215
- x.d = null;
12216
- return x;
12217
- }
12218
- if (isHex.test(str)) {
12219
- base = 16;
12220
- str = str.toLowerCase();
12221
- } else if (isBinary.test(str)) {
12222
- base = 2;
12223
- } else if (isOctal.test(str)) {
12224
- base = 8;
12225
- } else {
12226
- throw Error(invalidArgument + str);
12227
- }
12228
- i = str.search(/p/i);
12229
- if (i > 0) {
12230
- p = +str.slice(i + 1);
12231
- str = str.substring(2, i);
12232
- } else {
12233
- str = str.slice(2);
12234
- }
12235
- i = str.indexOf(".");
12236
- isFloat = i >= 0;
12237
- Ctor = x.constructor;
12238
- if (isFloat) {
12239
- str = str.replace(".", "");
12240
- len = str.length;
12241
- i = len - i;
12242
- divisor = intPow(Ctor, new Ctor(base), i, i * 2);
12243
- }
12244
- xd = convertBase(str, base, BASE);
12245
- xe = xd.length - 1;
12246
- for (i = xe;xd[i] === 0; --i)
12247
- xd.pop();
12248
- if (i < 0)
12249
- return new Ctor(x.s * 0);
12250
- x.e = getBase10Exponent(xd, xe);
12251
- x.d = xd;
12252
- external2 = false;
12253
- if (isFloat)
12254
- x = divide(x, divisor, len * 4);
12255
- if (p)
12256
- x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
12257
- external2 = true;
12258
- return x;
12259
- }
12260
- function sine(Ctor, x) {
12261
- var k, len = x.d.length;
12262
- if (len < 3) {
12263
- return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
12264
- }
12265
- k = 1.4 * Math.sqrt(len);
12266
- k = k > 16 ? 16 : k | 0;
12267
- x = x.times(1 / tinyPow(5, k));
12268
- x = taylorSeries(Ctor, 2, x, x);
12269
- var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
12270
- for (;k--; ) {
12271
- sin2_x = x.times(x);
12272
- x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
12273
- }
12274
- return x;
12275
- }
12276
- function taylorSeries(Ctor, n, x, y, isHyperbolic) {
12277
- var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
12278
- external2 = false;
12279
- x2 = x.times(x);
12280
- u = new Ctor(y);
12281
- for (;; ) {
12282
- t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
12283
- u = isHyperbolic ? y.plus(t) : y.minus(t);
12284
- y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
12285
- t = u.plus(y);
12286
- if (t.d[k] !== undefined) {
12287
- for (j = k;t.d[j] === u.d[j] && j--; )
12288
- ;
12289
- if (j == -1)
12290
- break;
12291
- }
12292
- j = u;
12293
- u = y;
12294
- y = t;
12295
- t = j;
12296
- i++;
12297
- }
12298
- external2 = true;
12299
- t.d.length = k + 1;
12300
- return t;
12301
- }
12302
- function tinyPow(b, e) {
12303
- var n = b;
12304
- while (--e)
12305
- n *= b;
12306
- return n;
12307
- }
12308
- function toLessThanHalfPi(Ctor, x) {
12309
- var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(0.5);
12310
- x = x.abs();
12311
- if (x.lte(halfPi)) {
12312
- quadrant = isNeg ? 4 : 1;
12313
- return x;
12314
- }
12315
- t = x.divToInt(pi);
12316
- if (t.isZero()) {
12317
- quadrant = isNeg ? 3 : 2;
12318
- } else {
12319
- x = x.minus(t.times(pi));
12320
- if (x.lte(halfPi)) {
12321
- quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
12322
- return x;
12323
- }
12324
- quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
12325
- }
12326
- return x.minus(pi).abs();
12327
- }
12328
- function toStringBinary(x, baseOut, sd, rm) {
12329
- var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== undefined;
12330
- if (isExp) {
12331
- checkInt32(sd, 1, MAX_DIGITS);
12332
- if (rm === undefined)
12333
- rm = Ctor.rounding;
12334
- else
12335
- checkInt32(rm, 0, 8);
12336
- } else {
12337
- sd = Ctor.precision;
12338
- rm = Ctor.rounding;
12339
- }
12340
- if (!x.isFinite()) {
12341
- str = nonFiniteToString(x);
12342
- } else {
12343
- str = finiteToString(x);
12344
- i = str.indexOf(".");
12345
- if (isExp) {
12346
- base = 2;
12347
- if (baseOut == 16) {
12348
- sd = sd * 4 - 3;
12349
- } else if (baseOut == 8) {
12350
- sd = sd * 3 - 2;
12351
- }
12352
- } else {
12353
- base = baseOut;
12354
- }
12355
- if (i >= 0) {
12356
- str = str.replace(".", "");
12357
- y = new Ctor(1);
12358
- y.e = str.length - i;
12359
- y.d = convertBase(finiteToString(y), 10, base);
12360
- y.e = y.d.length;
12361
- }
12362
- xd = convertBase(str, 10, base);
12363
- e = len = xd.length;
12364
- for (;xd[--len] == 0; )
12365
- xd.pop();
12366
- if (!xd[0]) {
12367
- str = isExp ? "0p+0" : "0";
12368
- } else {
12369
- if (i < 0) {
12370
- e--;
12371
- } else {
12372
- x = new Ctor(x);
12373
- x.d = xd;
12374
- x.e = e;
12375
- x = divide(x, y, sd, rm, 0, base);
12376
- xd = x.d;
12377
- e = x.e;
12378
- roundUp = inexact;
12379
- }
12380
- i = xd[sd];
12381
- k = base / 2;
12382
- roundUp = roundUp || xd[sd + 1] !== undefined;
12383
- 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));
12384
- xd.length = sd;
12385
- if (roundUp) {
12386
- for (;++xd[--sd] > base - 1; ) {
12387
- xd[sd] = 0;
12388
- if (!sd) {
12389
- ++e;
12390
- xd.unshift(1);
12391
- }
12392
- }
12393
- }
12394
- for (len = xd.length;!xd[len - 1]; --len)
12395
- ;
12396
- for (i = 0, str = "";i < len; i++)
12397
- str += NUMERALS.charAt(xd[i]);
12398
- if (isExp) {
12399
- if (len > 1) {
12400
- if (baseOut == 16 || baseOut == 8) {
12401
- i = baseOut == 16 ? 4 : 3;
12402
- for (--len;len % i; len++)
12403
- str += "0";
12404
- xd = convertBase(str, base, baseOut);
12405
- for (len = xd.length;!xd[len - 1]; --len)
12406
- ;
12407
- for (i = 1, str = "1.";i < len; i++)
12408
- str += NUMERALS.charAt(xd[i]);
12409
- } else {
12410
- str = str.charAt(0) + "." + str.slice(1);
12411
- }
12412
- }
12413
- str = str + (e < 0 ? "p" : "p+") + e;
12414
- } else if (e < 0) {
12415
- for (;++e; )
12416
- str = "0" + str;
12417
- str = "0." + str;
12418
- } else {
12419
- if (++e > len)
12420
- for (e -= len;e--; )
12421
- str += "0";
12422
- else if (e < len)
12423
- str = str.slice(0, e) + "." + str.slice(e);
12424
- }
12425
- }
12426
- str = (baseOut == 16 ? "0x" : baseOut == 2 ? "0b" : baseOut == 8 ? "0o" : "") + str;
12427
- }
12428
- return x.s < 0 ? "-" + str : str;
12429
- }
12430
- function truncate(arr, len) {
12431
- if (arr.length > len) {
12432
- arr.length = len;
12433
- return true;
12434
- }
12435
- }
12436
- function abs(x) {
12437
- return new this(x).abs();
12438
- }
12439
- function acos(x) {
12440
- return new this(x).acos();
12441
- }
12442
- function acosh(x) {
12443
- return new this(x).acosh();
12444
- }
12445
- function add(x, y) {
12446
- return new this(x).plus(y);
12447
- }
12448
- function asin(x) {
12449
- return new this(x).asin();
12450
- }
12451
- function asinh(x) {
12452
- return new this(x).asinh();
12453
- }
12454
- function atan(x) {
12455
- return new this(x).atan();
12456
- }
12457
- function atanh(x) {
12458
- return new this(x).atanh();
12459
- }
12460
- function atan2(y, x) {
12461
- y = new this(y);
12462
- x = new this(x);
12463
- var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
12464
- if (!y.s || !x.s) {
12465
- r = new this(NaN);
12466
- } else if (!y.d && !x.d) {
12467
- r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
12468
- r.s = y.s;
12469
- } else if (!x.d || y.isZero()) {
12470
- r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
12471
- r.s = y.s;
12472
- } else if (!y.d || x.isZero()) {
12473
- r = getPi(this, wpr, 1).times(0.5);
12474
- r.s = y.s;
12475
- } else if (x.s < 0) {
12476
- this.precision = wpr;
12477
- this.rounding = 1;
12478
- r = this.atan(divide(y, x, wpr, 1));
12479
- x = getPi(this, wpr, 1);
12480
- this.precision = pr;
12481
- this.rounding = rm;
12482
- r = y.s < 0 ? r.minus(x) : r.plus(x);
12483
- } else {
12484
- r = this.atan(divide(y, x, wpr, 1));
12485
- }
12486
- return r;
12487
- }
12488
- function cbrt(x) {
12489
- return new this(x).cbrt();
12490
- }
12491
- function ceil(x) {
12492
- return finalise(x = new this(x), x.e + 1, 2);
12493
- }
12494
- function clamp(x, min, max) {
12495
- return new this(x).clamp(min, max);
12496
- }
12497
- function config(obj) {
12498
- if (!obj || typeof obj !== "object")
12499
- throw Error(decimalError + "Object expected");
12500
- var i, p, v, useDefaults = obj.defaults === true, ps = [
12501
- "precision",
12502
- 1,
12503
- MAX_DIGITS,
12504
- "rounding",
12505
- 0,
12506
- 8,
12507
- "toExpNeg",
12508
- -EXP_LIMIT,
12509
- 0,
12510
- "toExpPos",
12511
- 0,
12512
- EXP_LIMIT,
12513
- "maxE",
12514
- 0,
12515
- EXP_LIMIT,
12516
- "minE",
12517
- -EXP_LIMIT,
12518
- 0,
12519
- "modulo",
12520
- 0,
12521
- 9
12522
- ];
12523
- for (i = 0;i < ps.length; i += 3) {
12524
- if (p = ps[i], useDefaults)
12525
- this[p] = DEFAULTS[p];
12526
- if ((v = obj[p]) !== undefined) {
12527
- if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2])
12528
- this[p] = v;
12529
- else
12530
- throw Error(invalidArgument + p + ": " + v);
12531
- }
12532
- }
12533
- if (p = "crypto", useDefaults)
12534
- this[p] = DEFAULTS[p];
12535
- if ((v = obj[p]) !== undefined) {
12536
- if (v === true || v === false || v === 0 || v === 1) {
12537
- if (v) {
12538
- if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
12539
- this[p] = true;
12540
- } else {
12541
- throw Error(cryptoUnavailable);
12542
- }
12543
- } else {
12544
- this[p] = false;
12545
- }
12546
- } else {
12547
- throw Error(invalidArgument + p + ": " + v);
12548
- }
12549
- }
12550
- return this;
12551
- }
12552
- function cos(x) {
12553
- return new this(x).cos();
12554
- }
12555
- function cosh(x) {
12556
- return new this(x).cosh();
12557
- }
12558
- function clone(obj) {
12559
- var i, p, ps;
12560
- function Decimal(v) {
12561
- var e, i2, t, x = this;
12562
- if (!(x instanceof Decimal))
12563
- return new Decimal(v);
12564
- x.constructor = Decimal;
12565
- if (isDecimalInstance(v)) {
12566
- x.s = v.s;
12567
- if (external2) {
12568
- if (!v.d || v.e > Decimal.maxE) {
12569
- x.e = NaN;
12570
- x.d = null;
12571
- } else if (v.e < Decimal.minE) {
12572
- x.e = 0;
12573
- x.d = [0];
12574
- } else {
12575
- x.e = v.e;
12576
- x.d = v.d.slice();
12577
- }
12578
- } else {
12579
- x.e = v.e;
12580
- x.d = v.d ? v.d.slice() : v.d;
12581
- }
12582
- return;
12583
- }
12584
- t = typeof v;
12585
- if (t === "number") {
12586
- if (v === 0) {
12587
- x.s = 1 / v < 0 ? -1 : 1;
12588
- x.e = 0;
12589
- x.d = [0];
12590
- return;
12591
- }
12592
- if (v < 0) {
12593
- v = -v;
12594
- x.s = -1;
12595
- } else {
12596
- x.s = 1;
12597
- }
12598
- if (v === ~~v && v < 1e7) {
12599
- for (e = 0, i2 = v;i2 >= 10; i2 /= 10)
12600
- e++;
12601
- if (external2) {
12602
- if (e > Decimal.maxE) {
12603
- x.e = NaN;
12604
- x.d = null;
12605
- } else if (e < Decimal.minE) {
12606
- x.e = 0;
12607
- x.d = [0];
12608
- } else {
12609
- x.e = e;
12610
- x.d = [v];
12611
- }
12612
- } else {
12613
- x.e = e;
12614
- x.d = [v];
12615
- }
12616
- return;
12617
- }
12618
- if (v * 0 !== 0) {
12619
- if (!v)
12620
- x.s = NaN;
12621
- x.e = NaN;
12622
- x.d = null;
12623
- return;
12624
- }
12625
- return parseDecimal(x, v.toString());
12626
- }
12627
- if (t === "string") {
12628
- if ((i2 = v.charCodeAt(0)) === 45) {
12629
- v = v.slice(1);
12630
- x.s = -1;
12631
- } else {
12632
- if (i2 === 43)
12633
- v = v.slice(1);
12634
- x.s = 1;
12635
- }
12636
- return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
12637
- }
12638
- if (t === "bigint") {
12639
- if (v < 0) {
12640
- v = -v;
12641
- x.s = -1;
12642
- } else {
12643
- x.s = 1;
12644
- }
12645
- return parseDecimal(x, v.toString());
12646
- }
12647
- throw Error(invalidArgument + v);
12648
- }
12649
- Decimal.prototype = P;
12650
- Decimal.ROUND_UP = 0;
12651
- Decimal.ROUND_DOWN = 1;
12652
- Decimal.ROUND_CEIL = 2;
12653
- Decimal.ROUND_FLOOR = 3;
12654
- Decimal.ROUND_HALF_UP = 4;
12655
- Decimal.ROUND_HALF_DOWN = 5;
12656
- Decimal.ROUND_HALF_EVEN = 6;
12657
- Decimal.ROUND_HALF_CEIL = 7;
12658
- Decimal.ROUND_HALF_FLOOR = 8;
12659
- Decimal.EUCLID = 9;
12660
- Decimal.config = Decimal.set = config;
12661
- Decimal.clone = clone;
12662
- Decimal.isDecimal = isDecimalInstance;
12663
- Decimal.abs = abs;
12664
- Decimal.acos = acos;
12665
- Decimal.acosh = acosh;
12666
- Decimal.add = add;
12667
- Decimal.asin = asin;
12668
- Decimal.asinh = asinh;
12669
- Decimal.atan = atan;
12670
- Decimal.atanh = atanh;
12671
- Decimal.atan2 = atan2;
12672
- Decimal.cbrt = cbrt;
12673
- Decimal.ceil = ceil;
12674
- Decimal.clamp = clamp;
12675
- Decimal.cos = cos;
12676
- Decimal.cosh = cosh;
12677
- Decimal.div = div;
12678
- Decimal.exp = exp;
12679
- Decimal.floor = floor;
12680
- Decimal.hypot = hypot;
12681
- Decimal.ln = ln;
12682
- Decimal.log = log;
12683
- Decimal.log10 = log10;
12684
- Decimal.log2 = log2;
12685
- Decimal.max = max;
12686
- Decimal.min = min;
12687
- Decimal.mod = mod;
12688
- Decimal.mul = mul;
12689
- Decimal.pow = pow;
12690
- Decimal.random = random;
12691
- Decimal.round = round;
12692
- Decimal.sign = sign;
12693
- Decimal.sin = sin;
12694
- Decimal.sinh = sinh;
12695
- Decimal.sqrt = sqrt;
12696
- Decimal.sub = sub;
12697
- Decimal.sum = sum;
12698
- Decimal.tan = tan;
12699
- Decimal.tanh = tanh;
12700
- Decimal.trunc = trunc;
12701
- if (obj === undefined)
12702
- obj = {};
12703
- if (obj) {
12704
- if (obj.defaults !== true) {
12705
- ps = ["precision", "rounding", "toExpNeg", "toExpPos", "maxE", "minE", "modulo", "crypto"];
12706
- for (i = 0;i < ps.length; )
12707
- if (!obj.hasOwnProperty(p = ps[i++]))
12708
- obj[p] = this[p];
12709
- }
12710
- }
12711
- Decimal.config(obj);
12712
- return Decimal;
12713
- }
12714
- function div(x, y) {
12715
- return new this(x).div(y);
12716
- }
12717
- function exp(x) {
12718
- return new this(x).exp();
12719
- }
12720
- function floor(x) {
12721
- return finalise(x = new this(x), x.e + 1, 3);
12722
- }
12723
- function hypot() {
12724
- var i, n, t = new this(0);
12725
- external2 = false;
12726
- for (i = 0;i < arguments.length; ) {
12727
- n = new this(arguments[i++]);
12728
- if (!n.d) {
12729
- if (n.s) {
12730
- external2 = true;
12731
- return new this(1 / 0);
12732
- }
12733
- t = n;
12734
- } else if (t.d) {
12735
- t = t.plus(n.times(n));
12736
- }
12737
- }
12738
- external2 = true;
12739
- return t.sqrt();
12740
- }
12741
- function isDecimalInstance(obj) {
12742
- return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
12743
- }
12744
- function ln(x) {
12745
- return new this(x).ln();
12746
- }
12747
- function log(x, y) {
12748
- return new this(x).log(y);
12749
- }
12750
- function log2(x) {
12751
- return new this(x).log(2);
12752
- }
12753
- function log10(x) {
12754
- return new this(x).log(10);
12755
- }
12756
- function max() {
12757
- return maxOrMin(this, arguments, -1);
12758
- }
12759
- function min() {
12760
- return maxOrMin(this, arguments, 1);
12761
- }
12762
- function mod(x, y) {
12763
- return new this(x).mod(y);
12764
- }
12765
- function mul(x, y) {
12766
- return new this(x).mul(y);
12767
- }
12768
- function pow(x, y) {
12769
- return new this(x).pow(y);
12770
- }
12771
- function random(sd) {
12772
- var d, e, k, n, i = 0, r = new this(1), rd = [];
12773
- if (sd === undefined)
12774
- sd = this.precision;
12775
- else
12776
- checkInt32(sd, 1, MAX_DIGITS);
12777
- k = Math.ceil(sd / LOG_BASE);
12778
- if (!this.crypto) {
12779
- for (;i < k; )
12780
- rd[i++] = Math.random() * 1e7 | 0;
12781
- } else if (crypto.getRandomValues) {
12782
- d = crypto.getRandomValues(new Uint32Array(k));
12783
- for (;i < k; ) {
12784
- n = d[i];
12785
- if (n >= 4290000000) {
12786
- d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
12787
- } else {
12788
- rd[i++] = n % 1e7;
12789
- }
12790
- }
12791
- } else if (crypto.randomBytes) {
12792
- d = crypto.randomBytes(k *= 4);
12793
- for (;i < k; ) {
12794
- n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
12795
- if (n >= 2140000000) {
12796
- crypto.randomBytes(4).copy(d, i);
12797
- } else {
12798
- rd.push(n % 1e7);
12799
- i += 4;
12800
- }
12801
- }
12802
- i = k / 4;
12803
- } else {
12804
- throw Error(cryptoUnavailable);
12805
- }
12806
- k = rd[--i];
12807
- sd %= LOG_BASE;
12808
- if (k && sd) {
12809
- n = mathpow(10, LOG_BASE - sd);
12810
- rd[i] = (k / n | 0) * n;
12811
- }
12812
- for (;rd[i] === 0; i--)
12813
- rd.pop();
12814
- if (i < 0) {
12815
- e = 0;
12816
- rd = [0];
12817
- } else {
12818
- e = -1;
12819
- for (;rd[0] === 0; e -= LOG_BASE)
12820
- rd.shift();
12821
- for (k = 1, n = rd[0];n >= 10; n /= 10)
12822
- k++;
12823
- if (k < LOG_BASE)
12824
- e -= LOG_BASE - k;
12825
- }
12826
- r.e = e;
12827
- r.d = rd;
12828
- return r;
12829
- }
12830
- function round(x) {
12831
- return finalise(x = new this(x), x.e + 1, this.rounding);
12832
- }
12833
- function sign(x) {
12834
- x = new this(x);
12835
- return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
12836
- }
12837
- function sin(x) {
12838
- return new this(x).sin();
12839
- }
12840
- function sinh(x) {
12841
- return new this(x).sinh();
12842
- }
12843
- function sqrt(x) {
12844
- return new this(x).sqrt();
12845
- }
12846
- function sub(x, y) {
12847
- return new this(x).sub(y);
12848
- }
12849
- function sum() {
12850
- var i = 0, args = arguments, x = new this(args[i]);
12851
- external2 = false;
12852
- for (;x.s && ++i < args.length; )
12853
- x = x.plus(args[i]);
12854
- external2 = true;
12855
- return finalise(x, this.precision, this.rounding);
12856
- }
12857
- function tan(x) {
12858
- return new this(x).tan();
12859
- }
12860
- function tanh(x) {
12861
- return new this(x).tanh();
12862
- }
12863
- function trunc(x) {
12864
- return finalise(x = new this(x), x.e + 1, 1);
12865
- }
12866
- P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
12867
- P[Symbol.toStringTag] = "Decimal";
12868
- var Decimal = P.constructor = clone(DEFAULTS);
12869
- LN10 = new Decimal(LN10);
12870
- PI = new Decimal(PI);
12871
- var decimal_default = Decimal;
12872
-
12873
- // src/common/base/other.ts
12874
- var delay = (time = 1000) => {
12875
- return new Promise((resolve) => setTimeout(resolve, time));
12876
- };
12877
- var calcJsText = (expr, context) => {
12878
- const keys = Object.keys(context);
12879
- const values = keys.map((key2) => context[key2]);
12880
- return Function(...keys, `return (${expr})`)(...values);
12881
- };
12882
- var optionsToEnum = (options, text, key2) => {
12883
- return options.reduce((acc, cur) => {
12884
- acc[cur[key2]] = {
12885
- text: cur[text]
12886
- };
12887
- return acc;
12888
- }, {});
12889
- };
12890
- var performDecimalOperation = (num1, num2, operator) => {
12891
- if (num1 === undefined || num2 === undefined || !operator) {
12892
- return;
12893
- }
12894
- const decimalNum1 = new decimal_default(Number(num1));
12895
- const decimalNum2 = new decimal_default(Number(num2));
12896
- switch (operator) {
12897
- case "+":
12898
- return decimalNum1.plus(decimalNum2).toNumber();
12899
- case "-":
12900
- return decimalNum1.minus(decimalNum2).toNumber();
12901
- case "*":
12902
- return decimalNum1.times(decimalNum2).toNumber();
12903
- case "/":
12904
- if (num2 !== 0) {
12905
- return decimalNum1.dividedBy(decimalNum2).toNumber();
12906
- } else {
12907
- console.error("Division by zero is not allowed.");
12908
- return NaN;
12909
- }
12910
- default:
12911
- console.error("Invalid operator:", operator);
12912
- return NaN;
12913
- }
12914
- };
12915
- var printConsoleLog = (type, path2, params, response) => {
12916
- const styles = {
12917
- header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
12918
- value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
12919
- separator: "color: #409EFF; margin: 0 4px;"
12920
- };
12921
- console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
12922
- if (params) {
12923
- console.table(params);
12924
- }
12925
- if (response) {
12926
- console.table(response);
12927
- }
12928
- console.groupEnd();
12929
- };
12930
10481
 
12931
10482
  // src/common/base/array.ts
12932
- var shuffleArray = (array) => {
12933
- const shuffledArray = [...array];
12934
- for (let i = shuffledArray.length - 1;i > 0; i--) {
12935
- const j = Math.floor(Math.random() * (i + 1));
12936
- [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
12937
- }
12938
- return shuffledArray;
12939
- };
12940
10483
  var removeSimilarDuplicates = (arr, threshold, isLog) => {
12941
10484
  const uniqueArray = [];
12942
10485
  const similarPairs = [];
@@ -12966,65 +10509,26 @@ var removeSimilarDuplicates = (arr, threshold, isLog) => {
12966
10509
  }
12967
10510
  return uniqueArray;
12968
10511
  };
12969
- var getTotal = (arr, key2) => {
12970
- if (!Array.isArray(arr) || !key2) {
12971
- return 0;
12972
- }
12973
- return arr.reduce((total, item) => {
12974
- const itemValue = Number(item[key2]);
12975
- if (!isNaN(itemValue)) {
12976
- return performDecimalOperation(total, itemValue, "+");
12977
- }
12978
- return total;
12979
- }, 0);
12980
- };
12981
10512
 
12982
- // src/common/base/number.ts
12983
- var getRandomNum = (min2, max2) => {
12984
- return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
12985
- };
12986
- var limitDecimals = (v, num = 2, isForce) => {
12987
- let value = parseFloat(v);
12988
- if (isNaN(value)) {
12989
- if (isForce) {
12990
- value = 0;
12991
- } else {
12992
- return "";
10513
+ // src/common/base/object.ts
10514
+ var findAttr = (data, target, path2 = "data") => {
10515
+ if (Array.isArray(data)) {
10516
+ for (let i = 0;i < data.length; i++) {
10517
+ const res = findAttr(data[i], target, `${path2}[${i}]`);
10518
+ if (res)
10519
+ return res;
12993
10520
  }
12994
10521
  }
12995
- return value.toFixed(num).toString();
12996
- };
12997
- var formatFileSize = (bytes) => {
12998
- if (!bytes || bytes === 0) {
12999
- return "0 B";
13000
- }
13001
- const base = 1024;
13002
- const sizes = ["B", "KB", "MB", "GB"];
13003
- const index = Math.floor(Math.log(bytes) / Math.log(base));
13004
- return `${(bytes / Math.pow(base, index)).toFixed(1).replace(/\.0$/, "")} ${sizes[index]}`;
13005
- };
13006
- var isValidNumber = (value) => {
13007
- if (typeof value !== "number") {
13008
- return false;
13009
- }
13010
- if (isNaN(value)) {
13011
- return false;
13012
- }
13013
- if (value === Infinity || value === -Infinity) {
13014
- return false;
13015
- }
13016
- return true;
13017
- };
13018
- var numberWithCommas = (x) => {
13019
- if (x === undefined || x === null) {
13020
- return "";
10522
+ if (data && typeof data === "object") {
10523
+ if (target in data)
10524
+ return `${path2}.${target}`;
10525
+ for (const key2 in data) {
10526
+ const res = findAttr(data[key2], target, `${path2}.${key2}`);
10527
+ if (res)
10528
+ return res;
10529
+ }
13021
10530
  }
13022
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
13023
- };
13024
-
13025
- // src/common/base/object.ts
13026
- var findItem = (list, attr, value) => {
13027
- return list.find((item) => value === undefined ? item[attr] : item[attr] === value);
10531
+ return null;
13028
10532
  };
13029
10533
  var filterParams = (params, deep = false) => {
13030
10534
  const clean = (value) => {
@@ -13049,26 +10553,30 @@ var filterParams = (params, deep = false) => {
13049
10553
  };
13050
10554
  return clean(params);
13051
10555
  };
13052
- var watch = {
13053
- observe(obj, key2, watchFun) {
13054
- const val = obj[key2];
13055
- Object.defineProperty(obj, key2, {
13056
- configurable: true,
13057
- enumerable: true,
13058
- set(value) {
13059
- obj[key2] = value;
13060
- watchFun(value, val);
13061
- },
13062
- get() {
13063
- return val;
13064
- }
13065
- });
13066
- },
13067
- setWatcher(data = {}, watch2 = {}) {
13068
- Object.keys(watch2).forEach((v) => {
13069
- this.observe(data, v, watch2[v]);
13070
- });
10556
+
10557
+ // src/common/base/other.ts
10558
+ var delay = (time = 1000) => {
10559
+ return new Promise((resolve) => setTimeout(resolve, time));
10560
+ };
10561
+ var calcJsText = (expr, context) => {
10562
+ const keys = Object.keys(context);
10563
+ const values = keys.map((key2) => context[key2]);
10564
+ return Function(...keys, `return (${expr})`)(...values);
10565
+ };
10566
+ var logNetwork = (type, path2, params, response) => {
10567
+ const styles = {
10568
+ header: "color: #fff; background: #35495e; padding: 2px 8px; border-radius: 3px 0 0 3px;",
10569
+ value: "color: #35495e; background: #f0f4f8; padding: 2px 6px; border-radius: 0 3px 3px 0;",
10570
+ separator: "color: #409EFF; margin: 0 4px;"
10571
+ };
10572
+ console.groupCollapsed(`666 %c${type}%c${path2}`, styles.header, styles.value);
10573
+ if (params) {
10574
+ console.table(params);
13071
10575
  }
10576
+ if (response) {
10577
+ console.table(response);
10578
+ }
10579
+ console.groupEnd();
13072
10580
  };
13073
10581
 
13074
10582
  // src/common/base/promise.ts
@@ -13081,7 +10589,7 @@ var executePromise = async (promise) => {
13081
10589
  time
13082
10590
  };
13083
10591
  };
13084
- var retryPromise = async (promiseFn, retryInterval = 1000, retryCount = 3) => {
10592
+ var retryPromise = async (promiseFn, retryCount = 3, retryInterval = 1000) => {
13085
10593
  try {
13086
10594
  return await promiseFn();
13087
10595
  } catch (error) {
@@ -13097,10 +10605,10 @@ class EnumItem {
13097
10605
  label;
13098
10606
  value;
13099
10607
  extra;
13100
- constructor(config2) {
13101
- this.value = config2.value;
13102
- this.label = config2.label;
13103
- this.extra = config2.extra;
10608
+ constructor(config) {
10609
+ this.value = config.value;
10610
+ this.label = config.label;
10611
+ this.extra = config.extra;
13104
10612
  }
13105
10613
  }
13106
10614
  var Enum = {
@@ -13139,20 +10647,6 @@ var Enum = {
13139
10647
  return enumObj;
13140
10648
  }
13141
10649
  };
13142
- // src/common/image/index.ts
13143
- var import_axios9 = __toESM(require("axios"));
13144
- async function imageToBase64(url2) {
13145
- try {
13146
- const response = await import_axios9.default.get(url2, {
13147
- responseType: "arraybuffer"
13148
- });
13149
- const base64String = Buffer.from(response.data).toString("base64");
13150
- return `data:image/*;base64,${base64String}`;
13151
- } catch (error) {
13152
- console.error("Failed to fetch the image:", error);
13153
- throw error;
13154
- }
13155
- }
13156
10650
  // src/common/other/index.ts
13157
10651
  function getPublicUrl(objectKey) {
13158
10652
  if (!objectKey) {
@@ -13166,6 +10660,41 @@ function getPublicUrl(objectKey) {
13166
10660
  const key2 = objectKey.startsWith("/") ? objectKey : `/${objectKey}`;
13167
10661
  return `${baseUrl}${key2}`;
13168
10662
  }
10663
+ // src/common/antd/index.ts
10664
+ var options2valueEnum = (options) => {
10665
+ return (options || []).reduce((acc, cur) => {
10666
+ acc[cur] = { text: cur };
10667
+ return acc;
10668
+ }, {});
10669
+ };
10670
+ var optionsToEnum = (options, text, key2) => {
10671
+ return options.reduce((acc, cur) => {
10672
+ acc[cur[key2]] = {
10673
+ text: cur[text]
10674
+ };
10675
+ return acc;
10676
+ }, {});
10677
+ };
10678
+ var transformOptions = (inputArray) => {
10679
+ if (!inputArray?.length) {
10680
+ return [];
10681
+ }
10682
+ return inputArray.map((item) => {
10683
+ if (typeof item === "string") {
10684
+ return { label: item, value: item };
10685
+ }
10686
+ return item;
10687
+ });
10688
+ };
10689
+ var getColumns = (dataSource) => {
10690
+ if (!Array.isArray(dataSource)) {
10691
+ return [];
10692
+ }
10693
+ return Object.keys(dataSource?.[0] || {}).map((item) => ({
10694
+ title: item,
10695
+ dataIndex: item
10696
+ }));
10697
+ };
13169
10698
  // src/common/dayjs/index.ts
13170
10699
  var import_dayjs = __toESM(require("dayjs"));
13171
10700
  var import_isBetween = __toESM(require("dayjs/plugin/isBetween"));
@@ -13195,15 +10724,6 @@ var Timezone;
13195
10724
  Timezone2["EuropeLondon"] = "Europe/London";
13196
10725
  Timezone2["EuropeBerlin"] = "Europe/Berlin";
13197
10726
  })(Timezone ||= {});
13198
- var initChinaDayjs = () => {
13199
- import_dayjs.default.locale("zh-cn");
13200
- import_dayjs.default.tz.setDefault("Asia/Shanghai" /* AsiaShanghai */);
13201
- import_dayjs.default.updateLocale("zh-cn", {
13202
- weekStart: 1
13203
- });
13204
- return import_dayjs.default;
13205
- };
13206
- var chinaDayjs = initChinaDayjs();
13207
10727
  var dayjs_default = import_dayjs.default;
13208
10728
  // src/node/oss/index.ts
13209
10729
  var exports_oss = {};
@@ -13362,10 +10882,10 @@ var transporter = import_nodemailer.default.createTransport({
13362
10882
  secure: true,
13363
10883
  auth: authMap.gmail
13364
10884
  });
13365
- var send = (config2) => {
10885
+ var send = (config) => {
13366
10886
  return transporter.sendMail({
13367
10887
  from: authMap.gmail.user,
13368
- ...config2
10888
+ ...config
13369
10889
  });
13370
10890
  };
13371
10891
  // src/node/file/index.ts
@@ -13377,7 +10897,7 @@ __export(exports_file, {
13377
10897
  downloadFile: () => downloadFile
13378
10898
  });
13379
10899
  var import_fs_extra = __toESM(require("fs-extra"));
13380
- var import_axios10 = __toESM(require("axios"));
10900
+ var import_axios9 = __toESM(require("axios"));
13381
10901
  var import_url = __toESM(require("url"));
13382
10902
  var path2 = __toESM(require("path"));
13383
10903
  var import_crypto = __toESM(require("crypto"));
@@ -13430,23 +10950,14 @@ var getMimeType = (fileName) => {
13430
10950
  }
13431
10951
  };
13432
10952
  var replaceContentInFile = async (filePath, targetContent, replacement) => {
13433
- try {
13434
- const data = await import_fs_extra.default.readFile(filePath, "utf8");
13435
- if (replacement && data.includes(replacement)) {
13436
- console.error(`已替换过:${filePath}`);
13437
- return;
13438
- }
13439
- if (!data.includes(targetContent)) {
13440
- console.error(`不包含目标内容:${targetContent}`);
13441
- throw new Error(`不包含目标内容:${targetContent}`);
13442
- }
13443
- const updatedData = data.replace(new RegExp(targetContent, "g"), replacement);
13444
- await import_fs_extra.default.writeFile(filePath, updatedData, "utf8");
13445
- console.log(`成功替换文件中的内容!`);
13446
- } catch (err) {
13447
- console.error(`处理文件时发生错误:${err}`);
13448
- throw err;
10953
+ const data = await import_fs_extra.default.readFile(filePath, "utf8");
10954
+ if (!data.includes(targetContent)) {
10955
+ throw new Error(`未找到目标内容:${targetContent}`);
13449
10956
  }
10957
+ const updatedData = data.replaceAll(targetContent, replacement);
10958
+ if (updatedData === data)
10959
+ return;
10960
+ await import_fs_extra.default.writeFile(filePath, updatedData, "utf8");
13450
10961
  };
13451
10962
  var downloadFile = async (httpUrl, outputPath) => {
13452
10963
  try {
@@ -13458,7 +10969,7 @@ var downloadFile = async (httpUrl, outputPath) => {
13458
10969
  }
13459
10970
  outputPath = ".tmp/" + decodeURIComponent(fileName);
13460
10971
  }
13461
- const response = await import_axios10.default({
10972
+ const response = await import_axios9.default({
13462
10973
  url: httpUrl,
13463
10974
  method: "get",
13464
10975
  responseType: "stream"
@@ -13475,7 +10986,7 @@ var downloadFile = async (httpUrl, outputPath) => {
13475
10986
  throw error;
13476
10987
  }
13477
10988
  };
13478
- var generateUniqueFileName2 = (originalName = "") => {
10989
+ var generateUniqueFileName = (originalName = "") => {
13479
10990
  const ext = path2.extname(originalName);
13480
10991
  const nameWithoutExt = path2.basename(originalName, ext);
13481
10992
  const finalFileName = `${nameWithoutExt ? `${nameWithoutExt}_` : ""}${Date.now()}_${Math.random().toString(36).slice(2)}${ext}`;
@@ -13495,7 +11006,7 @@ var processFile = async (params) => {
13495
11006
  throw new Error("当类型为 url 时,file 必须是字符串");
13496
11007
  }
13497
11008
  try {
13498
- const response = await import_axios10.default.get(file, { responseType: "arraybuffer" });
11009
+ const response = await import_axios9.default.get(file, { responseType: "arraybuffer" });
13499
11010
  buffer = Buffer.from(response.data);
13500
11011
  } catch (error) {
13501
11012
  throw new Error(`无法从 URL 下载文件: ${error}`);
@@ -13532,7 +11043,7 @@ var processFile = async (params) => {
13532
11043
  }
13533
11044
  const size = buffer.length;
13534
11045
  const hash = import_crypto.default.createHash("md5").update(buffer).digest("hex");
13535
- const { finalFileName, ext } = generateUniqueFileName2(originalName);
11046
+ const { finalFileName, ext } = generateUniqueFileName(originalName);
13536
11047
  if (!mimeType) {
13537
11048
  mimeType = getMimeType(finalFileName);
13538
11049
  }