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.4.0 to 1.5.0

9

index.js

@@ -42,2 +42,3 @@ var flat = module.exports = flatten

var delimiter = opts.delimiter || '.'
var overwrite = opts.overwrite || false
var result = {}

@@ -68,3 +69,9 @@

while (key2 !== undefined) {
if (recipient[key1] === undefined) {
var type = Object.prototype.toString.call(recipient[key1])
var isobject = (
type === "[object Object]" ||
type === "[object Array]"
)
if ((overwrite && !isobject) || (!overwrite && recipient[key1] === undefined)) {
recipient[key1] = (

@@ -71,0 +78,0 @@ typeof key2 === 'number' &&

2

package.json
{
"name": "flat",
"version": "1.4.0",
"version": "1.5.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

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

```
### overwrite
When enabled, existing keys in the unflattened object may be overwritten if they cannot hold a newly encountered nested value:
```javascript
unflatten({
'TRAVIS': 'true',
'TRAVIS_DIR': '/home/travis/build/kvz/environmental'
}, { overwrite: true })
// TRAVIS: {
// DIR: '/home/travis/build/kvz/environmental'
// }
```
Without `overwrite` set to `true`, the `TRAVIS` key would already have been set to a string, thus could not accept the nested `DIR` element.
This only makes sense on ordered arrays, and since we're overwriting data, should be used with care.

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

test('Overwrite', function() {
assert.deepEqual({
travis: {
build: {
dir: "/home/travis/build/kvz/environmental"
}
}
}, unflatten({
travis: "true",
travis_build_dir: "/home/travis/build/kvz/environmental"
}, {
delimiter: '_',
overwrite: true,
}))
})
test('Messy', function() {

@@ -180,0 +196,0 @@ assert.deepEqual({

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