babel-plugin-transform-array-prototype-includes
v1.0.0
Published
Transforms `arr.includes(value)` to ES5 without a polyfill
Downloads
24
Maintainers
Readme
babel-plugin-transform-array-prototype-includes
Transforms arr.includes(value)
to ES5 without a polyfill
Inspired by babel-plugin-array-includes.
Example
In
[1, 2, 3].includes(1);
[1, 2, 3]['includes'](1);
arr.includes(1);
arr['includes'](1);
Out
[1, 2, 3].indexOf(1) !== -1;
[1, 2, 3].indexOf(1) !== -1;
Array.isArray(arr) ? arr.indexOf(1) !== -1 : arr.includes(1);
Array.isArray(arr) ? arr.indexOf(1) !== -1 : arr['includes'](1);
Installation
$ npm install babel-plugin-transform-array-prototype-includes
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["transform-array-prototype-includes"]
}
Via CLI
$ babel --plugins transform-array-prototype-includes script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["transform-array-prototype-includes"]
});