UNPKG

@serenity-js/core

Version:

The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure

57 lines 1.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Version = void 0; const semver_1 = __importDefault(require("semver")); const tiny_types_1 = require("tiny-types"); /** * A tiny type describing a version number, like `1.2.3` */ class Version extends tiny_types_1.TinyType { version; /** * @param {string} version * @returns {Version} */ static fromJSON(version) { return new Version(version); } /** * @param {string} version */ constructor(version) { super(); this.version = version; (0, tiny_types_1.ensure)('version', version, (0, tiny_types_1.isDefined)(), (0, tiny_types_1.isString)(), isValid()); } /** * @param {Version} other * @returns {boolean} */ isAtLeast(other) { return semver_1.default.gte(this.version, other.version); } /** * @returns {number} * Major version number of a given package version, i.e. `1` in `1.2.3` */ major() { return Number(this.version.split('.')[0]); } /** * @returns {string} */ toString() { return `${this.version}`; } } exports.Version = Version; /** * @package */ function isValid() { return tiny_types_1.Predicate.to(`be a valid version number`, (version) => !!semver_1.default.valid(version)); } //# sourceMappingURL=Version.js.map