@fileverse-dev/formulajs 4.4.15 → 4.4.17-fix-sort-fn-1

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.
@@ -1,4 +1,4 @@
1
- /* @fileverse-dev/formulajs v4.4.15 */
1
+ /* @fileverse-dev/formulajs v4.4.17-fix-sort-fn-1 */
2
2
  var _excluded = [ "confirmations", "dataDecoded" ];
3
3
 
4
4
  function _objectWithoutProperties(e, t) {
@@ -4858,34 +4858,60 @@ function _typeof(o) {
4858
4858
  var sort_index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
4859
4859
  var sort_order = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
4860
4860
  var by_col = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
4861
- if (!array || !Array.isArray(array)) {
4862
- return na;
4863
- }
4864
- if (array.length === 0) {
4865
- return 0;
4866
- }
4867
- sort_index = parseNumber(sort_index);
4868
- if (!sort_index || sort_index < 1) {
4869
- return value;
4870
- }
4871
- sort_order = parseNumber(sort_order);
4872
- if (sort_order !== 1 && sort_order !== -1) {
4861
+ if (!array || !Array.isArray(array)) return na;
4862
+ if (array.length === 0) return 0;
4863
+ var idx = parseNumber(sort_index);
4864
+ if (!idx || idx < 1) return value;
4865
+ idx = idx - 1;
4866
+ var order = parseNumber(sort_order);
4867
+ if (order !== 1 && order !== -1) return value;
4868
+ var byCol = parseBool(by_col);
4869
+ if (typeof byCol !== "boolean") return name;
4870
+ var matrix = fillMatrix(array);
4871
+ var working = byCol ? transpose(matrix) : matrix;
4872
+ if (!working.length || !working[0] || idx >= working[0].length) {
4873
4873
  return value;
4874
4874
  }
4875
- by_col = parseBool(by_col);
4876
- if (typeof by_col !== "boolean") {
4877
- return name;
4878
- }
4879
- var sortArray = function sortArray(arr) {
4880
- return arr.sort((function(a, b) {
4881
- a = parseString(a[sort_index - 1]);
4882
- b = parseString(b[sort_index - 1]);
4883
- return sort_order === 1 ? a < b ? sort_order * -1 : sort_order : a > b ? sort_order : sort_order * -1;
4884
- }));
4875
+ var isBlank = function isBlank(v) {
4876
+ return v === "" || v === null || v === undefined;
4885
4877
  };
4886
- var matrix = fillMatrix(array);
4887
- var result = by_col ? transpose(matrix) : matrix;
4888
- return sort_index >= 1 && sort_index <= result[0].length ? by_col ? transpose(sortArray(result)) : sortArray(result) : value;
4878
+ var cmp = function cmp(a, b) {
4879
+ var _parseString, _parseString2;
4880
+ var aBlank = isBlank(a);
4881
+ var bBlank = isBlank(b);
4882
+ if (aBlank && bBlank) return 0;
4883
+ if (aBlank) return 1;
4884
+ if (bBlank) return -1;
4885
+ var na = parseNumber(a);
4886
+ var nb = parseNumber(b);
4887
+ var aNum = Number.isFinite(na);
4888
+ var bNum = Number.isFinite(nb);
4889
+ if (aNum && bNum) {
4890
+ if (na < nb) return -1;
4891
+ if (na > nb) return 1;
4892
+ return 0;
4893
+ }
4894
+ var sa = ((_parseString = parseString(a)) !== null && _parseString !== void 0 ? _parseString : "").toString().toLowerCase();
4895
+ var sb = ((_parseString2 = parseString(b)) !== null && _parseString2 !== void 0 ? _parseString2 : "").toString().toLowerCase();
4896
+ if (sa < sb) return -1;
4897
+ if (sa > sb) return 1;
4898
+ return 0;
4899
+ };
4900
+ var decorated = working.map((function(row, i) {
4901
+ return {
4902
+ row: row,
4903
+ i: i
4904
+ };
4905
+ }));
4906
+ decorated.sort((function(A, B) {
4907
+ var base = cmp(A.row[idx], B.row[idx]);
4908
+ if (base !== 0) return base * order;
4909
+ return A.i - B.i;
4910
+ }));
4911
+ var sorted = decorated.map((function(d) {
4912
+ return d.row;
4913
+ }));
4914
+ return byCol ? transpose(sorted) : sorted;
4889
4915
  }
4890
4916
  function TRANSPOSE(array) {
4891
4917
  if (!array) {
@@ -17360,7 +17386,7 @@ function _typeof(o) {
17360
17386
  for (_i12 = 0, _Object$entries2 = Object.entries(prices); _i12 < _Object$entries2.length; _i12++) {
17361
17387
  _Object$entries2$_i = _slicedToArray(_Object$entries2[_i12], 2), cur = _Object$entries2$_i[0],
17362
17388
  val = _Object$entries2$_i[1];
17363
- out["".concat(token.charAt(0).toUpperCase() + token.slice(1), "_").concat(cur.toUpperCase())] = val;
17389
+ out["".concat(token.toUpperCase(), "_").concat(cur.toUpperCase())] = val;
17364
17390
  }
17365
17391
  }
17366
17392
  return _context20.abrupt("return", [ out ]);
@@ -18400,16 +18426,23 @@ function _typeof(o) {
18400
18426
  ethereum: 1
18401
18427
  };
18402
18428
  function formatNumber(raw, decimals) {
18403
- if (!decimals) {
18429
+ try {
18430
+ if (!decimals) {
18431
+ return raw;
18432
+ }
18433
+ var quorum = BigInt(raw);
18434
+ var divisor = Math.pow(10, decimals);
18435
+ var normalized = Number(quorum) / divisor;
18436
+ return new Intl.NumberFormat("en-US", {
18437
+ notation: "compact",
18438
+ maximumFractionDigits: 2
18439
+ }).format(normalized);
18440
+ } catch (error) {
18441
+ console.log({
18442
+ error: error
18443
+ });
18404
18444
  return raw;
18405
18445
  }
18406
- var quorum = BigInt(raw);
18407
- var divisor = Math.pow(10, decimals);
18408
- var normalized = Number(quorum) / divisor;
18409
- return new Intl.NumberFormat("en-US", {
18410
- notation: "compact",
18411
- maximumFractionDigits: 2
18412
- }).format(normalized);
18413
18446
  }
18414
18447
  var cachedChains = null;
18415
18448
  function getChainName(_x16) {
@@ -18469,7 +18502,7 @@ function _typeof(o) {
18469
18502
  }
18470
18503
  function _DUNE() {
18471
18504
  _DUNE = _asyncToGenerator(_regeneratorRuntime().mark((function _callee30() {
18472
- var _ref26, _json$activity, _ref27, _json$holders, _ref28, _json$tokens, _argsToArray31, _argsToArray32, type, input1, input2, input3, input4, route, buildQuery, address, qs, chain, _qs, tokenAddress, _qs2, _chain, apiKey, url, _getUrlAndHeaders1, finalUrl, HEADERS, res, json, _data6, result, _final, globalDecimals, _iterator43, _step43, _loop4, _args34 = arguments;
18505
+ var _ref26, _json$activity, _ref27, _json$holders, _ref28, _json$tokens, _argsToArray31, _argsToArray32, type, input1, input2, input3, input4, route, buildQuery, address, qs, chain, _qs, tokenAddress, _qs2, _chain, apiKey, url, _getUrlAndHeaders1, finalUrl, HEADERS, res, _data6, json, _data7, result, _final, globalDecimals, _iterator43, _step43, _loop4, _args34 = arguments;
18473
18506
  return _regeneratorRuntime().wrap((function _callee30$(_context34) {
18474
18507
  while (1) switch (_context34.prev = _context34.next) {
18475
18508
  case 0:
@@ -18537,22 +18570,34 @@ function _typeof(o) {
18537
18570
  case 18:
18538
18571
  res = _context34.sent;
18539
18572
  if (res.ok) {
18540
- _context34.next = 21;
18573
+ _context34.next = 26;
18574
+ break;
18575
+ }
18576
+ if (!(res.status === 400)) {
18577
+ _context34.next = 25;
18541
18578
  break;
18542
18579
  }
18543
- throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
18544
-
18545
- case 21:
18546
18580
  _context34.next = 23;
18547
18581
  return res.json();
18548
18582
 
18549
18583
  case 23:
18584
+ _data6 = _context34.sent;
18585
+ throw new ValidationError(_data6.message);
18586
+
18587
+ case 25:
18588
+ throw new NetworkError(SERVICES_API_KEY.DuneSim, res.status);
18589
+
18590
+ case 26:
18591
+ _context34.next = 28;
18592
+ return res.json();
18593
+
18594
+ case 28:
18550
18595
  json = _context34.sent;
18551
- _data6 = type === "activity" ? (_ref26 = (_json$activity = json === null || json === void 0 ? void 0 : json.activity) !== null && _json$activity !== void 0 ? _json$activity : json) !== null && _ref26 !== void 0 ? _ref26 : [] : type === "token-holders" ? (_ref27 = (_json$holders = json === null || json === void 0 ? void 0 : json.holders) !== null && _json$holders !== void 0 ? _json$holders : json) !== null && _ref27 !== void 0 ? _ref27 : [] : type === "price" ? (_ref28 = (_json$tokens = json === null || json === void 0 ? void 0 : json.tokens) !== null && _json$tokens !== void 0 ? _json$tokens : json) !== null && _ref28 !== void 0 ? _ref28 : [] : json !== null && json !== void 0 ? json : [];
18552
- result = Array.isArray(_data6) ? _data6 : [ _data6 ];
18596
+ _data7 = type === "activity" ? (_ref26 = (_json$activity = json === null || json === void 0 ? void 0 : json.activity) !== null && _json$activity !== void 0 ? _json$activity : json) !== null && _ref26 !== void 0 ? _ref26 : [] : type === "token-holders" ? (_ref27 = (_json$holders = json === null || json === void 0 ? void 0 : json.holders) !== null && _json$holders !== void 0 ? _json$holders : json) !== null && _ref27 !== void 0 ? _ref27 : [] : type === "price" ? (_ref28 = (_json$tokens = json === null || json === void 0 ? void 0 : json.tokens) !== null && _json$tokens !== void 0 ? _json$tokens : json) !== null && _ref28 !== void 0 ? _ref28 : [] : json !== null && json !== void 0 ? json : [];
18597
+ result = Array.isArray(_data7) ? _data7 : [ _data7 ];
18553
18598
  _final = [];
18554
18599
  _iterator43 = _createForOfIteratorHelper(result);
18555
- _context34.prev = 28;
18600
+ _context34.prev = 33;
18556
18601
  _loop4 = _regeneratorRuntime().mark((function _loop4() {
18557
18602
  var item, prices, _resData$tokens$, _chain2, _url, _getUrlAndHeaders10, _finalUrl, _HEADERS, _res, resData, decimals;
18558
18603
  return _regeneratorRuntime().wrap((function _loop4$(_context33) {
@@ -18659,44 +18704,44 @@ function _typeof(o) {
18659
18704
  }));
18660
18705
  _iterator43.s();
18661
18706
 
18662
- case 31:
18707
+ case 36:
18663
18708
  if ((_step43 = _iterator43.n()).done) {
18664
- _context34.next = 35;
18709
+ _context34.next = 40;
18665
18710
  break;
18666
18711
  }
18667
- return _context34.delegateYield(_loop4(), "t0", 33);
18712
+ return _context34.delegateYield(_loop4(), "t0", 38);
18668
18713
 
18669
- case 33:
18670
- _context34.next = 31;
18714
+ case 38:
18715
+ _context34.next = 36;
18671
18716
  break;
18672
18717
 
18673
- case 35:
18674
- _context34.next = 40;
18718
+ case 40:
18719
+ _context34.next = 45;
18675
18720
  break;
18676
18721
 
18677
- case 37:
18678
- _context34.prev = 37;
18679
- _context34.t1 = _context34["catch"](28);
18722
+ case 42:
18723
+ _context34.prev = 42;
18724
+ _context34.t1 = _context34["catch"](33);
18680
18725
  _iterator43.e(_context34.t1);
18681
18726
 
18682
- case 40:
18683
- _context34.prev = 40;
18727
+ case 45:
18728
+ _context34.prev = 45;
18684
18729
  _iterator43.f();
18685
- return _context34.finish(40);
18730
+ return _context34.finish(45);
18686
18731
 
18687
- case 43:
18732
+ case 48:
18688
18733
  return _context34.abrupt("return", _final);
18689
18734
 
18690
- case 46:
18691
- _context34.prev = 46;
18735
+ case 51:
18736
+ _context34.prev = 51;
18692
18737
  _context34.t2 = _context34["catch"](0);
18693
18738
  return _context34.abrupt("return", errorMessageHandler(_context34.t2, "DUNE"));
18694
18739
 
18695
- case 49:
18740
+ case 54:
18696
18741
  case "end":
18697
18742
  return _context34.stop();
18698
18743
  }
18699
- }), _callee30, null, [ [ 0, 46 ], [ 28, 37, 40, 43 ] ]);
18744
+ }), _callee30, null, [ [ 0, 51 ], [ 33, 42, 45, 48 ] ]);
18700
18745
  })));
18701
18746
  return _DUNE.apply(this, arguments);
18702
18747
  }