1.0.2 • Published 3 years ago

dottify v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

dottify - The easiest way to flat a object

How to use it ?

// Import it
const dottify = require('dottify')

// Example Object
let object = {

    a : 1,
    b : 'Hello',
    c : true,
    d : [0,1,2,false,'Dottify'],
    e : {
        a: {
            b : {
                c : 'This is an inner value',
                d : () => console.log(0)
            }
        }
    },
    f : undefined,
    g : null

}

// Flat & save it
// The second parameter is optional... the default separator is the dot.
let flatted = dottify(object,'.')

//Print the result 
console.log(flatted)


/* 

The Output

{
    a: 1,
    b: 'Hello',
    c: true,
    'd.0': 0,
    'd.1': 1,
    'd.2': 2,
    'd.3': false,
    'd.4': 'Dottify',
    'e.a.b.c': 'This is an inner value',
    'e.a.b.d': [Function: d],
    f: undefined,
    g: null
  }

  */