isValid
Whether version is a valid version in the given scheme. Never throws: any input that is
not valid, a non-string included, gives false.
'semver' (default) — SemVer 2.0.0, strictly: MAJOR.MINOR.PATCH with no leading zeros, an
optional -prerelease (numeric identifiers without leading zeros) and an optional +build.
Unlike parse, which reads anything, and unlike compare, a leading v is refused
by default (v1.2.3 is a git tag, not a version; see IsValidOptions.prefix to accept or
require it), and so are 1.2 and 1.2.3.4.
'gentoo', 'debian', 'rpm', 'pacman', 'pep440' — whether parse
accepts it (these schemes throw on invalid input, so their grammar is the one parse documents).
'maven' — any non-empty string: Maven reads every text as a version.
Available since v3.1.9
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
version | unknown | The value to check |
scheme | VersionScheme | Which version scheme to validate against. Defaults to `‘semver’`. |
options | IsValidOptions | The treatment of a leading `v` — see IsValidOptions |
Returns
Section titled “Returns”boolean — true if version is a valid version
Examples
Section titled “Examples”Validate a release version strictly
Section titled “Validate a release version strictly”Unlike parse, which reads anything, isValid refuses a v prefix, missing parts and leading zeros.
Check a git tag
Section titled “Check a git tag”prefix: ‘require’ demands the v of a tag; ‘allow’ accepts both spellings.
Validate in another scheme
Section titled “Validate in another scheme”Debian versions are checked against dpkg’s grammar.
Related Types
Section titled “Related Types”IsValidOptions
Section titled “IsValidOptions”Options for isValid.
VersionScheme
Section titled “VersionScheme”Identifies which version scheme parse/compare should use to interpret a
version string. Defaults to 'semver' everywhere it’s accepted.
