@hairy/ether-lib 1.12.0 → 1.13.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 +1 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.global.js +6 -8
- package/dist/index.js +2 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Bignumber: () => import_utils.Bignumber,
|
|
34
33
|
Errors: () => Errors,
|
|
35
34
|
formatEther: () => formatEther,
|
|
36
35
|
idprefix: () => idprefix,
|
|
@@ -73,7 +72,7 @@ var import_utils = require("@hairy/utils");
|
|
|
73
72
|
var import_ethers2 = require("ethers");
|
|
74
73
|
function formatEther(value = "0", options = {}) {
|
|
75
74
|
const { separator = false, decimals, delimiters = false, rounding, zeromove = true } = options;
|
|
76
|
-
const number = (0, import_ethers2.formatEther)((0, import_utils.
|
|
75
|
+
const number = (0, import_ethers2.formatEther)((0, import_utils.BigNum)((0, import_utils.numerfix)(value)).toFixed(0));
|
|
77
76
|
const groupSeparator = separator === false ? "" : ",";
|
|
78
77
|
return (0, import_utils.formatNumeric)(number, {
|
|
79
78
|
format: { groupSeparator, ...options.format },
|
|
@@ -106,7 +105,6 @@ async function wait(transaction) {
|
|
|
106
105
|
wait.subscribe = emitter.on.bind(emitter);
|
|
107
106
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
107
|
0 && (module.exports = {
|
|
109
|
-
Bignumber,
|
|
110
108
|
Errors,
|
|
111
109
|
formatEther,
|
|
112
110
|
idprefix,
|
package/dist/index.d.ts
CHANGED
package/dist/index.global.js
CHANGED
|
@@ -80,22 +80,20 @@
|
|
|
80
80
|
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
81
81
|
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
82
82
|
};
|
|
83
|
-
function
|
|
83
|
+
function BigNum(num = "0") {
|
|
84
84
|
return new import_bignumber.default(numerfix(num));
|
|
85
85
|
}
|
|
86
86
|
function gte(num, n) {
|
|
87
|
-
return
|
|
87
|
+
return BigNum(num).gte(BigNum(n));
|
|
88
88
|
}
|
|
89
89
|
function lt(num, n) {
|
|
90
|
-
return
|
|
90
|
+
return BigNum(num).lt(BigNum(n));
|
|
91
91
|
}
|
|
92
92
|
function zeromove(value) {
|
|
93
93
|
return value.toString().replace(/\.?0+$/, "");
|
|
94
94
|
}
|
|
95
95
|
function numerfix(value) {
|
|
96
96
|
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
97
|
-
if (_isNaN)
|
|
98
|
-
console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
|
|
99
97
|
return _isNaN ? "0" : String(value);
|
|
100
98
|
}
|
|
101
99
|
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
@@ -107,7 +105,7 @@
|
|
|
107
105
|
];
|
|
108
106
|
let options;
|
|
109
107
|
for (const analy of mappings) {
|
|
110
|
-
const opts = analy && analy(
|
|
108
|
+
const opts = analy && analy(BigNum(num).toFixed(0));
|
|
111
109
|
opts && (options = opts);
|
|
112
110
|
}
|
|
113
111
|
return options || { v: 1, d: 0, n: "" };
|
|
@@ -120,7 +118,7 @@
|
|
|
120
118
|
decimals = 2
|
|
121
119
|
} = options || {};
|
|
122
120
|
const config = parseNumeric(value, delimiters || []);
|
|
123
|
-
let number =
|
|
121
|
+
let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
|
|
124
122
|
decimalSeparator: ".",
|
|
125
123
|
groupSeparator: ",",
|
|
126
124
|
groupSize: 3,
|
|
@@ -137,7 +135,7 @@
|
|
|
137
135
|
var import_ethers2 = __toESM(require_ethers(), 1);
|
|
138
136
|
function formatEther(value = "0", options = {}) {
|
|
139
137
|
const { separator = false, decimals, delimiters = false, rounding, zeromove: zeromove2 = true } = options;
|
|
140
|
-
const number = (0, import_ethers2.formatEther)(
|
|
138
|
+
const number = (0, import_ethers2.formatEther)(BigNum(numerfix(value)).toFixed(0));
|
|
141
139
|
const groupSeparator = separator === false ? "" : ",";
|
|
142
140
|
return formatNumeric(number, {
|
|
143
141
|
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 {
|
|
32
|
+
import { BigNum, formatNumeric, numerfix } 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(
|
|
36
|
+
const number = _formatEther(BigNum(numerfix(value)).toFixed(0));
|
|
37
37
|
const groupSeparator = separator === false ? "" : ",";
|
|
38
38
|
return formatNumeric(number, {
|
|
39
39
|
format: { groupSeparator, ...options.format },
|
|
@@ -65,7 +65,6 @@ async function wait(transaction) {
|
|
|
65
65
|
}
|
|
66
66
|
wait.subscribe = emitter.on.bind(emitter);
|
|
67
67
|
export {
|
|
68
|
-
Bignumber,
|
|
69
68
|
Errors,
|
|
70
69
|
formatEther,
|
|
71
70
|
idprefix,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/ether-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.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.
|
|
29
|
+
"@hairy/utils": "1.13.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"ethers": "^6"
|