Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    babel-plugin-array-includespublic

    babel-plugin-array-includes

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

    Thanks to @sebmck 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"]
    });

    install

    npm i babel-plugin-array-includes

    Downloadsweekly downloads

    105,318

    version

    2.0.3

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar