npm

@flourish/semver

1.0.2 • Public • Published

A short and simple module for parsing and comparing semantic version numbers, following the Semantic Versioning 2.0.0 specification.

Does not support build metadata.

const semver = require("@flourish/semver");

semver.parse("1.0.0");
// Returns [1, 0, 0]

semver.parse("1.0.0-alpha.1.2.3");
// Returns [1, 0, 0, "alpha", 1, 2, 3]
semver.join([1, 2, 3]); // "1.2.3"

semver.join([1, 2, 3, "alpha", 2]); // "1.2.3-alpha.2"
semver.cmp(semver.parse("1.2.0"), semver.parse("1.2.1")); // -1

semver.cmp(semver.parse("1.2.0"), semver.parse("1.2.0")); // 0

semver.cmp(semver.parse("1.2.2"), semver.parse("1.2.2-alpha.1")); // +1

semver.cmp(semver.parse("1.2.2"), semver.parse("1.2.3-alpha.1")); // -1

// Sort a list of version numbers into order
version_numbers
    .map(semver.parse)
    .sort(semver.cmp)
    .map(semver.join);

Readme

Keywords

none

Package Sidebar

Install

npm i @flourish/semver

Weekly Downloads

134

Version

1.0.2

License

ISC

Unpacked Size

7.65 kB

Total Files

9

Last publish

Collaborators

  • abbiewadecanva
  • scottb-flourish
  • jontyt
  • rushlet
  • winna_canva
  • bruno-riddy
  • libruca
  • jwitcombe
  • katietannercanva
  • b3n-canva
  • caletilford
  • florin.oprina
  • robinhouston
  • duncanclark
  • daanlouter
  • hughsk
  • mark-kiln
  • animateddata
  • larsvers
  • luptilu
  • bobbysebolao
  • hrobertson
  • oampo