@hairy/ether-lib 1.38.0 → 1.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -72,7 +72,7 @@ var import_utils = require("@hairy/utils");
72
72
  var import_ethers2 = require("ethers");
73
73
  function formatEther(value = "0", options = {}) {
74
74
  const { separator = false, decimals, delimiters = false, rounding, zeromove = true, default: _default } = options;
75
- const number = (0, import_ethers2.formatEther)((0, import_utils.bignum)(value).toFixed(0));
75
+ const number = (0, import_ethers2.formatEther)((0, import_utils.bignumber)(value).toFixed(0));
76
76
  const groupSeparator = separator === false ? "" : ",";
77
77
  return (0, import_utils.formatNumeric)(number, {
78
78
  format: { groupSeparator, ...options.format },
@@ -74,26 +74,42 @@
74
74
 
75
75
  // ../util-core/src/number/index.ts
76
76
  var import_bignumber = __toESM(require_bignumber(), 1);
77
+
78
+ // ../util-core/src/util/converts.ts
79
+ function numberish(value) {
80
+ if (value === void 0 || value === null)
81
+ return "0";
82
+ if (Number.isNaN(Number(value)))
83
+ return "0";
84
+ return value.toString();
85
+ }
86
+
87
+ // ../util-core/src/number/index.ts
88
+ var DEFAULT_BIGNUM_CONFIG = {
89
+ ROUNDING_MODE: import_bignumber.default.ROUND_UP,
90
+ DECIMAL_PLACES: 6
91
+ };
92
+ var Bignumber = import_bignumber.default.clone(DEFAULT_BIGNUM_CONFIG);
77
93
  var BIG_INTS = {
78
94
  t: { v: 10 ** 12, d: 13, n: "t" },
79
95
  b: { v: 10 ** 9, d: 10, n: "b" },
80
96
  m: { v: 10 ** 6, d: 7, n: "m" },
81
97
  k: { v: 10 ** 3, d: 4, n: "k" }
82
98
  };
83
- function bignum(n = "0") {
84
- return new import_bignumber.default(numfix(n));
85
- }
86
- function numfix(value) {
87
- return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
99
+ function bignumber(n = "0", base) {
100
+ return new Bignumber(numberish(n), base);
88
101
  }
102
+ bignumber.clone = function(config) {
103
+ return Bignumber.clone({ ...DEFAULT_BIGNUM_CONFIG, ...config });
104
+ };
89
105
  function gte(a, b) {
90
- return bignum(a).gte(bignum(b));
106
+ return bignumber(a).gte(bignumber(b));
91
107
  }
92
108
  function lt(a, b) {
93
- return bignum(a).lt(bignum(b));
109
+ return bignumber(a).lt(bignumber(b));
94
110
  }
95
111
  function zeromove(value) {
96
- return value.toString().replace(/\.?0+$/, "");
112
+ return numberish(value).toString().replace(/\.?0+$/, "");
97
113
  }
98
114
  function parseNumeric(num, delimiters = ["t", "b", "m"]) {
99
115
  const mappings = [
@@ -104,22 +120,22 @@
104
120
  ];
105
121
  let options;
106
122
  for (const analy of mappings) {
107
- const opts = analy && analy(bignum(num).toFixed(0));
123
+ const opts = analy && analy(bignumber(num).toFixed(0));
108
124
  opts && (options = opts);
109
125
  }
110
126
  return options || { v: 1, d: 0, n: "" };
111
127
  }
112
128
  function formatNumeric(value = "0", options) {
113
- if (options?.default && bignum(value).isZero())
129
+ if (options?.default && bignumber(value).isZero())
114
130
  return options?.default;
115
131
  const {
116
- rounding = import_bignumber.default.ROUND_DOWN,
132
+ rounding = Bignumber.ROUND_DOWN,
117
133
  delimiters,
118
134
  format,
119
135
  decimals = 2
120
136
  } = options || {};
121
137
  const config = parseNumeric(value, delimiters || []);
122
- let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
138
+ let number = bignumber(value).div(config.v).toFormat(decimals, rounding, {
123
139
  decimalSeparator: ".",
124
140
  groupSeparator: ",",
125
141
  groupSize: 3,
@@ -136,7 +152,7 @@
136
152
  var import_ethers2 = __toESM(require_ethers(), 1);
137
153
  function formatEther(value = "0", options = {}) {
138
154
  const { separator = false, decimals, delimiters = false, rounding, zeromove: zeromove2 = true, default: _default } = options;
139
- const number = (0, import_ethers2.formatEther)(bignum(value).toFixed(0));
155
+ const number = (0, import_ethers2.formatEther)(bignumber(value).toFixed(0));
140
156
  const groupSeparator = separator === false ? "" : ",";
141
157
  return formatNumeric(number, {
142
158
  format: { groupSeparator, ...options.format },
package/dist/index.js CHANGED
@@ -29,11 +29,11 @@ function idprefix(errorCallString) {
29
29
  }
30
30
 
31
31
  // src/number.ts
32
- import { bignum, formatNumeric } from "@hairy/utils";
32
+ import { bignumber, formatNumeric } from "@hairy/utils";
33
33
  import { formatEther as _formatEther } from "ethers";
34
34
  function formatEther(value = "0", options = {}) {
35
35
  const { separator = false, decimals, delimiters = false, rounding, zeromove = true, default: _default } = options;
36
- const number = _formatEther(bignum(value).toFixed(0));
36
+ const number = _formatEther(bignumber(value).toFixed(0));
37
37
  const groupSeparator = separator === false ? "" : ",";
38
38
  return formatNumeric(number, {
39
39
  format: { groupSeparator, ...options.format },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/ether-lib",
3
3
  "type": "module",
4
- "version": "1.38.0",
4
+ "version": "1.40.0",
5
5
  "description": "Library for ether",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "mitt": "^3.0.1",
29
- "@hairy/utils": "1.38.0"
29
+ "@hairy/utils": "1.40.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "ethers": "^6"