Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
babel-plugin-functional-composition
Advanced tools
Babel plugin for functional code bases
npm install --save-dev babel-plugin-functional-composition
// .babelrc
{
"plugins": ["functional-composition", {
"name": "pipe" // optional - defaults to `pipe`
"as": "pipe" // optional - defaults to `pipe`
"from": "ramda" // optional, but required for automatic imports
}]
}
>>
const add3 = x => x + 3
const add2 = x => x + 2
const y = add2 >> add3
// will become
const y = pipe(add2, add3)
<<
const add3 = x => x + 3
const add2 = x => x + 2
const y = add2 << add3
// will become
const y = pipe(add3, add2)
const add3 = x => x + 3
const add2 = x => x + 2
const add1 = x => x + 1
const y = add2 >> add3 << add1
// will become
const y = pipe(add1, pipe(add2, add3))
>>>
For non-curried functionsSuppose you have a functional API that is not curried you can now do this.
>>>
will place the left expression as the last parameter to the right expression.
import { map, from, scan } from 'most'
const add1 = x => x + 1
const x = from([1, 2, 3]) >>> map(add1) >>> scan(add1, 0)
// will become
const x = scan(add1, 0, map(add1, from([1, 2, 3])))
const y = 3 >>> add1
// will become
const y = add1(3)
use fc
By default >>
, <<
, and >>>
will do nothing for you that JS
does not already do, because in order to activate these features a directive must be applied.
3 >>> 3 // still a bitwise operation
const add1 = x => x + 1
function add1To (x) {
'use fc' // activates plugin in this scope
return x >>> add1 // becomes add1(x)
}
If the (optional) options object is provided, with at the minimum from
, if the
import does not exist yet, the import will be added for you. This is useful for
things like eslint complaining about unused imports. name
is the the part of the
object that you would normally import e.g. pipe
in import { pipe } from 'ramda'
.
If name
is not the name you'd like to have imported as, perhaps it conflicts with
another import, you can specify as
to import it as something else.
import { pipe as sequence } from 'ramda'
, will be added to your files if the as
option is provided.
So for instance if your are using ramda all you will need is
{
"plugins": [
["functional-composition", { "from": "ramda" }]
]
}
and at the top of your file this plugin will add import { pipe } from 'ramda'
for you.
FAQs
Functional Composition for JavaScript
We found that babel-plugin-functional-composition demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.