0.0.2 • Published 7 years ago

babel-plugin-auto-argument v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Using auto argument in JavaScript like Scala

GitHub stars GitHub forks npm npm npm

See Also:

1. Install

npm install --save-dev babel-plugin-auto-argument

2. Basic Usage

Edit your .babelrc file:

{
  "plugins": [
    "auto-argument"
  ]
}

In your js file:

[1, 2, 3].map(_ * 2)

And it will be compiled to:

[1, 2, 3].map(function (_) { 
    return _ * 2
})

In your js file:

const a = [
    [1, 2],
    [3, 4, 5],
    [6, 7, 8, 9]
].filter(_.length <= 3).map(_.filter(10 % _ === 0));
console.log(a);

And it will print:

[
    [1, 2],
    [5]
]

3. Usage with custom variable name

Edit your .babelrc file:

{
  "plugins": [
    "auto-argument",
    {
      "variableName": "$"
    }
  ]
}

In your js file:

[1, 2, 3].map($ * 2)