@igor.dvlpr/keppo v1.1.0
🎡 Keppo(1.x.x) 🧮
🎡 Parse, manage, compare and output SemVer-compatible version numbers. 🧮
Install it by running
npm i "@igor.dvlpr/keppo"API
There are 2 available constructors:
constructor(major?: number = 0, minor?: number = 0, patch?: number = 0, strict?: boolean = true, label?: string = '')major?: number = 0 -> major version number,
minor?: number = 0 => minor version number,
patch?: number = 0 => patch version number,
strict?: boolean = true => determines whether the parsing should be strict or not, i.e. use v as prefix, e.g. v1.0.0,
label?: string = '' => label for the version, no need to prefix with a dash.
and
constructor(version: string)version: string => a valid SemVer version string, either in strict or non-strict format, i.e. 1.0.0 or v1.0.0, strict mode is inferred from the input string.
If any of the parameters in either constructor is not valid, it will throw an appropriate error.
parse(version: string): Keppo;Parses the provided string as a SemVer version.
version: string => A valid SemVer version represented as a string, e.g. "1.2.3", "v1.5.3", "2.3.4-alpha", "v2.4.6-beta".
Throws an exception if the passed parameter is not valid.
Returns a new instance of Keppo with the parsed version.
isStrict(isStrict?: boolean = true): KeppoSets the strict mode for the SemVer version, i.e. allow v as a prefix for SemVer, e.g. v1.0.0. By default, strict mode is true.
increaseMajor(major?: number = 1): KeppoIncreases the major version number for the provided value.
major: number = 1 => The major version number to increase by, defaults to 1.
Throws an exception if the passed parameter is not valid.
increaseMinor(minor?: number = 1): KeppoIncreases the minor version number for the provided value.
minor: number = 1 => The minor version number to increase by, defaults to 1.
Throws an exception if the passed parameter is not valid.
increasePatch(patch?: number = 1): KeppoIncreases the patch version number for the provided value.
patch: number = 1 => The patch version number to increase by, defaults to 1.
Throws an exception if the passed parameter is not valid.
decreaseMajor(major?: number = 1): KeppoDecreases the major version number for the provided value.
major: number = 1 => The major version number to decrease by, defaults to 1.
Throws an exception if the passed parameter is not valid.
decreaseMinor(minor?: number = 1): KeppoDecreases the minor version number for the provided value.
minor: number = 1 => The minor version number to decrease by, defaults to 1.
Throws an exception if the passed parameter is not valid.
decreasePatch(patch?: number = 1): KeppoDecreases the patch version number for the provided value.
patch: number = 1 => The patch version number to decrease by, defaults to 1.
Throws an exception if the passed parameter is not valid.
setMajor(major: number | string): KeppoSets the major version number for the current Keppo instance.
major: number | string => The major version number, either as a number or as a string.
Throws an exception if the passed parameter is not valid.
setMinor(minor: number | string): KeppoSets the minor version number for the current Keppo instance.
minor: number | string => The minor version number, either as a number or as a string.
Throws an exception if the passed parameter is not valid.
setPatch(patch: number | string): KeppoSets the patch version number for the current Keppo instance.
patch: number | string => The patch version number, either as a number or as a string.
Throws an exception if the passed parameter is not valid.
setLabel(label: string): KeppoSets the version label for the current Keppo instance. No need to prefix with a dash "-", i.e. "alpha" and its output would be 0.1.0-alpha.
Throws an exception if the passed parameter is not valid.
compare(version: Keppo | string): numberCompares the current Keppo SemVer-compatible version with a provided one. The passed argument can either be another instance of Keppo or a valid SemVer string.
Returns a value defined as:
-1if the current instance version is less than the provided version,0if the compared versions are equal,1if the current instance version is greater than the provided version.
output(): voidPrints to console the String representation of the current Keppo object.
setVersion(version: string): KeppoSets the current Keppo version. The passed value must be a valid SemVer string. This will replace all the previous version information.
Throws an exception if the passed parameter is not valid or the passed parameter is not a valid SemVer version.
toString(): stringFormats the current Keppo object as a String.
static isValid(version: string, isStrict: boolean = true): booleanA static method that checks whether the provided String is a valid SemVer version number. Useful for checking whether a version is valid before calling setVersion().
version: string => A String representing a SemVer version number,
isStrict: boolean => A Boolean representing whether the strict mode is enabled, defaults to true and is not inferred from this instance's strict property.
Returns a Boolean result.
canIncreaseMajor(major: number = 1): booleanChecks whether this instance's major version can be safely increased by the given value.
major: number = 1 => The value to increase by.
Returns a Boolean result.
Read more about Integer safety on MDN.
canIncreaseMinor(minor: number = 1): booleanChecks whether this instance's minor version can be safely increased by the given value.
minor: number = 1 => The value to increase by.
Returns a Boolean result.
Read more about Integer safety on MDN.
canIncreasePatch(patch: number = 1): booleanChecks whether this instance's patch version can be safely increased by the given value.
patch: number = 1 => The value to increase by.
Returns a Boolean result.
Read more about Integer safety on MDN.
maxIncreaseMajor(): numberReturns the maximum possible value that can be used to increase the major version number.
Read more about Integer safety on MDN.
maxIncreaseMinor(): numberReturns the maximum possible value that can be used to increase the minor version number.
Read more about Integer safety on MDN.
maxIncreasePatch(): numberReturns the maximum possible value that can be used to increase the patch version number.
Usage
const { Keppo } = require('@igor.dvlpr/keppo')
new Keppo(1, 0, 0).toString() // returns '1.0.0'
new Keppo(1, 0, 0, true, 'alpha').toString() // returns '1.0.0-alpha'
new Keppo('1.0.0').increaseMajor(2).toString() // returns '3.0.0'
new Keppo(1, 0, 0).compare('2.0.0') // returns -1
new Keppo('1.0.32').maxIncreasePatch() // returns 9007199254740959
new Keppo('1.0.1').canIncreasePatch(1) // returns true
// static method
Keppo.isValid('v1.0.0', false) //returns true
Keppo.isValid('v1.0.0') // returns falseSee the test directory for more examples and insight of the Keppo's API capabilities.