@hyperfrontend/versioning/semver/increment

increment

Version bumping: increment a SemVer by a BumpType and compute the diff between two versions.

increment(version, bumpType) produces the next version for major, minor, patch, and the equivalent prerelease bumps. incrementPrerelease is the dedicated helper for advancing -rc.1-rc.2 style identifiers without touching the numeric core. diff(a, b) returns the smallest BumpType that explains the change between two versions, used by changelog and dependent-package logic to decide what kind of bump a downstream package needs.

API Reference

ƒ Functions

§function

diff(older: SemVer, newer: SemVer): BumpType

Calculates the difference type between two versions.

Parameters

NameTypeDescription
§older
SemVer
The older version
§newer
SemVer
The newer version

Returns

BumpType
The type of difference, or null if versions are equal

Example

Calculate the difference type between two versions
diff(parseVersion('1.0.0'), parseVersion('2.0.0')) // 'major'
diff(parseVersion('1.0.0'), parseVersion('1.1.0')) // 'minor'
diff(parseVersion('1.0.0'), parseVersion('1.0.1')) // 'patch'
§function

increment(version: SemVer, type: BumpType, prereleaseId?: string): SemVer

Increments a version based on the bump type.

Parameters

NameTypeDescription
§version
SemVer
The version to increment
§type
BumpType
The type of bump (major, minor, patch, etc.)
§prereleaseId?
string
Optional prerelease identifier for prerelease bumps

Returns

SemVer
A new incremented SemVer

Example

Increment version by bump type
increment(parseVersion('1.2.3'), 'minor') // 1.3.0
increment(parseVersion('1.2.3'), 'major') // 2.0.0
increment(parseVersion('1.2.3'), 'prerelease', 'alpha') // 1.2.4-alpha.0
§function

incrementPrerelease(version: SemVer, id?: string): SemVer

Increments the prerelease portion of a version.

Parameters

NameTypeDescription
§version
SemVer
The version to increment
§id?
string
Optional prerelease identifier

Returns

SemVer
A new version with incremented prerelease

Example

Increment the prerelease portion of a version

incrementPrerelease(parseVersionStrict('1.0.0')) // => 1.0.1-alpha.0
incrementPrerelease(parseVersionStrict('1.0.0-alpha.0')) // => 1.0.0-alpha.1
incrementPrerelease(parseVersionStrict('1.0.0'), 'beta') // => 1.0.1-beta.0