Skip to content

Compares two version number strings based on Semantic Versioning 2.0.0

License

Notifications You must be signed in to change notification settings

questocat/version-comparator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

version-comparator

Compares two version number strings based on Semantic Versioning 2.0.0

StyleCI Build Status Scrutinizer Code Quality Code Coverage Packagist

Installation

Using Composer to add the package to your project's dependencies:

$ composer require questocat/version-comparator

Usage

Using compare method

$semVerManager = new SemVerManager();
$semVerManager->compare('2.9.0', '2.9.6', '<');                           // true
$semVerManager->compare('5.1.0', '5.1.0-alpha', '>');                     // true
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '<');           // false
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '>');           // true
$semVerManager->compare('2.0.1-alpha.2', '2.0.1-alpha.1', '!=');          // true
$semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<');        // true
$semVerManager->compare('2.0.1-alpha-abc.2', '2.0.1-alpha-abc.1', '>');   // true
$semVerManager->compare('1.0.0-alpha', '1.0.0-beta', '<');                // true
$semVerManager->compare('0.0.0+0', '0.0.0+1', '=');                       // true
$semVerManager->compare('1.0.0-alpha+001', '1.0.0+20130313144700', '<');  // true
$semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '<');         // false
$semVerManager->compare('1.0.0-rc.1+build.1', '1.0.0-rc.1', '=');         // true
$semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '<');         // fasle
$semVerManager->compare('1.0.0-rc.2+build.1', '1.0.0-rc.1', '>=');        // true

Other examples

$semVerManager->compare('1.0.0-alpha', '1.0.0-alpha.1', '<');
$semVerManager->compare('1.0.0-alpha.1', '1.0.0-alpha.beta', '<');
$semVerManager->compare('1.0.0-alpha.beta', '1.0.0-beta', '<');
$semVerManager->compare('1.0.0-beta', '1.0.0-beta.2', '<');
$semVerManager->compare('1.0.0-beta.2', '1.0.0-beta.11', '<');
$semVerManager->compare('1.0.0-beta.11', '1.0.0-rc.1', '<');
$semVerManager->compare('1.0.0-rc.1', '1.0.0', '<');

Conclusion

1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0- rc.1 < 1.0.0

Using compareTo method

$semVerManager = new SemVerManager('2.9.0');
$semVerManager->compareTo('2.9.6', '<');        // true
$semVerManager->compareTo('2.8.9', '>');        // true
$semVerManager->compareTo('2.8.9-alpha', '>');  // true

Reference

License

Licensed under the MIT license.

About

Compares two version number strings based on Semantic Versioning 2.0.0

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages