Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

obj-flat

edwincen27MIT1.2.4

Flatten object to simple key/value object with customized separator

flat, flatten, flat-object, flatten-object, flatten, flattenDeep

readme

flatten-object

JavaScript Style Guide Greenkeeper badge Build Status

Flatten object to simple key/value object with customized separator

Install

npm install --save obj-flat

Usage

flattenObject(object, [options={}])

Arguments

  • object(Object) - The object to process.
  • [options={}](object) - The option object.
  • [options.sort=false](boolean) - Return key-sorted object or not, default is false

Returns

(Object) - Returns new flattened object.

Sample

Flatten normal object

const flattenObject = require('lodash-flatten-object')()
const data = {
  z: 1,
  x: 2,
  a: 3,
  b: 4
}
const output = flattenObject(data, { sort: true })
// {
//   a: 3,
//   b: 4,
//   x: 2,
//   z: 1
// }

Flatten object with multiple levels nested properties

const flattenObject = require('lodash-flatten-object')()
const data = {
  a: 1,
  b: {
    b2: 4,
    b1: {
      b12: 3,
      b11: 2
    },
    b3: [
      {
        b32: 6,
        b31: 5
      },
      {
        b34: 8,
        b33: 7,
        b35: {
          b352: 10,
          b351: 9
        }
      }
    ]
  },
  c: [ 11, 12, 13 ]
}
const output = flattenObject(data, { sorted: true })
// {
//   'a': 1
//   'b.b1.b11': 2
//   'b.b1.b12': 3
//   'b.b2': 4
//   'b.b3.0.b31': 5
//   'b.b3.0.b32': 6
//   'b.b3.1.b33': 7
//   'b.b3.1.b34': 8
//   'b.b3.1.b35.b351': 9
//   'b.b3.1.b35.b352': 10
//   'c.0': 11
//   'c.1': 12
//   'c.2': 13
// }

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.2.4 (2019-05-13)

Bug Fixes

  • $main: Add support for buffer type value in object (22a35cf)

1.2.3 (2019-05-13)

1.2.2 (2019-05-13)

1.2.1 (2019-05-13)

Build System

  • $npm: Change package name to obj-flat (a3f2d90)

1.2.0 (2019-05-13)

Features

  • $index: 1. Remove lodash dependencies; 2. Add customizable separator (6da3766)

1.1.0 (2019-05-13)

Build System

  • $npm: Add standar release script (7ffe9b2)

Features