tdl
Version:
Node.js bindings to TDLib (Telegram Database library)
76 lines (75 loc) • 2.35 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Version = void 0;
class Version {
/** Parse version from a string */
constructor(ver) {
const [majorStr, minorStr, patchStr] = ver.split('.');
const major = Number(majorStr);
const minor = Number(minorStr);
const patch = Number(patchStr) || 0;
if (!majorStr || !minorStr || Number.isNaN(major) || Number.isNaN(minor))
throw new Error(`Invalid TDLib version '${ver}'`);
this._major = major;
this._minor = minor;
this._patch = patch;
}
/** v1.gt(v2) is v1 > v2 */
gt(other) {
if (this._major > other._major)
return true;
if (this._major < other._major)
return false;
if (this._minor > other._minor)
return true;
if (this._minor < other._minor)
return false;
return this._patch > other._patch;
}
/** v1.lt(v2) is v1 < v2 */
lt(other) {
if (this._major < other._major)
return true;
if (this._major > other._major)
return false;
if (this._minor < other._minor)
return true;
if (this._minor > other._minor)
return false;
return this._patch < other._patch;
}
/** v1.gte(v2) is v1 >= v2 */
gte(other) {
if (this._major > other._major)
return true;
if (this._major < other._major)
return false;
if (this._minor > other._minor)
return true;
if (this._minor < other._minor)
return false;
return this._patch >= other._patch;
}
/** v1.lte(v2) is v1 <= v2 */
lte(other) {
if (this._major < other._major)
return true;
if (this._major > other._major)
return false;
if (this._minor < other._minor)
return true;
if (this._minor > other._minor)
return false;
return this._patch <= other._patch;
}
/** v1.eq(v2) is v1 == v2 */
eq(other) {
return this._major === other._major
&& this._minor === other._minor
&& this._patch === other._patch;
}
toString() {
return `${this._major}.${this._minor}.${this._patch}`;
}
}
exports.Version = Version;