babel-plugin-transform-pipe-operator
v0.1.1
Published
Adds a pipe operator to call pure, synchronous transformer functions within JSX expressions.
Downloads
8
Readme
babel-plugin-transform-pipe-operator
Adds a pipe operator to call pure, synchronous transformer functions within JSX expressions.
Example
A pipe inside a JSX expression,
const Shout = ({ name }) => (
<div>YO, { name | toUpperCase }!</div>
);
Becomes a function call in the result:
const Shout = ({ name }) => (
<div>YO, { toUpperCase(name) }!</div>
);
To pass a parameter, implement the transformer as a factory.
const toFixed = (places) => (value) => value.toFixed(places);
const Cell = ({ value }) => (
<td>{ value | toFixed(2) }</td>
);
const toFixed = (places) => (value) => value.toFixed(places);
const Cell = ({ value }) => (
<td>{ toFixed(2)(value) }</td>
);