Socket
Socket
Sign inDemoInstall

flat

Package Overview
Dependencies
Maintainers
1
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.0.0 to 1.1.0

2

index.js

@@ -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 @@

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