Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ddddxxx/semver
Swift Semantic Versioning library
https://github.com/ddddxxx/semver
semver swift
Last synced: 2 months ago
JSON representation
Swift Semantic Versioning library
- Host: GitHub
- URL: https://github.com/ddddxxx/semver
- Owner: ddddxxx
- License: mit
- Created: 2017-05-03T03:54:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-08T05:39:59.000Z (about 4 years ago)
- Last Synced: 2024-10-02T09:05:26.705Z (3 months ago)
- Topics: semver, swift
- Language: Swift
- Homepage:
- Size: 60.5 KB
- Stars: 23
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Semver
[![Github CI Status](https://github.com/ddddxxx/Semver/workflows/CI/badge.svg)](https://github.com/ddddxxx/Semver/actions)
![supports](https://img.shields.io/badge/supports-Swift_PM%20%7C%20Carthage-brightgreen.svg)
![platforms](https://img.shields.io/badge/platforms-Linux%20%7C%20macOS%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-lightgrey.svg)Semver is a Swift implementation of the [Semantic Versioning](http://semver.org/).
## Requirements
- Swift 5.0+
## Usage
### Quick Start
```swift
import Semver// A leading "v" character is ignored.
let version = Semver("v1.3.8-rc.1+build.3")!version > Semver("1.0.2+39f1d74")! // true
```### Equality
The `Equatable` conformance respect Semver semantic equality and ignore build metadata. This also affect `Comparable` and `Hashable`.
You can use `===` and `!==` to take build metadata into account.
```swift
let v1 = Version("1.0.0+100")!
let v2 = Version("1.0.0+200")!v1 == v2 // true
v1 <= v2 // true
v1.hashValue == v2.hashValue // true
Set([v1, v2]).count == 1 // ❗️truev1 === v2 // false
v1 !== v2 // true
```### Validity Check
The string initializer `Semver.init?(_:)` always produce valid version (or nil). The literal initializer `Semver.init(stringLiteral:)` only accept `StaticString` and crash when failed.
However, the member wise initializer `Semver.init(major:minor:patch:prerelease:buildMetadata:)` doesn't perform validity checks on its fields. It's possible to form an invalid version. You can manually validate a version using `Semver.isValid`.
```swift
let version = Semver(major: 0, minor: 0, patch: -1) // invalid version 0.0.-1
version.isValid // false
```## Installation
### [Swift Package Manager](https://github.com/apple/swift-package-manager)
Add the project to your `Package.swift` file:
```swift
package.dependencies += [
.package(url: "https://github.com/ddddxxx/Semver", .upToNextMinor("0.2.0"))
]
```### [Carthage](https://github.com/Carthage/Carthage)
Add the project to your `Cartfile`:
```
github "ddddxxx/Semver"
```### Copy File
This is a lightweight library contains only one file. You can simply copy/paste [the Semver file](Sources/Semver/Semver.swift) into your project.
## License
Semver is available under the MIT license. See the [LICENSE file](LICENSE).