UNPKG

@pearnaly/semantic-version

Version:

Javascript/Typescript class to represent, parse and compare semantic versions according to semver.org

96 lines (95 loc) 4.47 kB
/** * Result of a comparison of two versions (-1/0/1) */ export declare enum ComparisonResult { Lower = -1, Equal = 0, Greater = 1 } /** * Represents a Semantic Version as described in [https://semver.org](semver.org) */ export declare class SemVersion { readonly strVersion: string; readonly isValid: boolean; readonly major: number; readonly minor: number; readonly patch: number; readonly preReleaseIdentifiers: string[]; readonly buildMetadataIdentifiers: string[]; private static readonly REGEX; constructor(strVersion: string); /** * Compare the two provided versions. * -1 if version1 < version2 * 0 if version1 == version2 * 1 if version1 > version2 * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static compare(version1: SemVersion | string, version2: SemVersion | string): ComparisonResult; /** * Greater than? true if the first version is strictly greater (>) than the second * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static gt(version1: SemVersion | string, version2: SemVersion | string): boolean; /** * Greater or equal? true if the first version is greater than or equal to (>=) the second * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static ge(version1: SemVersion | string, version2: SemVersion | string): boolean; /** * Lower than? true if the first version is strictly lower (<) than the second * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static lt(version1: SemVersion | string, version2: SemVersion | string): boolean; /** * Lower or equal? true if the first version is lower than or equal to (<=) the second * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static le(version1: SemVersion | string, version2: SemVersion | string): boolean; /** * equal? true if the first version is equal to (==) the second * @param version1 first version to compare - as instance of SemVersion or string * @param version2 second version to compare - as instance of SemVersion or string */ static eq(version1: SemVersion | string, version2: SemVersion | string): boolean; /** * Compare this version to the provided one * -1 if this < comparison * 0 if this == comparison * 1 if this > comparison * @param comparison second version to compare - as instance of SemVersion or string */ compareTo(comparison: SemVersion | string): ComparisonResult; /** * Greater than? true if this version is strictly greater (>) than the compared one * @param comparison second version to compare - as instance of SemVersion or string */ gt(comparison: SemVersion | string): boolean; /** * Greater or equal? true if this version is greater than or equal to (>=) the compared one * @param comparison second version to compare - as instance of SemVersion or string */ ge(comparison: SemVersion | string): boolean; /** * Lower than? true this version is strictly lower (<) than the compared one * @param comparison second version to compare - as instance of SemVersion or string */ lt(comparison: SemVersion | string): boolean; /** * Lower or equal? true this version is lower than or equal to (<=) the compared one * @param comparison second version to compare - as instance of SemVersion or string */ le(comparison: SemVersion | string): boolean; /** * equal? true if this version is equal to (==) the compared one * @param comparison second version to compare - as instance of SemVersion or string */ eq(comparison: SemVersion | string): boolean; toString(): string; }