Skip to main content

@std/semver@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score76%
Published2 years ago (0.215.0)

Examples

Example 1

import {
  parse,
  parseRange,
  greaterThan,
  lessThan,
  format
} from "@std/semver";

const semver = parse("1.2.3");
const range = parseRange("1.x || >=2.5.0 || 5.0.0 - 7.2.3");

const s0 = parse("1.2.3");
const s1 = parse("9.8.7");
greaterThan(s0, s1); // false
lessThan(s0, s1); // true

format(semver) // "1.2.3"

Functions

f
canParse(version: string): boolean
No documentation available
f
compare(
s0: SemVer,
s1: SemVer
): 1 | 0 | -1

Compare two semantic version objects.

f
difference(
s0: SemVer,
s1: SemVer
): ReleaseType | undefined

Returns difference between two versions by the release type, or undefined if the versions are the same.

f
equals(
s0: SemVer,
s1: SemVer
): boolean

Returns true if both semantic versions are logically equivalent, even if they're not the exact same version object.

f
format(semver: SemVer): string

Format a SemVer object into a string.

f
formatRange(range: Range): string

Formats the range into a string

f
greaterOrEqual(
s0: SemVer,
s1: SemVer
): boolean

Greater than or equal to comparison

f
greaterThan(
s0: SemVer,
s1: SemVer
): boolean

Greater than comparison

f
increment(
version: SemVer,
release: ReleaseType,
prerelease?: string,
buildmetadata?: string
): SemVer

Returns the new version resulting from an increment by release type.

f
isRange(value: unknown): value is Range

Does a deep check on the object to determine if its a valid range.

f
isSemVer(value: unknown): value is SemVer

Checks to see if value is a valid SemVer object. It does a check into each field including prerelease and build.

f
lessOrEqual(
s0: SemVer,
s1: SemVer
): boolean

Less than or equal to comparison

f
lessThan(
s0: SemVer,
s1: SemVer
): boolean

Less than comparison

f
maxSatisfying(
versions: SemVer[],
range: Range
): SemVer | undefined

Returns the highest version in the list that satisfies the range, or undefined if none of them do.

f
minSatisfying(
versions: SemVer[],
range: Range
): SemVer | undefined

Returns the lowest version in the list that satisfies the range, or undefined if none of them do.

f
notEquals(
s0: SemVer,
s1: SemVer
): boolean

Not equal comparison

f
parse(version: string): SemVer

Attempt to parse a string as a semantic version, returning either a SemVer object or throws a TypeError.

f
parseRange(range: string): Range

Parses a range string into a Range object or throws a TypeError.

f
rangeIntersects(
r0: Range,
r1: Range
): boolean

The ranges intersect every range of AND comparators intersects with a least one range of OR ranges.

f
rangeMax(range: Range): SemVer

The maximum valid SemVer for a given range or INVALID

f
rangeMin(range: Range): SemVer

The minimum valid SemVer for a given range or INVALID

f
testRange(
version: SemVer,
range: Range
): boolean

Test to see if the version satisfies the range.

f
tryParse(version?: string): SemVer | undefined

Returns the parsed version, or undefined if it's not valid.

f
tryParseRange(range: string): Range | undefined

A tries to parse a valid Range string or returns undefined

f
gtr(
version: SemVer,
range: Range
): boolean

Checks to see if the version is greater than all possible versions of the range.

f
ltr(
version: SemVer,
range: Range
): boolean

Less than range comparison

f
reverseSort(versions: SemVer[]): SemVer[]

Sorts a list of semantic versions in descending order.

Interfaces

I

The shape of a valid semantic version comparator

  • operator: Operator
    No documentation available
  • semver: SemVer
    No documentation available
I

A SemVer object parsed into its constituent parts.

  • build: string[]
    No documentation available
  • major: number
    No documentation available
  • minor: number
    No documentation available
  • patch: number
    No documentation available
  • prerelease: (string | number)[]
    No documentation available

Type Aliases

T
Operator = OPERATORS[number]

SemVer comparison operators.

T
Range = Comparator[][]

A type representing a semantic version range. The ranges consist of a nested array, which represents a set of OR comparisons while the inner array represents AND comparisons.

T
ReleaseType =
"pre"
| "major"
| "premajor"
| "minor"
| "preminor"
| "patch"
| "prepatch"
| "prerelease"

The possible release types are used as an operator for the increment function and as a result of the difference function.

Variables

v
ALL: Comparator

A comparator which will span all valid semantic versions

v
ANY: SemVer

ANY is a sentinel value used by some range calculations. It is not a valid SemVer object and should not be used directly.

v
INVALID: SemVer

A sentinel value used to denote an invalid SemVer object which may be the result of impossible ranges or comparator operations.

v
MAX: SemVer

MAX is a sentinel value used by some range calculations. It is equivalent to ∞.∞.∞.

v
MIN: SemVer

The minimum valid SemVer object. Equivalent to 0.0.0.

v
NONE: Comparator

A comparator which will not span any semantic versions

v
No documentation available

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.