given-that
A minimalist approach to control flow, by extending the standard Javascript Object.
Install
yarn add given-that
or
npm install given-that
Purpose
The idea behind given-that
is to provide a plainer way of speaking when it comes to a programs control flow. Take the following example:
iftypeof foo === 'boolean' && typeof bar === 'string' || typeof bar === 'number' ifthismyVariable === false console; else ifthismyVariable console;
Control flow can quickly become both cumbersome and hard to follow. Now - the same example with given-that
:
note, given-that
comes in two flavours, which are toggleable, one is a standalone object which will add a small footprint to your code
the other will add a global is
parameter to everything
Standalone
ifgivenisaboolean && givenisastring || givenisanumber ifgivenisfalse console; else ifgivenistruthy console;
Object inherited
iffooisaboolean && barisastring || barisanumber ifthismyVariableisfalse console; else ifthismyVariableistruthy console;
Both methods provide a syntactically clear set of rules by which a developer can read clearly.