MoodleVersion
A class for parsing and representing version information for the Moodle VLE.
The class can parse both the human-friendly Moodle release strings like
3.3.6 (Build: 20180517)
, and the underlying raw version numbers like
2017051506
.
Note that this class only reliably understands version information from Moodle 2.2 up. The reason for this limitation is that this is the first Moodle version which uses the now standard versioning conventions.
Static Member Summary
Static Public Members | ||
public static get |
A regular expression for matching human-friendly Moodle release strings. |
|
public static get |
A regular expression for matching under-the-hood version numbers like
|
|
public static get |
A regular expression for matching short version strings like |
Static Method Summary
Static Public Methods | ||
public static |
Convert a branch number into a branch string, i.e. |
|
public static |
Convert a branching date number to a branch, e.g. |
|
public static |
Convert a branch string into a branch number, i.e. |
|
public static |
Convert a branching date number to a branch number, e.g. |
|
public static |
Convert a branch to a branching date number, e.g. |
|
public static |
Convert a branch number to a branching date number, e.g. |
|
public static |
Compare two values to see if they represent the same version, a greater version, or a lesser version. |
|
public static |
dateFromDateNumber(dn: DateNumber): Date Convert a date number to a date object. |
|
public static |
Convert a date object to a date number. |
|
public static |
fromObject(obj: Object): * A factory method for producing a Moodle Version object given all its properties. |
|
public static |
fromString(verStr: string): MoodleVersion Build a version object from a version string. |
|
public static |
Test if a given value is a branch string, e.g. |
|
public static |
isBranchNumber(val: *, strictTypeCheck: boolean): boolean Test if a given value is a branch number, e.g. |
|
public static |
isDateNumber(val: *, strictTypeCheck: boolean): boolean Test if a given value is a date number, i.e. |
|
public static |
isReleaseNumber(val: *, strictTypeCheck: boolean): boolean Test if a given value is a release number. |
|
public static |
isReleaseSuffix(val: *): boolean Test if a given value is a valid release suffix. |
|
public static |
isReleaseType(val: *): boolean Test if a given value is a valid release type. |
|
public static |
numberFromReleaseType(rt: *): number Convert a release type to a number. |
|
public static |
Convert a release type to a release suffix, e.g. |
|
public static |
Convert a relase suffix to a release type, e.g. |
Constructor Summary
Public Constructor | ||
public |
constructor(versionInfo: string | Object) By default version objects contain no information. |
Member Summary
Public Members | ||
public get |
The major version part of the version number, officially known as the branch. |
|
public set |
The branch (AKA major version) must be a string consisting of two digits separated by a period, e.g. |
|
public get |
The version's branch number, if known. This is the two-digit number used internally within the Moodle code to identify a branch, or major release. For example, all Moodle 3.5.* releases will have the branch number |
|
public set |
The branch number must be a two-digit integer between 10 and 99. |
|
public get |
The known mappings between branching date numbers and Moodle branch numbers. |
|
public get |
The known mappings between branching date numbers and Moodle branches. |
|
public get |
The branching date as a date object. |
|
public set |
Setting the branching date will update the branch to match. |
|
public get |
The branching date as a DateNumber. |
|
public set |
Setting the branching date will update the branch to match. |
|
public get |
The known mappings between Moodle braches and branching date numbers. |
|
public get |
The known mappings between Moodle brache numberss and branching date numbers. |
|
public get |
The build number. |
|
public set |
Build numbers must be valid date numbers, i.e. |
|
public get |
The long human-friendly form of the version information. |
|
public get |
The release number part of the version number. |
|
public set |
The release number must be an integer greater than or equal to zero. |
|
public get |
The release suffix for the release's type, e.g. |
|
public set |
The release suffix must be one of |
|
public get |
The release's type, e.g. |
|
public set |
The release type must be one of |
|
public get |
The short human-friendly form of the version number. |
|
public get |
The under-the-hood form of the version number. |
Method Summary
Public Methods | ||
public |
atLeast(mv: MoodleVersion): boolean | undefined Determine whether this version is greater than or equal to the given version. |
|
public |
Create a new Moodle version object representing the same version information. |
|
public |
compareTo(mv: MoodleVersion): number Compare this version to another. |
|
public |
Test if a given value is a Moodle Version object representing the same version. |
|
public |
greaterThan(mv: MoodleVersion): boolean | undefined Determine whether this version is greater than a given version. |
|
public |
Is this version on a branch the library knows about? |
|
public |
Determine whether or not this is version is on a long-term support branch. |
|
public |
Is this a stable release? I.e. |
|
public |
lessThan(mv: MoodleVersion): boolean | undefined Determine whether this version is less than a given version. |
|
public |
sameBranch(mv: MoodleVersion): boolean | undefined Determine whether this versions is on the same branch as a given version. |
|
public |
The version as a plain object indexed by zero or more of: |
|
public |
toSemVerArray(): Array<number> An array containing a SemVer (Semantic Versioning) representation of the version information. |
|
public |
toSemVerObject(): {major: number, minor: number, patch: number} An object containing a SemVer (Semantic Versioning) representation of the version information. |
|
public |
Return a string representation of the version. |
Static Public Members
public static get releaseRE: RegExp source
A regular expression for matching human-friendly Moodle release strings. This RE is case-insensitive and will allow for the optional pre-fixing of the word Moodle with or whithout a separating space.
See:
public static get versionNumberRE: RegExp source
A regular expression for matching under-the-hood version numbers like
'2017051506'
or '2017051506.00'
.
See:
Static Public Methods
public static branchFromBranchNumber(bn: BranchNumber): BranchString | undefined source
Convert a branch number into a branch string, i.e. 35
to '3.5'
and
310
to '3.10'
.
Params:
Name | Type | Attribute | Description |
bn | BranchNumber |
Return:
BranchString | undefined | If the passed value can't be converted
to a branch |
public static branchFromBranchingDateNumber(bdn: DateNumber): BranchString | undefined source
Convert a branching date number to a branch, e.g. 20180517
to
'3.5'
.
Params:
Name | Type | Attribute | Description |
bdn | DateNumber |
public static branchNumberFromBranch(b: BranchString): number | undefined source
Convert a branch string into a branch number, i.e. '3.5'
to 35
.
Params:
Name | Type | Attribute | Description |
b | BranchString |
public static branchNumberFromBranchingDateNumber(bdn: DateNumber): number | undefined source
Convert a branching date number to a branch number, e.g. 20180517
to
35
.
Params:
Name | Type | Attribute | Description |
bdn | DateNumber |
public static branchingDateNumberFromBranch(b: BranchString): number | undefined source
Convert a branch to a branching date number, e.g. '3.5'
to 20180517
.
Params:
Name | Type | Attribute | Description |
b | BranchString |
public static branchingDateNumberFromBranchNumber(bn: BranchNumber): number | undefined source
Convert a branch number to a branching date number, e.g. 35
to 20180517
.
Params:
Name | Type | Attribute | Description |
bn | BranchNumber |
public static compare(val1: *, val2: *): number source
Compare two values to see if they represent the same version, a greater version, or a lesser version.
When ranking versions, the branch is given the highest weight, then the
release number, then the release type,
and finally the build number. When comparing release types,
'development'
is considered earlier 'official'
, which is considered
earlier than 'weekly'
.
Params:
Name | Type | Attribute | Description |
val1 | * | ||
val2 | * |
Return:
number | Unless both values are moodle vesion objects, |
public static dateFromDateNumber(dn: DateNumber): Date source
Convert a date number to a date object. The date object will represent midnight UTC on the given date.
Params:
Name | Type | Attribute | Description |
dn | DateNumber |
Throw:
public static dateNumberFromDate(d: Date): DateNumber source
Convert a date object to a date number. The date will be interpreted as UTC.
Params:
Name | Type | Attribute | Description |
d | Date |
Throw:
public static fromObject(obj: Object): * source
A factory method for producing a Moodle Version object given all its properties.
If only one of the branch and branching date are passed, and if a known mapping exists, the other is auto-completed.
This function can be used to create version objects which contain unknown mappings between Moodle branches and branching dates.
Params:
Name | Type | Attribute | Description |
obj | Object | an object defining zero or more of the following keys:
|
Return:
* |
Throw:
A type error is thrown if an object is not passed, or, if any of the keys within that object map to an invalid value. |
public static fromString(verStr: string): MoodleVersion source
Build a version object from a version string. The vesion string can be in one of the following formats:
- A human-friendly full release string (ReleaseString), e.g.
'Moodle 3.5+ (Build: 20180614)'
(will be accepted with or without the'Moodle'
prefix). - A human-friendly short version string (VersionString), e.g.
'Moodle 3.3.6+'
(will be accepted with or without the'Moodle'
prefix). - An under-the-hood version number (VersionNumber), e.g.
'2017051506'
or'2017051506.00'
.- A string as returned by calling
.toString()
on an instance of this class.
Params:
Name | Type | Attribute | Description |
verStr | string | the version string to parse. |
Throw:
public static isBranch(val: *): boolean source
Test if a given value is a branch string, e.g. '3.5'
or '3.10'
.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
public static isBranchNumber(val: *, strictTypeCheck: boolean): boolean source
Test if a given value is a branch number, e.g. 35
, '35'
, 310
or
`'310'.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
|
strictTypeCheck | boolean |
|
whether or not to enable
strict type checking. With strict type cheking enabled, string
representation of otherwise valid values will return |
public static isDateNumber(val: *, strictTypeCheck: boolean): boolean source
Test if a given value is a date number, i.e. an 8-digit number of the
form YYYYMMDD
.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
|
strictTypeCheck | boolean |
|
whether or not to enable
strict type checking. With strict type cheking enabled, string
representation of otherwise valid values will return |
public static isReleaseNumber(val: *, strictTypeCheck: boolean): boolean source
Test if a given value is a release number.
Note that if strict type checking is not enabled, the empty string is considered a valid release number, being synonymous with zero in Moodle release strings.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
|
strictTypeCheck | boolean |
|
whether or not to enable
strict type checking. With strict type cheking enabled, string
representation of otherwise valid values will return |
public static isReleaseSuffix(val: *): boolean source
Test if a given value is a valid release suffix.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
See:
public static isReleaseType(val: *): boolean source
Test if a given value is a valid release type.
Params:
Name | Type | Attribute | Description |
val | * | the value to test. |
See:
public static numberFromReleaseType(rt: *): number source
Convert a release type to a number. Useful for version comparisons.
All invalid values convert to 0
, 'development'
to 1
, 'official'
to 2
, and 'weekly'
to 3.
Params:
Name | Type | Attribute | Description |
rt | * |
public static releaseSuffixFromReleaseType(rt: ReleaseType): ReleaseSuffix | undefined source
Convert a release type to a release suffix, e.g. 'weekly'
to '+'
.
Params:
Name | Type | Attribute | Description |
rt | ReleaseType |
public static releaseTypeFromReleaseSuffix(rs: ReleaseSuffix): ReleaseType | undefined source
Convert a relase suffix to a release type, e.g. '+'
to 'weekly'
.
Params:
Name | Type | Attribute | Description |
rs | ReleaseSuffix |
Public Constructors
public constructor(versionInfo: string | Object) source
By default version objects contain no information.
If a string is passed, the object is initialised using MoodleVersion.fromString, and if an object is passed then MoodleVersion.fromObject is used instead.
Throw:
* |
TypeError |
* |
RangeError |
Public Members
public get branch: BranchString | undefined source
The major version part of the version number, officially known as the branch.
For example, the branch for each of the 3.4, 3.4+, 3.4.1, and 3.4.1+
releases is '3.4'
.
public set branch: BranchString source
The branch (AKA major version) must be a string consisting of two
digits separated by a period, e.g. '3.5'
.
Setting the branch will also update the branching date to match.
To create an object with an un-known combination of branch and branching date, use the MoodleVersion.fromObject factory method.
Throw:
A range error is thrown if the branch does not have a known mapping to a branching date. |
public get branchNumber: number | undefined source
The version's branch number, if known. This is the two-digit number used internally within the Moodle code to identify a branch, or major release.
For example, all Moodle 3.5.* releases will have the branch number 35
.
public set branchNumber: BranchNumber | undefined source
The branch number must be a two-digit integer between 10 and 99.
Setting the branch number will also update the branching date to match.
To create an object with an un-known combination of branch and branching date, use the MoodleVersion.fromObject factory method.
Throw:
A range error is thrown if the branch does not have a known mapping to a branching date. |
public get brancheNumbersByBranchingDateNumber: * source
The known mappings between branching date numbers and Moodle branch numbers.
@type{Map<DateNumber, BranchNumber>}
public get branchesByBranchingDateNumber: * source
The known mappings between branching date numbers and Moodle branches.
@type{Map<DateNumber, Branch>}
public set branchingDate source
Setting the branching date will update the branch to match.
To create an object with an un-known combination of branch and branching date, use the MoodleVersion.fromObject factory method.
@type{Date|undefined}
Throw:
A range error is thrown if the branching date does not have a known mapping to a branch. |
public set branchingDateNumber source
Setting the branching date will update the branch to match.
To create an object with an un-known combination of branch and branching date, use the MoodleVersion.fromObject factory method.
@type{DateNumber|undefined}
Throw:
A range error is thrown if the branching date does not have a known mapping to a branch. |
public get branchingDateNumbersByBranch: * source
The known mappings between Moodle braches and branching date numbers.
@type{Map<Branch, DateNumber>}
public get branchingDateNumbersByBranchNumber: * source
The known mappings between Moodle brache numberss and branching date numbers.
@type{Map<BranchNumber, DateNumber>}
public set buildNumber: ReleaseSuffix | undefined source
Build numbers must be valid date numbers, i.e. of the form YYYYMMDD
.
Throw:
public get release: ReleaseString source
The long human-friendly form of the version information.
In keeping with how Moodle presents version strings, release numbers of
zero are omitted. If the release type is unknown no suffix is appended.
If the branch is unknown it is represented as '??.??'
, if the
release number is unknown it's represented as '.??'
, and if the build
number is unknown it's represented as '????????'
.
public get releaseNumber: ReleaseNumber | undefined source
The release number part of the version number.
public set releaseNumber: ReleaseNumber | undefined source
The release number must be an integer greater than or equal to zero.
Throw:
public get releaseSuffix: ReleaseSuffix | undefined source
The release suffix for the release's type, e.g. '+'
for weekly
updates to the official releases.
public set releaseSuffix: ReleaseSuffix | undefined source
The release suffix must be one of 'dev'
, an empty string, or '+'
. The
value will get automatically cast to lower case before validation is
applied.
Throw:
public set releaseType: ReleaseType | undefined source
The release type must be one of 'development'
, 'official'
, or
'weekly'
. The value will get automatically cast to lower case before
validation is applied.
Throw:
public get version: VersionString source
The short human-friendly form of the version number.
In keeping with how Moodle presents version strings, release numbers of
zero are omitted. If the release type is unknown no suffix is appended.
If the branch is unknown it is represented as '??.??'
, and if the
release number is unknown it's represented as '.??'
.
public get versionNumber: VersionNumber source
The under-the-hood form of the version number.
If the branch is unknown its replaced with eight question marks, and if the release number is unknown it's replaced with two.
Public Methods
public atLeast(mv: MoodleVersion): boolean | undefined source
Determine whether this version is greater than or equal to the given version.
Params:
Name | Type | Attribute | Description |
mv | MoodleVersion |
public clone(): MoodleVersion source
Create a new Moodle version object representing the same version information.
public compareTo(mv: MoodleVersion): number source
Compare this version to another.
Params:
Name | Type | Attribute | Description |
mv | MoodleVersion |
Return:
number |
|
public equals(val: *): boolean source
Test if a given value is a Moodle Version object representing the same version.
Params:
Name | Type | Attribute | Description |
val | * |
public greaterThan(mv: MoodleVersion): boolean | undefined source
Determine whether this version is greater than a given version.
Params:
Name | Type | Attribute | Description |
mv | MoodleVersion |
public isLTS(): boolean | undefined source
Determine whether or not this is version is on a long-term support
branch. If the branch is not defined or unknown, undefined
is returned.
public isStable(): boolean | undefined source
Is this a stable release? I.e. is the release type official
or
weekly
?
public lessThan(mv: MoodleVersion): boolean | undefined source
Determine whether this version is less than a given version.
Params:
Name | Type | Attribute | Description |
mv | MoodleVersion |
public sameBranch(mv: MoodleVersion): boolean | undefined source
Determine whether this versions is on the same branch as a given version.
Params:
Name | Type | Attribute | Description |
mv | MoodleVersion |
public toObject(): Object source
The version as a plain object indexed by zero or more of:
version
versionNumber
release
branch
branchNumber
branchingDateNumber
branchingDate
releaseNumber
releaseType
releaseSuffix
buildNumber
public toSemVerArray(): Array<number> source
An array containing a SemVer (Semantic Versioning) representation of the version information. The first element will be the major version number, the second the minor, and the third the patch.
public toSemVerObject(): {major: number, minor: number, patch: number} source
An object containing a SemVer (Semantic Versioning) representation of the version information.