DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on • Updated on

✨ Flatify-obj: Flatten nested objects into a single-depth object.

✨ Flatify-obj is a simple module that flattens nested javascript objects into a single-depth object.

GitHub logo rocktimsaikia / flatify-obj

Flatten nested javascript objects into a single-depth object.


This module can come in pretty handy in situations where you are dealing with deeply nested objects.

Installation

npm install flatify-obj
Enter fullscreen mode Exit fullscreen mode

Usage

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

flattenObject({foo: {bar: {unicorn: '🦄'}}})
//=> { 'foo.bar.unicorn': '🦄' }

flattenObject({foo: {unicorn: '🦄'}, bar: 'unicorn'}, {onlyLeaves: true});
//=> {unicorn: '🦄', bar: 'unicorn'}

Enter fullscreen mode Exit fullscreen mode





[ PS: I created this tool to use it in a project that I am working on. I thought someone might find it handy so made a quick post. Leave a star at the repo 🌟 if find this helpful. Thanks for reading 🦄 👋]

Top comments (0)