Modules@robinpath/semver

@robinpath/semver

0.1.0Public

Parse, compare, validate, and manipulate semantic version strings (semver 2.0.0 compliant)

@robinpath/semver

Parse, compare, validate, and manipulate semantic version strings (semver 2.0.0 compliant)

Category Functions Auth License

Why use this module?

The semver module lets you:

  • Parse a semver version string into its components (major, minor, patch, prerelease, build)
  • Check whether a string is a valid semver version
  • Compare two semver versions, returning -1 (v1 < v2), 0 (equal), or 1 (v1 > v2)
  • Check if the first version is greater than the second
  • Check if the first version is less than the second

All functions are callable directly from RobinPath scripts with a simple, consistent API.

Installation

npm install @robinpath/semver

Quick Start

No credentials needed — start using it right away:

semver.isValid "1.2.3"

Available Functions

FunctionDescription
semver.parseParse a semver version string into its components (major, minor, patch, prerelease, build)
semver.isValidCheck whether a string is a valid semver version
semver.compareCompare two semver versions, returning -1 (v1 < v2), 0 (equal), or 1 (v1 > v2)
semver.gtCheck if the first version is greater than the second
semver.ltCheck if the first version is less than the second
semver.eqCheck if two versions are equal (ignoring build metadata)
semver.gteCheck if the first version is greater than or equal to the second
semver.lteCheck if the first version is less than or equal to the second
semver.satisfiesCheck if a version satisfies a semver range (supports ^, ~, >=, <=, >, <, =, x wildcard,
semver.incIncrement a version by the specified release type (major, minor, patch, or prerelease)
semver.majorExtract the major version number from a semver string
semver.minorExtract the minor version number from a semver string
semver.patchExtract the patch version number from a semver string
semver.coerceCoerce a loose version string into a clean semver string (e.g. "v1" becomes "1.0.0")
semver.diffDetermine the type of difference between two versions (major, minor, patch, prerelease, or null)

Examples

Check whether a string is a valid semver version

semver.isValid "1.2.3"

Compare two semver versions, returning -1 (v1 < v2), 0 (equal), or 1 (v1 > v2)

semver.compare "1.2.3" "1.3.0"

Check if the first version is greater than the second

semver.gt "2.0.0" "1.9.9"

Integration with RobinPath

import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/semver";

const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);

const result = await rp.executeScript(`
  semver.isValid "1.2.3"
`);

Full API Reference

See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.

Related Modules

License

MIT

Versions (1)

VersionTagPublished
0.1.0latestyesterday
Install
$ robinpath install @robinpath/semver
Version0.1.0
LicenseMIT
Unpacked Size7.0 KB
Versions1
Weekly Downloads0
Total Downloads0
Stars0
Last Publishyesterday
Createdyesterday

Category

utilities