badbadnotgood
Functional validation, built for composition.

Usage
import {
all,
any,
onlyIf,
not,
divisibleBy
equals,
minLength,
} from 'badbadnotgood'
const isFoo = equals('foo')
isFoo('foo')
isFoo('bar')
const isBar = equals('bar', 'Value must be "bar"')
isFoo('foo')
isFoo('bar')
const isNotFoo = not(equals('foo'), 'Value must not be "foo"')
isNotFoo('foo')
isNotFoo('bar')
const isFooOrBar = any(
[equals('foo'), equals('bar')],
'Value must be "foo" or "bar"'
)
isFooOrBar('foo')
isFooOrBar('baz')
const isDivisibleBy3And4 = all([
divisibleBy(3, 'Not divisible by 3'),
divisibleBy(4, 'Not divisible by 4')
])
isDivisibleBy3And4(12)
isDivisibleBy3And4(6)
isDivisibleBy3And4(1)
const atLeast6CharsUnlessFoo = onlyIf(
not(equals('foo')),
minLength(6, 'Must be at least 6 characters')
)
atLeast6CharsUnlessFoo('foo')
atLeast6CharsUnlessFoo('bar')
atLeast6CharsUnlessFoo('foobar')
const allAreFoo = forEach(equals('foo', 'Item is not "foo"'), 'All items must be "foo"')
allAreFoo(['foo'])
allAreFoo(['foo', 'bar'])