Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flattn

Travis

There are lots of flattening libraries out there, but I decided to write my own because I wanted to write my own :)

Mainly, I wanted to write it in the latest ES6 that nodejs 6.x gives us, with beautiful things like default params!

If you use this in a frontend project, make sure it gets transpiled!

Getting started

npm install flattn

Then, in your JS file:

const flattn = require('flattn');

const myCrazyDeepObject = {
  nested: {
    stuff: 'here'
  }
};

flattn(myCrazyDeepObject); // outputs a beautifully flat object

Options

flattn(object, {}) takes a couple optional params:

  • crush (array) - this will remove a nesting namespace from the final product (ie. if you crush [ 'metadata' ], then { metadata: { hello: 'world' }} will return { hello: 'world' })
  • stringifyNull (boolean) - this will turn nulls into ''
  • separator (string) - by default, this lib uses an underscore. But, if you want something else...
  • pruneFunctions (boolean) - if the value of a key is a function, then you can opt to not have those in the result

About

Flattens javascript objects nicely, in an entirely type-aware way.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages