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 5.1.2 to 5.2.0

20

CHANGELOG.md
# Changelog
## Version 5.2.0
Fix:
* escape: enforce validation
Project management:
* babel: include .babelrc to git
* ts: rename RowDelimiter to RecordDelimiter
* ts: convert camel case to snake case
## Version 5.1.2

@@ -31,3 +43,3 @@

Project Management:
Project management:

@@ -42,3 +54,3 @@ * package: latest dev dependencies

* `record_delimiter`: was `row_delimiter`
* options: instance options stored in underscore form
* options: instance options stored in snake case
* nodejs: drop support for version 7, use './lib/es5'

@@ -49,3 +61,3 @@

* `quoted_match`: new option
* options: accept underscore and camelcase forms
* options: accept snake case and camel case

@@ -57,3 +69,3 @@ Minor enhancements:

Project Management:
Project management:

@@ -60,0 +72,0 @@ * package: update license to MIT

52

lib/es5/index.js

@@ -176,6 +176,18 @@ "use strict";

options.eof = true;
}
} // options.escape ?= '"'
// Normalize option `escape`
if (options.escape == null) {
if (options.escape === null || options.escape === void 0) {
options.escape = '"';
} else {
if (Buffer.isBuffer(options.escape)) {
options.escape = options.escape.toString();
}
if (typeof options.escape !== 'string') {
throw new Error("Invalid Option: escape must be a boolean, a buffer or a string, got ".concat(JSON.stringify(options.escape)));
} else if (options.escape.length > 1) {
throw new Error("Invalid Option: escape must be one character, got ".concat(options.escape.length, " characters"));
}
}

@@ -221,5 +233,10 @@

if ((base = options.cast).string == null) {
base.string = function (value) {
return value;
if ((base = options.cast).boolean == null) {
base.boolean = function (value) {
// Cast boolean to string by default
if (value) {
return '1';
} else {
return '';
}
};

@@ -235,15 +252,4 @@ }

if ((base2 = options.cast).boolean == null) {
base2.boolean = function (value) {
// Cast boolean to string by default
if (value) {
return '1';
} else {
return '';
}
};
}
if ((base3 = options.cast).number == null) {
base3.number = function (value) {
if ((base2 = options.cast).number == null) {
base2.number = function (value) {
// Cast number to string using native casting by default

@@ -254,4 +260,4 @@ return '' + value;

if ((base4 = options.cast).object == null) {
base4.object = function (value) {
if ((base3 = options.cast).object == null) {
base3.object = function (value) {
// Stringify object as JSON by default

@@ -262,2 +268,8 @@ return JSON.stringify(value);

if ((base4 = options.cast).string == null) {
base4.string = function (value) {
return value;
};
}
if (options.record_delimiter === void 0 || options.record_delimiter === null || options.record_delimiter === false) {

@@ -264,0 +276,0 @@ if (options.record_delimiter == null) {

@@ -14,3 +14,3 @@ /// <reference types="node" />

type RowDelimiter = string | 'auto' | 'unix' | 'mac' | 'windows' | 'ascii' | 'unicode'
type RecordDelimiter = string | 'auto' | 'unix' | 'mac' | 'windows' | 'ascii' | 'unicode'

@@ -52,3 +52,3 @@ type Cast<T> = (value: T, context: CastingContext) => string

/**
* Add the value of "options.rowDelimiter" on the last line, default to true.
* Add the value of "options.RecordDelimiter" on the last line, default to true.
*/

@@ -80,3 +80,3 @@ eof?: boolean

*/
quotedEmpty?: boolean
quoted_empty?: boolean

@@ -86,3 +86,3 @@ /**

*/
quotedString?: boolean
quoted_string?: boolean

@@ -94,3 +94,3 @@ /**

*/
rowDelimiter?: RowDelimiter
record_delimiter?: RecordDelimiter

@@ -97,0 +97,0 @@ /**

@@ -128,4 +128,15 @@ // Generated by CoffeeScript 2.3.2

}
if (options.escape == null) {
// options.escape ?= '"'
// Normalize option `escape`
if (options.escape === null || options.escape === void 0) {
options.escape = '"';
} else {
if (Buffer.isBuffer(options.escape)) {
options.escape = options.escape.toString();
}
if (typeof options.escape !== 'string') {
throw new Error(`Invalid Option: escape must be a boolean, a buffer or a string, got ${JSON.stringify(options.escape)}`);
} else if (options.escape.length > 1) {
throw new Error(`Invalid Option: escape must be one character, got ${options.escape.length} characters`);
}
}

@@ -162,5 +173,10 @@ if (options.header == null) {

// Custom cast
if ((base = options.cast).string == null) {
base.string = function(value) {
return value;
if ((base = options.cast).boolean == null) {
base.boolean = function(value) {
// Cast boolean to string by default
if (value) {
return '1';
} else {
return '';
}
};

@@ -174,14 +190,4 @@ }

}
if ((base2 = options.cast).boolean == null) {
base2.boolean = function(value) {
// Cast boolean to string by default
if (value) {
return '1';
} else {
return '';
}
};
}
if ((base3 = options.cast).number == null) {
base3.number = function(value) {
if ((base2 = options.cast).number == null) {
base2.number = function(value) {
// Cast number to string using native casting by default

@@ -191,4 +197,4 @@ return '' + value;

}
if ((base4 = options.cast).object == null) {
base4.object = function(value) {
if ((base3 = options.cast).object == null) {
base3.object = function(value) {
// Stringify object as JSON by default

@@ -198,2 +204,7 @@ return JSON.stringify(value);

}
if ((base4 = options.cast).string == null) {
base4.string = function(value) {
return value;
};
}
if (options.record_delimiter === void 0 || options.record_delimiter === null || options.record_delimiter === false) {

@@ -200,0 +211,0 @@ if (options.record_delimiter == null) {

{
"version": "5.1.2",
"version": "5.2.0",
"name": "csv-stringify",

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

@@ -9,5 +9,2 @@

})
stringifier.write([ 'root','x','0','0','root','/root','/bin/bash' ])
stringifier.write([ 'someone','x','1022','1022','','/home/someone','/bin/bash' ])
stringifier.end()
stringifier.on('readable', function(){

@@ -24,3 +21,3 @@ let row;

assert.equal(
data.join('\n'),
data.join(''),
"root:x:0:0:root:/root:/bin/bash\n" +

@@ -30,1 +27,4 @@ "someone:x:1022:1022::/home/someone:/bin/bash\n"

})
stringifier.write([ 'root','x','0','0','root','/root','/bin/bash' ])
stringifier.write([ 'someone','x','1022','1022','','/home/someone','/bin/bash' ])
stringifier.end()
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