
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@drag13/when-do
Advanced tools
Small function that can be used instead if-then statement in functional style programming with JavaScript
Small function that can be used instead of 'if-then' statement in functional style programming with JavaScript. Takes a predicate and one or two handlers. Returns new function that will check the predicate and execute a true/false handler.
No external dependencies, uses ES6 inside, TypeScript ready.
npm install @drag13/when-do
Usage is simple: WhenDo function returns a new function that will be executed depending on a predicate. You can pass params and expect return result.
const wd = require('@drag13/when-do');
const myComposedFunction = wd(() => true, (name) => `hello ${name}`);
console.assert(myComposedFunction('mate') === 'hello mate');
If you pass a predicate as a function, it will not be invoked until composed function call is executed.
const wd = require('@drag13/when-do');
const log = console.log;
const demo = wd(()=> { log('predicate calculated'); return true;},
()=> log('trueFunction executed'));
log('start');
demo();
Result will be
start
predicate calculated
trueFunction executed
If you want to have if-then-else statement inside react - try this example
import iftrue from '@drag13/when-do';
render() {
return (
<div className="WhenDoExample">
{
iftrue(this.state.counter % 2,
() => <div>Odd</div>,
() => <div>Even</div>)()
}
<button onClick={() => this.setState({ counter: this.state.counter + 1 })}>CLICK</button>
</div>
);
}
Tip: You can name WhenDo function whatever you want, just change name inside the import!
import ifthenelse from '@drag13/when-do';
import iftrue from '@drag13/when-do'
Feel free to use it with TypeScript
import * as whenDo from '@drag13/when-do';
const myComposedFunction = wd(() => true, (name) => `hello ${name}`);
console.assert(myComposedFunction('mate') === 'hello mate');
npm test
Any bug fixing is appreciated. If you want to add new functionality - you're welcome. But KISS it please.
FAQs
Small function that can be used instead if-then statement in functional style programming with JavaScript
We found that @drag13/when-do 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.