js-api-smith

0.1.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i js-api-smith

Weekly Downloads

44

Version

0.1.2

License

MIT

Unpacked Size

17.6 kB

Total Files

10

Last publish

Collaborators

  • luislee818