DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on • Edited on

3 1

✨ 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)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay