@drozdik.m/version
Version:
Version package for version management
85 lines (84 loc) • 2.84 kB
JavaScript
exports.__esModule = true;
var Version = /** @class */ (function () {
/**
* Creates new Version object
* @param major Major version number
* @param minor Minor version number
* @param patch Patch version number
*/
function Version(major, minor, patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
}
/**
* Returns the major version number
* */
Version.prototype.Major = function () {
return this.major;
};
/**
* Returns the minor version number
* */
Version.prototype.Minor = function () {
return this.minor;
};
/**
* Returns the patch version number
* */
Version.prototype.Patch = function () {
return this.patch;
};
Version.prototype.GetComparator = function () {
return function (version1, version2) {
if (version1.major < version2.major)
return -1;
else if (version1.major > version2.major)
return 1;
if (version1.minor < version2.minor)
return -1;
else if (version1.minor > version2.minor)
return 1;
if (version1.patch < version2.patch)
return -1;
else if (version1.patch > version2.patch)
return 1;
return 0;
};
};
Version.prototype.CompareTo = function (obj) {
return this.GetComparator()(this, obj);
};
Version.prototype.Equals = function (obj) {
return this.GetComparator()(this, obj) == 0;
};
Version.prototype.LessThan = function (obj) {
return this.GetComparator()(this, obj) < 0;
};
Version.prototype.GreaterThan = function (obj) {
return this.GetComparator()(this, obj) > 0;
};
Version.prototype.toString = function () {
return this.major.toString() + "." + this.minor.toString() + "." + this.patch.toString();
};
/**
* Returns Version object based on a string.
* Version -1 is filled if value is not parsed correctly.
* Version 0 is fileld if value is not found.
* */
Version.FromString = function (string) {
var versions = string.split(".");
var major = typeof versions[0] == "undefined" ? -1 : parseInt(versions[0]);
var minor = typeof versions[1] == "undefined" ? 0 : parseInt(versions[1]);
var patch = typeof versions[2] == "undefined" ? 0 : parseInt(versions[2]);
if (isNaN(major))
major = -1;
if (isNaN(minor))
minor = -1;
if (isNaN(patch))
patch = -1;
return new Version(major, minor, patch);
};
return Version;
}());
exports.Version = Version;