Skip to content

Latest commit

History

History
35 lines (27 loc) 路 879 Bytes

File metadata and controls

35 lines (27 loc) 路 879 Bytes

semanticVersion

Back to root readme.md

This function uses the rulr.isSemanticVersion guard to check the input is a valid semantic version as shown in the example below. It should only throw rulr.InvalidSemanticVersionError. This function uses the much loved validator package.

import * as rulr from 'rulr'

const constrainToExample = rulr.object({
	required: {
		example: rulr.semanticVersion,
	},
})

type Example = rulr.Static<typeof constrainToExample>
// {
//   example: rulr.SemanticVersion
// }

// Valid
const example1: Example = constrainToExample({
	example: '0.0.4',
})

// Invalid: Not a valid semantic version
const example2: Example = constrainToExample({
	example: '-invalid+invalid',
})

// Invalid: Not a string
const example3: Example = constrainToExample({
	example: 1,
})