genezio
Version:
Command line utility to interact with Genezio infrastructure.
42 lines (41 loc) • 1.19 kB
JavaScript
import { UserError } from "../errors.js";
export class SemanticVersion {
constructor(versionString) {
const match = versionString.match(/^(\d+)\.(\d+)\.(\d+)$/);
if (!match) {
throw new UserError(`Invalid SemVer version string: ${versionString}`);
}
this.major = Number(match[1]);
this.minor = Number(match[2]);
this.patch = Number(match[3]);
}
toString() {
return `${this.major}.${this.minor}.${this.patch}`;
}
isGreaterThan(other) {
if (this.major > other.major) {
return true;
}
else if (this.major < other.major) {
return false;
}
else if (this.minor > other.minor) {
return true;
}
else if (this.minor < other.minor) {
return false;
}
else if (this.patch > other.patch) {
return true;
}
else {
return false;
}
}
isLessThan(other) {
return other.isGreaterThan(this);
}
isEqualTo(other) {
return (this.major === other.major && this.minor === other.minor && this.patch === other.patch);
}
}