LogoPear Docs
ReferencesBareModules

bare-semver

Reference for bare-semver: a minimal semantic-versioning library for Bare—parse versions, build comparators and ranges, and test satisfaction.

stable

bare-semver is a minimal semantic-versioning library for Bare: parse and compare versions, and build and test ranges. It's pure JavaScript and underpins Bare's module/addon resolution.

npm i bare-semver

Usage

const semver = require('bare-semver')

const version = semver.Version.parse('1.2.3-alpha.1+build.42')
console.log(version.major, version.minor, version.patch) // 1 2 3

console.log(semver.satisfies('1.2.3', '>=1.0.0 <2.0.0')) // true

API

const satisfied = semver.satisfies(version, range)

Test whether version satisfies range. Both version and range may be strings, in which case they will be parsed.

semver.constants

An object containing the comparison operator constants:

constants = {
  EQ: 1,
  LT: 2,
  LTE: 3,
  GT: 4,
  GTE: 5
}

semver.errors

The SemVerError class. Thrown when parsing invalid versions or ranges.

Version

const version = new semver.Version(major, minor, patch[, options])

Create a new version with the given major, minor, and patch components.

Options include:

options = {
  prerelease: [],
  build: []
}

version.major

The major version number.

version.minor

The minor version number.

version.patch

The patch version number.

version.prerelease

An array of prerelease tags.

version.build

An array of build metadata tags.

const result = version.compare(other)

Compare version with other, returning 1 if version is greater, -1 if less, or 0 if equal. Comparison follows the Semantic Versioning 2.0.0 specification, including prerelease precedence rules.

const string = version.toString()

Return the string representation of version.

const version = semver.Version.parse(input)

Parse a semantic version string into a Version instance. Throws a SemVerError with code INVALID_VERSION if input is not a valid version string.

const result = semver.Version.compare(a, b)

Compare two Version instances, returning 1, -1, or 0.

Comparator

const comparator = new semver.Comparator(operator, version)

Create a new comparator with the given operator constant and version.

comparator.operator

The comparison operator constant.

comparator.version

The Version instance to compare against.

const satisfied = comparator.test(version)

Test whether version satisfies the comparator.

const string = comparator.toString()

Return the string representation of the comparator, for example, >=1.0.0.

Range

const range = new semver.Range([comparators])

Create a new range from a two-dimensional array of Comparator instances. Each inner array represents a set of comparators joined by intersection, and the outer array represents the union of those sets.

range.comparators

The two-dimensional array of Comparator instances.

const satisfied = range.test(version)

Test whether version satisfies the range.

const string = range.toString()

Return the string representation of the range.

const range = semver.Range.parse(input)

Parse a range string into a Range instance. Supports comparison operators (<, <=, >, >=, =), partial versions, and logical OR (||), for example, >=1.0.0 <2.0.0 or 1.2.3 || >=2.0.0.

See also

On this page