UNPKG

@serenity-js/core

Version:

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

50 lines 1.19 kB
import semver from 'semver'; import { ensure, isDefined, isString, Predicate, TinyType } from 'tiny-types'; /** * A tiny type describing a version number, like `1.2.3` */ export class Version extends TinyType { version; /** * @param {string} version * @returns {Version} */ static fromJSON(version) { return new Version(version); } /** * @param {string} version */ constructor(version) { super(); this.version = version; ensure('version', version, isDefined(), isString(), isValid()); } /** * @param {Version} other * @returns {boolean} */ isAtLeast(other) { return semver.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}`; } } /** * @package */ function isValid() { return Predicate.to(`be a valid version number`, (version) => !!semver.valid(version)); } //# sourceMappingURL=Version.js.map