A Millwork codec for semantic versions with semver.
pnpm add @millwork-ts/semver @millwork-ts/core semver
| Codec | Value | Raw |
|---|---|---|
semver |
a frozen SemVer |
"1.2.3-beta.1" |
SemVer instance, and the codec freezes it.value.inc() and value.format() change the instance, so they throw a TypeError on the
frozen value. To get the next version, use semver.inc(value.version, 'patch') from the
semver package. It gives a string."1.2.3+sha.5114f85".v is removed: "v1.2.3" is written as "1.2.3".| Option | Type | Use |
|---|---|---|
loose |
boolean |
Read loose forms, such as "=1.2.3" and "01.2.3". The default is false. |
equals uses semver.eq. It ignores build metadata, as SemVer 2.0.0 tells. "1.2.3+a"
equals "1.2.3+b". To sort versions, use semver.compare.
Register the codecs before the store calls transformations(), because transformations()
reads the registry when it runs. See the
@millwork-ts/warp-drive README.
import { codecs } from '@millwork-ts/semver'
import { registerCodecs, valueField } from '@millwork-ts/warp-drive'
import { withDefaults } from '@warp-drive/core/reactive'
registerCodecs(codecs)
export const ReleaseSchema = withDefaults({
type: 'release',
fields: [valueField('version', 'semver')],
})