json-to-table
Advanced tools
Comparing version 2.1.3 to 2.1.4
76
index.js
@@ -15,46 +15,46 @@ var traverse = require('traverse'); | ||
var headers = _.keys(traverse(docs).reduce( | ||
function(headers, value) { | ||
var self = this; | ||
if (this.notRoot && _.isArray(value)) { | ||
if (options.includeCollectionLength) { | ||
headers[_.rest(this.path).join('.') + '.length'] = true; | ||
} | ||
if (options.excludeSubArrays) { | ||
this.update(value, true); | ||
} | ||
} | ||
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; | ||
} | ||
} | ||
return headers; | ||
}, {}) | ||
); | ||
function (headers, value) { | ||
var self = this; | ||
if (this.notRoot && _.isArray(value)) { | ||
if (options.includeCollectionLength) { | ||
headers[_.tail(this.path).join('.') + '.length'] = true; | ||
} | ||
if (options.excludeSubArrays) { | ||
this.update(value, true); | ||
} | ||
} | ||
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[_.tail(this.path).join('.')] = true; | ||
} | ||
} | ||
return headers; | ||
}, {}) | ||
); | ||
// Go through each object again, this time, attempt to grab the value | ||
// At each possible path. | ||
var data = [headers]; | ||
data = data.concat(_.map(docs, function(doc) { | ||
return _.map(headers, function(header) { | ||
if (options.checkKeyBeforePath && doc[header]) { | ||
return doc[header]; | ||
} | ||
if (header.indexOf('`') > -1 && 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, ''); | ||
data = data.concat(_.map(docs, function (doc) { | ||
return _.map(headers, function (header) { | ||
if (options.checkKeyBeforePath && doc[header]) { | ||
return doc[header]; | ||
} | ||
if (header.indexOf('`') > -1 && header.indexOf('.') > -1) { // One of those special cases where a path is nested, AND has a dot in the name. | ||
var parts = header.split('.`'); | ||
var head = parts[0].replace(/\`/g, ''); | ||
var tail = parts[1].replace(/\`/g, ''); | ||
return _.get(doc, head, {})[tail]; | ||
} | ||
return _.get(doc, header, options.defaultVal); | ||
}); | ||
})); | ||
return _.get(doc, head, {})[tail]; | ||
} | ||
return _.get(doc, header, options.defaultVal); | ||
}); | ||
})); | ||
return data; | ||
}; |
{ | ||
"name": "json-to-table", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"description": "Convert an array of Objects into a table format", | ||
@@ -29,9 +29,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^3.10.1", | ||
"lodash": "^4.5.1", | ||
"traverse": "^0.6.6" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.10.0", | ||
"chai": "^3.5.0", | ||
"mocha": "^2.1.0" | ||
} | ||
} |
@@ -8,3 +8,3 @@ json-to-table converts an array of Javascript objects into a table format. | ||
``` | ||
npm install node-to-table | ||
npm install json-to-table | ||
``` | ||
@@ -11,0 +11,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
17728
+ Addedlodash@4.17.21(transitive)
- Removedlodash@3.10.1(transitive)
Updatedlodash@^4.5.1