File: README.md

package info (click to toggle)
node-babel-plugin-array-includes 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 116 kB
  • sloc: makefile: 9; sh: 2
file content (73 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# babel-plugin-array-includes

> Replaces `arr.includes(val)` with `arr.indexOf(val) >= 0`.

Thanks to [@sebmck](https://github.com/sebmck) for the help.

## Example

**In**

```javascript
[1, 2, 3, 5, 8, 13].includes(4);
```

**Out**

```javascript
"use strict";

[1, 2, 3, 5, 8, 13].indexOf(4) >= 0;
```

## Pitfalls

This doesn't work:

**In**

```js
function foo(arr) {
  return arr.includes('foo');
}
```

**Out**

```js
function foo(arr) {
  return arr.includes('foo'); // still includes
}
```

## Installation

```sh
$ npm install babel-plugin-array-includes
```

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "plugins": ["array-includes"]
}
```

### Via CLI

```sh
$ babel --plugins array-includes script.js
```

### Via Node API

```javascript
require("babel-core").transform("code", {
  plugins: ["array-includes"]
});
```