@amplitude/ampli
Version:
Amplitude CLI
42 lines (41 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class SemanticVersion {
constructor(major, minor = 0, patch = 0) {
this.major = major;
this.minor = minor;
this.patch = patch;
}
toString() {
return `${this.major}.${this.minor}.${this.patch}`;
}
toStringShort() {
let suffix = '';
if (this.minor > 0 || this.patch > 0) {
suffix += `.${this.minor}`;
}
if (this.patch > 0) {
suffix += `.${this.patch}`;
}
return `${this.major}${suffix}`;
}
equals(other) {
return this.major === other.major
&& this.minor === other.minor
&& this.patch === other.patch;
}
equalTo(semver) {
return this.equals(SemanticVersion.fromString(semver));
}
static areEqual(semver1, semver2) {
return SemanticVersion.fromString(semver1).equals(SemanticVersion.fromString(semver2));
}
static fromString(version, delimiter = '.') {
const [major = 0, minor = 0, patch = 0] = version.split(delimiter);
return new SemanticVersion(Number(major), Number(minor), Number(patch));
}
static fromAmpliVersion(version) {
return new SemanticVersion(version.majorVersion, version.minorVersion || 0, version.patchVersion || 0);
}
}
exports.default = SemanticVersion;