betterbe
A minimally flexible data validator
Features:
- Props are required by default
- Strict by default (no type cohersion)
- No unknown properties allowed
Example
import { boolean, number, object, string } from 'betterbe'
const validateUid = string({
minLength: 10,
maxLength: 12,
alphabet: '0123456789',
})
const validateMessage = object({
from: object({
uid: validateUid,
}),
message: string({ minLength: 1, maxLength: 280 }),
utcTime: number({ integer: true }),
urgent: boolean({ required: false }),
})
validateMessage.validate({
from: { uid: '1234567890' },
message: 'Hello, World!',
utcTime: 1630000000,
})
validateMessage.validate({
from: { uid: '1234567-90' },
message: 'Hello, World!',
utcTime: 1630000000,
})
API Reference
See docs