@exodus/bigint 1.0.0 → 1.0.1-rc.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.
- package/package.json +1 -1
- package/src/bn.js +3 -0
- package/src/native-bigint.js +9 -7
package/package.json
CHANGED
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,8 @@ 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
|
+
|
|
13
15
|
export default class Wrapper {
|
|
14
16
|
static name = 'native-bigint'
|
|
15
17
|
|
|
@@ -33,11 +35,11 @@ export default class Wrapper {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
static get ZERO() {
|
|
36
|
-
return memoizedWrap(
|
|
38
|
+
return memoizedWrap(BI_ZERO)
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
static get TEN() {
|
|
40
|
-
return memoizedWrap(
|
|
42
|
+
return memoizedWrap(BigInt(10))
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
__value__
|
|
@@ -105,11 +107,11 @@ export default class Wrapper {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
abs() {
|
|
108
|
-
return this.__value__ <
|
|
110
|
+
return this.__value__ < BI_ZERO ? Wrapper.wrap(-this.__value__) : this
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
mutateAbs() {
|
|
112
|
-
if (this.__value__ <
|
|
114
|
+
if (this.__value__ < BI_ZERO) this.__value__ = -this.__value__
|
|
113
115
|
return this
|
|
114
116
|
}
|
|
115
117
|
|
|
@@ -134,15 +136,15 @@ export default class Wrapper {
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
isZero() {
|
|
137
|
-
return this.__value__ ===
|
|
139
|
+
return this.__value__ === BI_ZERO
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
isNegative() {
|
|
141
|
-
return this.__value__ <
|
|
143
|
+
return this.__value__ < BI_ZERO
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
isPositive() {
|
|
145
|
-
return this.__value__ >
|
|
147
|
+
return this.__value__ > BI_ZERO
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
toString(base) {
|