Wynn Netherland changelog.com/posts

node-semver: The semver parser for Node that powers npm

Isaac Z. Schlueter, who is not looking for work, btw, has released a Semver library for Node.js. An extraction from his popular npm package manager for Node.js, node-semver parses version numbers in the Semantic Versioning format advocated by GitHub founder Tom Preston-Warner.

As expected, you can install via npm:

$ npm install semver

You can then use in your Node apps:

semver.valid('1.2.3') // true
semver.valid('a.b.c') // false
semver.clean('  =v1.2.3   ') // '1.2.3'
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
semver.gt('1.2.3', '9.8.7') // false
semver.lt('1.2.3', '9.8.7') // true

… or from the command line with the included semver command line utility:

$ semver -h

Usage: semver -v <version> [-r <range>]
Test if version(s) satisfy the supplied range(s),
and sort them.

Multiple versions or ranges may be supplied.

Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.

If no versions are valid, or ranges are not satisfied,
then exits failure.

Versions are printed in ascending order, so supplying
multiple versions to the utility will just sort them.

Be sure and check the Readme for more details. And yes, as many of you have pointed out, we know our episode numbers are not semantically versioned.

[Source on GitHub]


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00