From e3324a3e5ca04fbcf8b71c23e105277e7c375fe9 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Fri, 20 Sep 2019 12:47:50 +0100 Subject: [PATCH] docs: add docs for no-pipeline-operator --- docs/no-pipeline-operator.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/no-pipeline-operator.md diff --git a/docs/no-pipeline-operator.md b/docs/no-pipeline-operator.md new file mode 100644 index 0000000..3701dee --- /dev/null +++ b/docs/no-pipeline-operator.md @@ -0,0 +1,33 @@ +# no-pipeline-operator + +This prevents the use of the Pipeline Operator + +```js +const result = "hello" |> capitalize |> exclaim +``` + +These will not be allowed because they are not supported in the following browsers: + + - Edge (any version at the time of writing) + - Safari (any version at the time of writing) + - Firefox (any version at the time of writing) + - Chrome (any version at the time of writing) + +## What is the Fix? + +For simple expressions you can wrap each function inside the previous pipeline call: + +```js +// these are equivalent: +const result = "hello" |> capitalize |> exclaim +const result = exclaim(capitalize("hello")) +``` + +Lastly, you could consider using a utility function such as [lodash' `_.flow`](https://lodash.com/docs/4.17.15#flow) or [`_.flowRight`](https://lodash.com/docs/4.17.15#flowRight) + +```js +const result = _.flow(capitalize, exclaim)("hello") +const result = _.flowRight(exclaim, capitalize)("hello") +``` + +This can be safely disabled if you intend to compile code with the `@babel/plugin-proposal-pipeline-operator` Babel plugin.