dreamworkAPI
Ctrl K
GitHub
classDocs / Version

Version

classsharedmenusource
Object → Version

A semantic version object.

See https://semver.org/

Constructor

Version(major: integer?, minor: integer?, patch: integer?, pre_release: string?, build: string?): Version

Fields

NameTypeDescription
majorintegerThe major version number. (0-1023)
minorintegerThe minor version number. (0-2047)
patchintegerThe patch version number. (0-2047)
pre_releasestringThe pre-release identifiers, empty string if none.
buildstringThe build metadata, empty string if none.

Static functions

addAdds a version to the current version.
copyCreates a copy of the version.
fromStringGets a version object from a version string.
selectReturns the first version that satisfies the range selector.
validateChecks if the string is a valid semantic version.

#Version.add

sharedmenunodiscardsource
function Version.add(self: Version, major: integer | nil, minor: integer | nil, patch: integer | nil, pre_release: integer | nil): Version

Adds a version to the current version.

Parameters
NameTypeDescription
selfVersionThe version.
majorinteger | nilThe major version.
minorinteger | nilThe minor version.
patchinteger | nilThe patch version.
pre_releaseinteger | nilThe value to add to the last numeric pre-release identifier.
Returns
TypeNameDescription
Versionversion_objThe current version.

#Version.copy

sharedmenunodiscardsource
function Version.copy(self: Version): Version

Creates a copy of the version.

Parameters
NameTypeDescription
selfVersionThe version.
Returns
TypeNameDescription
Versionversion_objThe new version.

#Version.fromString

sharedmenunodiscardsource
function Version.fromString(str: string): Version

Gets a version object from a version string.

The string must be a valid semantic version, an optional v prefix is allowed.

Parameters
NameTypeDescription
strstringThe version string in the format major.minor.patch[-pre_release][+build].
Returns
TypeNameDescription
Versionversion_objThe version object.

#Version.select

sharedmenunodiscardsource
function Version.select(versions: Version[], selector: string): Version | nil, integer

Returns the first version that satisfies the range selector.

Parameters
NameTypeDescription
versionsVersion[]The versions to search.
selectorstringThe range selector.
Returns
TypeNameDescription
Version | nilmatched_versionThe matched version, or nil if not found.
integerversion_positionThe position of the matched version, or -1 if not found.

#Version.validate

sharedmenunodiscardsource
function Version.validate(str: string): boolean

Checks if the string is a valid semantic version.

Parameters
NameTypeDescription
strstringThe version string.
Returns
TypeNameDescription
booleanis_validtrue if the string is a valid version, false otherwise.

Methods

compareCompares two versions by precedence, build metadata is ignored.
matchChecks if the version satisfies the range selector.
subSubtracts a version from the current version.

#Version:compare

sharedmenunodiscardsource
function Version:compare(version_obj: Version): integer

Compares two versions by precedence, build metadata is ignored.

Parameters
NameTypeDescription
version_objVersionThe version to compare with.
Returns
TypeNameDescription
integercomparison-1 if the current version is lower, 1 if higher, 0 if equal.

#Version:match

sharedmenunodiscardsource
function Version:match(selector: string): boolean

Checks if the version satisfies the range selector.

Supports npm-style ranges: 1.2.3, >=1.2.3 <2.0.0, 1.2.x, ~1.2.3, ^1.2.3, 1.2.3 - 2.3.4, 1.x || >=2.5.0.

Parameters
NameTypeDescription
selectorstringThe range selector.
Returns
TypeNameDescription
booleanis_matchedtrue if the version satisfies the range, false otherwise.

#Version:sub

sharedmenunodiscardsource
function Version:sub(major: integer | nil, minor: integer | nil, patch: integer | nil, pre_release: integer | nil): Version

Subtracts a version from the current version.

Parameters
NameTypeDescription
majorinteger | nilThe major version.
minorinteger | nilThe minor version.
patchinteger | nilThe patch version.
pre_releaseinteger | nilThe value to subtract from the last numeric pre-release identifier.
Returns
TypeNameDescription
Versionversion_objThe current version.
Generated from the dreamwork meta branch.