{"id":27928460,"url":"https://github.com/ph1ps/swift-semantic-version","last_synced_at":"2025-05-07T02:07:21.199Z","repository":{"id":290198661,"uuid":"973669240","full_name":"ph1ps/swift-semantic-version","owner":"ph1ps","description":"A fast, spec-compliant semantic versioning library for Swift","archived":false,"fork":false,"pushed_at":"2025-05-04T16:07:24.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-04T17:21:21.835Z","etag":null,"topics":["nsregularexpression","semantic-version","semver","string-processing","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ph1ps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-27T13:44:24.000Z","updated_at":"2025-05-04T16:07:27.000Z","dependencies_parsed_at":"2025-04-27T14:43:43.488Z","dependency_job_id":null,"html_url":"https://github.com/ph1ps/swift-semantic-version","commit_stats":null,"previous_names":["ph1ps/swift-semantic-version"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph1ps%2Fswift-semantic-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph1ps%2Fswift-semantic-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph1ps%2Fswift-semantic-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph1ps%2Fswift-semantic-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ph1ps","download_url":"https://codeload.github.com/ph1ps/swift-semantic-version/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252798854,"owners_count":21805888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nsregularexpression","semantic-version","semver","string-processing","swift"],"created_at":"2025-05-07T02:07:20.614Z","updated_at":"2025-05-07T02:07:21.182Z","avatar_url":"https://github.com/ph1ps.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Semantic Version\n\nA fast, spec-compliant semantic versioning library for Swift.\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fph1ps%2Fswift-semantic-version%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/ph1ps/swift-semantic-version)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fph1ps%2Fswift-semantic-version%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/ph1ps/swift-semantic-version)\n\n## Details\n\nThis library provides a lightweight and efficient implementation of [Semantic Versioning 2.0.0](https://semver.org/) in Swift.  \nIt offers a structured `SemanticVersion` type for representing versions with:\n\n- `major`: Major version component (e.g., `1` in `1.2.3`).\n- `minor`: Minor version component (e.g., `2` in `1.2.3`).\n- `patch`: Patch version component (e.g., `3` in `1.2.3`).\n- `prerelease`: Optional prerelease identifiers (e.g., `[\"alpha\", \"1\"]` in `1.2.3-alpha.1`).\n- `build`: Optional build metadata (e.g., `\"build.5\"` in `1.2.3+build.5`).\n\nParsing, comparison, and validation are fully compliant with the [Semantic Versioning 2.0.0 specification](https://semver.org/).\n\n### Runtime Parsing\n\nYou can parse a version string at runtime using the failable initializer:\n\n```swift\nlet version = SemanticVersion(versionString) // -\u003e Optional\u003cSemanticVersion\u003e\n```\n\nIf the string is not a valid semantic version, the initializer will return `nil`.\n\n### Compile-Time Parsing\n\nThis library also provides a macro for compile-time safe parsing of semantic versions:\n\n```swift\nlet version = #SemanticVersion(\"1.2.3-alpha.1+build.5\") // -\u003e SemanticVersion\n```\n\nIf the provided string is invalid, a compile-time error will be produced.  \nThis ensures that all semantic versions used in your code are guaranteed to be valid at build time.\n\nTo use the macro:\n\n1. Add `SemanticVersionMacro` as a dependency in your `Package.swift`:\n\n```swift\n.target(\n  name: \"YourTarget\",\n  dependencies: [\n    .product(name: \"SemanticVersionMacro\", package: \"swift-semantic-version\")\n  ]\n)\n```\n\n2. Import `SemanticVersionMacro` in the file where you use the macro:\n\n```swift\nimport SemanticVersionMacro\n```\n\n### Package Traits\n\nThis library uses Swift 6.1’s **package traits** feature to offer two selectable parsing backends:\n\n- `FoundationBackend` (default): Uses Foundation's `NSRegularExpression` for parsing.\n- `StringProcessingBackend`: Ues Swift's native `Regex` literals for parsing.\n\nTo configure which parsing backend is used, specify traits in your `Package.swift` dependency declaration:\n\n```swift\n.package(\n  url: \"https://github.com/ph1ps/swift-semantic-version\",\n  from: \u003ccurrent version\u003e,\n  traits: [\n    \"StringProcessingBackend\"\n  ]\n)\n```\n\n#### Choosing the parsing backend\n\n- **Performance**: `FoundationBackend` generally provides faster parsing performance (see [Benchmarks](#benchmarks)), while `StringProcessingBackend` is slightly slower.\n- **Binary Size**: `FoundationBackend` has a big impact on binary size for platforms where `Foundation` is statically linked like `Musl`, `Android` or `WASM`. `StringProcessingBackend` on the other hand uses a pure Swift Standard Library implementation, which means no impact on binary size.\n- **Availability**: The different traits have different platform availabilities due to their implementation details, which might be important to you, if you want to increase platform coverage\n  - `FoundationBackend`: Requires `iOS 8.0`, `iPadOS 8.0`, `macOS 10.15`, `macCatalyst 13.1`, `tvOS 9.0`, `watchOS 2.0`, `visionOS 1.0`\n  - `StringProcessingBackend`: Requires `iOS 16.0`, `iPadOS 16.0`, `macOS 13.0`, `macCatalyst 16.0`, `tvOS 16.0`, `watchOS 9.0`, `visionOS 1.0`\n\n## Benchmarks\n\nPerformance benchmarks were conducted to compare the two available parsing backends: `FoundationBackend` and `StringProcessingBackend`.\n\nThe benchmarks use a set of 30 valid and 40 invalid semantic version strings, based on a variety of real-world examples and edge cases.  \nEach benchmark measures the time taken to parse all provided versions repeatedly under scaled iterations.\n\nThe following parsing paths were benchmarked:\n- Parsing invalid versions with `Foundation`\n- Parsing valid versions with `Foundation`\n- Parsing invalid versions with `StringProcessing`\n- Parsing valid versions with `StringProcessing`\n\n**Time (total CPU)**\n| Test                                           | p0  | p25 | p50 | p75 | p90 | p99 | p100 | Samples |\n|------------------------------------------------|-----|-----|-----|-----|-----|-----|------|---------|\n| InitBenchmark:Foundation invalid (μs) *        |  56 |  57 |  57 |  57 |  58 |  69 |  234 |   9653  |\n| InitBenchmark:Foundation valid (μs) *          | 100 | 104 | 105 | 106 | 110 | 131 |  385 |   6415  |\n| InitBenchmark:StringProcessing invalid (μs) *  | 162 | 164 | 164 | 165 | 166 | 186 |  364 |   4685  |\n| InitBenchmark:StringProcessing valid (μs) *    |1219 |1227 |1231 |1237 |1246 |1401 | 2038 |    774  |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph1ps%2Fswift-semantic-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fph1ps%2Fswift-semantic-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph1ps%2Fswift-semantic-version/lists"}