Comparing version 1.6.1 to 2.0.0
@@ -85,3 +85,8 @@ var isBuffer = require('is-buffer') | ||
if ((overwrite && !isobject) || (!overwrite && recipient[key1] === undefined)) { | ||
// do not write over falsey, non-undefined values if overwrite is false | ||
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') { | ||
return | ||
} | ||
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) { | ||
recipient[key1] = ( | ||
@@ -88,0 +93,0 @@ typeof key2 === 'number' && |
{ | ||
"name": "flat", | ||
"version": "1.6.1", | ||
"version": "2.0.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -266,2 +266,23 @@ var assert = require('assert') | ||
suite('Overwrite + non-object values in key positions', function() { | ||
test('non-object keys + overwrite should be overwritten', function() { | ||
assert.deepEqual(flat.unflatten({ a: null, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } }) | ||
assert.deepEqual(flat.unflatten({ a: 0, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } }) | ||
assert.deepEqual(flat.unflatten({ a: 1, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } }) | ||
assert.deepEqual(flat.unflatten({ a: '', 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } }) | ||
}) | ||
test('overwrite value should not affect undefined keys', function() { | ||
assert.deepEqual(flat.unflatten({ a: undefined, 'a.b': 'c' }, {overwrite: true}), { a: { b: 'c' } }) | ||
assert.deepEqual(flat.unflatten({ a: undefined, 'a.b': 'c' }, {overwrite: false}), { a: { b: 'c' } }) | ||
}) | ||
test('if no overwrite, should ignore nested values under non-object key', function() { | ||
assert.deepEqual(flat.unflatten({ a: null, 'a.b': 'c' }), { a: null }) | ||
assert.deepEqual(flat.unflatten({ a: 0, 'a.b': 'c' }), { a: 0 }) | ||
assert.deepEqual(flat.unflatten({ a: 1, 'a.b': 'c' }), { a: 1 }) | ||
assert.deepEqual(flat.unflatten({ a: '', 'a.b': 'c' }), { a: '' }) | ||
}) | ||
}) | ||
suite('.safe', function() { | ||
@@ -268,0 +289,0 @@ test('Should protect arrays when true', function() { |
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
18092
505