0.1.5 • Published 8 years ago

object-iron v0.1.5

Weekly downloads
8
License
MIT
Repository
github
Last release
8 years ago

object-iron

Flattens deeply nested object into a single level object with optional filtering.

var flatten = require('object-iron');
var nestedObject = {
  name : {
    legal : "Sam Fisher",
    given : {
      first : "Samantha",
      last : "Fisherson"
    }
  },
  info : {
    needless : {
      nesting : {
        check : {
          it: "out"
        }
      }
    },
    tags : [
      "person",
      "tagged",
      { "objects" : "work here too" }
    ]
  }
};

var flatObject = flatten(nestedObject);
console.log(flatObject);

// { 'name.legal': 'Sam Fisher',
//   'name.given.first': 'Samantha',
//   'name.given.last': 'Fisherson',
//   'info.needless.nesting.check.it': 'out',
//   'info.tags[0]': 'person',
//   'info.tags[1]': 'tagged',
//   'info.tags[2].objects': 'work here too' }

Filtering

This library also accepts an optional array of types to filter on. Accepts all types from typeof, as well as "array" Check the MDN documentation for the full list.

Be careful with array filtering, as this could remove more than just array values (arrays of nested objects, for example).

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago