Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Library for reshaping Javascript objects
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

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);

Something went wrong with that request. Please try again.