Version
Represents an immutable MAJOR.MINOR.PATCH version following semantic versioning rules.
Constructor
new Version(version: { major: number, minor: number, patch: number, preRelease: string, build: string })
new Version(version: string)
new Version(major?: number, minor?: number, patch?: number, preRelease?: string, build?: string)
new Version()
Parses a version out of another version, a semantic versioning string, or individual major.minor.patch components.
An empty constructor call will result in a valid 0.0.0
version.
Public Properties
major
|
The major component of the version. Increments whenever incompatible
API changes are introduced, with the exception of 0.x.y , which is
for initial development and may see breaking changes at any time.
|
minor
|
The minor component of the version. Increments whenever backwards- compatible functionality is added. |
patch
|
The patch component of the version. Increments whenever backwards- compatible bug fixes are introduced. |
preRelease
|
The pre-release component of the version. Is separated from the other
components with a dash (- ) and clearly distinguishes the version
from a “normal” version (e.g. an alpha version), marking it as
potentially unstable.
|
build
|
The build metadata of the version. Is separated from the other components
with a plus (+ ) and can contain additional information about the
specific build.
|
Public Computed Properties
valid
|
Returns a value indicating whether this Version instance
represents a valid semantic version.
If this value is false , all components of the instance are
either NaN or an empty string.
|
Public Non-Mutator Methods
Returns a new If the version is invalid, the new instance will also be invalid. |
|
Returns a new If the version is invalid, the new instance will also be invalid. |
|
Returns a new If the version is invalid, the new instance will also be invalid. |
|
Returns Note that two invalid versions are always identical. |
|
Returns the proper semantic string representation of this semantic version. Note that invalid versions return "Invalid Version". |
|
Same output as `toString()`. |
|
Compares this version with another one, returning a result based on which should take precedence over the other. If this version is lower than the passed version in precedence, returns
A pre-release version is always lower in precedence. If both versions have a pre-release component, each dot-separated identifier is compared numerically or lexically, whichever applies. If the number of identifiers is not equal and all preceding identifiers are the same, the version with more identifiers wins. Note that a result of |
Remarks
This class is not capable of representing versions with individual components
larger than
Number.MAX_SAFE_INTEGER
.
Versions constructed with such large numbers are not inherently invalid, but
their version components will be rounded to the next representable integer
value.