Skip to content

chore: make Long alias functions into methods #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 63 additions & 21 deletions src/long.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ export class Long {
}

/** This is an alias of {@link Long.compare} */
comp = Long.prototype.compare;
comp(other: string | number | Long | Timestamp): 0 | 1 | -1 {
return this.compare(other);
}

/**
* Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
Expand Down Expand Up @@ -485,7 +487,9 @@ export class Long {
}

/**This is an alias of {@link Long.divide} */
div = Long.prototype.divide;
div(divisor: string | number | Long | Timestamp): Long {
return this.divide(divisor);
}

/**
* Tests if this Long's value equals the specified's.
Expand All @@ -499,7 +503,9 @@ export class Long {
}

/** This is an alias of {@link Long.equals} */
eq = Long.prototype.equals;
eq(other: string | number | Long | Timestamp): boolean {
return this.equals(other);
}

/** Gets the high 32 bits as a signed integer. */
getHighBits(): number {
Expand Down Expand Up @@ -539,17 +545,23 @@ export class Long {
}

/** This is an alias of {@link Long.greaterThan} */
gt = Long.prototype.greaterThan;
gt(other: string | number | Long | Timestamp): boolean {
return this.greaterThan(other);
}

/** Tests if this Long's value is greater than or equal the specified's. */
greaterThanOrEqual(other: string | number | Long | Timestamp): boolean {
return this.comp(other) >= 0;
}

/** This is an alias of {@link Long.greaterThanOrEqual} */
gte = Long.prototype.greaterThanOrEqual;
gte(other: string | number | Long | Timestamp): boolean {
return this.greaterThanOrEqual(other);
}
/** This is an alias of {@link Long.greaterThanOrEqual} */
ge = Long.prototype.greaterThanOrEqual;
ge(other: string | number | Long | Timestamp): boolean {
return this.greaterThan(other);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be greaterThanOrEqual

}

/** Tests if this Long's value is even. */
isEven(): boolean {
Expand Down Expand Up @@ -582,15 +594,19 @@ export class Long {
}

/** This is an alias of {@link Long#lessThan}. */
lt = Long.prototype.lessThan;
lt(other: string | number | Long | Timestamp): boolean {
return this.lessThan(other);
}

/** Tests if this Long's value is less than or equal the specified's. */
lessThanOrEqual(other: string | number | Long | Timestamp): boolean {
return this.comp(other) <= 0;
}

/** This is an alias of {@link Long.lessThanOrEqual} */
lte = Long.prototype.lessThanOrEqual;
lte(other: string | number | Long | Timestamp): boolean {
return this.lessThanOrEqual(other);
}

/** Returns this Long modulo the specified. */
modulo(divisor: string | number | Long | Timestamp): Long {
Expand All @@ -611,9 +627,13 @@ export class Long {
}

/** This is an alias of {@link Long.modulo} */
mod = Long.prototype.modulo;
mod(divisor: string | number | Long | Timestamp): Long {
return this.modulo(divisor);
}
/** This is an alias of {@link Long.modulo} */
rem = Long.prototype.modulo;
rem(divisor: string | number | Long | Timestamp): Long {
return this.modulo(divisor);
}

/**
* Returns the product of this and the specified Long.
Expand Down Expand Up @@ -684,7 +704,9 @@ export class Long {
}

/** This is an alias of {@link Long.multiply} */
mul = Long.prototype.multiply;
mul(multiplier: string | number | Long | Timestamp): Long {
return this.multiply(multiplier);
}

/** Returns the Negation of this Long's value. */
negate(): Long {
Expand All @@ -693,7 +715,9 @@ export class Long {
}

/** This is an alias of {@link Long.negate} */
neg = Long.prototype.negate;
neg(): Long {
return this.negate();
}

/** Returns the bitwise NOT of this Long. */
not(): Long {
Expand All @@ -706,9 +730,13 @@ export class Long {
}

/** This is an alias of {@link Long.notEquals} */
neq = Long.prototype.notEquals;
neq(other: string | number | Long | Timestamp): boolean {
return this.notEquals(other);
}
/** This is an alias of {@link Long.notEquals} */
ne = Long.prototype.notEquals;
ne(other: string | number | Long | Timestamp): boolean {
return this.notEquals(other);
}

/**
* Returns the bitwise OR of this Long and the specified.
Expand Down Expand Up @@ -736,7 +764,9 @@ export class Long {
}

/** This is an alias of {@link Long.shiftLeft} */
shl = Long.prototype.shiftLeft;
shl(numBits: number | Long): Long {
return this.shiftLeft(numBits);
}

/**
* Returns this Long with bits arithmetically shifted to the right by the given amount.
Expand All @@ -756,7 +786,9 @@ export class Long {
}

/** This is an alias of {@link Long.shiftRight} */
shr = Long.prototype.shiftRight;
shr(numBits: number | Long): Long {
return this.shiftRight(numBits);
}

/**
* Returns this Long with bits logically shifted to the right by the given amount.
Expand All @@ -782,9 +814,13 @@ export class Long {
}

/** This is an alias of {@link Long.shiftRightUnsigned} */
shr_u = Long.prototype.shiftRightUnsigned;
shr_u(numBits: number | Long): Long {
return this.shiftRightUnsigned(numBits);
}
/** This is an alias of {@link Long.shiftRightUnsigned} */
shru = Long.prototype.shiftRightUnsigned;
shru(numBits: number | Long): Long {
return this.shiftRightUnsigned(numBits);
}

/**
* Returns the difference of this and the specified Long.
Expand All @@ -797,7 +833,9 @@ export class Long {
}

/** This is an alias of {@link Long.subtract} */
sub = Long.prototype.subtract;
sub(subtrahend: string | number | Long | Timestamp): Long {
return this.subtract(subtrahend);
}

/** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
toInt(): number {
Expand Down Expand Up @@ -925,10 +963,14 @@ export class Long {
}

/** This is an alias of {@link Long.isZero} */
eqz = Long.prototype.isZero;
eqz(): boolean {
return this.isZero();
}

/** This is an alias of {@link Long.lessThanOrEqual} */
le = Long.prototype.lessThanOrEqual;
le(other: string | number | Long | Timestamp): boolean {
return this.lessThanOrEqual(other);
}

/*
****************************************************************
Expand Down