Skip to content

lanttu/reshape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Library for reshaping Javascript objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published