Socket
Socket
Sign inDemoInstall

babel-plugin-drop-hof

Package Overview
Dependencies
50
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-drop-hof

Transforms higher-order function calls such as `map`, `filter`, and `reduce` to loops.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

babel-plugin-drop-hof

Transforms higher-order function calls to loops.

Currently supported higher-order functions are: forEach, map, filter, every, some, and reduce.

Example

In

var result = array.map(function (x) {
  return x * 2;
});

Out

var _a = array;
var _i = 0;

var _f = function _f(x) {
  return x * 2;
};

var _r = [];

for (; _i < _a.length; _i++) {
  var _e = _a[_i];

  var _z;

  _z = _f(_e, _i, _a);

  _r.push(_z);
}

var result = _r;

Some corner cases are handled properly:

In

isValid() && array.map(function (x) {
  return x * 2;
});

while (array.map(function (x) {
  return x * 2;
}));

Out

// **Same as input**

Installation

npm install --save babel-plugin-drop-hof

Usage

Via .babelrc

.babelrc

{
  "plugins": ["babel-plugin-drop-hof"]
}

Via CLI

babel --plugins babel-plugin-drop-hof script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["babel-plugin-drop-hof"]
});

FAQs

Last updated on 29 Sep 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc