babel-plugin-transform-array-prototype-includes
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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"]
});

Package Sidebar

Install

npm i babel-plugin-transform-array-prototype-includes

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

5.48 kB

Total Files

5

Last publish

Collaborators

  • mhassan1