Giter Site home page Giter Site logo

version's Introduction

Version badge-platforms badge-languages badge-ci badge-jazzy badge-codecov

A µ-framework for representing, comparing, encoding and utilizing semantic versions, eg. 1.2.3 or 2.0.0-beta.

This is Version.swift from the Swift Package Manager, with some minor adjustments:

  1. More compact Codable implementation †
  2. Implements LosslessStringConvertible
  3. Not a massive-single-source-file (MSSF)
  4. Online documentation
  5. Extensions for Bundle and ProcessInfo
  6. Removal of the potentially fatal ExpressibleByStringLiteral conformance
  7. A “tolerant” initializer for user input like 10.0 or v3
  8. Idiomatic implementations for Range<Version>
  9. Initialization from StringProtocol, not just String

We have automatic monitoring for changes at Apple’s repo to alert us if we should need merge any fixes.

Semantic versions can be losslessly expressed as strings; thus we do so.

‡ Like Int we can losslessly store a semantic version from a valid string, so we conform to the same protocol.

Support mxcl

Hey there, I’m Max Howell. I’m a prolific producer of open source software and probably you already use some of it (for example, I created brew). I work full-time on open source and it’s hard; currently I earn less than minimum wage. Please help me continue my work, I appreciate it 🙏🏻

Other ways to say thanks.

Usage

import Version

// these two initializers are the same, use whichever suits the code context
let v1 = Version(1,0,0)
let v2 = Version(major: 1, minor: 0, patch: 0)

let v3 = Version("1.2.3")           // =>  1.2.3: Version?
let v4 = Version(tolerant: "10.1")  // => 10.1.0: Version?
let v5 = Version(tolerant: "10")    // => 10.0.0: Version?

// a real Version object from your app’s Info.plist
let v6 = Bundle.main.version

let range = Version(1,2,3)..<Version(2,0,0)

let null: Version = .null  // => Version(0,0,0)

let foo = Version(1,2,3) < Version(2,0,0)  // => true

Installation

SwiftPM:

package.append(.package(url: "https://github.com/mxcl/Version.git", from: "2.0.0"))

Carthage:

Waiting on: @Carthage#1945.

Ranges

Ranges work as you expect, but there are caveats for prerelease identifiers, here are the rules:

1.0.0..<2.0.0 does not include eg. 2.0.0-alpha

This is probably what you expected. However:

1.0.0..<2.0.0 also does not include eg. 1.5.0-alpha

However:

1.0.0..<2.0.0-beta does include eg. 2.0.0-alpha

This is how the majority of Semantic Version libraries work.

Comparable, Equatable & Hashable

Both comparable and equatable ignore build metadata as per the specification. Thus:

Version("1.2.3+14") == Version("1.2.3+15")  // => true
Version("1.2.3+14") <= Version("1.2.3+15")  // => true
Version("1.2.3+14") <  Version("1.2.3+15")  // => false

This also means that Hashable must mirror this behavior, thus:

dict[Version("1.2.3+14")] = 1
dict[Version("1.2.3+15")] = 2
dict.count  // => 1
dict        // => ["1.2.3+15": 2]

Be aware of this as it may catch you out, naturally this will also effect structures that depend on Hashable, eg. Set.

version's People

Contributors

acecilia avatar cherryblossom000 avatar mxcl avatar repo-ranger[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

version's Issues

Version listening idea

Not sire if there is value here, but I've created a SemanticVersion framework that is focused on listening for changes and then updating the various places where you may have used the Semantic Version. The intent is for libraries where you have to list our your version in multiple places but only want to update it once.

https://gitlab.com/thecb4/SemVerSwift

Thoughts?

Build metadata should be ignored when determining version precedence

I think I've found an issue with metadata:
Based on https://semver.org/#spec-item-10 when you compare two version the metadata should be ignored.

Build metadata MAY be denoted by appending a plus sign and a series of dot separated identifiers immediately following the patch or pre-release version. Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Build metadata MUST be ignored when determining version precedence. Thus two versions that differ only in the build metadata, have the same precedence. Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85.

So I think the following code should work:

if let v1 = Version("1.0.0+build1"), let v2 = Version("1.0.0+build2") {
    assert(v1 == v2)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.