Skip to content

stoeffel/babel-plugin-array-includes

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

babel-plugin-array-includes

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

Thanks to @kittens for the help.

Example

In

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

Out

"use strict";

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

Pitfalls

This doesn't work:

In

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

Out

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

Installation

$ npm install babel-plugin-array-includes

Usage

Via .babelrc (Recommended)

.babelrc

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

Via CLI

$ babel --plugins array-includes script.js

Via Node API

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published