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

json2csvexporter

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json2csvexporter - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

42

lib/CSVExportService.js

@@ -32,7 +32,6 @@ 'use strict';

}
/**
* Creates a Blob based on the provided data and configuration options.
* @param {Array} data - An array of JSON objects that will be mapped to the Blob.
* @return {Object} - The Blob object. Is an instance of Blob, but typeof Object.
*/
* Shorthand for createCSV() with a pre-set writerType
*/

@@ -43,2 +42,27 @@

value: function createCSVBlob(data) {
return this.createCSV(data);
}
/**
* Shorthand for createCSV() with a pre-set writerType
*/
}, {
key: 'dataToString',
value: function dataToString(data) {
return this.createCSV(data, 'string');
}
/**
* Creates a Blob based on the provided data and configuration options.
* @param {Array} data - An array of JSON objects that will be mapped to the Blob.
* @param {String} writerType - ENUM for choosing the return type. Default to 'blo'
* @return {Object|String} - The Blob object (Is an instance of Blob, but typeof Object) or a String version of the CSV with newlines.
*/
}, {
key: 'createCSV',
value: function createCSV(data) {
var writerType = arguments.length <= 1 || arguments[1] === undefined ? 'blob' : arguments[1];
var _ref = this.options || {};

@@ -78,3 +102,3 @@

});
return writer.toBlob();
return writerType === 'string' ? writer.toString() : writer.toBlob();
}

@@ -112,3 +136,3 @@ /**

try {
var blob = this.createCSVBlob(data);
var blob = this.createCSV(data, 'blob');
var filename = this.options.filename || 'export-' + (new Date().getTime() / 1000 | 0) + '.csv';

@@ -125,2 +149,8 @@ this.download(blob, filename);

}
}, {
key: 'toString',
value: function toString(data) {
var writer = new _WriterService2.default(delimeter, contentType);
}
/**

@@ -127,0 +157,0 @@ * Shorthand for constructor.

{
"name": "json2csvexporter",
"version": "0.2.1",
"version": "0.2.2",
"author": "Filip Danic <filip@spicefactory.com> (danicfilip.com)",

@@ -25,3 +25,8 @@ "main": "lib/CSVExportService.js",

"csv",
"tsv",
"json2csv",
"json2tsv",
"csv export",
"download csv",
"csv client download",
"exporter"

@@ -28,0 +33,0 @@ ],

@@ -16,2 +16,3 @@ # json2csvexporter

3. Example with TSV and Formaters
4. JSON to CSV/TSV encoded String/Blob (without downloading on the client)
4. API and Options Docs

@@ -118,2 +119,27 @@ 5. Contributing

## JSON to CSV/TSV encoded String/Blob (without downloading on the client)
```javascript
import CSVExportService from 'json2csvexporter';
...
const vehiclesJSON = [
{id: 1, make: 'Toyota', model: 'Corolla', year: 2014},
{id: 2, make: 'Ford', model: 'Mustang', year: 2012},
{id: 3, make: 'Toyota', model: '', year: ''}
];
const exporter = CSVExportService.create();
exporter.dataToString(vehiclesJSON);
```
This will return the CSV as a JavaScript String. This allows you to further manipulate the data, save to a file, a database or anything else.
Similarly, calling:
```javascript
exporter.createCSVBlob(vehiclesJSON);
```
Will return a `Blob {size: 76, type: "text/csv"}`, or in other words, a regular JavaScript blob object that is encoded as the type you specified (in this case a plain text/csv). You then manipulate this Blob object however you like.
## API and Options Docs

@@ -120,0 +146,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