given-that

0.0.4 • Public • Published

CircleCI Build Status Maintainability Test Coverage

given-that

A minimalist approach to control flow, by extending the standard Javascript Object.


Install

yarn add given-that

or

npm install given-that

npmjs.org

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:

if(typeof foo === 'boolean' && (typeof bar === 'string' || typeof bar === 'number')) {
  if(this.myVariable === false) {
    console.log('foobar!');  
  } else if(this.myVariable) {
    console.log('barfoo!');
  }  
}

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

if(given.that(foo).is.a.boolean && (given.that(bar).is.a.string || given.that(bar).is.a.number)) {
  if(given.that(this.myVariable).is.false) {
    console.log('foobar!');  
  }else if(given.that(this.myVariable).is.truthy) {
    console.log('barfoo!');
  }
}

Object inherited

if(foo.is.a.boolean && (bar.is.a.string || bar.is.a.number)) {
  if(this.myVariable.is.false) {
    console.log('foobar!');  
  }else if(this.myVariable.is.truthy) {
    console.log('barfoo!');
  }
}

Both methods provide a syntactically clear set of rules by which a developer can read clearly.

Package Sidebar

Install

npm i given-that

Weekly Downloads

0

Version

0.0.4

License

ISC

Unpacked Size

12.8 MB

Total Files

18

Last publish

Collaborators

  • david_bindloss