-
-
Notifications
You must be signed in to change notification settings - Fork 0
semver
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isSemVer(it: unknown): it is SemVer;
Check if the given value is a valid semantic version string, according to the Semantic Versioning 2.0.0 specification as per https://semver.org. This function does not check if the version is a valid version range, but simply validates it against the regular expression pattern from the specification.
Name | Info |
---|---|
it |
The value to check. |
true
if it is a valid semantic version string, false
otherwise.
Strings
import { isSemVer } from "jsr:@nick/is/semver";
console.log(isSemVer("1.2.3")); // true
console.log(isSemVer("1.2.3-alpha")); // true
console.log(isSemVer("1.2.3+build")); // true
console.log(isSemVer("1.2.3-alpha+build")); // true
console.log(isSemVer("1.2.3-alpha.1")); // true
console.log(isSemVer("1.2")); // false
export type MaybeSemVer = Flavor<string, "SemVer">;
Less-strict form of the SemVer
type,
which allows for strings to be assigned to it that might not be valid semantic
version strings.
Strings
export type SemVer = Brand<string, "SemVer">;
Represents a validated Semantic Version (SemVer v2.0.0) string. This is the type
the isSemVer
function narrows its
input values to.
Strings