@dev-build-deploy/version-it
Version:
Version Management Library
118 lines (117 loc) • 3.75 kB
TypeScript
import { IVersion } from "./interfaces";
import { Modifier } from "./modifiers";
/**
* SemVer increment types
* @type SemVerIncrement
* @member major Major version
* @member minor Minor version
* @member patch Patch version
* @member preRelease Pre-release identifier
*/
export type SemVerIncrement = "MAJOR" | "MINOR" | "PATCH" | "PRERELEASE";
/**
* A simple SemVer implementation
* @interface ISemVer
* @member major Major version
* @member minor Minor version
* @member patch Patch version
* @member preRelease Pre-release identifier
* @member build Build identifier
*/
export interface ISemVer {
prefix?: string;
major: number;
minor: number;
patch: number;
preReleases: Modifier[];
build?: string;
}
/**
* A simple SemVer implementation
* @class SemVer
* @implements ISemVer
* @member major Major version
* @member minor Minor version
* @member patch Patch version
* @member preRelease Pre-release identifier
* @member build Build identifier
* @method toString Returns the SemVer as a string
*/
export declare class SemVer implements IVersion<SemVer, SemVerIncrement>, ISemVer {
prefix?: string;
major: number;
minor: number;
patch: number;
preReleases: Modifier[];
build?: string;
constructor(version?: Partial<ISemVer>);
/**
* Creates a SemVer object from a string
* @param version Version string
* @param prefix Prefix associated with the version
* @returns SemVer or null if the version string is invalid
*/
static fromString(version: string, prefix?: string): SemVer | null;
/**
* Increments the SemVer based on the provided type:
* - major: 1.0.0 => 2.0.0
* - minor: 1.0.0 => 1.1.0
* - patch: 1.0.0 => 1.0.1
* - preRelease: 1.0.0 => 1.0.0-rc.1
*
* Incrementing a type will reset any lesser significant types (e.g. incrementing minor will reset patch, preRelease).
* order of significance: major > minor > patch > preRelease
*
* @param type Type of increment
* @param modifier Modifier to increment
* @returns Incremented SemVer
*/
increment(type: SemVerIncrement, modifier?: string): SemVer;
/**
* Returns 0 when current version is equal to the provided version,
* 1 when current version is greater than the provided version,
* and -1 when current version is less than the provided version.
*
* Resulting in the following ordering:
*
* 0.0.1
* 0.0.2
* 0.1.0
* 0.2.0-rc.1
* 0.2.0-rc.2
* 0.2.0
* 0.2.0+build.1
* 0.2.0+build.2
* 0.2.1-rc.1+build.1
* 0.2.1-rc.1+build.2
* 0.2.1-rc.2
* 1.0.0
*
* @param other SemVer to compare to
* @returns
*/
compareTo(other: ISemVer): number;
/**
* Compares to Semantic Versions and returns true if they are equal
* @param other Other Semantic Version
* @returns True if the versions are equal, false otherwise
*/
isEqualTo(other: ISemVer): boolean;
/**
* Compares to Semantic Versions and returns true if the current version is greater than the other version
* @param other Other Semantic Version
* @returns True if the current version is greater than the other version, false otherwise
*/
isGreaterThan(other: ISemVer): boolean;
/**
* Compares to Semantic Versions and returns true if the current version is less than the other version
* @param other Other Semantic Version
* @returns True if the current version is less than the other version, false otherwise
*/
isLessThan(other: ISemVer): boolean;
/**
* Returns the SemVer as a string
* @returns SemVer as a string
*/
toString(): string;
}