How to use the long.isLong function in long

To help you get started, we’ve selected a few long examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heremaps / harp.gl / @here / harp-omv-datasource / lib / OmvData.ts View on Github external
function decodeFeatureId(
    feature: com.mapbox.pb.Tile.IFeature,
    logger?: ILogger
): number | undefined {
    if (feature.id !== undefined) {
        if (typeof feature.id === "number") {
            return feature.id;
        } else if (Long.isLong(feature.id)) {
            if (feature.id.greaterThan(Number.MAX_SAFE_INTEGER)) {
                if (logger !== undefined) {
                    logger.error(
                        "Invalid ID: Larger than largest available Number in feature: ",
                        feature
                    );
                }
            }
            return (feature.id as any).toNumber(); // long
        }
    }
    return undefined;
}
github hsiaosiyuan0 / jlua / src / asm / dump.js View on Github external
writeLuaInt(n) {
    if (this.header.luaIntSize === 4) {
      if (long.isLong(n)) n = n.toNumber();
      this.wb.writeInt32(n);
    } else this.wb.writeInt64(n);
  }
github wallix / datapeps-sdk-js / src / ID.js View on Github external
function compare(a, b) {
        if (Long.isLong(a))
            return a.compare(b);
        return new Long(a).compare(b);
    }
    ID.compare = compare;
github hazelcast / hazelcast-nodejs-client / src / proxy / PNCounterProxy.ts View on Github external
subtractAndGet(delta: Long | number): Promise {
        if (!Long.isLong(delta)) {
            delta = Long.fromNumber(delta as number);
        }
        return this.invokeInternal(PNCounterProxy.EMPTY_ARRAY, null, PNCounterAddCodec, (delta as Long).neg(), false);
    }
github hazelcast / hazelcast-nodejs-client / src / ClientMessage.ts View on Github external
private writeLongInternal(value: any, offset: number): void {
        if (!Long.isLong(value)) {
            value = Long.fromValue(value);
        }

        this.buffer.writeInt32LE(value.low, offset);
        this.buffer.writeInt32LE(value.high, offset + 4);
    }
github Zilliqa / Zilliqa-JavaScript-Library / packages / zilliqa-js-util / src / validation.ts View on Github external
export const isLong = (x: unknown): x is Long => {
  return Long.isLong(x);
};
github cyraxx / pogobuf / pogobuf / pogobuf.utils.js View on Github external
convertLongs: function(object) {
        if (!object || typeof object !== 'object') return object;
        if (object instanceof ByteBuffer) return object;

        if (Long.isLong(object)) {
            return object.lessThanOrEqual(Number.MAX_SAFE_INTEGER)
                && object.greaterThanOrEqual(Number.MIN_SAFE_INTEGER)
                ? object.toNumber() : object.toString();
        }

        for (var i in object) {
            if (object.hasOwnProperty(i)) {
                if (Long.isLong(object[i])) {
                    object[i] = object[i].lessThanOrEqual(Number.MAX_SAFE_INTEGER) && object[i].greaterThanOrEqual(
                        Number.MIN_SAFE_INTEGER) ? object[i].toNumber() : object[i].toString();
                } else if (typeof object[i] === 'object') {
                    object[i] = this.convertLongs(object[i]);
                }
            }
        }
github googleapis / gapic-showcase / nodejs-server / src / echoServer.ts View on Github external
private static toMilliseconds(
    seconds: number | Long | null | undefined,
    nanos: number | null | undefined
  ): number {
    let milliseconds = 0;
    if (Long.isLong(seconds)) {
      milliseconds += (seconds as Long).toNumber() * 1000;
    } else if (seconds) {
      milliseconds += (seconds as number) * 1000;
    }
    if (nanos) {
      milliseconds += nanos / 1000000;
    }
    return milliseconds;
  }
github hsiaosiyuan0 / jlua / src / buffer / write.js View on Github external
writeInt64(n) {
    this.guard(kSizeofUInt64);
    n = long.isLong(n) ? n : long.fromNumber(n);
    this.guard(kSizeofUInt64);
    const bs = this.endian === "BE" ? n.toBytesBE() : n.toBytesLE();
    for (let i = 0; i < kSizeofUInt64; i++) this.writeUInt8(bs[i]);
  }