decova-dotnet-developer
Version:
This package provides fundumentals that a .net developer may miss while working with Typescript, whether they are missing functinalities or funcionalities provided in a non-elegant design in javascript. Bad naming, bad design of optional parameters, non-c
64 lines • 2.36 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SemVersion = void 0;
const Exceptions_1 = require("../Exceptions/Exceptions");
const semver_1 = __importDefault(require("semver"));
class SemVersion {
constructor(version) {
this._version = null;
this.IsValid = false;
if (!version) {
throw new Exceptions_1.Exception(`SemVer is invalid`);
}
this._version = semver_1.default.clean(version);
if (this._version !== semver_1.default.valid(this._version)) {
throw new Exceptions_1.Exception(`SemVer is invalid`);
}
this.IsValid = true;
}
get Text() {
return this._version;
}
IsInRange(rangeExpression) {
return semver_1.default.satisfies(this._version, rangeExpression);
}
IsGreaterThan(semVer) {
if (this.IsValid == false)
throw new Exceptions_1.Exception(`SemVer is invalid`);
const ver = typeof (semVer) == 'string' ? new SemVersion(semVer) : semVer;
return semver_1.default.gt(this._version, ver._version);
}
IsLessThan(semVer) {
if (this.IsValid == false)
throw new Exceptions_1.Exception(`SemVer is invalid`);
const ver = typeof (semVer) == 'string' ? new SemVersion(semVer) : semVer;
return semver_1.default.lt(this._version, ver._version);
}
get MinVersion() {
var _a;
return new SemVersion((_a = semver_1.default.minVersion(this._version)) === null || _a === void 0 ? void 0 : _a.version);
}
get Patch() {
return semver_1.default.patch(this._version);
}
set Patch(value) {
this._version = `${this.Major}.${this.Minor}.${value}`;
}
get Minor() {
return semver_1.default.minor(this._version);
}
set Minor(value) {
this._version = `$${this.Major}.{value}.${this.Patch}`;
}
get Major() {
return semver_1.default.major(this._version);
}
set Major(value) {
this._version = `${value}.${this.Minor}.${this.Patch}`;
}
}
exports.SemVersion = SemVersion;
//# sourceMappingURL=SemVersion.js.map