collapse-lib

1.0.4 • Public • Published

collapseLib

Library to collapse an multi-level object into one level object, using dot notation

Note

This script isn't mine. I just took it from this gist made by alabid

Example use:

var object = {
   "obj1key": {
   	"obj2key": [
   		{
   			"obj3key": {
   				"tell":"me"
   			}
   		}
   	]
   },
   "obj4key": {
   	"obj5key": {
   		"obj6key": "hi!",
   		"obj7key": "how are you?"
   	}
   }
};

var objectCollapsed = CollapseLib.collapseObj(object);

Results in:

{
	"obj1key.obj2key.[0].obj3key.tell": "me",
	"obj4key.obj5key.obj6key": "hi!",
	"obj4key.obj5key.obj7key": "how are you?"
}

TODO: Fix bug with empty plain object

Package Sidebar

Install

npm i collapse-lib

Weekly Downloads

0

Version

1.0.4

License

none

Last publish

Collaborators

  • lucho_1312