Giter VIP home page Giter VIP logo

semanticversion's Introduction

๐Ÿท SemanticVersion

SemanticVersion is a simple Codable, Comparable, Equatable, Hashable, and LosslessStringConvertible struct that can represent semantic versions.

Here's what using SemanticVersion looks like in practise:

import SemanticVersion
import Foundation

// Query semantic version components
let v123 = SemanticVersion(1, 2, 3)
v123.isStable        // true
v123.isPreRelease    // false
v123.isMajorRelease  // false
v123.isMinorRelease  // false
v123.isPatchRelease  // true

// Parse semantic version from String
let v200 = SemanticVersion("2.0.0")!
v200.isStable        // true
v200.isPreRelease    // false
v200.isMajorRelease  // true
v200.isMinorRelease  // false
v200.isPatchRelease  // false

// Supports beta versions
let v300rc1 = SemanticVersion("3.0.0-rc1-test")!
v300rc1.isStable        // false
v300rc1.isPreRelease    // true
v300rc1.isMajorRelease  // false
v300rc1.isMinorRelease  // false
v300rc1.isPatchRelease  // false
v300rc1.major           // 3
v300rc1.minor           // 0
v300rc1.patch           // 0
v300rc1.preRelease      // "rc1-test"

// SemanticVersion is Comparable and Equatable
v123 < v200          // true
SemanticVersion("2.0.0")! < SemanticVersion("2.0.1")!  // true
// NB: beta versions come before their releases
SemanticVersion("2.0.0")! > SemanticVersion("2.0.0-b1")!  // true
v123 == SemanticVersion("1.2.3")  // true
SemanticVersion("v1.2.3-beta1+build5")
    == SemanticVersion(1, 2, 3, "beta1", "build5")  // true

// SemanticVersion is Hashable
let dict = [         // [{major 3, minor 0, patch 0,...
    v123: 1,
    v200: 2,
    v300rc1: 3
]

// SemanticVersion is Codable
let data = try JSONEncoder().encode(v123)  // 58 bytes
let decoded = try JSONDecoder().decode(SemanticVersion.self, from: data)  // 1.2.3
decoded == v123  // true

semanticversion's People

Contributors

finestructure avatar daveverwer 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.