falcon-punch
v0.0.6
Published
Flatten your objects and arrays by a delimiter
Downloads
48
Maintainers
Readme
falcon-punch
Flatten your objects and arrays by a delimiter
Install
$ npm install --save falcon-punch
Not using Node or a module bundler? Use a UMD build via the <script>
tag.
- https://unpkg.com/falcon-punch/dist/falcon-punch.js
- https://unpkg.com/falcon-punch/dist/falcon-punch.min.js
Usage
import falconPunch from 'falcon-punch'
const o = {
a: 1,
b: {
c: 'falcon',
d: {
e: 'punch'
}
}
}
// { a: 1, 'b_c': 'falcon', 'b_d_e': 'punch' }
falconPunch(o)
// Specify opts: delimiter & maxDepth
// { a: 1, 'b???c': 'falcon', 'b???d': { e: 'punch' } }
falconPunch(o, { delimiter: '???', maxDepth: 1 })
// go crazy
const arr = [
{
a: [
[
{
b: 0,
c: 1
},
10
],
{
d: {
e: null,
f: [],
g: {},
h: undefined
}
}
]
},
[[1, [{}]]]
]
/*
{
'0.a.0.0.b': 0,
'0.a.0.0.c': 1,
'0.a.0.1': 10,
'0.a.1.d.e': null,
'0.a.1.d.f': [],
'0.a.1.d.g': {},
'0.a.1.d.h': undefined,
'1.0.0': 1,
'1.0.1.0': {}
}
*/
falconPunch(arr, { delimiter: '.' })