Comparing version 1.5.1 to 1.6.0
@@ -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 @@ } |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
16722
0
486
162