Skip to main content
Home

@std/semver@1.0.8
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads3/wk
Published3 weeks ago (1.0.8)

Parsing and comparing of semantic versions (SemVer)

Functions

f
canParse(value: string): boolean

Returns true if the string can be parsed as SemVer.

f
compare(
version1: SemVer,
version2: SemVer
): 1 | 0 | -1

Compare two SemVers.

f
difference(
version1: SemVer,
version2: SemVer
): ReleaseType | undefined

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

f
equals(
version1: SemVer,
version2: SemVer
): boolean

Returns true if both SemVers are equivalent.

f
format(version: SemVer): string

Format a SemVer object into a string.

f
formatRange(range: Range): string

Formats the SemVerrange into a string.

f
greaterOrEqual(
version1: SemVer,
version2: SemVer
): boolean

Greater than or equal to comparison for two SemVers.

f
greaterThan(
version1: SemVer,
version2: SemVer
): boolean

Greater than comparison for two SemVers.

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

Check if the SemVer is greater than the range.

f
increment(
version: SemVer,
release: ReleaseType,
options?: IncrementOptions
): SemVer

Returns the new SemVer 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(
version1: SemVer,
version2: SemVer
): boolean

Less than or equal to comparison for two SemVers.

f
lessThan(
version1: SemVer,
version2: SemVer
): boolean

Less than comparison for two SemVers.

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

Check if the SemVer is less than the range.

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

Returns the highest SemVer 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 SemVer in the list that satisfies the range, or undefined if none of them do.

f
notEquals(
version1: SemVer,
version2: SemVer
): boolean

Not equal comparison for two SemVers.

f
parse(value: string): SemVer

Attempt to parse a string as a semantic version, returning a SemVer object.

f
parseRange(value: string): Range

Parses a range string into a Range object.

f
rangeIntersects(
range1: Range,
range2: Range
): boolean

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

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

Test to see if the SemVer satisfies the range.

f
tryParse(value: string): SemVer | undefined

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

f
tryParseRange(value: string): Range | undefined

Parses the given range string and returns a Range object. If the range string is invalid, undefined is returned.

Interfaces

I

The shape of a valid SemVer comparator.

I

Options for increment.

  • build: string

    The build metadata of the new version.

  • prerelease: string

    The pre-release of the new version.

I

A SemVer object parsed into its constituent parts.

  • build: string[]

    The build metadata

  • major: number

    The major version

  • minor: number

    The minor version

  • patch: number

    The patch version

  • prerelease: (string | number)[]

    The prerelease version

Type Aliases

T
Operator = undefined | "=" | "!=" | ">" | ">=" | "<" | "<="

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.

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.

Add Package

deno add jsr:@std/semver

Import symbol

import * as mod from "@std/semver";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/semver";