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

export-to-csv

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

export-to-csv - npm Package Compare versions

Comparing version 0.1.2 to 0.2.1

coverage/Chrome 71.0.3578 (Linux 0.0.0)/html/base.css

4

build/export-to-csv.d.ts

@@ -5,6 +5,7 @@ export interface Options {

quoteStrings?: string;
decimalseparator?: string;
decimalSeparator?: string;
showLabels?: boolean;
showTitle?: boolean;
title?: string;
useTextFile?: boolean;
useBom?: boolean;

@@ -24,2 +25,3 @@ headers?: string[];

static DEFAULT_SHOW_LABELS: boolean;
static DEFAULT_USE_TEXT_FILE: boolean;
static DEFAULT_USE_BOM: boolean;

@@ -26,0 +28,0 @@ static DEFAULT_HEADER: string[];

@@ -15,2 +15,3 @@ "use strict";

CsvConfigConsts.DEFAULT_SHOW_LABELS = false;
CsvConfigConsts.DEFAULT_USE_TEXT_FILE = false;
CsvConfigConsts.DEFAULT_USE_BOM = true;

@@ -26,6 +27,7 @@ CsvConfigConsts.DEFAULT_HEADER = [];

quoteStrings: CsvConfigConsts.DEFAULT_QUOTE,
decimalseparator: CsvConfigConsts.DEFAULT_DECIMAL_SEPARATOR,
decimalSeparator: CsvConfigConsts.DEFAULT_DECIMAL_SEPARATOR,
showLabels: CsvConfigConsts.DEFAULT_SHOW_LABELS,
showTitle: CsvConfigConsts.DEFAULT_SHOW_TITLE,
title: CsvConfigConsts.DEFAULT_TITLE,
useTextFile: CsvConfigConsts.DEFAULT_USE_TEXT_FILE,
useBom: CsvConfigConsts.DEFAULT_USE_BOM,

@@ -83,13 +85,16 @@ headers: CsvConfigConsts.DEFAULT_HEADER,

// consumer doesn't set the shouldReturnCsv param
var blob = new Blob([this._csv], { "type": "text/csv;charset=utf8;" });
var FileType = this._options.useTextFile ? 'plain' : 'csv';
var fileExtension = this._options.useTextFile ? '.txt' : '.csv';
var blob = new Blob([this._csv], { "type": "text/" + FileType + ";charset=utf8;" });
if (navigator.msSaveBlob) {
var filename = this._options.filename.replace(/ /g, "_") + ".csv";
var filename = this._options.filename.replace(/ /g, "_") + fileExtension;
navigator.msSaveBlob(blob, filename);
}
else {
var uri = 'data:attachment/csv;charset=utf-8,' + encodeURI(this._csv);
var attachmentType = this._options.useTextFile ? 'text' : 'csv';
var uri = 'data:attachment/' + attachmentType + ';charset=utf-8,' + encodeURI(this._csv);
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.setAttribute('visibility', 'hidden');
link.download = this._options.filename.replace(/ /g, "_") + ".csv";
link.download = this._options.filename.replace(/ /g, "_") + fileExtension;
document.body.appendChild(link);

@@ -138,7 +143,7 @@ link.click();

ExportToCsv.prototype._formatData = function (data) {
if (this._options.decimalseparator === 'locale' && this._isFloat(data)) {
if (this._options.decimalSeparator === 'locale' && this._isFloat(data)) {
return data.toLocaleString();
}
if (this._options.decimalseparator !== '.' && this._isFloat(data)) {
return data.toString().replace('.', this._options.decimalseparator);
if (this._options.decimalSeparator !== '.' && this._isFloat(data)) {
return data.toString().replace('.', this._options.decimalSeparator);
}

@@ -145,0 +150,0 @@ if (typeof data === 'string') {

{
"name": "export-to-csv",
"version": "0.1.2",
"version": "0.2.1",
"description": "Easily create CSV data from json collection",

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

@@ -46,6 +46,7 @@ # export-to-csv | Export to CSV Mini Library

quoteStrings: '"',
decimalseparator: '.',
decimalSeparator: '.',
showLabels: true,
showTitle: true,
title: 'My Awesome CSV',
useTextFile: false,
useBom: true,

@@ -70,3 +71,3 @@ useKeysAsHeaders: true,

| **quoteStrings** | " | If provided, will use this characters to "escape" fields, otherwise will use double quotes as deafult |
| **decimalseparator** | . | Defines the decimal separator character (default is .). If set to "locale", it uses the [language sensitive representation of the number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString).|
| **decimalSeparator** | . | Defines the decimal separator character (default is .). If set to "locale", it uses the [language sensitive representation of the number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString).|
| **showLabels** | false | If true, the first row will be the `headers` option or object keys if `useKeysAsHeaders` is present|

@@ -76,2 +77,3 @@ | **showTitle** | false | Includes the title as the first line in the generated file |

| **useBom** | true | If true, adds a BOM character at the start of the CSV to improve file compatibility |
| **useTextFile** | false | If true, returns a `.txt` file instead of `.csv` |
| **useKeysAsHeaders** | false | If true, this will use the keys of the first object in the collection as the column headers|

@@ -78,0 +80,0 @@ | **headers** | [] | Expects an array of strings, which if supplied, will be used as the column headers|

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