Library for reshaping Javascript objects
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
.jshintrc
README.md
index.js
package.json

README.md

reshape

Library for reshaping Javascript objects. Like copying but with directives. Notation inspired by Angular.

// With reshape you can make this..
{
    name: {
        first: 'John',
        last: 'Doe'
    },
    email: {
        home: 'john@home',
        work: 'john@work'
    },
    address: 'Road 1' // Not needed
}
// ..to this..
{
    name: 'John',
    email: 'john@home'
}

to thi

Directive examples

reshape({
    name: '@name'
});

// This is same
reshape({
    name: '@'
});

// And also this
reshape(['name']);

// Nesting
reshape({
    name: {
        first: '@firstname',
        last: '@lastname'
    }
});

// Flattening
reshape({
    firstname: '@name.first',
    lastname: '@name.last'
});

// Custom function
reshape({
    fullname: function (user) {
        return user.firstname + ' ' + user.lastname;
    }
});

Usage

var reshapeUser = reshape(directive);
var reshaped = reshapeUser(user);