Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/taji-taji/semanticversioning
This package provides the Swift protocol compatible with Semantic Versioning (2.0.0).
https://github.com/taji-taji/semanticversioning
semantic-version semantic-versioning semantic-versions swift swift-package-manager swift5 swift5-5 swift5-6 swift5-7
Last synced: 5 days ago
JSON representation
This package provides the Swift protocol compatible with Semantic Versioning (2.0.0).
- Host: GitHub
- URL: https://github.com/taji-taji/semanticversioning
- Owner: taji-taji
- License: mit
- Created: 2022-09-22T06:46:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-15T14:38:24.000Z (about 1 year ago)
- Last Synced: 2024-10-28T14:27:14.463Z (23 days ago)
- Topics: semantic-version, semantic-versioning, semantic-versions, swift, swift-package-manager, swift5, swift5-5, swift5-6, swift5-7
- Language: Swift
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SemanticVersioning [x.x.x]
This package provides the Swift protocol compatible with [Semantic Versioning (2.0.0)](https://semver.org/).
![Test](https://github.com/taji-taji/SemanticVersioning/actions/workflows/test.yml/badge.svg)
[![MIT License](https://img.shields.io/github/license/taji-taji/SemanticVersioning)](https://github.com/taji-taji/SemanticVersioning/blob/main/LICENSE)
[![Latest Version](https://img.shields.io/github/v/release/taji-taji/SemanticVersioning?label=latest%20version)](https://github.com/taji-taji/SemanticVersioning/releases/latest)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ftaji-taji%2FSemanticVersioning%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/taji-taji/SemanticVersioning)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ftaji-taji%2FSemanticVersioning%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/taji-taji/SemanticVersioning)## Features
- By conforming to the `SemanticVersioning` protocol, it can be represented as a type that behaves as a version of software compliant with Semantic Versioning (2.0.0).
```swift
import SemanticVersioning// conforms to SemanticVersioning
struct MyAppVersion: SemanticVersioning {
let major: Int
let minor: Int
let patch: Int
let preRelease: PreRelease?
let buildMetaData: String?
}
```- Can be initialized from String literals.
```swift
let appVersion: MyAppVersion = "1.1.1"
// String literals can also contain pre-release and build metadata.
// let appVersion: MyAppVersion = "1.1.1-alpha"
// let appVersion: MyAppVersion = "1.1.1-alpha+build.1"
```- Comparable and Equatable.
```swift
if appVersion > "1.0.0" {
// Some operation when appVersion is greater than 1.0.0
} else if appVersion == "0.1.0" {
// Some operation when appVersion is 0.1.0
}
```- Increment version number.
```swift
print(appVersion)
// -> 1.1.1
print(appVersion.increment(.major))
// -> 2.0.0
print(appVersion.increment(.minor))
// -> 1.2.0
print(appVersion.increment(.patch))
// -> 1.1.2
```
- Validate version format with macro.
```swift
import SemanticVersioningMacrolet validVersionString = #semanticVersioning("1.0.0") // Valid format!
let invalidVersionString = #semanticVersioning("1.0.a") // Invalid format! Compile error!
```## Requirements
- Swift 5.9 or later
- macOS 10.15+ or iOS 12.0+ or watchOS 4.0+ or tvOS 1.0+## Supported Platforms
- Apple Platforms
- Linux## Usage
### Package.swift
1. Add SemanticVersioning to your `Package.swift` dependencies:
```swift
.package(url: "https://github.com/taji-taji/SemanticVersioning.git", from: "1.0.0")
```2. Add SemanticVersioning to your dependencies of `SemanticVersioning` target:
```swift
.product(name: "SemanticVersioning", package: "SemanticVersioning"),
// If you want to use macro, add `SemanticVersioningMacro`.
.product(name: "SemanticVersioningMacro", package: "SemanticVersioning"),
```