Skip to content

Commit 1760d02

Browse files
committed
feat: Support conversion from/to BigInt
1 parent d0f7475 commit 1760d02

File tree

4 files changed

+165
-92
lines changed

4 files changed

+165
-92
lines changed

README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ API
103103

104104
### Utility
105105

106-
* Long.**isLong**(obj: `*`): `boolean`<br />
106+
* type **LongLike**: `Long | number | bigint | string`<br />
107+
Any value or object that either is or can be converted to a Long.
108+
109+
* Long.**isLong**(obj: `any`): `boolean`<br />
107110
Tests if the specified object is a Long.
108111

109112
* Long.**fromBits**(lowBits: `number`, highBits: `number`, unsigned?: `boolean`): `Long`<br />
@@ -124,28 +127,31 @@ API
124127
* Long.**fromNumber**(value: `number`, unsigned?: `boolean`): `Long`<br />
125128
Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
126129

130+
* Long.**fromBigInt**(value: `bigint`, unsigned?: `boolean`): `Long`<br />
131+
Returns a Long representing the given big integer.
132+
127133
* Long.**fromString**(str: `string`, unsigned?: `boolean`, radix?: `number`)<br />
128134
Long.**fromString**(str: `string`, radix: `number`)<br />
129135
Returns a Long representation of the given string, written using the specified radix.
130136

131-
* Long.**fromValue**(val: `*`, unsigned?: `boolean`): `Long`<br />
137+
* Long.**fromValue**(val: `LongLike`, unsigned?: `boolean`): `Long`<br />
132138
Converts the specified value to a Long using the appropriate from* function for its type.
133139

134140
### Methods
135141

136-
* Long#**add**(addend: `Long | number | string`): `Long`<br />
142+
* Long#**add**(addend: `LongLike`): `Long`<br />
137143
Returns the sum of this and the specified Long.
138144

139-
* Long#**and**(other: `Long | number | string`): `Long`<br />
145+
* Long#**and**(other: `LongLike`): `Long`<br />
140146
Returns the bitwise AND of this Long and the specified.
141147

142-
* Long#**compare**/**comp**(other: `Long | number | string`): `number`<br />
148+
* Long#**compare**/**comp**(other: `LongLike`): `number`<br />
143149
Compares this Long's value with the specified's. Returns `0` if they are the same, `1` if the this is greater and `-1` if the given one is greater.
144150

145-
* Long#**divide**/**div**(divisor: `Long | number | string`): `Long`<br />
151+
* Long#**divide**/**div**(divisor: `LongLike`): `Long`<br />
146152
Returns this Long divided by the specified.
147153

148-
* Long#**equals**/**eq**(other: `Long | number | string`): `boolean`<br />
154+
* Long#**equals**/**eq**(other: `LongLike`): `boolean`<br />
149155
Tests if this Long's value equals the specified's.
150156

151157
* Long#**getHighBits**(): `number`<br />
@@ -163,10 +169,10 @@ API
163169
* Long#**getNumBitsAbs**(): `number`<br />
164170
Gets the number of bits needed to represent the absolute value of this Long.
165171

166-
* Long#**greaterThan**/**gt**(other: `Long | number | string`): `boolean`<br />
172+
* Long#**greaterThan**/**gt**(other: `LongLike`): `boolean`<br />
167173
Tests if this Long's value is greater than the specified's.
168174

169-
* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `Long | number | string`): `boolean`<br />
175+
* Long#**greaterThanOrEqual**/**gte**/**ge**(other: `LongLike`): `boolean`<br />
170176
Tests if this Long's value is greater than or equal the specified's.
171177

172178
* Long#**isEven**(): `boolean`<br />
@@ -184,16 +190,16 @@ API
184190
* Long#**isZero**/**eqz**(): `boolean`<br />
185191
Tests if this Long's value equals zero.
186192

187-
* Long#**lessThan**/**lt**(other: `Long | number | string`): `boolean`<br />
193+
* Long#**lessThan**/**lt**(other: `LongLike`): `boolean`<br />
188194
Tests if this Long's value is less than the specified's.
189195

190-
* Long#**lessThanOrEqual**/**lte**/**le**(other: `Long | number | string`): `boolean`<br />
196+
* Long#**lessThanOrEqual**/**lte**/**le**(other: `LongLike`): `boolean`<br />
191197
Tests if this Long's value is less than or equal the specified's.
192198

193-
* Long#**modulo**/**mod**/**rem**(divisor: `Long | number | string`): `Long`<br />
199+
* Long#**modulo**/**mod**/**rem**(divisor: `LongLike`): `Long`<br />
194200
Returns this Long modulo the specified.
195201

196-
* Long#**multiply**/**mul**(multiplier: `Long | number | string`): `Long`<br />
202+
* Long#**multiply**/**mul**(multiplier: `LongLike`): `Long`<br />
197203
Returns the product of this and the specified Long.
198204

199205
* Long#**negate**/**neg**(): `Long`<br />
@@ -208,28 +214,28 @@ API
208214
* Long#**countTrailingZeros**/**ctz**(): `number`<br />
209215
Returns count trailing zeros of this Long.
210216

211-
* Long#**notEquals**/**neq**/**ne**(other: `Long | number | string`): `boolean`<br />
217+
* Long#**notEquals**/**neq**/**ne**(other: `LongLike`): `boolean`<br />
212218
Tests if this Long's value differs from the specified's.
213219

214-
* Long#**or**(other: `Long | number | string`): `Long`<br />
220+
* Long#**or**(other: `LongLike`): `Long`<br />
215221
Returns the bitwise OR of this Long and the specified.
216222

217-
* Long#**shiftLeft**/**shl**(numBits: `Long | number | string`): `Long`<br />
223+
* Long#**shiftLeft**/**shl**(numBits: `Long | number`): `Long`<br />
218224
Returns this Long with bits shifted to the left by the given amount.
219225

220-
* Long#**shiftRight**/**shr**(numBits: `Long | number | string`): `Long`<br />
226+
* Long#**shiftRight**/**shr**(numBits: `Long | number`): `Long`<br />
221227
Returns this Long with bits arithmetically shifted to the right by the given amount.
222228

223-
* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number | string`): `Long`<br />
229+
* Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number`): `Long`<br />
224230
Returns this Long with bits logically shifted to the right by the given amount.
225231

226-
* Long#**rotateLeft**/**rotl**(numBits: `Long | number | string`): `Long`<br />
232+
* Long#**rotateLeft**/**rotl**(numBits: `Long | number`): `Long`<br />
227233
Returns this Long with bits rotated to the left by the given amount.
228234

229-
* Long#**rotateRight**/**rotr**(numBits: `Long | number | string`): `Long`<br />
235+
* Long#**rotateRight**/**rotr**(numBits: `Long | number`): `Long`<br />
230236
Returns this Long with bits rotated to the right by the given amount.
231237

232-
* Long#**subtract**/**sub**(subtrahend: `Long | number | string`): `Long`<br />
238+
* Long#**subtract**/**sub**(subtrahend: `LongLike`): `Long`<br />
233239
Returns the difference of this and the specified Long.
234240

235241
* Long#**toBytes**(le?: `boolean`): `number[]`<br />
@@ -247,6 +253,9 @@ API
247253
* Long#**toNumber**(): `number`<br />
248254
Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
249255

256+
* Long#**toBigInt**(): `bigint`<br />
257+
Converts the Long to its big integer representation.
258+
250259
* Long#**toSigned**(): `Long`<br />
251260
Converts this Long to signed.
252261

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy