semvish

1.1.0 • Public • Published

SemVish Build Status Code Climate License

A versioning interpretter that can process multiple versioning schemes such as

  • SemVer
  • <Max>-<Min>
  • <Max>-<Min>-<release>
  • <Max>
  • <Max>-<release>
  • <release>

Passes some 1290 tests (mostly from node-semver)

Install

$ [sudo] npm install semvish

Motivation

jsDelivr needed a multi version comparitor scheme

API

Borrows directly from node-semver's API

  • clean process a SemVer-ish string to a SemVer compliant string
clean("1.2") // => 1.2.0
clean("1.2.0") // => 1.2.0
clean("1.2.0-beta1") // => 1.2.0-beta1
clean("1.2.0beta1") // => 1.2.0-beta1
clean("1.2-alpha1") // => 1.2.0-alpha1
clean("1.2alpha1") // => 1.2.0-alpha1
clean("1") // => 1.0.0
clean("1-rc1") // => 1.0.0-rc1
clean("1rc1") // => 1.0.0-rc1
clean("alpha1") // => 0.0.0-alpha1
 
// Handes prefixs and trims strings for all inputs (pretty much every stupid scheme I've ever seen)
clean("v-1.2.0     ") // => 1.2.0
clean("   v1.2   ") // => 1.2.0
clean("==v==1.2") // => 1.2.0
clean("_v--1.2.0") // => 1.2.0
clean("V1.2") // => 1.2.0
clean("-VERSION-1.2 ") // => 1.2.0
clean("v.1.2") // => 1.2.0
  • valid is some string semverish?

  • satisfies(version, range, loose): whethere a given (SemVish) version matches a semver range - currently only supports semver ranges so ^2015-20-15 and similar will not work, instead use ^0.0.0-2015-20-15.

  • gt(v1, v2): v1 > v2

  • gte(v1, v2): v1 >= v2

  • lt(v1, v2): v1 < v2

  • lte(v1, v2): v1 <= v2

  • eq(v1, v2): v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.

  • neq(v1, v2): v1 != v2 The opposite of eq.

  • cmp(v1, comparator, v2): Pass in a comparison string, and it'll call the corresponding function above. "===" and "!==" do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided.

  • compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort().

  • rcompare(v1, v2): The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort().

Differences from semver spec

  • Minorly divergent (see #1) in the way pre-releases are handled: prereleases are compared naturally while the semver spec states that

Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each dot separated identifier from left to right until a difference is found as follows: identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order.

Therefore as defined by Semver: 0.0.0-a100 < 0.0.0-a2. This minor rule limited us in the alternate supported versioning schemes so we forked the handling.

Package Sidebar

Install

npm i semvish

Weekly Downloads

2

Version

1.1.0

License

wtfpl (wtfpl.net)

Last publish

Collaborators

  • megawac