Skip to content

Flatten nested javascript objects into a single-depth object.

License

Notifications You must be signed in to change notification settings

rocktimsaikia/flatify-obj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flatify-obj build

Flatten nested javascript objects into a single-depth object.

Install

$ npm install flatify-obj

Usage

   const flatifyObject = require('flatify-obj');

   flatifyObject({foo: {bar: {unicorn: 'πŸ¦„'}}})
   //=> { 'foo.bar.unicorn': 'πŸ¦„' }

   flatifyObject({foo: {unicorn: 'πŸ¦„'}, bar: 'unicorn'}, {onlyLeaves: true});
   //=> {unicorn: 'πŸ¦„', bar: 'unicorn'}

API

flatifyObject(object, options?)

object

Type: object
Object to flatten

options

onlyLeaves

Type: boolean
Default: false

Removes the parent property and only returns the leaf nodes of the object

License

MIT Β© Rocktim Saikia