bson 4.2.2 → 4.4.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/HISTORY.md +44 -0
- package/bower.json +1 -1
- package/bson.d.ts +77 -6
- package/dist/bson.browser.esm.js +2116 -1292
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +2172 -1347
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +2174 -1347
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +2061 -1241
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +71 -60
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +60 -52
- package/lib/bson.js.map +1 -1
- package/lib/code.js +18 -15
- package/lib/code.js.map +1 -1
- package/lib/db_ref.js +40 -30
- package/lib/db_ref.js.map +1 -1
- package/lib/decimal128.js +135 -124
- package/lib/decimal128.js.map +1 -1
- package/lib/double.js +24 -21
- package/lib/double.js.map +1 -1
- package/lib/ensure_buffer.js +4 -7
- package/lib/ensure_buffer.js.map +1 -1
- package/lib/extended_json.js +113 -71
- package/lib/extended_json.js.map +1 -1
- package/lib/float_parser.js +21 -21
- package/lib/float_parser.js.map +1 -1
- package/lib/int_32.js +19 -16
- package/lib/int_32.js.map +1 -1
- package/lib/long.js +248 -230
- package/lib/long.js.map +1 -1
- package/lib/map.js +54 -45
- package/lib/map.js.map +1 -1
- package/lib/max_key.js +16 -11
- package/lib/max_key.js.map +1 -1
- package/lib/min_key.js +16 -11
- package/lib/min_key.js.map +1 -1
- package/lib/objectid.js +96 -93
- package/lib/objectid.js.map +1 -1
- package/lib/parser/calculate_size.js +17 -15
- package/lib/parser/calculate_size.js.map +1 -1
- package/lib/parser/deserializer.js +135 -123
- package/lib/parser/deserializer.js.map +1 -1
- package/lib/parser/serializer.js +108 -88
- package/lib/parser/serializer.js.map +1 -1
- package/lib/parser/utils.js +47 -25
- package/lib/parser/utils.js.map +1 -1
- package/lib/regexp.js +16 -15
- package/lib/regexp.js.map +1 -1
- package/lib/symbol.js +21 -18
- package/lib/symbol.js.map +1 -1
- package/lib/timestamp.js +50 -27
- package/lib/timestamp.js.map +1 -1
- package/lib/uuid.js +173 -42
- package/lib/uuid.js.map +1 -1
- package/lib/uuid_utils.js +34 -0
- package/lib/uuid_utils.js.map +1 -0
- package/lib/validate_utf8.js +12 -12
- package/lib/validate_utf8.js.map +1 -1
- package/package.json +5 -4
- package/src/binary.ts +20 -6
- package/src/bson.ts +3 -0
- package/src/code.ts +6 -2
- package/src/db_ref.ts +14 -5
- package/src/decimal128.ts +14 -5
- package/src/double.ts +4 -2
- package/src/ensure_buffer.ts +7 -7
- package/src/extended_json.ts +64 -16
- package/src/int_32.ts +4 -2
- package/src/long.ts +22 -8
- package/src/max_key.ts +5 -1
- package/src/min_key.ts +5 -1
- package/src/objectid.ts +15 -20
- package/src/parser/calculate_size.ts +8 -11
- package/src/parser/deserializer.ts +46 -36
- package/src/parser/serializer.ts +13 -12
- package/src/parser/utils.ts +49 -17
- package/src/regexp.ts +5 -5
- package/src/symbol.ts +4 -2
- package/src/timestamp.ts +6 -1
- package/src/uuid.ts +192 -40
- package/src/uuid_utils.ts +31 -0
package/lib/long.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Long = void 0;
|
|
4
|
-
|
|
4
|
+
var utils_1 = require("./parser/utils");
|
|
5
5
|
/**
|
|
6
6
|
* wasm optimizations, to do native i64 multiplication and divide
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
var wasm = undefined;
|
|
9
9
|
try {
|
|
10
10
|
wasm = new WebAssembly.Instance(new WebAssembly.Module(
|
|
11
11
|
// prettier-ignore
|
|
@@ -14,15 +14,15 @@ try {
|
|
|
14
14
|
catch (_a) {
|
|
15
15
|
// no wasm support
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
var TWO_PWR_16_DBL = 1 << 16;
|
|
18
|
+
var TWO_PWR_24_DBL = 1 << 24;
|
|
19
|
+
var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
|
20
|
+
var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
|
21
|
+
var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
|
22
22
|
/** A cache of the Long representations of small integer values. */
|
|
23
|
-
|
|
23
|
+
var INT_CACHE = {};
|
|
24
24
|
/** A cache of the Long representations of small unsigned integer values. */
|
|
25
|
-
|
|
25
|
+
var UINT_CACHE = {};
|
|
26
26
|
/**
|
|
27
27
|
* A class representing a 64-bit integer
|
|
28
28
|
* @public
|
|
@@ -41,18 +41,35 @@ const UINT_CACHE = {};
|
|
|
41
41
|
* case would often result in infinite recursion.
|
|
42
42
|
* Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
var Long = /** @class */ (function () {
|
|
45
45
|
/**
|
|
46
46
|
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
|
|
47
47
|
* See the from* functions below for more convenient ways of constructing Longs.
|
|
48
|
+
*
|
|
49
|
+
* Acceptable signatures are:
|
|
50
|
+
* - Long(low, high, unsigned?)
|
|
51
|
+
* - Long(bigint, unsigned?)
|
|
52
|
+
* - Long(string, unsigned?)
|
|
53
|
+
*
|
|
48
54
|
* @param low - The low (signed) 32 bits of the long
|
|
49
55
|
* @param high - The high (signed) 32 bits of the long
|
|
50
56
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
51
57
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this
|
|
55
|
-
|
|
58
|
+
function Long(low, high, unsigned) {
|
|
59
|
+
if (low === void 0) { low = 0; }
|
|
60
|
+
if (!(this instanceof Long))
|
|
61
|
+
return new Long(low, high, unsigned);
|
|
62
|
+
if (typeof low === 'bigint') {
|
|
63
|
+
Object.assign(this, Long.fromBigInt(low, !!high));
|
|
64
|
+
}
|
|
65
|
+
else if (typeof low === 'string') {
|
|
66
|
+
Object.assign(this, Long.fromString(low, !!high));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.low = low | 0;
|
|
70
|
+
this.high = high | 0;
|
|
71
|
+
this.unsigned = !!unsigned;
|
|
72
|
+
}
|
|
56
73
|
Object.defineProperty(this, '__isLong__', {
|
|
57
74
|
value: true,
|
|
58
75
|
configurable: false,
|
|
@@ -68,17 +85,17 @@ class Long {
|
|
|
68
85
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
69
86
|
* @returns The corresponding Long value
|
|
70
87
|
*/
|
|
71
|
-
|
|
88
|
+
Long.fromBits = function (lowBits, highBits, unsigned) {
|
|
72
89
|
return new Long(lowBits, highBits, unsigned);
|
|
73
|
-
}
|
|
90
|
+
};
|
|
74
91
|
/**
|
|
75
92
|
* Returns a Long representing the given 32 bit integer value.
|
|
76
93
|
* @param value - The 32 bit integer in question
|
|
77
94
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
78
95
|
* @returns The corresponding Long value
|
|
79
96
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
Long.fromInt = function (value, unsigned) {
|
|
98
|
+
var obj, cachedObj, cache;
|
|
82
99
|
if (unsigned) {
|
|
83
100
|
value >>>= 0;
|
|
84
101
|
if ((cache = 0 <= value && value < 256)) {
|
|
@@ -103,14 +120,14 @@ class Long {
|
|
|
103
120
|
INT_CACHE[value] = obj;
|
|
104
121
|
return obj;
|
|
105
122
|
}
|
|
106
|
-
}
|
|
123
|
+
};
|
|
107
124
|
/**
|
|
108
125
|
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
|
|
109
126
|
* @param value - The number in question
|
|
110
127
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
111
128
|
* @returns The corresponding Long value
|
|
112
129
|
*/
|
|
113
|
-
|
|
130
|
+
Long.fromNumber = function (value, unsigned) {
|
|
114
131
|
if (isNaN(value))
|
|
115
132
|
return unsigned ? Long.UZERO : Long.ZERO;
|
|
116
133
|
if (unsigned) {
|
|
@@ -128,16 +145,16 @@ class Long {
|
|
|
128
145
|
if (value < 0)
|
|
129
146
|
return Long.fromNumber(-value, unsigned).neg();
|
|
130
147
|
return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
|
131
|
-
}
|
|
148
|
+
};
|
|
132
149
|
/**
|
|
133
150
|
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
|
|
134
151
|
* @param value - The number in question
|
|
135
152
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
136
153
|
* @returns The corresponding Long value
|
|
137
154
|
*/
|
|
138
|
-
|
|
155
|
+
Long.fromBigInt = function (value, unsigned) {
|
|
139
156
|
return Long.fromString(value.toString(), unsigned);
|
|
140
|
-
}
|
|
157
|
+
};
|
|
141
158
|
/**
|
|
142
159
|
* Returns a Long representation of the given string, written using the specified radix.
|
|
143
160
|
* @param str - The textual representation of the Long
|
|
@@ -145,7 +162,7 @@ class Long {
|
|
|
145
162
|
* @param radix - The radix in which the text is written (2-36), defaults to 10
|
|
146
163
|
* @returns The corresponding Long value
|
|
147
164
|
*/
|
|
148
|
-
|
|
165
|
+
Long.fromString = function (str, unsigned, radix) {
|
|
149
166
|
if (str.length === 0)
|
|
150
167
|
throw Error('empty string');
|
|
151
168
|
if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity')
|
|
@@ -160,7 +177,7 @@ class Long {
|
|
|
160
177
|
radix = radix || 10;
|
|
161
178
|
if (radix < 2 || 36 < radix)
|
|
162
179
|
throw RangeError('radix');
|
|
163
|
-
|
|
180
|
+
var p;
|
|
164
181
|
if ((p = str.indexOf('-')) > 0)
|
|
165
182
|
throw Error('interior hyphen');
|
|
166
183
|
else if (p === 0) {
|
|
@@ -168,12 +185,12 @@ class Long {
|
|
|
168
185
|
}
|
|
169
186
|
// Do several (8) digits each time through the loop, so as to
|
|
170
187
|
// minimize the calls to the very expensive emulated div.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
for (
|
|
174
|
-
|
|
188
|
+
var radixToPower = Long.fromNumber(Math.pow(radix, 8));
|
|
189
|
+
var result = Long.ZERO;
|
|
190
|
+
for (var i = 0; i < str.length; i += 8) {
|
|
191
|
+
var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
|
|
175
192
|
if (size < 8) {
|
|
176
|
-
|
|
193
|
+
var power = Long.fromNumber(Math.pow(radix, size));
|
|
177
194
|
result = result.mul(power).add(Long.fromNumber(value));
|
|
178
195
|
}
|
|
179
196
|
else {
|
|
@@ -183,7 +200,7 @@ class Long {
|
|
|
183
200
|
}
|
|
184
201
|
result.unsigned = unsigned;
|
|
185
202
|
return result;
|
|
186
|
-
}
|
|
203
|
+
};
|
|
187
204
|
/**
|
|
188
205
|
* Creates a Long from its byte representation.
|
|
189
206
|
* @param bytes - Byte representation
|
|
@@ -191,60 +208,60 @@ class Long {
|
|
|
191
208
|
* @param le - Whether little or big endian, defaults to big endian
|
|
192
209
|
* @returns The corresponding Long value
|
|
193
210
|
*/
|
|
194
|
-
|
|
211
|
+
Long.fromBytes = function (bytes, unsigned, le) {
|
|
195
212
|
return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
|
|
196
|
-
}
|
|
213
|
+
};
|
|
197
214
|
/**
|
|
198
215
|
* Creates a Long from its little endian byte representation.
|
|
199
216
|
* @param bytes - Little endian byte representation
|
|
200
217
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
201
218
|
* @returns The corresponding Long value
|
|
202
219
|
*/
|
|
203
|
-
|
|
220
|
+
Long.fromBytesLE = function (bytes, unsigned) {
|
|
204
221
|
return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned);
|
|
205
|
-
}
|
|
222
|
+
};
|
|
206
223
|
/**
|
|
207
224
|
* Creates a Long from its big endian byte representation.
|
|
208
225
|
* @param bytes - Big endian byte representation
|
|
209
226
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
210
227
|
* @returns The corresponding Long value
|
|
211
228
|
*/
|
|
212
|
-
|
|
229
|
+
Long.fromBytesBE = function (bytes, unsigned) {
|
|
213
230
|
return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned);
|
|
214
|
-
}
|
|
231
|
+
};
|
|
215
232
|
/**
|
|
216
233
|
* Tests if the specified object is a Long.
|
|
217
234
|
*/
|
|
218
235
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
219
|
-
|
|
236
|
+
Long.isLong = function (value) {
|
|
220
237
|
return utils_1.isObjectLike(value) && value['__isLong__'] === true;
|
|
221
|
-
}
|
|
238
|
+
};
|
|
222
239
|
/**
|
|
223
240
|
* Converts the specified value to a Long.
|
|
224
241
|
* @param unsigned - Whether unsigned or not, defaults to signed
|
|
225
242
|
*/
|
|
226
|
-
|
|
243
|
+
Long.fromValue = function (val, unsigned) {
|
|
227
244
|
if (typeof val === 'number')
|
|
228
245
|
return Long.fromNumber(val, unsigned);
|
|
229
246
|
if (typeof val === 'string')
|
|
230
247
|
return Long.fromString(val, unsigned);
|
|
231
248
|
// Throws for non-objects, converts non-instanceof Long:
|
|
232
249
|
return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
|
|
233
|
-
}
|
|
250
|
+
};
|
|
234
251
|
/** Returns the sum of this and the specified Long. */
|
|
235
|
-
add(addend) {
|
|
252
|
+
Long.prototype.add = function (addend) {
|
|
236
253
|
if (!Long.isLong(addend))
|
|
237
254
|
addend = Long.fromValue(addend);
|
|
238
255
|
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
256
|
+
var a48 = this.high >>> 16;
|
|
257
|
+
var a32 = this.high & 0xffff;
|
|
258
|
+
var a16 = this.low >>> 16;
|
|
259
|
+
var a00 = this.low & 0xffff;
|
|
260
|
+
var b48 = addend.high >>> 16;
|
|
261
|
+
var b32 = addend.high & 0xffff;
|
|
262
|
+
var b16 = addend.low >>> 16;
|
|
263
|
+
var b00 = addend.low & 0xffff;
|
|
264
|
+
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
248
265
|
c00 += a00 + b00;
|
|
249
266
|
c16 += c00 >>> 16;
|
|
250
267
|
c00 &= 0xffff;
|
|
@@ -257,26 +274,26 @@ class Long {
|
|
|
257
274
|
c48 += a48 + b48;
|
|
258
275
|
c48 &= 0xffff;
|
|
259
276
|
return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
|
260
|
-
}
|
|
277
|
+
};
|
|
261
278
|
/**
|
|
262
279
|
* Returns the sum of this and the specified Long.
|
|
263
280
|
* @returns Sum
|
|
264
281
|
*/
|
|
265
|
-
and(other) {
|
|
282
|
+
Long.prototype.and = function (other) {
|
|
266
283
|
if (!Long.isLong(other))
|
|
267
284
|
other = Long.fromValue(other);
|
|
268
285
|
return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
|
269
|
-
}
|
|
286
|
+
};
|
|
270
287
|
/**
|
|
271
288
|
* Compares this Long's value with the specified's.
|
|
272
289
|
* @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
|
|
273
290
|
*/
|
|
274
|
-
compare(other) {
|
|
291
|
+
Long.prototype.compare = function (other) {
|
|
275
292
|
if (!Long.isLong(other))
|
|
276
293
|
other = Long.fromValue(other);
|
|
277
294
|
if (this.eq(other))
|
|
278
295
|
return 0;
|
|
279
|
-
|
|
296
|
+
var thisNeg = this.isNegative(), otherNeg = other.isNegative();
|
|
280
297
|
if (thisNeg && !otherNeg)
|
|
281
298
|
return -1;
|
|
282
299
|
if (!thisNeg && otherNeg)
|
|
@@ -289,16 +306,16 @@ class Long {
|
|
|
289
306
|
(other.high === this.high && other.low >>> 0 > this.low >>> 0)
|
|
290
307
|
? -1
|
|
291
308
|
: 1;
|
|
292
|
-
}
|
|
309
|
+
};
|
|
293
310
|
/** This is an alias of {@link Long.compare} */
|
|
294
|
-
comp(other) {
|
|
311
|
+
Long.prototype.comp = function (other) {
|
|
295
312
|
return this.compare(other);
|
|
296
|
-
}
|
|
313
|
+
};
|
|
297
314
|
/**
|
|
298
315
|
* Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
|
|
299
316
|
* @returns Quotient
|
|
300
317
|
*/
|
|
301
|
-
divide(divisor) {
|
|
318
|
+
Long.prototype.divide = function (divisor) {
|
|
302
319
|
if (!Long.isLong(divisor))
|
|
303
320
|
divisor = Long.fromValue(divisor);
|
|
304
321
|
if (divisor.isZero())
|
|
@@ -315,12 +332,12 @@ class Long {
|
|
|
315
332
|
// be consistent with non-wasm code path
|
|
316
333
|
return this;
|
|
317
334
|
}
|
|
318
|
-
|
|
335
|
+
var low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
|
|
319
336
|
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
320
337
|
}
|
|
321
338
|
if (this.isZero())
|
|
322
339
|
return this.unsigned ? Long.UZERO : Long.ZERO;
|
|
323
|
-
|
|
340
|
+
var approx, rem, res;
|
|
324
341
|
if (!this.unsigned) {
|
|
325
342
|
// This section is only relevant for signed longs and is derived from the
|
|
326
343
|
// closure library as a whole.
|
|
@@ -332,7 +349,7 @@ class Long {
|
|
|
332
349
|
return Long.ONE;
|
|
333
350
|
else {
|
|
334
351
|
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
|
335
|
-
|
|
352
|
+
var halfThis = this.shr(1);
|
|
336
353
|
approx = halfThis.div(divisor).shl(1);
|
|
337
354
|
if (approx.eq(Long.ZERO)) {
|
|
338
355
|
return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
|
|
@@ -379,12 +396,12 @@ class Long {
|
|
|
379
396
|
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
|
|
380
397
|
// We will tweak the approximate result by changing it in the 48-th digit or
|
|
381
398
|
// the smallest non-fractional digit, whichever is larger.
|
|
382
|
-
|
|
383
|
-
|
|
399
|
+
var log2 = Math.ceil(Math.log(approx) / Math.LN2);
|
|
400
|
+
var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
|
|
384
401
|
// Decrease the approximation until it is smaller than the remainder. Note
|
|
385
402
|
// that if it is too large, the product overflows and is negative.
|
|
386
|
-
|
|
387
|
-
|
|
403
|
+
var approxRes = Long.fromNumber(approx);
|
|
404
|
+
var approxRem = approxRes.mul(divisor);
|
|
388
405
|
while (approxRem.isNegative() || approxRem.gt(rem)) {
|
|
389
406
|
approx -= delta;
|
|
390
407
|
approxRes = Long.fromNumber(approx, this.unsigned);
|
|
@@ -398,143 +415,143 @@ class Long {
|
|
|
398
415
|
rem = rem.sub(approxRem);
|
|
399
416
|
}
|
|
400
417
|
return res;
|
|
401
|
-
}
|
|
418
|
+
};
|
|
402
419
|
/**This is an alias of {@link Long.divide} */
|
|
403
|
-
div(divisor) {
|
|
420
|
+
Long.prototype.div = function (divisor) {
|
|
404
421
|
return this.divide(divisor);
|
|
405
|
-
}
|
|
422
|
+
};
|
|
406
423
|
/**
|
|
407
424
|
* Tests if this Long's value equals the specified's.
|
|
408
425
|
* @param other - Other value
|
|
409
426
|
*/
|
|
410
|
-
equals(other) {
|
|
427
|
+
Long.prototype.equals = function (other) {
|
|
411
428
|
if (!Long.isLong(other))
|
|
412
429
|
other = Long.fromValue(other);
|
|
413
430
|
if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
|
|
414
431
|
return false;
|
|
415
432
|
return this.high === other.high && this.low === other.low;
|
|
416
|
-
}
|
|
433
|
+
};
|
|
417
434
|
/** This is an alias of {@link Long.equals} */
|
|
418
|
-
eq(other) {
|
|
435
|
+
Long.prototype.eq = function (other) {
|
|
419
436
|
return this.equals(other);
|
|
420
|
-
}
|
|
437
|
+
};
|
|
421
438
|
/** Gets the high 32 bits as a signed integer. */
|
|
422
|
-
getHighBits() {
|
|
439
|
+
Long.prototype.getHighBits = function () {
|
|
423
440
|
return this.high;
|
|
424
|
-
}
|
|
441
|
+
};
|
|
425
442
|
/** Gets the high 32 bits as an unsigned integer. */
|
|
426
|
-
getHighBitsUnsigned() {
|
|
443
|
+
Long.prototype.getHighBitsUnsigned = function () {
|
|
427
444
|
return this.high >>> 0;
|
|
428
|
-
}
|
|
445
|
+
};
|
|
429
446
|
/** Gets the low 32 bits as a signed integer. */
|
|
430
|
-
getLowBits() {
|
|
447
|
+
Long.prototype.getLowBits = function () {
|
|
431
448
|
return this.low;
|
|
432
|
-
}
|
|
449
|
+
};
|
|
433
450
|
/** Gets the low 32 bits as an unsigned integer. */
|
|
434
|
-
getLowBitsUnsigned() {
|
|
451
|
+
Long.prototype.getLowBitsUnsigned = function () {
|
|
435
452
|
return this.low >>> 0;
|
|
436
|
-
}
|
|
453
|
+
};
|
|
437
454
|
/** Gets the number of bits needed to represent the absolute value of this Long. */
|
|
438
|
-
getNumBitsAbs() {
|
|
455
|
+
Long.prototype.getNumBitsAbs = function () {
|
|
439
456
|
if (this.isNegative()) {
|
|
440
457
|
// Unsigned Longs are never negative
|
|
441
458
|
return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
|
442
459
|
}
|
|
443
|
-
|
|
444
|
-
|
|
460
|
+
var val = this.high !== 0 ? this.high : this.low;
|
|
461
|
+
var bit;
|
|
445
462
|
for (bit = 31; bit > 0; bit--)
|
|
446
463
|
if ((val & (1 << bit)) !== 0)
|
|
447
464
|
break;
|
|
448
465
|
return this.high !== 0 ? bit + 33 : bit + 1;
|
|
449
|
-
}
|
|
466
|
+
};
|
|
450
467
|
/** Tests if this Long's value is greater than the specified's. */
|
|
451
|
-
greaterThan(other) {
|
|
468
|
+
Long.prototype.greaterThan = function (other) {
|
|
452
469
|
return this.comp(other) > 0;
|
|
453
|
-
}
|
|
470
|
+
};
|
|
454
471
|
/** This is an alias of {@link Long.greaterThan} */
|
|
455
|
-
gt(other) {
|
|
472
|
+
Long.prototype.gt = function (other) {
|
|
456
473
|
return this.greaterThan(other);
|
|
457
|
-
}
|
|
474
|
+
};
|
|
458
475
|
/** Tests if this Long's value is greater than or equal the specified's. */
|
|
459
|
-
greaterThanOrEqual(other) {
|
|
476
|
+
Long.prototype.greaterThanOrEqual = function (other) {
|
|
460
477
|
return this.comp(other) >= 0;
|
|
461
|
-
}
|
|
478
|
+
};
|
|
462
479
|
/** This is an alias of {@link Long.greaterThanOrEqual} */
|
|
463
|
-
gte(other) {
|
|
480
|
+
Long.prototype.gte = function (other) {
|
|
464
481
|
return this.greaterThanOrEqual(other);
|
|
465
|
-
}
|
|
482
|
+
};
|
|
466
483
|
/** This is an alias of {@link Long.greaterThanOrEqual} */
|
|
467
|
-
ge(other) {
|
|
484
|
+
Long.prototype.ge = function (other) {
|
|
468
485
|
return this.greaterThanOrEqual(other);
|
|
469
|
-
}
|
|
486
|
+
};
|
|
470
487
|
/** Tests if this Long's value is even. */
|
|
471
|
-
isEven() {
|
|
488
|
+
Long.prototype.isEven = function () {
|
|
472
489
|
return (this.low & 1) === 0;
|
|
473
|
-
}
|
|
490
|
+
};
|
|
474
491
|
/** Tests if this Long's value is negative. */
|
|
475
|
-
isNegative() {
|
|
492
|
+
Long.prototype.isNegative = function () {
|
|
476
493
|
return !this.unsigned && this.high < 0;
|
|
477
|
-
}
|
|
494
|
+
};
|
|
478
495
|
/** Tests if this Long's value is odd. */
|
|
479
|
-
isOdd() {
|
|
496
|
+
Long.prototype.isOdd = function () {
|
|
480
497
|
return (this.low & 1) === 1;
|
|
481
|
-
}
|
|
498
|
+
};
|
|
482
499
|
/** Tests if this Long's value is positive. */
|
|
483
|
-
isPositive() {
|
|
500
|
+
Long.prototype.isPositive = function () {
|
|
484
501
|
return this.unsigned || this.high >= 0;
|
|
485
|
-
}
|
|
502
|
+
};
|
|
486
503
|
/** Tests if this Long's value equals zero. */
|
|
487
|
-
isZero() {
|
|
504
|
+
Long.prototype.isZero = function () {
|
|
488
505
|
return this.high === 0 && this.low === 0;
|
|
489
|
-
}
|
|
506
|
+
};
|
|
490
507
|
/** Tests if this Long's value is less than the specified's. */
|
|
491
|
-
lessThan(other) {
|
|
508
|
+
Long.prototype.lessThan = function (other) {
|
|
492
509
|
return this.comp(other) < 0;
|
|
493
|
-
}
|
|
510
|
+
};
|
|
494
511
|
/** This is an alias of {@link Long#lessThan}. */
|
|
495
|
-
lt(other) {
|
|
512
|
+
Long.prototype.lt = function (other) {
|
|
496
513
|
return this.lessThan(other);
|
|
497
|
-
}
|
|
514
|
+
};
|
|
498
515
|
/** Tests if this Long's value is less than or equal the specified's. */
|
|
499
|
-
lessThanOrEqual(other) {
|
|
516
|
+
Long.prototype.lessThanOrEqual = function (other) {
|
|
500
517
|
return this.comp(other) <= 0;
|
|
501
|
-
}
|
|
518
|
+
};
|
|
502
519
|
/** This is an alias of {@link Long.lessThanOrEqual} */
|
|
503
|
-
lte(other) {
|
|
520
|
+
Long.prototype.lte = function (other) {
|
|
504
521
|
return this.lessThanOrEqual(other);
|
|
505
|
-
}
|
|
522
|
+
};
|
|
506
523
|
/** Returns this Long modulo the specified. */
|
|
507
|
-
modulo(divisor) {
|
|
524
|
+
Long.prototype.modulo = function (divisor) {
|
|
508
525
|
if (!Long.isLong(divisor))
|
|
509
526
|
divisor = Long.fromValue(divisor);
|
|
510
527
|
// use wasm support if present
|
|
511
528
|
if (wasm) {
|
|
512
|
-
|
|
529
|
+
var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
|
|
513
530
|
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
514
531
|
}
|
|
515
532
|
return this.sub(this.div(divisor).mul(divisor));
|
|
516
|
-
}
|
|
533
|
+
};
|
|
517
534
|
/** This is an alias of {@link Long.modulo} */
|
|
518
|
-
mod(divisor) {
|
|
535
|
+
Long.prototype.mod = function (divisor) {
|
|
519
536
|
return this.modulo(divisor);
|
|
520
|
-
}
|
|
537
|
+
};
|
|
521
538
|
/** This is an alias of {@link Long.modulo} */
|
|
522
|
-
rem(divisor) {
|
|
539
|
+
Long.prototype.rem = function (divisor) {
|
|
523
540
|
return this.modulo(divisor);
|
|
524
|
-
}
|
|
541
|
+
};
|
|
525
542
|
/**
|
|
526
543
|
* Returns the product of this and the specified Long.
|
|
527
544
|
* @param multiplier - Multiplier
|
|
528
545
|
* @returns Product
|
|
529
546
|
*/
|
|
530
|
-
multiply(multiplier) {
|
|
547
|
+
Long.prototype.multiply = function (multiplier) {
|
|
531
548
|
if (this.isZero())
|
|
532
549
|
return Long.ZERO;
|
|
533
550
|
if (!Long.isLong(multiplier))
|
|
534
551
|
multiplier = Long.fromValue(multiplier);
|
|
535
552
|
// use wasm support if present
|
|
536
553
|
if (wasm) {
|
|
537
|
-
|
|
554
|
+
var low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
|
|
538
555
|
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
539
556
|
}
|
|
540
557
|
if (multiplier.isZero())
|
|
@@ -556,15 +573,15 @@ class Long {
|
|
|
556
573
|
return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
|
|
557
574
|
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
|
|
558
575
|
// We can skip products that would overflow.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
576
|
+
var a48 = this.high >>> 16;
|
|
577
|
+
var a32 = this.high & 0xffff;
|
|
578
|
+
var a16 = this.low >>> 16;
|
|
579
|
+
var a00 = this.low & 0xffff;
|
|
580
|
+
var b48 = multiplier.high >>> 16;
|
|
581
|
+
var b32 = multiplier.high & 0xffff;
|
|
582
|
+
var b16 = multiplier.low >>> 16;
|
|
583
|
+
var b00 = multiplier.low & 0xffff;
|
|
584
|
+
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
568
585
|
c00 += a00 * b00;
|
|
569
586
|
c16 += c00 >>> 16;
|
|
570
587
|
c00 &= 0xffff;
|
|
@@ -586,51 +603,51 @@ class Long {
|
|
|
586
603
|
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
|
587
604
|
c48 &= 0xffff;
|
|
588
605
|
return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
|
589
|
-
}
|
|
606
|
+
};
|
|
590
607
|
/** This is an alias of {@link Long.multiply} */
|
|
591
|
-
mul(multiplier) {
|
|
608
|
+
Long.prototype.mul = function (multiplier) {
|
|
592
609
|
return this.multiply(multiplier);
|
|
593
|
-
}
|
|
610
|
+
};
|
|
594
611
|
/** Returns the Negation of this Long's value. */
|
|
595
|
-
negate() {
|
|
612
|
+
Long.prototype.negate = function () {
|
|
596
613
|
if (!this.unsigned && this.eq(Long.MIN_VALUE))
|
|
597
614
|
return Long.MIN_VALUE;
|
|
598
615
|
return this.not().add(Long.ONE);
|
|
599
|
-
}
|
|
616
|
+
};
|
|
600
617
|
/** This is an alias of {@link Long.negate} */
|
|
601
|
-
neg() {
|
|
618
|
+
Long.prototype.neg = function () {
|
|
602
619
|
return this.negate();
|
|
603
|
-
}
|
|
620
|
+
};
|
|
604
621
|
/** Returns the bitwise NOT of this Long. */
|
|
605
|
-
not() {
|
|
622
|
+
Long.prototype.not = function () {
|
|
606
623
|
return Long.fromBits(~this.low, ~this.high, this.unsigned);
|
|
607
|
-
}
|
|
624
|
+
};
|
|
608
625
|
/** Tests if this Long's value differs from the specified's. */
|
|
609
|
-
notEquals(other) {
|
|
626
|
+
Long.prototype.notEquals = function (other) {
|
|
610
627
|
return !this.equals(other);
|
|
611
|
-
}
|
|
628
|
+
};
|
|
612
629
|
/** This is an alias of {@link Long.notEquals} */
|
|
613
|
-
neq(other) {
|
|
630
|
+
Long.prototype.neq = function (other) {
|
|
614
631
|
return this.notEquals(other);
|
|
615
|
-
}
|
|
632
|
+
};
|
|
616
633
|
/** This is an alias of {@link Long.notEquals} */
|
|
617
|
-
ne(other) {
|
|
634
|
+
Long.prototype.ne = function (other) {
|
|
618
635
|
return this.notEquals(other);
|
|
619
|
-
}
|
|
636
|
+
};
|
|
620
637
|
/**
|
|
621
638
|
* Returns the bitwise OR of this Long and the specified.
|
|
622
639
|
*/
|
|
623
|
-
or(other) {
|
|
640
|
+
Long.prototype.or = function (other) {
|
|
624
641
|
if (!Long.isLong(other))
|
|
625
642
|
other = Long.fromValue(other);
|
|
626
643
|
return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
|
627
|
-
}
|
|
644
|
+
};
|
|
628
645
|
/**
|
|
629
646
|
* Returns this Long with bits shifted to the left by the given amount.
|
|
630
647
|
* @param numBits - Number of bits
|
|
631
648
|
* @returns Shifted Long
|
|
632
649
|
*/
|
|
633
|
-
shiftLeft(numBits) {
|
|
650
|
+
Long.prototype.shiftLeft = function (numBits) {
|
|
634
651
|
if (Long.isLong(numBits))
|
|
635
652
|
numBits = numBits.toInt();
|
|
636
653
|
if ((numBits &= 63) === 0)
|
|
@@ -639,17 +656,17 @@ class Long {
|
|
|
639
656
|
return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
|
|
640
657
|
else
|
|
641
658
|
return Long.fromBits(0, this.low << (numBits - 32), this.unsigned);
|
|
642
|
-
}
|
|
659
|
+
};
|
|
643
660
|
/** This is an alias of {@link Long.shiftLeft} */
|
|
644
|
-
shl(numBits) {
|
|
661
|
+
Long.prototype.shl = function (numBits) {
|
|
645
662
|
return this.shiftLeft(numBits);
|
|
646
|
-
}
|
|
663
|
+
};
|
|
647
664
|
/**
|
|
648
665
|
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
|
649
666
|
* @param numBits - Number of bits
|
|
650
667
|
* @returns Shifted Long
|
|
651
668
|
*/
|
|
652
|
-
shiftRight(numBits) {
|
|
669
|
+
Long.prototype.shiftRight = function (numBits) {
|
|
653
670
|
if (Long.isLong(numBits))
|
|
654
671
|
numBits = numBits.toInt();
|
|
655
672
|
if ((numBits &= 63) === 0)
|
|
@@ -658,26 +675,26 @@ class Long {
|
|
|
658
675
|
return Long.fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
|
|
659
676
|
else
|
|
660
677
|
return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
|
|
661
|
-
}
|
|
678
|
+
};
|
|
662
679
|
/** This is an alias of {@link Long.shiftRight} */
|
|
663
|
-
shr(numBits) {
|
|
680
|
+
Long.prototype.shr = function (numBits) {
|
|
664
681
|
return this.shiftRight(numBits);
|
|
665
|
-
}
|
|
682
|
+
};
|
|
666
683
|
/**
|
|
667
684
|
* Returns this Long with bits logically shifted to the right by the given amount.
|
|
668
685
|
* @param numBits - Number of bits
|
|
669
686
|
* @returns Shifted Long
|
|
670
687
|
*/
|
|
671
|
-
shiftRightUnsigned(numBits) {
|
|
688
|
+
Long.prototype.shiftRightUnsigned = function (numBits) {
|
|
672
689
|
if (Long.isLong(numBits))
|
|
673
690
|
numBits = numBits.toInt();
|
|
674
691
|
numBits &= 63;
|
|
675
692
|
if (numBits === 0)
|
|
676
693
|
return this;
|
|
677
694
|
else {
|
|
678
|
-
|
|
695
|
+
var high = this.high;
|
|
679
696
|
if (numBits < 32) {
|
|
680
|
-
|
|
697
|
+
var low = this.low;
|
|
681
698
|
return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
|
|
682
699
|
}
|
|
683
700
|
else if (numBits === 32)
|
|
@@ -685,57 +702,57 @@ class Long {
|
|
|
685
702
|
else
|
|
686
703
|
return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned);
|
|
687
704
|
}
|
|
688
|
-
}
|
|
705
|
+
};
|
|
689
706
|
/** This is an alias of {@link Long.shiftRightUnsigned} */
|
|
690
|
-
shr_u(numBits) {
|
|
707
|
+
Long.prototype.shr_u = function (numBits) {
|
|
691
708
|
return this.shiftRightUnsigned(numBits);
|
|
692
|
-
}
|
|
709
|
+
};
|
|
693
710
|
/** This is an alias of {@link Long.shiftRightUnsigned} */
|
|
694
|
-
shru(numBits) {
|
|
711
|
+
Long.prototype.shru = function (numBits) {
|
|
695
712
|
return this.shiftRightUnsigned(numBits);
|
|
696
|
-
}
|
|
713
|
+
};
|
|
697
714
|
/**
|
|
698
715
|
* Returns the difference of this and the specified Long.
|
|
699
716
|
* @param subtrahend - Subtrahend
|
|
700
717
|
* @returns Difference
|
|
701
718
|
*/
|
|
702
|
-
subtract(subtrahend) {
|
|
719
|
+
Long.prototype.subtract = function (subtrahend) {
|
|
703
720
|
if (!Long.isLong(subtrahend))
|
|
704
721
|
subtrahend = Long.fromValue(subtrahend);
|
|
705
722
|
return this.add(subtrahend.neg());
|
|
706
|
-
}
|
|
723
|
+
};
|
|
707
724
|
/** This is an alias of {@link Long.subtract} */
|
|
708
|
-
sub(subtrahend) {
|
|
725
|
+
Long.prototype.sub = function (subtrahend) {
|
|
709
726
|
return this.subtract(subtrahend);
|
|
710
|
-
}
|
|
727
|
+
};
|
|
711
728
|
/** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
|
|
712
|
-
toInt() {
|
|
729
|
+
Long.prototype.toInt = function () {
|
|
713
730
|
return this.unsigned ? this.low >>> 0 : this.low;
|
|
714
|
-
}
|
|
731
|
+
};
|
|
715
732
|
/** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */
|
|
716
|
-
toNumber() {
|
|
733
|
+
Long.prototype.toNumber = function () {
|
|
717
734
|
if (this.unsigned)
|
|
718
735
|
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
719
736
|
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
720
|
-
}
|
|
737
|
+
};
|
|
721
738
|
/** Converts the Long to a BigInt (arbitrary precision). */
|
|
722
|
-
toBigInt() {
|
|
739
|
+
Long.prototype.toBigInt = function () {
|
|
723
740
|
return BigInt(this.toString());
|
|
724
|
-
}
|
|
741
|
+
};
|
|
725
742
|
/**
|
|
726
743
|
* Converts this Long to its byte representation.
|
|
727
744
|
* @param le - Whether little or big endian, defaults to big endian
|
|
728
745
|
* @returns Byte representation
|
|
729
746
|
*/
|
|
730
|
-
toBytes(le) {
|
|
747
|
+
Long.prototype.toBytes = function (le) {
|
|
731
748
|
return le ? this.toBytesLE() : this.toBytesBE();
|
|
732
|
-
}
|
|
749
|
+
};
|
|
733
750
|
/**
|
|
734
751
|
* Converts this Long to its little endian byte representation.
|
|
735
752
|
* @returns Little endian byte representation
|
|
736
753
|
*/
|
|
737
|
-
toBytesLE() {
|
|
738
|
-
|
|
754
|
+
Long.prototype.toBytesLE = function () {
|
|
755
|
+
var hi = this.high, lo = this.low;
|
|
739
756
|
return [
|
|
740
757
|
lo & 0xff,
|
|
741
758
|
(lo >>> 8) & 0xff,
|
|
@@ -746,13 +763,13 @@ class Long {
|
|
|
746
763
|
(hi >>> 16) & 0xff,
|
|
747
764
|
hi >>> 24
|
|
748
765
|
];
|
|
749
|
-
}
|
|
766
|
+
};
|
|
750
767
|
/**
|
|
751
768
|
* Converts this Long to its big endian byte representation.
|
|
752
769
|
* @returns Big endian byte representation
|
|
753
770
|
*/
|
|
754
|
-
toBytesBE() {
|
|
755
|
-
|
|
771
|
+
Long.prototype.toBytesBE = function () {
|
|
772
|
+
var hi = this.high, lo = this.low;
|
|
756
773
|
return [
|
|
757
774
|
hi >>> 24,
|
|
758
775
|
(hi >>> 16) & 0xff,
|
|
@@ -763,21 +780,21 @@ class Long {
|
|
|
763
780
|
(lo >>> 8) & 0xff,
|
|
764
781
|
lo & 0xff
|
|
765
782
|
];
|
|
766
|
-
}
|
|
783
|
+
};
|
|
767
784
|
/**
|
|
768
785
|
* Converts this Long to signed.
|
|
769
786
|
*/
|
|
770
|
-
toSigned() {
|
|
787
|
+
Long.prototype.toSigned = function () {
|
|
771
788
|
if (!this.unsigned)
|
|
772
789
|
return this;
|
|
773
790
|
return Long.fromBits(this.low, this.high, false);
|
|
774
|
-
}
|
|
791
|
+
};
|
|
775
792
|
/**
|
|
776
793
|
* Converts the Long to a string written in the specified radix.
|
|
777
794
|
* @param radix - Radix (2-36), defaults to 10
|
|
778
795
|
* @throws RangeError If `radix` is out of range
|
|
779
796
|
*/
|
|
780
|
-
toString(radix) {
|
|
797
|
+
Long.prototype.toString = function (radix) {
|
|
781
798
|
radix = radix || 10;
|
|
782
799
|
if (radix < 2 || 36 < radix)
|
|
783
800
|
throw RangeError('radix');
|
|
@@ -788,7 +805,7 @@ class Long {
|
|
|
788
805
|
if (this.eq(Long.MIN_VALUE)) {
|
|
789
806
|
// We need to change the Long value before it can be negated, so we remove
|
|
790
807
|
// the bottom-most digit in this base and then recurse to do the rest.
|
|
791
|
-
|
|
808
|
+
var radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
|
|
792
809
|
return div.toString(radix) + rem1.toInt().toString(radix);
|
|
793
810
|
}
|
|
794
811
|
else
|
|
@@ -796,15 +813,15 @@ class Long {
|
|
|
796
813
|
}
|
|
797
814
|
// Do several (6) digits each time through the loop, so as to
|
|
798
815
|
// minimize the calls to the very expensive emulated div.
|
|
799
|
-
|
|
816
|
+
var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
|
|
800
817
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
801
|
-
|
|
802
|
-
|
|
818
|
+
var rem = this;
|
|
819
|
+
var result = '';
|
|
803
820
|
// eslint-disable-next-line no-constant-condition
|
|
804
821
|
while (true) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
822
|
+
var remDiv = rem.div(radixToPower);
|
|
823
|
+
var intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
|
|
824
|
+
var digits = intval.toString(radix);
|
|
808
825
|
rem = remDiv;
|
|
809
826
|
if (rem.isZero()) {
|
|
810
827
|
return digits + result;
|
|
@@ -815,67 +832,68 @@ class Long {
|
|
|
815
832
|
result = '' + digits + result;
|
|
816
833
|
}
|
|
817
834
|
}
|
|
818
|
-
}
|
|
835
|
+
};
|
|
819
836
|
/** Converts this Long to unsigned. */
|
|
820
|
-
toUnsigned() {
|
|
837
|
+
Long.prototype.toUnsigned = function () {
|
|
821
838
|
if (this.unsigned)
|
|
822
839
|
return this;
|
|
823
840
|
return Long.fromBits(this.low, this.high, true);
|
|
824
|
-
}
|
|
841
|
+
};
|
|
825
842
|
/** Returns the bitwise XOR of this Long and the given one. */
|
|
826
|
-
xor(other) {
|
|
843
|
+
Long.prototype.xor = function (other) {
|
|
827
844
|
if (!Long.isLong(other))
|
|
828
845
|
other = Long.fromValue(other);
|
|
829
846
|
return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
|
830
|
-
}
|
|
847
|
+
};
|
|
831
848
|
/** This is an alias of {@link Long.isZero} */
|
|
832
|
-
eqz() {
|
|
849
|
+
Long.prototype.eqz = function () {
|
|
833
850
|
return this.isZero();
|
|
834
|
-
}
|
|
851
|
+
};
|
|
835
852
|
/** This is an alias of {@link Long.lessThanOrEqual} */
|
|
836
|
-
le(other) {
|
|
853
|
+
Long.prototype.le = function (other) {
|
|
837
854
|
return this.lessThanOrEqual(other);
|
|
838
|
-
}
|
|
855
|
+
};
|
|
839
856
|
/*
|
|
840
857
|
****************************************************************
|
|
841
858
|
* BSON SPECIFIC ADDITIONS *
|
|
842
859
|
****************************************************************
|
|
843
860
|
*/
|
|
844
|
-
toExtendedJSON(options) {
|
|
861
|
+
Long.prototype.toExtendedJSON = function (options) {
|
|
845
862
|
if (options && options.relaxed)
|
|
846
863
|
return this.toNumber();
|
|
847
864
|
return { $numberLong: this.toString() };
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
|
|
865
|
+
};
|
|
866
|
+
Long.fromExtendedJSON = function (doc, options) {
|
|
867
|
+
var result = Long.fromString(doc.$numberLong);
|
|
851
868
|
return options && options.relaxed ? result.toNumber() : result;
|
|
852
|
-
}
|
|
869
|
+
};
|
|
853
870
|
/** @internal */
|
|
854
|
-
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
871
|
+
Long.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
855
872
|
return this.inspect();
|
|
856
|
-
}
|
|
857
|
-
inspect() {
|
|
858
|
-
return
|
|
859
|
-
}
|
|
860
|
-
|
|
873
|
+
};
|
|
874
|
+
Long.prototype.inspect = function () {
|
|
875
|
+
return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
|
|
876
|
+
};
|
|
877
|
+
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
878
|
+
/** Maximum unsigned value. */
|
|
879
|
+
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
880
|
+
/** Signed zero */
|
|
881
|
+
Long.ZERO = Long.fromInt(0);
|
|
882
|
+
/** Unsigned zero. */
|
|
883
|
+
Long.UZERO = Long.fromInt(0, true);
|
|
884
|
+
/** Signed one. */
|
|
885
|
+
Long.ONE = Long.fromInt(1);
|
|
886
|
+
/** Unsigned one. */
|
|
887
|
+
Long.UONE = Long.fromInt(1, true);
|
|
888
|
+
/** Signed negative one. */
|
|
889
|
+
Long.NEG_ONE = Long.fromInt(-1);
|
|
890
|
+
/** Maximum signed value. */
|
|
891
|
+
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
892
|
+
/** Minimum signed value. */
|
|
893
|
+
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
894
|
+
return Long;
|
|
895
|
+
}());
|
|
861
896
|
exports.Long = Long;
|
|
862
|
-
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
863
|
-
/** Maximum unsigned value. */
|
|
864
|
-
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
865
|
-
/** Signed zero */
|
|
866
|
-
Long.ZERO = Long.fromInt(0);
|
|
867
|
-
/** Unsigned zero. */
|
|
868
|
-
Long.UZERO = Long.fromInt(0, true);
|
|
869
|
-
/** Signed one. */
|
|
870
|
-
Long.ONE = Long.fromInt(1);
|
|
871
|
-
/** Unsigned one. */
|
|
872
|
-
Long.UONE = Long.fromInt(1, true);
|
|
873
|
-
/** Signed negative one. */
|
|
874
|
-
Long.NEG_ONE = Long.fromInt(-1);
|
|
875
|
-
/** Maximum signed value. */
|
|
876
|
-
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
877
|
-
/** Minimum signed value. */
|
|
878
|
-
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
879
897
|
Object.defineProperty(Long.prototype, '__isLong__', { value: true });
|
|
880
898
|
Object.defineProperty(Long.prototype, '_bsontype', { value: 'Long' });
|
|
881
899
|
//# sourceMappingURL=long.js.map
|