0.1.0 • Published 7 years ago

jf-flatten v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

jf-flatten stable

npm install jf-flatten

Recursively looks for other objects and places their keys in the root object discarding any non-scalar or undefined values.

If an array exists with the same key elements are not replaced, they are added at the end if second parameter is different of false.

Examples

const assert    = require('assert');
const jfFlatten = require('./index');
assert.deepStrictEqual(
    jfFlatten(
        {
            a : [1,2],
            b : {
                c : 2,
                d : {
                    a : [4,5],
                    b : false,
                    c : 3,
                    f : () => {},
                    n : null,
                    s : 'string'
                },
                u : undefined
            }
        }
    ),
    {
        a : [1,2,4,5],
        b : false,
        c : 3,
        n : null,
        s : 'string'
    }
);
// No concat arrays.
assert.deepStrictEqual(
    jfFlatten(
        {
            a : [1,2],
            b : {
                d : {
                    a : [4,5]
                }
            }
        },
        false
    ),
    {
        a : [4,5]
    }
);