npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-holes

v0.9.0

Published

Consistent Scala-like holes to increase code expressivity

Downloads

14

Readme

babel-plugin-holes

NPM Version NPM Downloads

This plugin is made to bring the powerful expressivity of Scala functions to JavaScript. It provides a powerful system of holes to help on functional programming and function composition, enforcing the point-free style.

It's very well tested and has consistent rules that shouldn't break when used with other plugins. You can also abstract the native JavaScript operations with it without overheads!

Examples

// Binary operators
const add = _ + _
const increment = _ + 1

console.log(add(100, 200)) // 300
console.log(increment(1000)) // 1001


// Unary operators
const negate = -_

console.log(negate(10)) // -10


// Operators as functions
const at = _[_]
const call = _(_)

console.log(at([5, 10, 15], 1)) // 10
call(console.log, 'Hello!') // 'Hello!'


// Identity function
const id = _

console.log(id('frobnicate')) // 'frobnicate'


// Method calls
const toString = _.toString()
const toHexString = _.toString(16)

console.log(toString(10)) // 10
console.log(toHexString(10)) // 'a'


// Binary property access
const goodPassword = _.length >= 8
const ageSum = _.age + _.age

console.log(goodPassword('dolphins')) // true
console.log(ageSum({ age: 21 }, { age: 30 })) // 51


// Binary method call
const ellipsize = _.toString() + '...'

console.log(ellipsize(100)) // 100...

It works on identifiers, simple members, computed members, calls, binary and unary expressions, so you can compose functions that take more parameters, for example:

const assocOne = assoc(_, 1, _)

console.log(assocOne('value', {})) // { value: 1 }

Disabling in current scope

If you want to use the original underscore, you can disable this plugin in current scope (and its children scopes) using 'no holes' directive.

Options

You can pass your own curry function with { curry: 'curry' }. The generated functions will use it, so:

{
    "plugins": ["holes", { "curry": "curry" }]
}
const add = _ + _

will emit:

const add = curry((_2, _3) => _2 + _3)

Installation

$ npm install --save-dev babel-plugin-holes

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["holes"]
}

Via CLI

$ babel --plugins holes script.js

Via Node API

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

Observation

Using ++ and -- has no warranties because Babel code generator has a bug that emits wrong code for a correct AST node. Their use is not recommended.

License

MIT