
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Simple functional library to offer if conditions as expressions, not statements
A simple functional library to offer if conditions as expressions, not statements.
Using NPM:
npm i ifexpr
Using Yarn:
yarn add ifexpr
Note that this module has been developed using TypeScript with proper typings. So you mostly don't need to read this part and you can skip to examples section to see some real usages.
You need to pass a boolean or a () => boolean as first param.
The next 2 params can be a T or a () => T. First one will be returned/executed and returned as expression value if the passed condition/condition function is/returns truthy. The last one will be returned/executed and returned as expression value if the passed condition/condition function is/returns falsy.
import ifexpr from 'ifexpr'
const age = 20
const isOldEnough = ifexpr(age > 18, true, false) // returns true
const isOldEnough2 = ifexpr(() => {
return age > 18
}, true, false) // returns true
const isOldEnough3 = ifexpr<'yes' | 'no'>(age > 18, () => {
// some other stuff to execute in case of truthy
return 'yes'
}, () => {
// some other stuff to execute in case of falsy
return 'no'
}) // returns 'yes'
You can check unit tests inside src directory to read all possible usages.
You can report bugs and issues here.
You can also send a PR if you feel like you can improve or fix something. Don't forget to write/update tests for your changes.
FAQs
Simple functional library to offer if conditions as expressions, not statements
We found that ifexpr 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.