1.0.2 • Published 1 year ago

@michpl/flatten-object v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Flattens object to a single level deep.

example workflow

Simple function to flattens object to a single level deep object without dependencies. Can be useful for getting a request to MongoDB from an object.

Install

npm i -S @michpl/flatten-object

Example

flattenObject({
  test: 1,
  deep: {
    level1: [{item1: 1}, {item1: 2}],
    deep: {
      level2: 2
    }
  }
})
/* returns {
  test: 1,
  'deep.level1.0.item1': 1,
  'deep.level1.1.item1': 2,
  'deep.deep.level2': 2
} */

Options

nametypedefaultdescription
flattenArraybooleantrueSet flatten array or not
delimiterstring'.'Delimiter for object keys
1.0.2

1 year ago

1.0.1

3 years ago

1.0.0

3 years ago