Skip to content

bredele/deus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Don't mess with a function's arguments

Resources

License

Stars

Watchers

Forks

Packages

No packages published