Socket
Book a DemoInstallSign in
Socket

flat-obj

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat-obj

Flatten a nested Object with customizable glue

Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
119
2.59%
Maintainers
1
Weekly downloads
 
Created
Source

flat-obj Build Status

Flatten a nested Object with customizable glue

Install

$ npm install --save flat-obj

Usage

const flatObj = require('flat-obj');

flatObj({
  a: 'hi',
  b: {
    a: null,
    b: '',
    d: 'hello',
    e: {
      a: 'yo',
      b: undefined,
      c: 'sup',
      d: 0
    }
  },
  c: 'world'
});
//=> { a:'hi', b_b:'', b_d:'hello', b_e_a:'yo', b_e_c:'sup', b_e_d:0, c:'world' }

Note: null and undefined values are purged.

API

flatObj(obj, [glue])

obj

Type: Object

The object to flatten.

glue

Type: String
Default: _

A string used to join parent key names to nested child key names.

{
  foo: {
    bar: 123
  }
} //=> { foo_bar:123 }

Benchmarks

flat-obj (current)
  --> 540,089 ops/sec ±0.65% (83 runs sampled)
flat-obj (1.0.0)
  --> 511,842 ops/sec ±0.62% (91 runs sampled)
flat
  --> 140,012 ops/sec ±0.59% (96 runs sampled)
flatten-object
  --> 154,127 ops/sec ±0.78% (93 runs sampled)

License

MIT © Luke Edwards

Keywords

flatten

FAQs

Package last updated on 24 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts