-
Notifications
You must be signed in to change notification settings - Fork 8
Types
James edited this page May 30, 2017
·
1 revision
🌊 types
🎼
- typed(
?name: string
):TypeChainFactory- validators(
object
):TypeChainFactory. with keys that are accessed fromtyped
when using astring
- typed:TypeChainFactory
-
string
: uses property matching the string invalidators
-
Function
: callback to do validation
-
- onValid(
Function
):TypeChainFactory - onInvalid(
Function
):TypeChainFactory - name(
string
):TypeChainFactory
- validators(
- prop(
string
):TypeChainFactory. property name
const chain = new Chain()
.typed('short')
.type(val => typeof val === 'function')
chain.short(val => {}) // valid function
chain.short(!!Boolean) // boolean, not a function, throws
const chain = new Chain()
.typed()
.validators({string: val => typeof val === 'string'})
.type('string')
.name('eh')
.onValid((val, chain) => chain.set('eh', val))
.onInvalid((val, chain) => console.log('ignore it.'))
.end()
chain.eh('valid string') // .onValid
chain.eh(Number) // invalid, triggers .onInvalid