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.4 to 0.3.0

.idea/json2csvexporter.iml

10

lib/CSVExportService.js

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

}
/**

@@ -146,7 +147,2 @@ * Creates and passes the blob and filename params to the download() method. In case of error, calls the onError callback (if provided) and prints a error mesage if devMode is enabled via options.

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

@@ -164,5 +160,7 @@ /**

}
/**
* Shorthand for initialization and download() call.
* @param {Array} data - An array of objects to map and store.
* @param {Array} data - An array of objects to map and store.
* @param {Object} options
* @return {undefined}

@@ -169,0 +167,0 @@ */

62

lib/WriterService.js

@@ -12,10 +12,11 @@ 'use strict';

/**
* Provides an interface for maping JS datatypes to a delimiter-seperated value.
* Provides an interface for mapping JS data types to a delimiter-separated value.
* Creates a list of lists called rows and maps it to a Blob via toBlob().
*/
var WriterService = function () {
/**
* Default constructors. Takes two optional params.
* @param {String} delimiter - Delimitercharacter(s) to be used in the CSV.
* @param {String} contentType - Type of file.
* @param {string} delimiter - Delimiter character(s) to be used in the CSV.
* @param {string} contentType - Type of file.
*/

@@ -32,2 +33,3 @@ function WriterService() {

}
/**

@@ -40,25 +42,15 @@ * Returns the current row

_createClass(WriterService, [{
key: 'wrapWithQuotes',
key: 'writeValue',
/**
* Returns the input string
* @param {String} string - The input string.
* @return {String} - A safe strings wrapped in quotes.
*/
value: function wrapWithQuotes(string) {
var safeString = string.replace(/"/g, '""');
return '"' + safeString + '"';
}
/**
* Pushes a new value into the current row.
* @param {Any} value - The value to push.
* @param {*} value - The value to push.
*/
}, {
key: 'writeValue',
value: function writeValue(value) {
var stringValue = value === undefined ? '' : String(value);
var stringValue = this.sanitizeValue(value);
var needsQuotes = stringValue.indexOf(this.delimiter) !== -1 || /"\r\n/.test(stringValue);
this.currentRow.push(needsQuotes ? this.wrapWithQuotes(stringValue) : stringValue);
}
/**

@@ -73,5 +65,6 @@ * Adds a en empty array to rows property. This maps to an empty line.

}
/**
* Flatten rows to a String.
* @return {String} - A string representation of the rows..
* @return {string} - A string representation of the rows..
*/

@@ -90,5 +83,7 @@

}
/**
* Transform the rows into a Blob.
* @return {Object} - A representation of the rows in the form of a Blob. The returned Object is an instance of Blob, but typeof Object.
* @return {Object} - A representation of the rows in the form of
* a Blob. The returned Object is an instance of Blob, but typeof Object.
*/

@@ -106,2 +101,29 @@

}
/**
* Returns the input string
* @param {string} string - The input string.
* @return {string} - A safe strings wrapped in quotes.
*/
}], [{
key: 'wrapWithQuotes',
value: function wrapWithQuotes(string) {
var safeString = string.replace(/"/g, '""');
return '"' + safeString + '"';
}
/**
* @param {*} value
* @return {string}
*/
}, {
key: 'sanitizeValue',
value: function sanitizeValue(value) {
if (value === undefined || value === null || typeof value === 'function') {
return '';
}
return String(value);
}
}]);

@@ -108,0 +130,0 @@

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

@@ -5,0 +5,0 @@ "main": "lib/CSVExportService.js",

@@ -15,10 +15,11 @@ # json2csvexporter

2. [Example with Custom Options](#example-with-custom-options)
3. [Example with TSV and Formaters](#example-with-tsv-and-formaters)
3. [Example with TSV and Formatters](#example-with-tsv-and-formatters)
4. [JSON to CSV/TSV encoded String/Blob (without downloading on the client)](#json-to-csvtsv-encoded-stringblob-without-downloading-on-the-client)
4. [API and Options Docs](#api-and-options-docs)
5. [Contributing](#contributing)
5. [API and Options Docs](#api-and-options-docs)
6. [Browsers Support](#browsers-support)
7. [Contributing](#contributing)
## Simple Example
In this simple example we take a JSON object and print all of the properties in it to the CSV.
In this simple example we take a JSON object and print all of the properties in it to the CSV. There is also [an online demo available via RequireBin.](http://requirebin.com/?gist=a830925068890ad30533e13e51206194)

@@ -81,3 +82,3 @@ ```javascript

## Example with TSV and Formaters
## Example with TSV and Formatters

@@ -100,6 +101,6 @@ In this example, we will make a TSV file and create formatting functions to style the content of certain properties.

model: (model) => {
return model || 'Unkown model';
return model || 'Unknown model';
},
year: (year) => {
return year || 'Unkown year';
return year || 'Unknown year';
}

@@ -118,3 +119,3 @@ }

#2 Ford Mustang 2012
#3 Toyota Unkown model Unkown year
#3 Toyota Unknown model Unknown year
```

@@ -169,11 +170,24 @@

The `CSVExportService` implements two static methods: `create(options)` which returns a new instance of CSVExportSevice and `download(data, options)` which initalizes a new service and downloads the data right away.
The `CSVExportService` implements two static methods: `create(options)` which returns a new instance of CSVExportService and `download(data, options)` which initializes a new service and downloads the data right away.
For more info, dive into the code. It is a very simple class.
## Browsers Support
| [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/edge.png" alt="IE / Edge" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>IE / Edge | [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/firefox.png" alt="Firefox" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/chrome.png" alt="Chrome" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/safari.png" alt="Safari" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>Safari | [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/opera.png" alt="Opera" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>Opera | [<img src="https://raw.githubusercontent.com/godban/browsers-support-badges/master/src/images/safari-ios.png" alt="iOS Safari" width="16px" height="16px" />](http://godban.github.io/browsers-support-badges/)</br>iOS Safari |
| --------- | --------- | --------- | --------- | --------- | --------- |
| IE10, IE11, Edge| 4+ | 13+ | 5+ | 12+ | 7+ |
## Contributing
1. Submit issues or suggest features.
2. Send PRs with bugfixes, tests, new methods, better docs etc.
2. Send PRs with bug fixes, tests, new methods, better docs etc.
3. Share the love!
## Contributor list
1. [@filipdanic](https://github.com/filipdanic)
2. [@androidfanboi](https://github.com/androidfanboi)
3. [@erickzhao](https://github.com/erickzhao)
4. [@bira91](https://github.com/bira91)

Sorry, the diff of this file is not supported yet

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