babel-plugin-transform-pipeline
Compile pipeline operator (
|>
) to ES5
Proposal: mindeavor/es-pipeline-operator
Example
Basic
In
var user = name: 'SuperPaintman' ; { return str;} { return 'Hello, ' + name + '!';} var res = username |> capitalize |> sayHello; // => "Hello, SUPERPAINTMAN!"
Out
var user = name: 'SuperPaintman' ; { return str;} { return 'Hello, ' + name + '!';} var res = ; // => "Hello, SUPERPAINTMAN!"
With multi-argument functions
In
var user = score: 4049138 ; var res = userscore |> _ * 2 |> _; // => 80.98
Out
var user = score: 4049138 ; var res = _ * 2 _userscore; // => 80.98
Real use-case
var path = ; var rootDir filePath |> path |> pathdirname |> res |> '/' + res === '.' ? '' : res + '/'; ;// => "/api/users/" ;// => "/"
Out
var path = ; var '/' + res === '.' ? '' : res + '/' respath; ;// => "/api/users/" ;// => "/"
FAQ
Why do we need parentheses around multi-argument functions?
Because they separate the =>
from the |>
.
Ie. the following code:
var res = userscore |> _ * 2 |> double;
Is equivalent to:
var res = userscore |> _ * ; // or var secondArg = 2 |> double; var res = userscore |> _ * secondArg;
Why
|>
?
Firstly, it is a invalid token in terms of javascript (ES3-ES2017).
Secondly, in vanilla javascript there are only 3 token starting with |
: |
, ||
and |=
;
Installation
npm install --save-dev babel-plugin-transform-pipeline # or yarn add --dev babel-plugin-transform-pipeline
Usage
.babelrc
(Recommended)
Via .babelrc
Via CLI
babel --plugins transform-pipeline script.js
Via Node API
;
Build
npm run build
Test
npm run test
Contributing
- Fork it (https://github.com/SuperPaintman/babel-plugin-transform-pipeline/fork)
- Create your feature branch (
git checkout -b feature/<feature_name>
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin feature/<feature_name>
) - Create a new Pull Request
Contributors
- SuperPaintman SuperPaintman - creator, maintainer