
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
babel-plugin-transform-array-prototype-find
Advanced tools
Transforms `arr.find(predicate)` to ES5 without a polyfill
Transforms arr.find(predicate)
to ES5 without a polyfill
Inspired by babel-plugin-array-includes.
In
[1, 2, 3].find(v => v === 1);
[1, 2, 3]['find'](v => v === 1);
arr.find(v => v === 1);
arr['find'](v => v === 1);
Out
[1, 2, 3].filter(v => v === 1)[0];
[1, 2, 3].filter(v => v === 1)[0];
Array.isArray(arr) ? arr.filter(v => v === 1)[0] : arr.find(v => v === 1);
Array.isArray(arr) ? arr.filter(v => v === 1)[0] : arr['find'](v => v === 1);
This is not a true replacement for find
.
While find
stops iterating when it finds a match, filter
does not.
If the predicate causes side effects, do not use this plugin.
$ npm install babel-plugin-transform-array-prototype-find
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-array-prototype-find"]
}
$ babel --plugins transform-array-prototype-find script.js
require("@babel/core").transform("code", {
plugins: ["transform-array-prototype-find"]
});
FAQs
Transforms `arr.find(predicate)` to ES5 without a polyfill
The npm package babel-plugin-transform-array-prototype-find receives a total of 29 weekly downloads. As such, babel-plugin-transform-array-prototype-find popularity was classified as not popular.
We found that babel-plugin-transform-array-prototype-find demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.