@hairy/ether-lib 1.30.0 → 1.32.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 } = options;
75
- const number = (0, import_ethers2.formatEther)((0, import_utils.BigNum)((0, import_utils.numerfix)(value)).toFixed(0));
75
+ const number = (0, import_ethers2.formatEther)((0, import_utils.bignum)(value).toFixed(0));
76
76
  const groupSeparator = separator === false ? "" : ",";
77
77
  return (0, import_utils.formatNumeric)(number, {
78
78
  format: { groupSeparator, ...options.format },
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ type GenericTransactionResponse = TransactionResponse | ContractTransactionRespo
40
40
  declare function wait(transaction: GenericTransactionResponse): Promise<TransactionReceipt | null | undefined>;
41
41
  declare namespace wait {
42
42
  var subscribe: {
43
- <Key extends "before" | "after" | "error">(type: Key, handler: mitt.Handler<{
43
+ <Key extends "error" | "after" | "before">(type: Key, handler: mitt.Handler<{
44
44
  before: void;
45
45
  after: TransactionReceipt | null | undefined;
46
46
  error: Error;
@@ -80,22 +80,21 @@
80
80
  m: { v: 10 ** 6, d: 7, n: "m" },
81
81
  k: { v: 10 ** 3, d: 4, n: "k" }
82
82
  };
83
- function BigNum(num = "0") {
84
- return new import_bignumber.default(numerfix(num));
83
+ function bignum(n = "0") {
84
+ return new import_bignumber.default(numfix(n));
85
85
  }
86
- function gte(num, n) {
87
- return BigNum(num).gte(BigNum(n));
86
+ function numfix(value) {
87
+ return Number.isNaN(Number(value)) || value.toString() === "NaN" ? "0" : String(value);
88
88
  }
89
- function lt(num, n) {
90
- return BigNum(num).lt(BigNum(n));
89
+ function gte(a, b) {
90
+ return bignum(a).gte(bignum(b));
91
+ }
92
+ function lt(a, b) {
93
+ return bignum(a).lt(bignum(b));
91
94
  }
92
95
  function zeromove(value) {
93
96
  return value.toString().replace(/\.?0+$/, "");
94
97
  }
95
- function numerfix(value) {
96
- const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
97
- return _isNaN ? "0" : String(value);
98
- }
99
98
  function parseNumeric(num, delimiters = ["t", "b", "m"]) {
100
99
  const mappings = [
101
100
  delimiters.includes("t") && ((n) => gte(n, BIG_INTS.t.v) && BIG_INTS.t),
@@ -105,7 +104,7 @@
105
104
  ];
106
105
  let options;
107
106
  for (const analy of mappings) {
108
- const opts = analy && analy(BigNum(num).toFixed(0));
107
+ const opts = analy && analy(bignum(num).toFixed(0));
109
108
  opts && (options = opts);
110
109
  }
111
110
  return options || { v: 1, d: 0, n: "" };
@@ -118,7 +117,7 @@
118
117
  decimals = 2
119
118
  } = options || {};
120
119
  const config = parseNumeric(value, delimiters || []);
121
- let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
120
+ let number = bignum(value).div(config.v).toFormat(decimals, rounding, {
122
121
  decimalSeparator: ".",
123
122
  groupSeparator: ",",
124
123
  groupSize: 3,
@@ -135,7 +134,7 @@
135
134
  var import_ethers2 = __toESM(require_ethers(), 1);
136
135
  function formatEther(value = "0", options = {}) {
137
136
  const { separator = false, decimals, delimiters = false, rounding, zeromove: zeromove2 = true } = options;
138
- const number = (0, import_ethers2.formatEther)(BigNum(numerfix(value)).toFixed(0));
137
+ const number = (0, import_ethers2.formatEther)(bignum(value).toFixed(0));
139
138
  const groupSeparator = separator === false ? "" : ",";
140
139
  return formatNumeric(number, {
141
140
  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, numerfix } from "@hairy/utils";
32
+ import { bignum, 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 } = options;
36
- const number = _formatEther(BigNum(numerfix(value)).toFixed(0));
36
+ const number = _formatEther(bignum(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.30.0",
4
+ "version": "1.32.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.30.0"
29
+ "@hairy/utils": "1.32.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "ethers": "^6"