Socket
Book a DemoInstallSign in
Socket

babel-plugin-transform-array-prototype-find

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-array-prototype-find

Transforms `arr.find(predicate)` to ES5 without a polyfill

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
40
53.85%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-array-prototype-find

Transforms arr.find(predicate) to ES5 without a polyfill

Inspired by babel-plugin-array-includes.

Example

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);

Caveats

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.

Installation

$ npm install babel-plugin-transform-array-prototype-find

Usage

.babelrc

{
  "plugins": ["transform-array-prototype-find"]
}

Via CLI

$ babel --plugins transform-array-prototype-find script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["transform-array-prototype-find"]
});

Keywords

babel

FAQs

Package last updated on 11 Sep 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.