Socket
Socket
Sign inDemoInstall

flatulence

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatulence

Flatten objects and arrays so that each key is the full path to a primitive value. Paths are lodash-compatible. Inflate flattened objects and make them regular JS objects again.


Version published
Weekly downloads
90
decreased by-48.86%
Maintainers
1
Weekly downloads
 
Created
Source

flatulence

Flatten objects and arrays so that each key is the full path to a primitive value. Paths are lodash-compatible. Unflatten flattened objects and make them regular JS objects again.

const flatulence = require('flatulence')

// Create a flat object
const flattened =  flatulence.flatten({
  a: 1,
  b: {
    c: 1,
    d: [1,2,3]
  }
})
// { a: 1, 'b.c': 1, 'b.d[0]': 1, 'b.d[1]': 2, 'b.d[2]': 3 }

// Create a flat object and provide a prefix to each key
var flattened2 = flatulence.flatten(
    { a: 1, b: { c: 1, d: [ 1, 2, 3 ] } }, 
    'my.prefix.key'
)

//{ 'my.prefix.key.a': 1,
//  'my.prefix.key.b.c': 1,
//  'my.prefix.key.b.d[0]': 1,
//  'my.prefix.key.b.d[1]': 2,
//  'my.prefix.key.b.d[2]': 3 }




const regular = flatulence.unflatten(flattened)
// { a: 1, b: { c: 1, d: [ 1, 2, 3 ] } }


// Only unflatten a sub object
const b = flatulence.unflatten(flattened, 'b')
// { c: 1, d: [ 1, 2, 3 ] }

// Sub objects can even be arrays
const array = flatulence.unflatten(flattened, 'b.d')
// [ 1, 2, 3 ]

Keywords

FAQs

Package last updated on 08 Nov 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc