Giter Club home page Giter Club logo

version-compare's Introduction

Version compare

Compares two software version numbers (e.g. "1.7.1" or "1.2b").

Forked from: https://gist.githubusercontent.com/TheDistantSea/8021359

@param {string} v1 The first version to be compared.

@param {string} v2 The second version to be compared.

@param {object} [options] Optional flags that affect comparison behavior:

  • lexicographical: (true/[false]) compares each part of the version strings lexicographically instead of naturally; this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than "1.2".
  • zeroExtend: ([true]/false) changes the result if one version string has less parts than the other. In this case the shorter string will be padded with "zero" parts instead of being considered smaller.

@returns {number|NaN}

  • 0 if the versions are equal
  • a negative integer if v1 < v2
  • a positive integer if v1 > v2
  • NaN if either version string is in the wrong format

UPDATE 1.1 (10-04-2018)

  • added defaults to lexicographical (false) and zeroExtend (true)
  • added alpha/beta versioning as valid parts
  • empty v1 or v2 param is assumed as version "0"
  • version not compared with lex options can accept a single char (ex: "1.10a" > "1.10")

version-compare's People

Contributors

rombecchi avatar

Watchers

James Cloos avatar Yair Ansbacher 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.