All Projects → nikolaposa → Version

nikolaposa / Version

Licence: mit
♈ Value Object that represents a SemVer-compliant version number.

Projects that are alternatives of or similar to Version

Semver.c
Semantic version library written in ANSI C
Stars: ✭ 147 (+25.64%)
Mutual labels:  version, semver
next-ver
Tells you the next semantic version for your local package
Stars: ✭ 27 (-76.92%)
Mutual labels:  semver, version
Version
Represent and compare versions via semantic versioning (SemVer) in Swift
Stars: ✭ 160 (+36.75%)
Mutual labels:  version, semver
Semantic Release
📦🚀 Fully automated version management and package publishing
Stars: ✭ 14,364 (+12176.92%)
Mutual labels:  version, semver
version-check
An action that allows you to check whether your npm package version has been updated
Stars: ✭ 65 (-44.44%)
Mutual labels:  semver, version
Grabver
Gradle Automatic Build Versioning Plugin - An easy Gradle plugin that follows semver.org rules to automatically generate the Patch version, Build number and Code version, while Major, Minor and Pre-Release suffix remain under our control.
Stars: ✭ 39 (-66.67%)
Mutual labels:  version, semver
bin-version-cli
Get the version of a binary in semver format
Stars: ✭ 36 (-69.23%)
Mutual labels:  semver, version
Reckon
Infer a project's version from your Git repository.
Stars: ✭ 124 (+5.98%)
Mutual labels:  version, semver
perfekt
Release, changelog and version your packages with perfe(k)t 👌 ease!
Stars: ✭ 15 (-87.18%)
Mutual labels:  semver, version
bump
A generic version tracking and update tool
Stars: ✭ 33 (-71.79%)
Mutual labels:  semver, version
zerover
0️⃣ Minimalist versioning scheme for devs who can't be bothered.
Stars: ✭ 141 (+20.51%)
Mutual labels:  semver, version
Python Semver
Python package to work with Semantic Versioning (http://semver.org/)
Stars: ✭ 264 (+125.64%)
Mutual labels:  version, semver
semver
Semantic version object for Perl
Stars: ✭ 12 (-89.74%)
Mutual labels:  semver, version
Cli
🆑📍 Setup automated semver compliant package publishing
Stars: ✭ 272 (+132.48%)
Mutual labels:  version, semver
Metav
Release and Versioning of Clojure projects using tools.deps
Stars: ✭ 62 (-47.01%)
Mutual labels:  version
Dotnetversionlister
Use Svendsen Tech's Get-STDotNetVersion function to get a list of installed .NET versions on (remote) Windows computers
Stars: ✭ 101 (-13.68%)
Mutual labels:  version
Apps Version Update
高扩展性的多APP版本更新API接口与后台管理系统
Stars: ✭ 50 (-57.26%)
Mutual labels:  version
Publish Nuget
📦 GitHub action to automate publishing NuGet packages when project version changes
Stars: ✭ 109 (-6.84%)
Mutual labels:  version
Semver
Nx plugin to automate semantic versioning and CHANGELOG generation.
Stars: ✭ 99 (-15.38%)
Mutual labels:  semver
Dependency Land
Find the npm modules that depend on a specific module and semver range.
Stars: ✭ 34 (-70.94%)
Mutual labels:  semver

Version

Build Scrutinizer Code Quality Code Coverage Latest Stable Version PDS Skeleton

Value Object that represents a SemVer-compliant version number.

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:

composer require nikolaposa/version

Usage

Creating a Version object via named constructor and accessing its values

use Version\Extension\Build;
use Version\Extension\PreRelease;
use Version\Version;

$v = Version::from(2, 0, 0, PreRelease::from('alpha', '1'), Build::from('20191222232137'));

echo $v->getMajor(); //2
echo $v->getMinor(); //0
echo $v->getPatch(); //0
print_r($v->getPreRelease()->getIdentifiers()); //Array([0] => alpha [1] => 1)
echo $v->getPreRelease()->toString(); //alpha.1
print_r($v->getBuild()->getIdentifiers()); //Array([0] => 20191222232137)
echo $v->getBuild()->toString(); //20191222232137

Creating a Version object from a string

$v = Version::fromString('1.10.0');

echo $v->toString(); //1.10.0

Comparing Version objects

$v1 = Version::fromString('1.10.0');
$v2 = Version::fromString('2.3.3');

var_dump($v1->isLessThan($v2)); //bool(true)
var_dump($v1->isGreaterThan($v2)); //bool(false)
var_dump($v1->isEqualTo($v2)); //bool(false)

var_dump($v2->isLessThan($v1)); //bool(false)
var_dump($v2->isGreaterThan($v1)); //bool(true)

Matching Version objects against constraints

$v = Version::fromString('2.2.0');

var_dump($v->matches(OperationConstraint::equalTo(Version::fromString('2.2.0')))); //bool(true)
var_dump($v->matches(OperationConstraint::notEqualTo(Version::fromString('2.2.0')))); //bool(true)
var_dump($v->matches(OperationConstraint::fromString('>=2.0.0 <2.3.0'))); //bool(true)
var_dump($v->matches(OperationConstraint::fromString('>=2.0.0 <2.1.0 || 2.2.0'))); //bool(true)

Version operations

$v = Version::fromString('1.10.0');

$v1101 = $v->incrementPatch();
echo $v1101->toString(); //1.10.1

$v1110 = $v1101->incrementMinor();
echo $v1110->toString(); //1.11.0

$v2 = $v1101->incrementMajor();
echo $v2->toString(); //2.0.0

$v2Alpha = $v2->withPreRelease('alpha');
echo $v2Alpha->toString(); //2.0.0-alpha

$v2Alpha111 = $v2Alpha->withBuild('111');
echo $v2Alpha111->toString(); //2.0.0-alpha+111

Version Collection

$versions = new VersionCollection(
    Version::from(1, 0, 1),
    Version::fromString('1.1.0'),
    Version::fromString('2.3.3')
);

echo count($versions); //3

$versions = $versions->sortedDescending();

//Outputs: 2.3.3, 1.1.0, 1.0.1
foreach ($versions as $version) {
    echo $version->toString();
}

$minorReleases = $versions->minorReleases();
echo $minorReleases->first(); //1.1.0

Credits

License

Released under MIT License - see the License File for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].