Skip to content

Latest commit

History

History
40 lines (31 loc) 路 833 Bytes

File metadata and controls

40 lines (31 loc) 路 833 Bytes

positiveInteger

Back to root readme.md

This function uses the rulr.isPositiveInteger guard to check the input is a valid positiveInteger as shown in the example below. It should only throw rulr.InvalidPositiveIntegerError.

import * as rulr from 'rulr'

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

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

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

// Invalid: Not positive
const example2: Example = constrainToExample({
	example: -1,
})

// Invalid: Not integer
const example3: Example = constrainToExample({
	example: 1.1,
})

// Invalid: Not a number
const example4: Example = constrainToExample({
	example: '-1',
})