json2csvexporter
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _WriterService = _interopRequireDefault(require("./WriterService")); | ||
var _WriterService = require('./WriterService'); | ||
var _WriterService2 = _interopRequireDefault(_WriterService); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -18,2 +15,6 @@ | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
/** | ||
@@ -24,3 +25,3 @@ * Provides an ExportService that uses WriterService to mentain an in-memory representation of the CSV file. | ||
*/ | ||
var CSVExportService = function () { | ||
var CSVExportService = /*#__PURE__*/function () { | ||
/** | ||
@@ -35,3 +36,2 @@ * Default constructor. Takes an optional options param. | ||
} | ||
/** | ||
@@ -43,7 +43,6 @@ * Shorthand for createCSV() with a pre-set writerType | ||
_createClass(CSVExportService, [{ | ||
key: 'createCSVBlob', | ||
key: "createCSVBlob", | ||
value: function createCSVBlob(data) { | ||
return this.createCSV(data); | ||
} | ||
/** | ||
@@ -54,7 +53,6 @@ * Shorthand for createCSV() with a pre-set writerType | ||
}, { | ||
key: 'dataToString', | ||
key: "dataToString", | ||
value: function dataToString(data) { | ||
return this.createCSV(data, 'string'); | ||
} | ||
/** | ||
@@ -68,3 +66,3 @@ * Creates a Blob based on the provided data and configuration options. | ||
}, { | ||
key: 'createCSV', | ||
key: "createCSV", | ||
value: function createCSV(data) { | ||
@@ -85,2 +83,3 @@ var writerType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'blob'; | ||
var formatters = optionsFormatters || {}; | ||
var getFormater = function getFormater(header) { | ||
@@ -91,6 +90,7 @@ return formatters[header] || function (v) { | ||
}; | ||
var headerNames = optionsHeaders || {}; | ||
var headers = optionsColumns || Object.getOwnPropertyNames(data[0]); | ||
var includeHeaders = optionsIncludeHeaders; | ||
var writer = new _WriterService2.default(delimiter, contentType); | ||
var writer = new _WriterService.default(delimiter, contentType); | ||
@@ -103,2 +103,3 @@ if (includeHeaders === undefined || includeHeaders) { | ||
} | ||
data.forEach(function (row) { | ||
@@ -119,3 +120,3 @@ headers.forEach(function (header) { | ||
}, { | ||
key: 'download', | ||
key: "download", | ||
value: function download(blob, filename) { | ||
@@ -126,2 +127,3 @@ if (navigator.msSaveBlob) { | ||
} | ||
var link = document.createElement('A'); | ||
@@ -136,3 +138,2 @@ var url = URL.createObjectURL(blob); | ||
} | ||
/** | ||
@@ -144,7 +145,7 @@ * 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: 'downloadCSV', | ||
key: "downloadCSV", | ||
value: function downloadCSV(data) { | ||
try { | ||
var blob = this.createCSV(data, 'blob'); | ||
var filename = this.options.filename || 'export-' + (new Date().getTime() / 1000 | 0) + '.csv'; | ||
var filename = this.options.filename || "export-".concat(new Date().getTime() / 1000 | 0, ".csv"); | ||
this.download(blob, filename); | ||
@@ -155,2 +156,3 @@ } catch (err) { | ||
} | ||
if (this.options.onError) { | ||
@@ -161,3 +163,2 @@ this.options.onError(err); | ||
} | ||
/** | ||
@@ -170,7 +171,6 @@ * Shorthand for constructor. | ||
}], [{ | ||
key: 'create', | ||
key: "create", | ||
value: function create(options) { | ||
return new CSVExportService(options); | ||
} | ||
/** | ||
@@ -184,6 +184,5 @@ * Shorthand for initialization and download() call. | ||
}, { | ||
key: 'download', | ||
key: "download", | ||
value: function download(data) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new CSVExportService(options).downloadCSV(data); | ||
@@ -190,0 +189,0 @@ } |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
/** | ||
@@ -16,4 +19,3 @@ * Provides an interface for mapping JS data types to a delimiter-separated value. | ||
*/ | ||
var WriterService = function () { | ||
var WriterService = /*#__PURE__*/function () { | ||
/** | ||
@@ -34,3 +36,2 @@ * Default constructors. Takes two optional params. | ||
} | ||
/** | ||
@@ -43,5 +44,4 @@ * Returns the current row | ||
_createClass(WriterService, [{ | ||
key: 'wrapWithQuotes', | ||
key: "wrapWithQuotes", | ||
/** | ||
@@ -54,5 +54,4 @@ * Returns the input string | ||
var safeString = string.replace(/"/g, '""'); | ||
return '"' + safeString + '"'; | ||
return "\"".concat(safeString, "\""); | ||
} | ||
/** | ||
@@ -64,3 +63,3 @@ * @param {*} value | ||
}, { | ||
key: 'sanitizeValue', | ||
key: "sanitizeValue", | ||
value: function sanitizeValue(value) { | ||
@@ -70,5 +69,5 @@ if (value === undefined || value === null || typeof value === 'function') { | ||
} | ||
return String(value); | ||
} | ||
/** | ||
@@ -80,3 +79,3 @@ * Pushes a new value into the current row. | ||
}, { | ||
key: 'writeValue', | ||
key: "writeValue", | ||
value: function writeValue(value) { | ||
@@ -87,3 +86,2 @@ var stringValue = this.sanitizeValue(value); | ||
} | ||
/** | ||
@@ -94,7 +92,6 @@ * Adds a en empty array to rows property. This maps to an empty line. | ||
}, { | ||
key: 'writeLine', | ||
key: "writeLine", | ||
value: function writeLine() { | ||
this.rows.push([]); | ||
} | ||
/** | ||
@@ -106,3 +103,3 @@ * Flatten rows to a String. | ||
}, { | ||
key: 'toString', | ||
key: "toString", | ||
value: function toString() { | ||
@@ -114,6 +111,5 @@ var _this = this; | ||
}).reduce(function (content, row) { | ||
return content + '\r\n' + row; | ||
return "".concat(content, "\r\n").concat(row); | ||
}); | ||
} | ||
/** | ||
@@ -126,8 +122,10 @@ * Transform the rows into a Blob. | ||
}, { | ||
key: 'toBlob', | ||
key: "toBlob", | ||
value: function toBlob() { | ||
return new Blob([this.toString()], { type: this.contentType }); | ||
return new Blob([this.toString()], { | ||
type: this.contentType | ||
}); | ||
} | ||
}, { | ||
key: 'currentRow', | ||
key: "currentRow", | ||
get: function get() { | ||
@@ -134,0 +132,0 @@ return this.rows[this.rows.length - 1]; |
{ | ||
"name": "json2csvexporter", | ||
"version": "0.4.0", | ||
"author": "Filip Danic <filip@spicefactory.com> (danicfilip.com)", | ||
"main": "lib/CSVExportService.js", | ||
"version": "0.5.0", | ||
"author": "Filip Danic <filipdanic7@gmail.com> (https://danicfilip.com)", | ||
"main": "dist/CSVExportService.js", | ||
"module": "module/CSVExportService.js", | ||
"scripts": { | ||
"compile": "babel --presets es2015,stage-0 -d lib/ src/", | ||
"rollup": "rollup --config", | ||
"babel": "babel -d lib/ src/", | ||
"compile": "npm run babel && npm run rollup", | ||
"prepublish": "npm run compile" | ||
@@ -14,5 +17,21 @@ }, | ||
"name": "Filip Danic", | ||
"email": "filip@spicefactory.co", | ||
"email": "filipdanic7@gmail.com", | ||
"twitter": "@DanicFilip", | ||
"github": "filipdanic" | ||
}, | ||
{ | ||
"name": "Onno van der Zee", | ||
"github": "ovanderzee" | ||
}, | ||
{ | ||
"name": "Erick Zhao", | ||
"github": "erickzhao" | ||
}, | ||
{ | ||
"name": "androidfanboi", | ||
"github": "androidfanboi" | ||
}, | ||
{ | ||
"name": "Rajat", | ||
"github": "RajatDM1" | ||
} | ||
@@ -32,9 +51,12 @@ ], | ||
"csv client download", | ||
"exporter" | ||
"exporter", | ||
"front-end" | ||
], | ||
"devDependencies": { | ||
"babel-cli": "^6.1.18", | ||
"babel-core": "^6.1.18", | ||
"babel-preset-es2015": "^6.1.18", | ||
"babel-preset-stage-0": "^6.16.0" | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
"core-js": "^3.6.4", | ||
"rollup": "^2.3.0", | ||
"rollup-plugin-babel": "^4.4.0" | ||
}, | ||
@@ -41,0 +63,0 @@ "engine": "node >= 0.10.x", |
@@ -11,2 +11,7 @@ # json2csvexporter | ||
Provided are: | ||
* umd-formatted file: dist/CSVExportService.js (browser-ready) | ||
* commonjs-formatted file: lib/CSVExportService.js | ||
* es-module: module/CSVExportService.js | ||
Table of contents: | ||
@@ -171,7 +176,7 @@ | ||
## Browsers Support | ||
## 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+ | | ||
| IE10, IE11, Edge| 4+ | 13+ | 5+ | 12+ | 7+ | | ||
@@ -178,0 +183,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
91925
20
805
194
6
1