0.1.2 • Published 7 years ago

js-api-smith v0.1.2

Weekly downloads
40
License
MIT
Repository
github
Last release
7 years ago

API Smith in JavaScript

A lightweight library for object transformations in JavaScript. Inspired by the API Smith Ruby library.

Synopsis

const apiSmith = require('js-api-smith');

// apiSmith.smash transforms object
const transformation = {
    foo: 'foo',
    baz: {
      from: ['bar', 'quxx'],
      transform: x => x + 1
    }
};
const from = {
    foo: 123,
    bar: {
      quxx: 99
    }
};
apiSmith.smash(transformation, from)
=> { foo: 123, baz: 100 }

// apiSmith.unset and apiSmith.unsetEmptyProperties unsets properties in object by mutation
let before = {
    foo: null,
    bar: {},
    quxx: {
        deep: undefined,
        more: {
            deeper: []
        }
    },
    another: {}
};
apiSmith.unset(before);
=> { }

// apiSmith.delegate defines delegation methods on target objects
const provider = {
    num: 123,
    getNum: function() { return this.num; }
};
let consumer = {};
delegate(provider, 'getNum', consumer);
consumer.getNum();
=> 123

Install

$ npm install js-api-smith

See also

0.1.2

7 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.1-c

8 years ago

0.0.1-b

8 years ago

0.0.1-a

8 years ago

0.0.1

8 years ago