Coder Social home page Coder Social logo

semver's Introduction

Semver

Github CI Status supports platforms

Semver is a Swift implementation of the Semantic Versioning.

Requirements

  • Swift 5.0+

Usage

Quick Start

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.

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 // ❗️true

v1 === 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.

let version = Semver(major: 0, minor: 0, patch: -1) // invalid version 0.0.-1
version.isValid // false

Installation

Add the project to your Package.swift file:

package.dependencies += [
    .package(url: "https://github.com/ddddxxx/Semver", .upToNextMinor("0.2.0"))
]

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 into your project.

License

Semver is available under the MIT license. See the LICENSE file.

semver's People

Contributors

ddddxxx avatar

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.