ver-sion

light-weighted semantic version implementation

Usage no npm install needed!

<script type="module">
  import verSion from 'https://cdn.skypack.dev/ver-sion';
</script>

README

ver.sion

light-weighted semantic version implementation and enhancement

total downloads of ver.sion ver.sion's License latest version of ver.sion

Table of contents

Links

Get Started

ver.sion is not only a Node.js module, but also a CLI tool. When installed, command version and command alias v2 will be created. Run the commands without any options for help info.

npm install -g ver.sion --prod

Of course, the main business is to be required as a module.

const ver = require('ver.sion');

// Compare two versions.
ver.lt('1.2.3', '1.3.0');  // true
ver.gt('1.2.3', '1.2.0');  // true
ver.eq('1.2.3', '1.2'  );  // true

const range = new ver.Range('^1.2.3');
range.covers('1.2.0');    // false
range.covers('1.2.3');    // true
range.covers('1.3.0');    // true
range.covers('2.0.0');    // false

API

Suppose ver is the name of required package:

const ver = require('ver.sion');
// OR require package named "ver-sion" if you prefer and have installed with such name.
const ver = require('ver-sion');

ver.sion accepts dot-number notation according to Semantic Versioning 2.0.0 (hereinafter referred as SemVer). However, versions having less or more than three numbers, which are understood as Major, Minor and Patch, are also accepted. For SemVer, 1.2.3 is valid, but 1.2.3.4 and 1.2 are invalid (1.2 is accepted as version range in NPM package semver). For ver.sion, all of them are valid versions.

Class ver.Range

const range = new ver.Range(version_range_code);

The syntax of version_range_code is compatible with which used in semver.

Comparators Methods

ver.sion has following static methods to compare two versions:

  • boolean eq(string v1, string v2)
  • boolean neq(string v1, string v2)
  • boolean lt(string v1, string v2)
  • boolean gt(string v1, string v2)
  • boolean lte(string v1, string v2)
  • boolean gte(string v1, string v2)
  • boolean equal(string v1, string v2)
  • boolean notEqual(string v1, string v2)
  • boolean lessThan(string v1, string v2)
  • boolean greaterThan(string v1, string v2)
  • boolean lessThanOrEqual(string v1, string v2)
  • boolean greaterThanOrEqual(string v1, string v2)

Range Methods

  • boolean ver.covers(string rangeCode, string version)
  • boolean ver.statisfy(string version, string rangeCode)

Examples

Read the unit tests for examples of ver.sion:

Why ver.sion

In general, SemVer is enough. However, there are still version notations smiliar to SemVer but have more or less than three numbers. E.g., run the following command and observe components' versions in Node.js.

node -e 'console.log(process.versions)'

The output looks like,

{ http_parser: '2.7.0',
  node: '6.11.1',
  v8: '5.1.281.103',
  uv: '1.11.0',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  icu: '58.2',
  modules: '48',
  openssl: '1.0.2k' }

With ver.sion, we can deal with versions made up of dots and numbers, exceeding the restriction of Major.Minor.Patch as SemVer requires.

Honorable Dependents

Welcome to be honorable dependents of ver.sion!

References