Flat-Plain-Object
A very simple utility for the purpose of flatting a plain object which is constituted by nested object(s).
Install
In node environment, install it with npm:
npm install -s flat-plain-object
or with yarn:
yarn add flat-plain-object
Usage
Import it as a function accepting two parameters.
// es6 style/* or CommonJS styleconst FlatPlainObj = require('flat-plain-object')*/
FlatPlainObj(objOrigin, options)
objOrigin
Your origin plain object needs to be flatted.
options
A parameter object accepting 2 properties: delimiter and flatArrayFlag
- delimiter, the delimiter for a flatted key path, the default is '.'
- flatArrayFlag, the bool variable to control whether to flat array, the default value is false
Sample
let objOrigin = a: 12 b: 'hello world!' c: c1: 34 c2: '!dlrow olleh' d: d1: d11: d111: 56 d12: 'he' let objFlatted = /*objFlatted represented as{ a: 12, b: 'hello world!', 'c.c1': 34, 'c.c2': '!dlrow olleh', 'd.d1.d11.d111': 56, 'd.d1.d12': 'he'}*/ objOrigin = a: 12 b: 'hello world!' c: 1 2 3objFlatted = /*objFlatted represented as{ a: 12, b, 'hello world!', c: [1, 2, 3],}*/ objFlatted = /*objFlatted represented as{ a: 12, b, 'hello world!', 'c.0': 1, 'c.1': 2, 'c.2': 3,}*/