# Welcome

[byContract](https://github.com/dsheiko/bycontract) is a small argument validation library based on [JSDOC syntax](https://jsdoc.app/tags-type.html). The library is available as a UMD-compatible module. Besides, it exposes `byContract` function globally when `window` object available, meaning you can still use it in non-modular programming.

It is covered with >100 unit-tests and ready for production. The project can be found on [GitHub](https://github.com/dsheiko/bycontract) where you can also find our [issue tracker](https://github.com/dsheiko/bycontract/issues).&#x20;

## Highlights

* Validation syntax based on JSDoc expressions
* Entry and exit point contract validation
* Explanatory exceptions in the style of aproba
* Recursive structure (object) validation
* Interface validation
* Template tag flavor
* Property decorators flavor
* Can be disabled or completely cut off for production

## Flavors

### Main

```javascript
function pdf( path, w, h, options, callback ) {
  validate( arguments, [
    "string",
    "!number",
    "!number",
    PdfOptionsType,
    "function=" ] );
}
```

### Template tag

```javascript
function pdf( path, w, h, options, callback ) {
  validateContract`
    {string}          ${ path }
    {!number}         ${ w }
    {!number}         ${ h }
    {#PdfOptionsType} ${ options }
    {function=}       ${ callback }
    `;
}
```

### Property decorator

```javascript
class Page {
  @validateJsdoc(`
    @param {string}          path
    @param {!number}         w
    @param {!number}         h
    @param {#PdfOptionsType} options
    @param {function=}       callback
    @returns {Promise}
  `)
  pdf( path, w, h, options, callback ) {
    return Promise.resolve();
  }
}
```
