Comparing version 1.0.0 to 1.1.0
@@ -58,3 +58,3 @@ var flat = module.exports = {} | ||
if (recipient[firstNibble] === undefined) { | ||
recipient[firstNibble] = ((typeof secondNibble === 'number') ? [] : {}) | ||
recipient[firstNibble] = ((typeof secondNibble === 'number') && !opts.object ? [] : {}) | ||
} | ||
@@ -61,0 +61,0 @@ |
{ | ||
"name": "flat", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -39,3 +39,3 @@ # flat [![Build Status](https://secure.travis-ci.org/hughsk/flat.png?branch=master)](http://travis-ci.org/hughsk/flat) | ||
### flat.flatten(original, options) | ||
### flat.unflatten(original, options) | ||
@@ -97,2 +97,23 @@ Flattening is reversible too, you can call `flat.unflatten()` on an object: | ||
// } | ||
``` | ||
``` | ||
### object | ||
When enabled, arrays will not be created automatically when using calling | ||
unflatten, like so: | ||
``` javascript | ||
unflatten({ | ||
'hello.you.0': 'ipsum', | ||
'hello.you.1': 'lorem', | ||
'hello.other.world': 'foo' | ||
}, { object: true }) | ||
// hello: { | ||
// you: { | ||
// 0: 'ipsum', | ||
// 1: 'lorem', | ||
// }, | ||
// other: { world: 'foo' } | ||
// } | ||
``` |
@@ -234,2 +234,39 @@ var assert = require('assert') | ||
}) | ||
suite('.object', function() { | ||
test('Should create object instead of array when true', function() { | ||
assert.deepEqual({ | ||
hello: { | ||
you: { | ||
0: 'ipsum', | ||
1: 'lorem', | ||
}, | ||
other: { world: 'foo' } | ||
} | ||
}, unflatten( | ||
{ | ||
'hello.you.0': 'ipsum', | ||
'hello.you.1': 'lorem', | ||
'hello.other.world': 'foo' | ||
}, { | ||
object: true | ||
})); | ||
}) | ||
test('Should not create object when false', function() { | ||
assert.deepEqual({ | ||
hello: { | ||
you: ['ipsum', 'lorem'], | ||
other: { world: 'foo' } | ||
} | ||
}, unflatten( | ||
{ | ||
'hello.you.0': 'ipsum', | ||
'hello.you.1': 'lorem', | ||
'hello.other.world': 'foo' | ||
}, { | ||
object: false | ||
})); | ||
}) | ||
}) | ||
}); | ||
@@ -236,0 +273,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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
13394
334
118
0