Skip to content

isPrerelease

Returns true when the version string has a prerelease suffix, according to the given scheme.

'semver' (default) — true when there’s a - after the core MAJOR.MINOR.PATCH.

'gentoo' — true when the last suffix segment is alpha/beta/pre/rc (these sort below the plain release). A p suffix or a -r revision don’t count — p sorts above the release, and a revision isn’t a prerelease of anything, it’s a rebuild of the same version.

'debian' — true when the upstream part contains ~, the Debian convention for a version that must sort before the final release (1.0~rc1). A ~ in the revision doesn’t count — 1.0-1~bpo12+1 is a backport of the 1.0 release, not a prerelease of it.

Available since v2.0.0

import { isPrerelease } from '@helpers4/version';
// or, from the all-in-one package (same code, one install):
import { isPrerelease } from 'helpers4/version';
isPrerelease(version: string, scheme?: VersionScheme): boolean
ParameterTypeDescription
versionstringA version string (e.g. `‘2.0.0-alpha.1’`, `‘1.0.0’`, `‘1.2.3_rc1’`).
schemeVersionSchemeWhich version scheme to interpret `version` as. Defaults to `‘semver’`. (optional)

boolean — true if the version is a prerelease, false otherwise.

Returns true for any version string that contains a prerelease suffix.

isPrerelease('2.0.0-alpha.1') // true
isPrerelease('1.0.0-rc.0')   // true

Returns false when the version has no prerelease suffix.

isPrerelease('1.0.0') // false
isPrerelease('2.1.3') // false

Works with the result of parse() — checks the prerelease array instead of string matching.

isPrerelease(parse('2.0.0-alpha.1')) // true
isPrerelease(parse('1.0.0'))         // false

A version parsed by parse, in whichever scheme it was parsed as — narrow on the scheme field to access scheme-specific properties (major/minor/patch for 'semver', components/letter/suffixes/revision for 'gentoo', epoch/upstream/revision for 'debian').

Deliberately not named ParsedVersion: that name has been public API since 2.0.0 for the flat SemVer-only shape (.major/.minor/.patch directly, no narrowing needed), and turning it into a union would silently break any existing code typed as ParsedVersion that reads those fields without narrowing first — a real compatibility break with no MIGRATION.md entry, since this repo ties breaking changes to major-version bumps.

type AnyParsedVersion = ParsedSemVerVersion | ParsedGentooVersion | ParsedDebianVersion

Identifies which version scheme parse/compare should use to interpret a version string. Defaults to 'semver' everywhere it’s accepted.

type VersionScheme = 'semver' | 'gentoo' | 'debian'

View source on GitHub