New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-implicit-function

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-implicit-function

Babel plugin to allow lazy expressions by implicit arrow functions via ~ operator

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
201
increased by6.91%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-implicit-function

This plugin is made to make JS syntax easier to work with functional programming by creating quoted expressions that may be lazily evaluated and work together with functional libraries, like Ramda. I've overloaded the ~ prefix unary operator for that.

Examples

import { cond } from 'ramda';

const precomputedResult = ~(10 === 20);
const otherwise = ~true;
const matches = cond([
    [precomputedResult, ~'Something is reeeeally wrong!'],
    [otherwise, ~'Nice! Math still works!']
]);

Turn into

import { cond } from 'ramda';

const precomputedResult = () => 10 === 20;
const otherwise = () => true;
const matches = cond([
    [precomputedResult, () => 'Something is reeeeally wrong!'],
    [otherwise, () => 'Nice! Math still works!']
]);

This is a good replacement for always function, because this is really lazy, and the value only gets computed when you need it. Using always can cause problems by premature evaluation:

getUsers()
    .then(always(doSomethingImportantAndReturn());

Note that doSomethingImportantAndReturn needs getUsers to be computed before, but that's not what happen, and this is a source of error and code smell. We could easily fix that with ~ operator. Remember: never use always!

getUsers()
    .then(~doSomethingImportantAndReturn());

Disabling in current scope

If you want to use the original bitwise negation operator, you can disable this plugin in current scope (and it children scopes) using 'no implicit function' directive.

Installation

$ npm install --save-dev babel-plugin-implicit-function

Usage

.babelrc

{
  "plugins": ["implicit-function"]
}

Via CLI

$ babel --plugins implicit-function script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['implicit-function']
});

License

MIT

Keywords

FAQs

Package last updated on 04 Sep 2017

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc