To create an easy to use, lightweight Version class that can handle basic version comparisons and operations.
npm run demowill run the sample main javascript filenpm run testwill run the mocha unit tests on the /tests folder
- positive integer value to represent the major version of the Version
- positive integer value to represent the minor version of the Version
- positive integer value to represent the build version of the Version
- positive integer value to represent the revision version of the Version
- creates a Version object with major, minor, build, and revision all set to 0
- var a = new Version();
- console.log(a);
- output: { major: 0, minor: 0, build: 0, revision: 0 }
- creates a Version object by splitting the string on '.' and assigning the major, minor, build, and revision values respectively.
- order used: major, minor, build, revision
- all version numbers in the string must be positive integers
- any missing values will be set to 0
- var a = new Version('1.3r5');
- console.log(a);
- output: { major: 1, minor: 3, build: 0, revision: 5 }
- var b = new Version('1.4.5-r2');
- console.log(b);
- output: { major: 1, minor: 4, build: 5, revision: 2 }
- "X.X.X.X"
- "X.X.X"
- "X.X"
- "X"
- "XrX"
- "X-rX"
- "X.XrX"
- "X.X-rX"
- "X.X.XrX"
- "X.X.X-rX" where X is a positive integer and r is the character 'r'
- if there is a 'r' character in the string with not trailing integer, the revision value will be set to 1
- if the parameter is not one of the acceptable string formats
- if a value in the string is not a positive integer excluding the 'r' or '-r'
- creates a Version object by assigning the values in the array to their respective version types
- order used: major, minor, build, revision
- all array values must be a positive integer or null
- any missing or null values will be set to 0
- var a = new Version([1,2]);
- console.log(a);
- output: { major: 1, minor: 2, build: 0, revision: 0 }
- consist of all positive integer or null values
- have a size of 4 or less
- if the parameter has a length greater than 4
- if any of the parameter values are not positive integers or null
- creates a Version object by assigning the values the parameters to their respective version types
- order used: major, minor, build, revision
- all parameter values must be a positive integer or null
- any missing or null values will be set to 0
- only the first four parameters are used, any more will be ignored
- var a = new Version(1,3,2);
- console.log(a);
- output: { major: 1, minor: 3, build: 2, revision: 0 }
- if any other parameters are not positive integers or are not null
- creates a Version object with the same major, minor, build, and revision values as the Version parameter passed to the constructor
- returns the major version of the Version object as an integer
- returns the minor version of the Version object as an integer
- returns the build version of the Version object as an integer
- returns the revision version of the Version object as an integer
- sets the major version of the Version object to the argument integer value
- argument must be a positive integer
- if the parameter is not a positive integer
- sets the minor version of the Version object to the argument integer value
- argument must be a positive integer
- if the parameter is not a positive integer
- sets the build version of the Version object to the argument integer value
- argument must be a positive integer
- if the parameter is not a positive integer
- sets the revision version of the Version object to the argument integer value
- argument must be a positive integer
- if the parameter is not a positive integer
- returns a boolean value if the Version object has a greater version number than the Version object argument
- if the parameter is not a Version object
- returns a boolean value if the Version object has a lesser version number than the Version object argument
- if the parameter is not a Version object
- returns a boolean value if the Version object has an equal version number than the Version object argument
- if the parameter is not a Version object
- returns an integer value to signify if the Version object version is greater, less, or equal to the Version argument's version
- outputs:
- if the Version object version is greater than the Version argument's version: 1
- if the Version object version is equal to the Version argument's version: 0
- if the Version object version is less than the Version argument's version: -1
- var a = new Version('1.0.0.0');
- var b = new Version(1,2,3);
- var c = new Version([1]);
- console.log(a.compare(b));
- output: -1
- console.log(b.compare(c));
- output: 1
- console.log(c.compare(a));
- output: 0
- if the parameter is not a Version object
- increments the Version object's major value by 1 and sets the minor, build, and revision values to 0
- increments the Version object's minor value by 1 and sets the build and revision values to 0
- Version object's major version is not altered
- increments the Version object's build value by 1 and sets the revision value to 0
- Version object's major and minor version are not altered
- increments the Version object's revision value by 1
- Version object's major, minor, and build version are not altered
- returns the Version object in this string representation: M.m.B.R
- M is the Version object's major version
- m is the Version object's minor version
- B is the Version object's build version
- R is the Version object's revision version
- var version = new Version('1.3.4.r2');
- version.toString();
- output: 1.3.4.2
- returns the Version object in the string representation that the string argument asks for
- characters used to format the output
- M is the Version object's major version
- m is the Version object's minor version
- B is the Version object's build version
- R is the Version object's revision version
- only the first of each of the format characters will used in the string
- any other character will be left in the returned string
- if string argument is an empty string then the output will be the same as the toString() function
- var version = new Version('1.3.4.2');
- version.toString("M.m");
- output: 1.3
- version.toString("M:m-B_R");
- output: 1:2-4_2
- version.toString("Version: M.m.B.R-milestone");
- output: Version: 1.3.4.2-milestone
- version.toString("");
- output: 1.3.4.2
- if the parameter is not a string or is not null
- returns the Version object in this string representation: M.m.BrR
- M is the Version object's major version
- m is the Version object's minor version
- B is the Version object's build version
- R is the Version object's revision version
- var version = new Version('1.3.4.2');
- version.toRString();
- output: 1.3.4r2
- returns the Version object in this string representation: M.m.B-rR
- M is the Version object's major version
- m is the Version object's minor version
- B is the Version object's build version
- R is the Version object's revision version
- var version = new Version('1.3.4.2');
- version.toHyphenRString();
- output: 1.3.4-r2
- returns an integer array of size 4 in this order: [M, m, B, R]
- M is the Version object's major version
- m is the Version object's minor version
- B is the Version object's build version
- R is the Version object's revision version
- var version = new Version('1.4.4.0');
- version.toArray();
- output: [1, 4, 4, 0]