deus

0.3.5 • Public • Published

deus

arguments convention over configuration

A little bit of functional programming to have a single function implementation whatever the arguments exists or their order.

Installation

with component:

$ component install bredele/deus

with nodejs:

$ npm install deus

Usage

It's a bit complicated to explain with words, so hopefully the example below speaks for itself.

create a function with deus:

// specify the arguments types (have to be different)
var init = deus('string', 'object', function(name, data) {
    console.log('name:', name);
    console.log('data:', data.github);
});

deus preserves the arguments:

init('olivier', { github : 'bredele'});
// => name: olivier
// => data: bredele

deus doesn't care if an argument is missing:

init({ github : 'bredele'});
// => name: undefined
// => data: bredele

deus allows you to switch the arguments order:

init({ github : 'bredele'}, 'olivier');
// => name: olivier
// => data: bredele

deus preseves the other arguments:

var other = deus('function', 'object', function(name, data, other) {
    console.log('other:', other);
});
other({
    github: 'bredele'
}, 'olivier');
// => olivier

Deus decreases the number of decisions the developer needs to make because the implementation is the same whatever the arguments are. The returned function is flexible and yet simple.

Package Sidebar

Install

npm i deus

Weekly Downloads

0

Version

0.3.5

License

MIT

Last publish

Collaborators

  • bredele