Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fregante/tiny-version-compare
Compare two software versions, with any number of points (<1KB)
https://github.com/fregante/tiny-version-compare
Last synced: about 2 months ago
JSON representation
Compare two software versions, with any number of points (<1KB)
- Host: GitHub
- URL: https://github.com/fregante/tiny-version-compare
- Owner: fregante
- License: mit
- Created: 2018-05-23T15:58:10.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-02-25T06:33:33.000Z (over 2 years ago)
- Last Synced: 2024-07-12T13:53:57.009Z (2 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 20
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# tiny-version-compare
> Compare two software versions, with any number of points (<1KB)
Supports most version types, from `r12.3` to `1.03.4.234567-RC4`. Development versions are sorted as: `dev`, `alpha`, `beta`, `rc`, `pre`.
Also [used by Refined GitHub](https://github.com/sindresorhus/refined-github/pull/1218).
## Install
```
$ npm install tiny-version-compare
```## Usage
```js
import compareVersions from 'tiny-version-compare';switch (compareVersions('1.2.3', '2.3.4')) {
case -1: console.log('Second one is greater'); break
case 1: console.log('Second one is lower'); break
case 0: console.log('Versions are equal'); break
}['v2.0-beta', '1.0', 'v2.0', '1.0.1'].sort(compareVersions);
// ['1.0', '1.0.1', 'v2.0-beta', 'v2.0']
```## API
### compareVersions(versionA, versionB)It follows the standard JavaScript [comparison function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description) for Arrays.
Returns `-1` if `versionB` is greater, `1` if `versionA` is greater, `0` if the versions are equivalent.
#### versionA, versionB
Type: `string`
The versions to compare.
## License
MIT © [Federico Brigante](https://fregante.com)