A [Babel](https://babeljs.io) [preset](https://babeljs.io/docs/en/presets) for transforming JavaScript code with modern language features into code compatible with [njs](https://github.com/nginx/njs) (NGINX JavaScript).
This preset includes support for all the ECMAScript features up to ES2021 — see [Plugins](#_plugins) for a complete list.

**TIP:** Take a look at [njs-typescript-starter](https://github.com/jirutka/njs-typescript-starter) for a complete starter template for developing njs scripts for [NGINX](https://nginx.org) server in [TypeScript](https://www.typescriptlang.org) (including integration tests).

## Installation

``` sh
# using npm:
npm install --save-dev babel-preset-njs
# or using yarn:
yarn add --dev babel-preset-njs
```

### Compatibility Matrix

| preset-njs    | njs     | Babel |
| ------------- | ------- | ----- |
| 0.1.0 – 0.2.1 | ≥ 0.5.0 | 7     |
| 0.7.0         | ≥ 0.7.0 | 7     |

## Usage

### With a Configuration File (Recommended)

``` json
{
  "presets": ["babel-preset-njs"]
}
```

### Via CLI

``` sh
babel --presets babel-preset-njs script.js
```

### Via Node API

``` js
require('@babel/core').transform('code', {
  presets: [require('babel-preset-njs')],
})
```

## Plugins

The list of included Babel plugins is available [here](https://github.com/jirutka/babel-preset-njs/blob/v0.7.0/README.adoc#plugins).

## References

  - [njs ECMAScript Compatibility](http://nginx.org/en/docs/njs/compatibility.html)

## License

This project is licensed under [MIT License](http://opensource.org/licenses/MIT/).
