Socket
Socket
Sign inDemoInstall

json-2-csv

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-2-csv - npm Package Compare versions

Comparing version 3.7.13 to 3.8.0

18

lib/json2csv.js

@@ -132,3 +132,8 @@ 'use strict';

function generateCsvHeader(params) {
params.header = params.headerFields.join(options.delimiter.field);
params.header = params.headerFields
.map(function(field) {
const headerKey = options.fieldTitleMap[field] ? options.fieldTitleMap[field] : field;
return wrapFieldValueIfNecessary(headerKey);
})
.join(options.delimiter.field);
return params;

@@ -144,2 +149,12 @@ }

function retrieveHeaderFields(data) {
if (options.keys) {
options.keys = options.keys.map((key) => {
if (utils.isObject(key) && key.field) {
options.fieldTitleMap[key.field] = key.title || key.field;
return key.field;
}
return key;
});
}
if (options.keys && !options.unwindArrays) {

@@ -162,2 +177,3 @@ return Promise.resolve(options.keys)

* @param params {Object}
* @param finalPass {boolean} Used to trigger one last pass to ensure no more arrays need to be expanded
* @returns {Promise}

@@ -164,0 +180,0 @@ */

@@ -41,2 +41,3 @@ 'use strict';

opts = {...constants.defaultOptions, ...opts || {}};
opts.fieldTitleMap = new Map();

@@ -43,0 +44,0 @@ // Copy the delimiter fields over since the spread operator does a shallow copy

2

package.json

@@ -8,3 +8,3 @@ {

"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
"version": "3.7.13",
"version": "3.8.0",
"homepage": "https://mrodrig.github.io/json-2-csv",

@@ -11,0 +11,0 @@ "repository": {

@@ -85,6 +85,8 @@ # json-2-csv

* Note: This may result in CSV output that does not map back exactly to the original JSON. See #102 for more information.
* `keys` - Array - Specify the keys (as strings) that should be converted.
* Default: `null`
* If you have a nested object (ie. {info : {name: 'Mike'}}), then set this to ['info.name']
* If you want all keys to be converted, then specify ```null``` or don't specify the option to utilize the default.
* `keys` - Array - Specify the keys (as strings) that should be converted.
* Default: These will be auto-detected from your data by default.
* Keys can either be specified as a String representing the key path that should be converted, or as an Object with the `key` property specifying the path. When specifying keys as an Object, you can also optionally specify a `title` which will be used for that column in the header. The list specified can contain a combination of Objects and Strings.
* `[ 'key1', 'key2', ... ]`
* `[ { key: 'key1', title: 'Key 1' }, { key: 'key2' }, 'key3', ... ]`
* Key Paths - If you are converting a nested object (ie. {info : {name: 'Mike'}}), then set this to ['info.name']
* `prependHeader` - Boolean - Should the auto-generated header be prepended as the first line in the CSV?

@@ -91,0 +93,0 @@ * Default: `true`

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