LogoPear Docs
ReferencesBareModules

bare-semver

Minimal semantic versioning library for Bare

stable

bare-semver — Minimal semantic versioning library for Bare.

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) // 1
console.log(version.minor) // 2
console.log(version.patch) // 3

const satisfied = semver.satisfies('1.2.3', '>=1.0.0 <2.0.0')

console.log(satisfied) // true

API

errors

errors.INVALID_RANGE(msg: string, fn?: Function): SemVerError

Source

Parameters

ParameterTypeDefaultDescription
msgstringThe error message.
fn?FunctionOptional function to omit from the top of the generated stack trace, passed to Error.captureStackTrace.

Returns SemVerError — A SemVerError with code set to 'INVALID_RANGE', for the caller to throw.

errors.INVALID_VERSION(msg: string, fn?: Function): SemVerError

Source

Parameters

ParameterTypeDefaultDescription
msgstringThe error message.
fn?FunctionOptional function to omit from the top of the generated stack trace, passed to Error.captureStackTrace.

Returns SemVerError — A SemVerError with code set to 'INVALID_VERSION', for the caller to throw.

Version

Version

new Version(major: number, minor: number, patch: number, opts?: { prerelease?: string[]; build?: string[] })
Source

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

Parameters

ParameterTypeDefaultDescription
majornumberThe major version number.
minornumberThe minor version number.
patchnumberThe patch version number.
opts?{ prerelease?: string[]; build?: string[] }Optional prerelease and build tag arrays; each defaults to an empty array.

build: string[]

Source

An array of build metadata tags.

compare(version: Version): boolean

Source

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.

Parameters

ParameterTypeDefaultDescription
versionVersionThe version to compare against.

major: number

Source

The major version number.

minor: number

Source

The minor version number.

patch: number

Source

The patch version number.

prerelease: string[]

Source

An array of prerelease tags.

Version.toString(): string

Source

Return the string representation of version.

Version.compare(a: Version, b: Version): number

Source

Parameters

ParameterTypeDefaultDescription
aVersion
bVersion

Version.parse(input: string): Version

Source

Parse a semantic version string into a Version instance.

Parameters

ParameterTypeDefaultDescription
inputstringThe version string to parse.

Throws

  • INVALID_VERSIONinput is not a valid version string.

Comparator

new Comparator(operator: number, version: Version)

Source

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

Parameters

ParameterTypeDefaultDescription
operatornumberOne of the constants operator values (EQ, LT, LTE, GT, GTE).
versionVersionThe version the comparator matches against.

operator: number

Source

The comparison operator constant.

Comparator.test(version: Version): boolean

Source

Test whether version satisfies the comparator.

Parameters

ParameterTypeDefaultDescription
versionVersionThe version to test against the comparator.

Returns booleantrue if version satisfies the comparator's operator and version, false otherwise.

Comparator.toString(): string

Source

Return the string representation of the comparator (operator and version), e.g. >=1.2.3.

version: Version

Source

The Version instance to compare against.

Range

new Range(comparators?: Comparator[][])

Source

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.

Parameters

ParameterTypeDefaultDescription
comparators?Comparator[][]Two-dimensional array of comparator sets: the outer array is a union (OR) of inner arrays, each an intersection (AND); defaults to an empty range that matches nothing.

comparators: Comparator[][]

Source

The two-dimensional array of Comparator instances.

Range.parse(input: string): Range

Source

Parse a range string into a Range instance. Supports comparison operators (<, <=, >, >=, =), partial versions, and logical OR (||).

Parameters

ParameterTypeDefaultDescription
inputstringThe range string to parse.

Throws

  • INVALID_VERSIONinput is not valid range syntax (reported via the INVALID_VERSION code — INVALID_RANGE is not currently thrown by the parser).

Range.test(version: Version): boolean

Source

Test whether version satisfies the range.

Parameters

ParameterTypeDefaultDescription
versionVersionThe version to test against the range.

Returns booleantrue if version satisfies any comparator set in the range, false otherwise.

Range.toString(): string

Source

Return the string representation of the range, e.g. >=1.2.3 <2.0.0.

Functions

satisfies(version: Version, range: Range): boolean

Source

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

Parameters

ParameterTypeDefaultDescription
versionVersionThe version to test, or a version string to parse.
rangeRangeThe range to test against, or a range string to parse.

Returns booleantrue if version matches range, false otherwise.

Throws

  • INVALID_VERSIONversion or range is a string that fails to parse.

Constants and variables

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

Source

An object containing the comparison operator constants.

See also

On this page