Semantic Versioning or SemVer is a versioning scheme used by Node.js to assign version numbers to packages.
It consists of three numbers separated by periods.
Patch version includes bug fixes and does not add or remove new functionality to the API. According to the SemVer specification, patch versions are backward compatible.
If the current version of a package is 4.17.2, then the next patch release version will be 4.17.3.
Minor version adds new functionality in a backward-compatible manner. It means, for example, anything working in version 4.17.2 will also work in 4.18.0.
When a minor version is released, the patch number is reset to 0. For example, if the current version of a package is 4.17.2, then the next minor version will be 4.18.0.
Major version deprecates functionality and adds new features in a backward incompatible manner. For example, if a function is working in version 4.17.2 might not work in version 5.0.0.
When a major version is released, both minor and patch numbers are reset to 0. For example, suppose you have a package whose current version is 4.17.2, and you want to release the next major update. In that case, the next major version will be 5.0.0.
In Semantic versioning, rule symbols are applied before the version number. These symbols are called prefixes or identifiers. There are nine rule symbols in Semantic Versioning:
^(caret): It freezes the major version, and changes are allowed in the minor or patch version. For example,
^4.17.2means all versions greater than or equal to 4.17.2 and less than 5.0.0 are valid.
~(tilde): In this, major and minor numbers are fixed, and only changes in the patch version are allowed. For example,
~4.17.2includes all versions greater than or equal to 4.17.2 and less than 4.18.0.
=: It means exact version.
<: Any version which is less than the one you mention. For example,
<4.17.2means versions less than 4.17.2 are valid.
<=: It means any version which is less than or equal to the one you specify. Example:
>: Any version greater than the one you mention is valid. Example:
>=: It includes any version greater than or equal to the provided version. Example:
-: You specify the range of versions using the dash sign. Example,
4.5.1 - 4.17.5
||: It is used to combine rule symbols. Example:
<4.0.0 || >4.17.5means version that are less than 4.0.0 and greater than 4.17.5 are valid.
Apart from these nine rule symbols, there is one more rule which is explained here:
x represents any number at that position.
x at Major position:
x as the version in package.json means any version of that package.
x at Minor position:
3.x means any version greater than or equal to 3.0.0 and less than 4.0.0 is valid. It is equivalent to
x at Patch position:
3.1.x means any version greater than or equal to 3.1.0 and less than 3.2.0 is valid. It is equivalent to
You can visit the semantic version calculator to play with the rule symbols.