Skip to content

increment

Increments a version, according to the given scheme.

'semver' (default) — bumps major/minor/patch per SemVer, resetting the finer-grained components (bumping major resets minor and patch to 0, etc.) and dropping any prerelease/build metadata.

'gentoo' — bumps the component at type’s position (major → 1st, minor → 2nd, patch → 3rd — Gentoo’s components array can be any length, but the first three follow the same positional convention as SemVer), zeroing everything after it and dropping the letter/suffixes/revision.

'debian' — throws: a Debian upstream version is free-form, with no major/minor/patch structure to bump.

Available since v1.9.0

import { increment } from '@helpers4/version';
// or, from the all-in-one package (same code, one install):
import { increment } from 'helpers4/version';
increment(version: string, type: IncrementType, scheme?: VersionScheme): string
ParameterTypeDescription
versionstringThe version to increment
typeIncrementTypeThe increment type (‘major’, ‘minor’, ‘patch’)
schemeVersionSchemeWhich version scheme to interpret `version` as. Defaults to `‘semver’`. (optional)

string — Incremented version string

Bumps the patch number while keeping major and minor.

increment('1.2.3', 'patch')
// => '1.2.4'

Bumps the minor number and resets patch to 0.

increment('1.2.3', 'minor')
// => '1.3.0'

The v prefix is preserved if present in the input.

increment('v1.0.0', 'major')
// => 'v2.0.0'

Drops any letter/suffix/revision and resets components after the bumped one, same as the SemVer scheme.

increment('1.2.3_rc1', 'patch', 'gentoo')
// => '1.2.4'

The unit to bump — see increment.

type IncrementType = 'major' | 'minor' | 'patch'

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