@hyperfrontend/versioning/semver/formatformat
String formatting for semver values, ranges, and comparators.
format(version) produces the canonical MAJOR.MINOR.PATCH[-prerelease][+build] rendering for a SemVer. formatSimple strips prerelease/build metadata when only the numeric core is wanted. formatRange and formatComparator round-trip a parsed Range or Comparator back to the npm-flavored range syntax they came from.
API Reference
ƒ Functions
Converts a SemVer to its canonical string representation.
Parameters
| Name | Type | Description |
|---|---|---|
§version | SemVer | The version to format |
Returns
stringThe version string (e.g., "1.2.3-alpha.1+build.123")
Example
Format a version to its canonical string
format(parseVersionStrict('1.2.3')) // => '1.2.3'
format(createSemVer({ major: 1, minor: 0, patch: 0, prerelease: ['beta', '1'] }))
// => '1.0.0-beta.1'Converts a Comparator to its string representation.
Parameters
| Name | Type | Description |
|---|---|---|
§comparator | Comparator | The comparator to format |
Returns
stringThe comparator string (e.g., ">=1.0.0")
Example
Format a comparator to its string representation
formatComparator(createComparator('>=', parseVersionStrict('1.0.0')))
// => '>=1.0.0'Converts a Range to its string representation.
Parameters
| Name | Type | Description |
|---|---|---|
§range | Range | The range to format |
Returns
stringThe range string
Example
Format a range to its string representation
formatRange(parseRangeStrict('^1.0.0')) // => '^1.0.0'
formatRange(createAnyRange()) // => '*'Converts a SemVer to a string without prerelease/build.
Parameters
| Name | Type | Description |
|---|---|---|
§version | SemVer | The version to format |
Returns
stringThe version string (e.g., "1.2.3")
Example
Format version without prerelease/build metadata
formatSimple(parseVersionStrict('1.2.3-beta.1+build')) // => '1.2.3'