This function uses the rulr.isLocale
guard to check the input is a valid locale as shown in the example below. It should only throw rulr.InvalidLocaleError
. This function uses the much loved validator package.
import * as rulr from 'rulr'
const constrainToExample = rulr.object({
required: {
example: rulr.locale,
},
})
type Example = rulr.Static<typeof constrainToExample>
// {
// example: rulr.Locale
// }
// Valid
const example1: Example = constrainToExample({
example: 'en-US',
})
// Invalid: Not a valid Locale
const example2: Example = constrainToExample({
example: '-',
})
// Invalid: Not a string
const example3: Example = constrainToExample({
example: 1,
})