1.3.0 • Published 6 years ago

spreadif v1.3.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

Usage

const spreadIf = require('spreadif');

const isCitizen = () => true;
const isResident = () => false;
const isEarthman = () => true;
const isAlien = () => false;

No more this:

const info = {};
if(isCitizen()) {
  info.city = 'spacertown';
}
if(isResident()) {
    info.resiNumber = 'X000X';
}
if(isAlien()) {
    info.alienType = 'spacer';
}
if(isEarthman()) {
    info.earthmanType = 'medievalist';
}

Better!

const info = {
   ...spreadIf(isCitizen(), {city: 'spacertown'}),
   ...spreadIf(isResident(), {resiNumber: 'X000X'}),
   ...spreadIf(isAlien(), {alienType: 'spacer'}),
   ...spreadIf(isEarthman(), {earthmanType: 'medievalists'})
}

console.log(info) // {city: 'spacertown', earthmanType: 'medievalists' }
1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago