Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/semver-diff
Get the diff type of two semver versions: 0.0.1 0.0.2 → patch
https://github.com/sindresorhus/semver-diff
Last synced: 7 days ago
JSON representation
Get the diff type of two semver versions: 0.0.1 0.0.2 → patch
- Host: GitHub
- URL: https://github.com/sindresorhus/semver-diff
- Owner: sindresorhus
- License: mit
- Created: 2014-04-22T10:51:05.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2021-05-03T12:27:57.000Z (almost 4 years ago)
- Last Synced: 2025-02-01T16:08:57.468Z (14 days ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 68
- Watchers: 7
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs - semver-diff - Get the diff type of two semver versions: 0.0.1 0.0.2 → patch. ![](https://img.shields.io/github/stars/sindresorhus/semver-diff.svg?style=social&label=Star) (Repository / NPM)
README
# semver-diff
> Get the diff type of two [semver](https://github.com/npm/node-semver) versions: `0.0.1 0.0.2` → `patch`
## Install
```
$ npm install semver-diff
```## Usage
```js
import semverDiff from 'semver-diff';semverDiff('1.1.1', '1.1.2');
//=> 'patch'semverDiff('1.1.1-foo', '1.1.2');
//=> 'prepatch'semverDiff('0.0.1', '1.0.0');
//=> 'major'semverDiff('0.0.1-foo', '1.0.0');
//=> 'premajor'semverDiff('0.0.1', '0.1.0');
//=> 'minor'semverDiff('0.0.1-foo', '0.1.0');
//=> 'preminor'semverDiff('0.0.1-foo', '0.0.1-foo.bar');
//=> 'prerelease'semverDiff('0.1.0', '0.1.0+foo');
//=> 'build'semverDiff('0.0.1', '0.0.1');
//=> undefinedsemverDiff('0.0.2', '0.0.1');
//=> undefined
```## API
### semverDiff(versionA, versionB)
Returns the difference type between two semver versions, or `undefined` if they are identical or the second one is lower than the first.
Possible values:
- `'major'`,
- `'premajor'`,
- `'minor'`,
- `'preminor'`,
- `'patch'`,
- `'prepatch'`,
- `'prerelease'`,
- `'build'`,
- `undefined`## Related
- [latest-semver](https://github.com/sindresorhus/latest-semver) - Get the latest stable semver version from an array of versions
- [to-semver](https://github.com/sindresorhus/to-semver) - Get an array of valid, sorted, and cleaned semver versions from an array of strings
- [semver-regex](https://github.com/sindresorhus/semver-regex) - Regular expression for matching semver versions
- [semver-truncate](https://github.com/sindresorhus/semver-truncate) - Truncate a semver version: `1.2.3` → `1.2.0`---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.