Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elliothux/babel-plugin-auto-argument

🍺 Using auto argument in JavaScript like Scala
https://github.com/elliothux/babel-plugin-auto-argument

auto-argument babel-plugin scala

Last synced: about 2 months ago
JSON representation

🍺 Using auto argument in JavaScript like Scala

Awesome Lists containing this project

README

        

### ⚠️ It‘s unstable!DO NOT use it on production environment.

# Using auto argument in JavaScript like Scala

[![GitHub stars](https://img.shields.io/github/stars/HuQingyang/babel-plugin-auto-argument.svg?style=social&label=Stars&style=plastic)](https://github.com/HuQingyang/babel-plugin-auto-argument)
[![GitHub forks](https://img.shields.io/github/forks/HuQingyang/babel-plugin-auto-argument.svg?style=social&label=Fork&style=plastic)](https://github.com/HuQingyang/babel-plugin-auto-argument)
[![npm](https://img.shields.io/npm/dw/babel-plugin-auto-argument.svg)](https://www.npmjs.com/package/babel-plugin-auto-argument)
[![npm](https://img.shields.io/npm/v/babel-plugin-auto-argument.svg)](https://www.npmjs.com/package/babel-plugin-auto-argument)
[![npm](https://img.shields.io/npm/l/babel-plugin-auto-argument.svg)](https://www.npmjs.com/package/babel-plugin-auto-argument)

**See Also:**
* Using two-way data binding in JSX: [babel-plugin-jsx-two-way-binding](https://github.com/HuQingyang/babel-plugin-jsx-two-way-binding)
* Using for-directive in JSX: [babel-plugin-jsx-for-directive](https://github.com/HuQingyang/babel-plugin-jsx-for-directive)
* Using if-directive in JSX: [babel-plugin-jsx-if-directive](https://github.com/HuQingyang/babel-plugin-jsx-if-directive)

## 1. Install
`npm install --save-dev babel-plugin-auto-argument`

## 2. Basic Usage
Edit your __.babelrc__ file:
```json
{
"plugins": [
"auto-argument"
]
}
```
In your js file:
```js
[1, 2, 3].map(_ * 2)
```
And it will be compiled to:
```js
[1, 2, 3].map(function (_) {
return _ * 2
})
```

In your js file:
```js
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:
```js
[
[1, 2],
[5]
]
```

## 3. Usage with custom variable name
Edit your __.babelrc__ file:
```json
{
"plugins": [
"auto-argument",
{
"variableName": "$"
}
]
}
```
In your js file:
```js
[1, 2, 3].map($ * 2)
```