Options
All
  • Public
  • Public/Protected
  • All
Menu

A simple utility class wrapping up some methods to manage your project's version from within the code.

export
implements

{IVersion}

Hierarchy

  • Version

Implements

Index

Constructors

  • new Version(major?: number, minor?: number, patch?: number, preRelease?: null | string, build?: null | string): Version
  • Creates an instance of Version.

    Parameters

    • major: number = 1
    • minor: number = 0
    • patch: number = 0
    • Optional preRelease: null | string
    • Optional build: null | string

    Returns Version

Accessors

  • get build(): null | string
  • Gets the [build] value.

    readonly

    Returns null | string

  • get major(): number
  • Gets the [major] value.

    readonly

    Returns number

  • get minor(): number
  • Gets the [minor] value.

    readonly

    Returns number

  • get patch(): number
  • Gets the [patch] value.

    readonly

    Returns number

  • get preRelease(): null | string
  • Gets the [pre-release] value.

    readonly

    Returns null | string

Methods

  • incrementMajor(): void
  • incrementMinor(): void
  • Increments the minor number by one, sets the patch number to 0 and does not update the major number.

    Returns void

  • incrementPatch(): void
  • resetBuild(): void
  • resetPreRelease(): void
  • setBuild(build: string): void
  • Sets the build suffix at the end of the version.

    throws

    The build suffix must be alphanumeric values separated by dots!

    Parameters

    • build: string

      the build suffix to add

    Returns void

  • setPreRelease(preRelease: string): void
  • Sets the pre-release suffix at the end of the version.

    throws

    The pre-release suffix must be alphanumeric values separated by dots!

    Parameters

    • preRelease: string

      the pre-release suffix to add

    Returns void

  • toJSON(): string
  • toString(): string
  • Outputs the version in the SemVer format: <major>.<minor>.<patch> with optional pre-release (-<pre-release>) and build (+<build>) suffixes.

    Returns string

  • update(type: UpdateType, preRelease?: null | string, build?: null | string): void
  • Updates the version properly.

    Parameters

    • type: UpdateType

      the type of the update

    • Optional preRelease: null | string

      the value of the pre-release (optional)

    • Optional build: null | string

      the value of the build (optional)

    Returns void

  • fromJSON(key: undefined | null | string, value: string): Version
  • Revives an instance of Version when it has been stringified via JSON.stringify.

    Parameters

    • key: undefined | null | string

      the property (should be null or undefined)

    • value: string

      the value for this property (should be the version as a string)

    Returns Version

    the newly created instance of Version

  • fromString(version: string): Version
  • Parses a string to detect if it fits in the Semantic Versioning format.

    throws

    The value [version] does not follow the semantic versioning format: <major>.<minor>.<patch>-<pre-release>+<build> where pre-release and build are optional.

    Parameters

    • version: string

      the version as a string in the SemVer format.

    Returns Version

    an instance of Version based on the input