Skip to content

Filter out objects using a predefined template object.

License

Notifications You must be signed in to change notification settings

martinhartt/match-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#match-template

A function which filters out an object according to set template object.

##Installation

npm install match-template

##Usage

var matchTemplate = require('match-template');

var template = {
    id: true,
    name: true,
    location: {
        town: true,
    }
};

var object = {
    id: 5,
    name: 'Tom',
    surname: 'Smith',
    isMember: false,
    location: {
        town: 'Manchester, UK',
        address: '32 Baker Street',
        postcode: 'M25 HA2',
    },
};

var filteredObject = matchTemplate(object, template);

console.log(filteredObject);
/**
{
    id: 5,
    name: 'Tom',
    location: {
        town: 'Manchester, UK',
    },
}
*/

##Todo

  • Add unit testing
  • Make more clear documentation
  • Comment the code

About

Filter out objects using a predefined template object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published