Socket
Socket
Sign inDemoInstall

flat

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flat - npm Package Compare versions

Comparing version 1.5.1 to 1.6.0

9

index.js

@@ -9,2 +9,4 @@ var flat = module.exports = flatten

var delimiter = opts.delimiter || '.'
var maxDepth = opts.maxDepth
var currentDepth = 1
var output = {}

@@ -27,3 +29,8 @@

if (!isarray && !isbuffer && isobject && Object.keys(value).length) {
if (!opts.maxDepth) {
maxDepth = currentDepth + 1;
}
if (!isarray && !isbuffer && isobject && Object.keys(value).length && currentDepth < maxDepth) {
++currentDepth
return step(value, newKey)

@@ -30,0 +37,0 @@ }

4

package.json
{
"name": "flat",
"version": "1.5.1",
"version": "1.6.0",
"main": "index.js",

@@ -8,3 +8,3 @@ "scripts": {

},
"license": "BSD",
"license": "BSD-3-Clause",
"description": "Take a nested Javascript object and flatten it, or unflatten an object with delimited keys",

@@ -11,0 +11,0 @@ "devDependencies": {

@@ -138,1 +138,25 @@ # flat [![Build Status](https://secure.travis-ci.org/hughsk/flat.png?branch=master)](http://travis-ci.org/hughsk/flat)

### maxDepth
Maximum number of nested objects to flatten.
``` javascript
var flatten = require('flat')
flatten({
key1: {
keyA: 'valueI'
},
key2: {
keyB: 'valueII'
},
key3: { a: { b: { c: 2 } } }
}, { maxDepth: 2 })
// {
// 'key1.keyA': 'valueI',
// 'key2.keyB': 'valueII',
// 'key3.a': { b: { c: 2 } }
// }
```

@@ -141,2 +141,18 @@ var assert = require('assert')

})
test('Custom Depth', function() {
assert.deepEqual(flatten({
hello: {
world: {
again: 'good morning'
}
}
}, {
maxDepth: 2
}), {
'hello.world': {
again: 'good morning'
}
})
})
})

@@ -143,0 +159,0 @@

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