Skip to content

mtso/babel-plugin-transform-pipe-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>
);