Skip to content
James edited this page May 30, 2017 · 1 revision

🌊 types 🎼

🌐 api

  • typed(?name: string):TypeChainFactory
    • validators(object):TypeChainFactory. with keys that are accessed from typed when using a string
    • typed:TypeChainFactory
      • string: uses property matching the string in validators
      • Function: callback to do validation
    • onValid(Function):TypeChainFactory
    • onInvalid(Function):TypeChainFactory
    • name(string):TypeChainFactory
  • prop(string):TypeChainFactory. property name

📘 examples

👾 minimal

const chain = new Chain()
  .typed('short')
  .type(val => typeof val === 'function')

chain.short(val => {})   // valid function
chain.short(!!Boolean)   // boolean, not a function, throws

advanced

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
Clone this wiki locally