0.3.5 • Published 11 years ago
deus v0.3.5
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/deuswith nodejs:
$ npm install deusUsage
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: bredeledeus doesn't care if an argument is missing:
init({ github : 'bredele'});
// => name: undefined
// => data: bredeledeus allows you to switch the arguments order:
init({ github : 'bredele'}, 'olivier');
// => name: olivier
// => data: bredeledeus preseves the other arguments:
var other = deus('function', 'object', function(name, data, other) {
console.log('other:', other);
});
other({
github: 'bredele'
}, 'olivier');
// => olivierDeus 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.