pantoninho / expressive-objects

create objects with long property chains

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Test Coverage Code Climate Issue Count dependencies Status devDependencies Status

expressive-objects

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

About

create objects with long property chains


Languages

Language:JavaScript 100.0%