# 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();
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dsheiko.gitbook.io/bycontract/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
