@exodus/bigint 1.0.0 → 1.1.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/package.json +3 -2
- package/src/bn.js +3 -0
- package/src/native-bigint.js +10 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bigint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "bigint wrappers for native BigUnt, bn.js and others",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -31,5 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/ExodusMovement/exodus-core/issues?q=is%3Aissue+is%3Aopen+label%3Abigint"
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "e5bfe616c692bc9f8f28af812777646895306a76"
|
|
35
36
|
}
|
package/src/bn.js
CHANGED
|
@@ -13,12 +13,15 @@ export default class Wrapper {
|
|
|
13
13
|
static isUnderlyingInstance(a) {
|
|
14
14
|
return BN.isBN(a)
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
static wrap(value, base) {
|
|
17
18
|
return new Wrapper(FACTORY_SYMBOL, value, base)
|
|
18
19
|
}
|
|
20
|
+
|
|
19
21
|
static get ZERO() {
|
|
20
22
|
return ZERO
|
|
21
23
|
}
|
|
24
|
+
|
|
22
25
|
static get TEN() {
|
|
23
26
|
return TEN
|
|
24
27
|
}
|
package/src/native-bigint.js
CHANGED
|
@@ -10,6 +10,9 @@ const unwrap = (value) => (value instanceof Wrapper ? value.unwrap() : value)
|
|
|
10
10
|
|
|
11
11
|
const memoizedWrap = memoize((value) => Wrapper.wrap(value))
|
|
12
12
|
|
|
13
|
+
const BI_ZERO = BigInt(0)
|
|
14
|
+
const BI_TEN = BigInt(10)
|
|
15
|
+
|
|
13
16
|
export default class Wrapper {
|
|
14
17
|
static name = 'native-bigint'
|
|
15
18
|
|
|
@@ -33,11 +36,11 @@ export default class Wrapper {
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static get ZERO() {
|
|
36
|
-
return memoizedWrap(
|
|
39
|
+
return memoizedWrap(BI_ZERO)
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
static get TEN() {
|
|
40
|
-
return memoizedWrap(
|
|
43
|
+
return memoizedWrap(BI_TEN)
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
__value__
|
|
@@ -105,11 +108,11 @@ export default class Wrapper {
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
abs() {
|
|
108
|
-
return this.__value__ <
|
|
111
|
+
return this.__value__ < BI_ZERO ? Wrapper.wrap(-this.__value__) : this
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
mutateAbs() {
|
|
112
|
-
if (this.__value__ <
|
|
115
|
+
if (this.__value__ < BI_ZERO) this.__value__ = -this.__value__
|
|
113
116
|
return this
|
|
114
117
|
}
|
|
115
118
|
|
|
@@ -134,15 +137,15 @@ export default class Wrapper {
|
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
isZero() {
|
|
137
|
-
return this.__value__ ===
|
|
140
|
+
return this.__value__ === BI_ZERO
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
isNegative() {
|
|
141
|
-
return this.__value__ <
|
|
144
|
+
return this.__value__ < BI_ZERO
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
isPositive() {
|
|
145
|
-
return this.__value__ >
|
|
148
|
+
return this.__value__ > BI_ZERO
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
toString(base) {
|