jf-flatten

0.1.0 • Public • Published

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]
    }
);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    2

Package Sidebar

Install

npm i jf-flatten

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • joaquinfq