Build expressive APIs with chained properties.
If you ever wanted to build something with an API like chai, you might be looking for this.
This does not create 'connectors' that keep returning the same object, instead this builds a real object with property chains (paths) defined by yourself.
const expressive = require('expressive-objects');
const api = [{
path: 'increment.two.by',
value: function(number) {
return 2 + number;
}
}, {
path: 'increment.two',
value: function() {
return 3;
}
}, {
path: 'this is a potato',
value: 'potato'
}, {
path: ['this', 'also', 'works'],
value: true
}];
const obj = expressive(api);
console.log(obj.increment.two.by(3)); // 5;
console.log(obj.increment.two()); // 3;
console.log(obj.this.is.a.potato); // 'potato';
console.log(obj.this.also.works); // true