Package Exports
- babel-plugin-array-includes
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-array-includes) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
babel-plugin-array-includes
Replaces
arr.includes(val)witharr.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
}You have to specify that arr is an array.
In
function foo(arr:Array) {
return arr.includes('foo');
}Out
function foo(arr) {
return arr.indexOf('foo') >= 0; // now it works
}Installation
$ npm install babel-plugin-array-includesUsage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["array-includes"]
}Via CLI
$ babel --plugins array-includes script.jsVia Node API
require("babel-core").transform("code", {
plugins: ["array-includes"]
});