Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-to-table

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-to-table - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

17

index.js

@@ -17,2 +17,3 @@ var traverse = require('traverse'),

function(headers, value) {
var self = this;
if (this.notRoot && _.isArray(value)) {

@@ -27,8 +28,11 @@ if (options.includeCollectionLength) {

if (this.isLeaf) {
this.path = _.map(this.path, function(level) {
if (level.indexOf('.') > -1 && self.level > 2) { // If a leaf contains a dot in it, then surround the whole path with ticks
level = '`' + level + '`';
}
return level;
});
if (!(_.isPlainObject(value) && _.keys(value).length === 0)) { // Check against empty objects. Don't treat these paths as a valid header value.
headers[_.rest(this.path).join('.')] = true;
}
// Make sure that we don't include empty objects as valid headers
// There are good reasons behind this that deal with projections, and non-homogenous objects in a collection.
}

@@ -46,2 +50,9 @@ return headers;

}
if (header.indexOf('`') > -1) { // One of those special cases where a path is nested, AND has a dot in the name.
var parts = header.split('.`'),
head = parts[0].replace(/\`/g, ''),
tail = parts[1].replace(/\`/g, '');
return dottie.get(doc, head, {})[tail];
}
return dottie.get(doc, header, options.defaultVal);

@@ -48,0 +59,0 @@ })

2

package.json
{
"name": "json-to-table",
"version": "2.0.0",
"version": "2.1.0",
"description": "Convert an array of Objects into a table format",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -302,2 +302,26 @@ var assert = require('chai').assert,

});
it('Should be able to resolve the path or key even with multiple dots in the name.', function() {
var jsonData = [
{
firstName: 'Scott',
contact: {
'phone.number': '801-999-8626'
}
},
{
firstName: 'Burt',
contact: {
'home.address': 'The Pentagon'
}
}
];
var tableData = jsonToTable(jsonData, { defaultVal: undefined, checkKeyBeforePath: true }),
expectedTableData = [ [ 'firstName', 'contact.`phone.number`', 'contact.`home.address`' ],
[ 'Scott', '801-999-8626', undefined ],
[ 'Burt', undefined, 'The Pentagon' ] ];
assert(_.isEqual(tableData, expectedTableData));
});
});
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