d-contract

1.0.5 • Public • Published

d-contract

For Support, Design by Contract(DBC)

Use

import dContract = require('d-contract');
const { validate, required } = dContract;
 
class Converter {
  @validate((result) => typeof result === 'number')
  toNumber(@required((numeric) => !isNaN(numeric)) numeric: string) {
    return Number(numeric);
  }
}
 
const converter = new Converter();
console.log(converter.toNumber('1213'));
console.log(converter.toNumber('aaa')); // throw assert error

Package Sidebar

Install

npm i d-contract

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

14.2 kB

Total Files

32

Last publish

Collaborators

  • araxsiyual