semantic-version
semantic-version
A small Crystal utility class for storing, parsing, and comparing SemVer-style version strings.
This class is a port of semantic Ruby gem over to Crystal.
Usage
This library exposes a single class - Semantic::Version
. Instantiate it a SemVer version as a string, hash, tuple or named tuple, and you've got a version object with a few methods.
require "semantic-version"
version = Semantic::Version.new("4.2.0")
version.major # => 4
version.minor # => 2
version.patch # => 0
release = Semantic::Version.new("5.2.0")
release > version # => true
version <=> release # => -1
with_tuple = Semantic::Version.new({4, 2, 0})
with_hash = Semantic::Version.new({ "major" => 2, "minor" => 3, "patch" => 0 })
with_ntuple = Semantic::Version.new({ major: 2, minor: 5, patch: 0, pre: nil, build: "build.1123" })
You can also compare versions.
v_new = Semantic::Version.new("4.2.0")
v_old = Semantic::Version.new("2.4.0")
v_new > v_old # => true
v_old < v_new # => true
v_new.gt?(v_old) # => true
v_old.lt?(v_new) # => true
Convenience methods include:
gt?
- greater thangte?
- greater than or equal tolt?
- less thanlte?
- less than or equal toeql?
- equal to
These work with SemVer version strings, too.
Some version constraints are supported. Wildcard (*) and tilde (~) version range operators are currently supported.
version = Version.new("4.2.0")
version.satisfies?("4.*") # => true (>= 4.0.0 && < 5.0.0)
version.satisfies?("4.1.*") # => false !(>= 4.1.0 && < 4.2.0)
version.satisfies?("4.2.*") # => true (>= 4.2.0 && < 4.3.0)
version.satisfies?("~ 4.1") # => true (>= 4.1.0 && < 5.0.0)
version.satisfies?("~ 4.1.5") # => false !(>= 4.1.5 && < 4.2.0)
Installation
Add this to your application's shard.yml
:
dependencies:
semantic-version:
github: ljuti/semantic-version
Contributing
- Fork it (https://github.com/ljuti/semantic-version/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- ljuti Lauri Jutila - creator, maintainer
Repository
semantic-version
Owner
Statistic
- 3
- 1
- 2
- 0
- 1
- about 6 years ago
- October 13, 2018
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 19:05:05 GMT
Languages