GithubHelp home page GithubHelp logo

beyang / go-version Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcuadros/go-version

0.0 1.0 0.0 107 KB

Version normalizer and comparison library for go

License: MIT License

Go 100.00%

go-version's Introduction

go-version Build Status

Version normalizer and comparison library for go, heavy based on PHP version_compare function and Version comparsion libs from Composer PHP project

Installation

The recommended way to install go-version

go get github.com/mcuadros/go-version

Examples

How import the package

import (
    "github.com/mcuadros/go-version"
)

version.Normalize(): Normalizes a version string to be able to perform comparisons on it

version.Normalize("10.4.13-b")
//Returns: 10.4.13.0-beta

version.CompareSimple(): Compares two normalizated version number strings

version.CompareSimple("1.2", "1.0.1")
//Returns: 1

version.CompareSimple("1.0rc1", "1.0")
//Returns: -1

version.Compare(): Compares two normalizated version number strings, for a particular relationship

version.Compare("1.0-dev", "1.0", "<")
//Returns: true

version.Compare("1.0rc1", "1.0", ">=")
//Returns: false

version.Compare("1.0", "1.0b1", "ge")
//Returns: true

version.ConstrainGroup.Match(): Match a given version againts a group of constrains, read about constraint string format at Composer documentation

c := version.NewConstrainGroupFromString(">2.0,<=3.0")
c.Match("2.5.0beta")
//Returns: true

c := version.NewConstrainGroupFromString("~1.2.3")
c.Match("1.2.3.5")
//Returns: true

version.Sort(): Sorts a string slice of version number strings using version.CompareSimple()

version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
//Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}

License

MIT, see LICENSE

go-version's People

Contributors

beyang avatar mcuadros avatar

Watchers

 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.