Overload the pipe operator (|
) to provide Elixir/F#/Shell-like behavior
import { map, filter } from 'lodash';
const array = [1, 2, 3, 4, 5];
array
| map(n => n * 2)
| filter(n => n % 3 == 0);
If you want to use the original pipe operator, you can disable this plugin in current scope (and it children scopes) using "no pipe"
directive
const fn = () => {
const arr = [1, 2, 3] | map(n => n + 1);
return () => {
"no pipe";
arr.map(n => n | 1);
};
};
$ npm install --save-dev babel-plugin-pipe-operator
.babelrc
{
"plugins": ["pipe-operator"]
}
$ babel --plugins pipe-operator script.js
require("babel-core").transform("code", {
plugins: ["pipe-operator"]
});
MIT