mini-type-decorator

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i mini-type-decorator

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • vweevers