Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
writeLuaInt(n) {
if (this.header.luaIntSize === 4) {
if (long.isLong(n)) n = n.toNumber();
this.wb.writeInt32(n);
} else this.wb.writeInt64(n);
}
function compare(a, b) {
if (Long.isLong(a))
return a.compare(b);
return new Long(a).compare(b);
}
ID.compare = compare;
if (parameterValue.every((item) => Long.isLong(item))) {
return;
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);
}
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);
}
export const isLong = (x: unknown): x is Long => {
return Long.isLong(x);
};
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]);
}
}
}
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;
}
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]);
}