Socket
Socket
Sign inDemoInstall

csv-stringify

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-stringify - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

52

lib/index.js

@@ -1,2 +0,6 @@

// Generated by CoffeeScript 1.12.7
// Generated by CoffeeScript 2.0.1
// # CSV Stringifier
// Please look at the [README], the [samples] and the [tests] for additional
// information.
var Stringifier, get, stream, util;

@@ -10,2 +14,11 @@

// ## Usage
// Callback approach, for ease of use:
// `stringify(data, [options], callback)`
// Stream API, for maximum of power:
// `stringify([options], [callback])`
module.exports = function() {

@@ -71,7 +84,8 @@ var callback, chunks, data, options, stringifier;

Stringifier = function(opts) {
// ## `Stringifier([options])`
// Options are documented [here](http://csv.adaltas.com/stringify/).
Stringifier = function(opts = {}) {
var base, base1, base10, base11, base12, base13, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v;
if (opts == null) {
opts = {};
}
// Immutable options
options = {};

@@ -83,2 +97,3 @@ for (k in opts) {

stream.Transform.call(this, options);
//# Default options
this.options = options;

@@ -117,2 +132,3 @@ if ((base = this.options).delimiter == null) {

base10.date = function(value) {
// Cast date to timestamp string by default
return '' + value.getTime();

@@ -123,2 +139,3 @@ };

base11.bool = function(value) {
// Cast boolean to string by default
if (value) {

@@ -133,2 +150,3 @@ return '1';

base12.object = function(value) {
// Stringify object as JSON by default
return JSON.stringify(value);

@@ -140,2 +158,3 @@ };

}
// Internal usage, state related
if (this.countWriten == null) {

@@ -167,2 +186,5 @@ this.countWriten = 0;

// ## `Stringifier.prototype.headers`
// Print the header line if the option "header" is "true".
Stringifier.prototype.headers = function() {

@@ -177,2 +199,3 @@ var k, label, labels;

labels = this.options.columns;
// If columns is an object, keys are fields and values are labels
if (typeof labels === 'object') {

@@ -210,2 +233,3 @@ labels = (function() {

preserve = typeof chunk !== 'object';
// Emit and stringify the record
if (!preserve) {

@@ -223,2 +247,3 @@ if (this.countWriten === 0 && !Array.isArray(chunk)) {

}
// Convert the record into a string
if (this.options.eof) {

@@ -234,3 +259,4 @@ chunk = this.stringify(chunk) + this.options.rowDelimiter;

if (typeof chunk === 'number') {
chunk = "" + chunk;
// Emit the csv
chunk = `${chunk}`;
}

@@ -246,2 +272,3 @@ if (this.countWriten === 0) {

// ## `Stringifier.prototype._transform(line)`
Stringifier.prototype._transform = function(chunk, encoding, callback) {

@@ -252,2 +279,5 @@ this.push(chunk);

// ## `Stringifier.prototype.stringify(line)`
// Convert a line to a string. Line may be an object, an array or a string.
Stringifier.prototype.stringify = function(line) {

@@ -280,3 +310,5 @@ var _line, column, columns, containsEscape, containsLinebreak, containsQuote, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, value;

_line = null;
} else if (columns) {
} else if (columns) { // Note, we used to have @options.columns
// We are getting an array but the user want specified output columns. In
// this case, we respect the columns indexes
line.splice(columns.length);

@@ -290,3 +322,5 @@ }

// fine 99% of the cases, keep going
} else if (typeof field === 'number') {
// Cast number to string
field = '' + field;

@@ -329,1 +363,5 @@ } else if (typeof field === 'boolean') {

};
// [readme]: https://github.com/wdavidw/node-csv-stringify
// [samples]: https://github.com/wdavidw/node-csv-stringify/tree/master/samples
// [tests]: https://github.com/wdavidw/node-csv-stringify/tree/master/test

14

lib/sync.js

@@ -1,13 +0,15 @@

// Generated by CoffeeScript 1.12.7
// Generated by CoffeeScript 2.0.1
// # CSV Stringify Sync
// Provides a synchronous alternative to the CSV stringifier.
// Usage: `data = stringify(records, [options]`
var StringDecoder, stringify;
StringDecoder = require('string_decoder').StringDecoder;
({StringDecoder} = require('string_decoder'));
stringify = require('./index');
module.exports = function(records, options) {
module.exports = function(records, options = {}) {
var data, decoder, i, len, record, stringifier;
if (options == null) {
options = {};
}
data = [];

@@ -14,0 +16,0 @@ if (records instanceof Buffer) {

{
"version": "1.1.2",
"version": "2.0.0",
"name": "csv-stringify",

@@ -16,4 +16,4 @@ "description": "CSV stringifier implementing the Node.js `stream.Transform` API",

"devDependencies": {
"coffee-script": "~1.12.7",
"csv-generate": "~1.0.0",
"coffeescript": "~2.0.1",
"csv-generate": "~2.0.0",
"mocha": "~4.0.1",

@@ -20,0 +20,0 @@ "should": "~13.1.2"

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