Skip to content

Object tree normalizer (transform structure of the tree)

License

Notifications You must be signed in to change notification settings

barrypeng6/tree-normalizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-normalizer

Object tree normalizer (transform structure of the tree)

Install

$ npm install tree-normalizer

Test

$ npm run test

Usage

Tree-normalizer can transform the structure of two objects, for the following example:

user {                            user { 
  index: value,                     create: value,
  create: value,     <=====>        update: value,
  update: value,                    delete: value
  delete: value                   },
}                                 index: value
import normalizer from 'tree-normalizer';

const output = normalizer(input, schema);

Example

import normalizer from 'tree-normalizer';

// schema example
const schema = {
  user: {
    create: null,
    update: null,
    delete: null
  },
  index: null
}

// input example
const input = {
  user: {
    index: true,
    create: true,
    update: true,
    delete: true
  }
};

console.log(JSON.stringify(
  normalizer(input, schema), null, 2
));

/* output
{
  "user": {
    "create": true,
    "update": true,
    "delete": true
  },
  "index": true
}
*/

About

Object tree normalizer (transform structure of the tree)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published