The verifiable instance is required.
Set the verifiable rule to be optional.
const r = eq({
a: string.optional,
b: string // .required by default
})
r.ok({ b: 'abc' }) === true
r.ok({ a: 'abc' }) === false
Set the verifiable rule to be required. please see required.
Assigns rules
The main check method which would invokes _check.
Extends parent
get rule
eq({ a: 'a' }).get('a') === 'a'
eq({ a: 'a' }).ok(
eq({ a: 'a' }).get()
) === true
Gets the rule string
oneOf(['123', string]).getRuleString() === "['123', string]"
Gets the type name
oneOf(['123', string]).getTypeName() === "oneOf"
Merge rules
set rule
eq({ a: 'a' }).set('a', 'bbb').ok({ a: 'bbb' }) === true
eq({ a: 'a' }).set(null, 'bbb').ok('bbb') === true
Gets the verifiable instance string
oneOf(['123', string]).getRuleString() === "oneOf(['123', string])"
be('2').toUnlawfulString('2') === ''
be('2').toUnlawfulString(2) === "expected: '2', actual: 2."
Generated using TypeDoc
alias:
eq
*Checks whether the actual and the expected are similar. please see the twin brother LooseEqual for more information.
eq([]).ok([]) === true eq('222').ok(222) === false eq(['222']).ok([222]) === false eq({ a: { b: '2' } }).ok({ a: { b: '2' } }) === true // The actual value contains `.c` which isn't allowed. eq({ a: { b: '2' } }).ok({ a: { b: '2' }, c: 'ddd' }) === false