betterbe
v0.8.1
Published
**A minimally flexible data validator**
Downloads
23
Readme
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 }),
})
// This is not expected to throw (valid input)
validateMessage.validate({
from: { uid: '1234567890' },
message: 'Hello, World!',
utcTime: 1630000000,
})
// This is expected to throw as character `-` is not valid in the uid alphabet
validateMessage.validate({
from: { uid: '1234567-90' },
message: 'Hello, World!',
utcTime: 1630000000,
})
API Reference
See docs