convex
Version:
Client for the Convex Cloud
78 lines (77 loc) • 2.5 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
export class Long {
constructor(low, high) {
__publicField(this, "low");
__publicField(this, "high");
__publicField(this, "__isUnsignedLong__");
this.low = low | 0;
this.high = high | 0;
this.__isUnsignedLong__ = true;
}
static isLong(obj) {
return (obj && obj.__isUnsignedLong__) === true;
}
// prettier-ignore
static fromBytesLE(bytes) {
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
);
}
// prettier-ignore
toBytesLE() {
const hi = this.high;
const lo = this.low;
return [
lo & 255,
lo >>> 8 & 255,
lo >>> 16 & 255,
lo >>> 24,
hi & 255,
hi >>> 8 & 255,
hi >>> 16 & 255,
hi >>> 24
];
}
static fromNumber(value) {
if (isNaN(value)) return UZERO;
if (value < 0) return UZERO;
if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
return new Long(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0);
}
toString() {
return (BigInt(this.high) * BigInt(TWO_PWR_32_DBL) + BigInt(this.low)).toString();
}
equals(other) {
if (!Long.isLong(other)) other = Long.fromValue(other);
if (this.high >>> 31 === 1 && other.high >>> 31 === 1) return false;
return this.high === other.high && this.low === other.low;
}
notEquals(other) {
return !this.equals(other);
}
comp(other) {
if (!Long.isLong(other)) other = Long.fromValue(other);
if (this.equals(other)) return 0;
return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
}
lessThanOrEqual(other) {
return this.comp(
/* validates */
other
) <= 0;
}
static fromValue(val) {
if (typeof val === "number") return Long.fromNumber(val);
return new Long(val.low, val.high);
}
}
const UZERO = new Long(0, 0);
const TWO_PWR_16_DBL = 1 << 16;
const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
const MAX_UNSIGNED_VALUE = new Long(4294967295 | 0, 4294967295 | 0);
//# sourceMappingURL=long.js.map