incrementPrerelease
Increments the prerelease portion of a version, according to the given scheme — the
semantics npm version prerelease --preid <id> uses, not covered by increment (which
only handles 'major' | 'minor' | 'patch').
'semver' (default):
- No current prerelease (a release version) → bumps
patchand starts a new prerelease line at<prereleaseId>.0(a prerelease of the version itself, e.g.1.2.3, would already be released). - Same prerelease type as the current version → increments its counter.
- Different prerelease type (e.g.
alpha→beta) → resets the counter to0.
Input prerelease can be any shape, but only the first two parts are considered;
output is always normalized to <prereleaseId>.<number>. Build metadata, if any, is
dropped — it’s tied to the specific build that produced the input version, not the new one.
A leading v is preserved if present, matching increment’s behavior (parse/
stringify alone would strip it — see their docs).
'gentoo' — the same rules, but prereleaseId must be one of the five real Gentoo
suffix types (alpha/beta/pre/rc/p), not a free-form string — Portage’s suffix
vocabulary is fixed by spec, unlike SemVer’s arbitrary prerelease identifiers. No current
prerelease suffix bumps the last numeric component instead of specifically patch, since
Gentoo’s components array can be any length.
'debian' — throws: a Debian upstream version is free-form, with no prerelease counter
to bump.
Available since v3.0.1
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
version | string | The version to increment |
prereleaseId | string | The prerelease type/identifier (e.g. `‘alpha’`, `‘beta’`, `‘rc’`) |
scheme | VersionScheme | Which version scheme to interpret `version` as. Defaults to `‘semver’`. (optional) |
Returns
Section titled “Returns”string — The version with an incremented or newly-started prerelease
Examples
Section titled “Examples”Start a new alpha line
Section titled “Start a new alpha line”Bumping a release version starts a fresh prerelease at .0, one patch ahead.
Increment the same prerelease type
Section titled “Increment the same prerelease type”Bumping with the same prereleaseId increments its counter.
Switch prerelease type
Section titled “Switch prerelease type”Switching to a different prereleaseId resets the counter to 0, e.g. graduating from alpha to beta.
Increment a Gentoo/Portage prerelease
Section titled “Increment a Gentoo/Portage prerelease”prereleaseId must be one of Gentoo’s fixed suffix types (alpha/beta/pre/rc/p), not a free-form string.
Related Types
Section titled “Related Types”VersionScheme
Section titled “VersionScheme”Identifies which version scheme parse/compare should use to interpret a
version string. Defaults to 'semver' everywhere it’s accepted.
