1.0.0 • Published 8 years ago

mini-type-decorator v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

mini-type-decorator

Concise type assertions like a<map<fn:s>> for class constructors and methods. For details on the type expressions, refer to mini-type-assert.

npm status Dependency status

example

const t = require('mini-type-decorator')

@t('a<s>', ['n', (n) => n <= 10], 'o<b>')
class Example {
  constructor(tags, grade, flags = {}) {
    this.tags = tags
  }

  @t('s')
  say(what) {
    console.log(what)
  }
}

// Throws because 200 is not a string
new Example([['ok', 200], 2, { a: true })

// Throws because 200 is more than 10
new Example(['ok'], 200, { a: true })

// Throws because 200 is not a boolean
new Example(['ok'], 2, { a: 200 })

Note: optional arguments (o<b>?) as well as wildcards (*) are on the roadmap.

install

With npm do:

npm install mini-type-decorator

license

MIT © Vincent Weevers