object-flat
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

object-flat

npm GitHub tylim88 dependencies

🐤 flat nested object and return with accurate typing.

🥰 0 dependency.

⛲️ Out of box typescript support.

🦺 Tested.

Installation

npm i object-flat

🎵 Usage

flatten nested object into flat object, you can define what character to join the nested key path.

NOTE: does not flatten array and what inside the array.

import flatten from 'object-flat'

const flattenObj = flatten(
	{ a: 1, b: { c: 3, d: { e: 4 } }, f: { g: { h: 'a', j: [{ a: 1 }] } } }, // target
	'.' // character to join the key path.
)
// return { a: 1, 'b.c': 3, 'b.d.e': 4, 'f.g.h': 'a', 'f.g.j': [{ a: 1 }]},
// type is { a: number, 'b.c': number, 'b.d.e': number, 'f.g.h': string, 'f.g.j': { a: number }[]]}

NOTE: Flatten ONLY object literal, does NOT flatten below data type

123 // number
null
undefined
'abc' // string
false
true
[]
new Number()
new Boolean()
() => {}
function () {}

Package Sidebar

Install

npm i object-flat

Weekly Downloads

8

Version

1.1.1

License

MIT

Unpacked Size

8.88 kB

Total Files

8

Last publish

Collaborators

  • tylim