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

jsonexport

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonexport - npm Package Compare versions

Comparing version 2.0.9 to 2.0.10

1

CHANGELOG.md
## Change log
----------------------
- v2.0.10 - enclose strings containing quotes with more quotes (dozen1488)
- v2.0.8 - cli improvements

@@ -4,0 +5,0 @@ - v2.0.7 - removed underscore as a dependency (dydx)

@@ -26,2 +26,9 @@ /* jshint node:true */

const enclosingCondition = (textDelimiter === '"') ?
(value) => (value.indexOf(rowDelimiter) >= 0 ||
value.indexOf(endOfLine) >= 0 ||
value.indexOf('"') >= 0)
: (value) => (value.indexOf(rowDelimiter) >= 0 ||
value.indexOf(endOfLine) >= 0);
return function(value) {

@@ -31,4 +38,4 @@ if (!value.replace) return value;

var newValue = value.replace(textDelimiterRegex, escapedDelimiter);
// Escape the whole field if it contains a rowDelimiter or a linebreak
if (newValue.indexOf(rowDelimiter) >= 0 || newValue.indexOf(endOfLine) >= 0) {
// Escape the whole field if it contains a rowDelimiter or a linebreak or double quote
if (enclosingCondition(value)) {
newValue = textDelimiter + newValue + textDelimiter;

@@ -35,0 +42,0 @@ }

2

package.json
{
"name": "jsonexport",
"version": "2.0.9",
"version": "2.0.10",
"description": "Makes easy to convert JSON to CSV",

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

@@ -20,3 +20,3 @@ /* jshint node:true */

}], {}, (err, csv) => {
expect(csv).to.equal(`name,lastname,escaped${os.EOL}Bob,Smith${os.EOL}James,David,I am a ""quoted"" field`);
expect(csv).to.equal(`name,lastname,escaped${os.EOL}Bob,Smith${os.EOL}James,David,"I am a ""quoted"" field"`);
});

@@ -23,0 +23,0 @@ });

@@ -15,3 +15,4 @@ /* jshint node:true */

simpleRow: 'I am a \n multi line field',
complexField: 'I am a \n multi line field containing "textDelimiters"'
complexField: 'I am a \n multi line field containing "textDelimiters"',
alreadyEscaped: '"I contain "double quotes" everywhere !"'
};

@@ -21,5 +22,10 @@

expect(escapeDelimiters(mocks.simpleText)).to.be.a.string;
expect(escapeDelimiters(mocks.simpleText)).to.be.equal('I am a ""quoted"" field');
expect(escapeDelimiters(mocks.simpleText)).to.be.equal('"I am a ""quoted"" field"');
});
it('should escape all textDelimiters', () => {
expect(escapeDelimiters(mocks.alreadyEscaped)).to.be.a.string;
expect(escapeDelimiters(mocks.alreadyEscaped)).to.be.equal('"""I contain ""double quotes"" everywhere !"""');
});
it('should escape rowDelimiters', () => {

@@ -26,0 +32,0 @@ expect(escapeDelimiters(mocks.simpleRow)).to.be.a.string;

@@ -32,5 +32,5 @@ /* jshint node:true */

}, {}, (err, csv) => {
expect(csv).to.equal(`cars,12${os.EOL}roads,5${os.EOL}traffic,slow${os.EOL}speed.max,123${os.EOL}speed.avg,20${os.EOL}speed.min,5${os.EOL}size,10;20${os.EOL}escaped,I am a ""quoted"" field`);
expect(csv).to.equal(`cars,12${os.EOL}roads,5${os.EOL}traffic,slow${os.EOL}speed.max,123${os.EOL}speed.avg,20${os.EOL}speed.min,5${os.EOL}size,10;20${os.EOL}escaped,"I am a ""quoted"" field"`);
});
});
});

@@ -28,3 +28,3 @@ /* jshint evil: true */

var write = getWriteStream((csv) => {
expect(csv).to.equal(`name,lastname,escaped${os.EOL}Bob,Smith${os.EOL}James,David,I am a ""quoted"" field`);
expect(csv).to.equal(`name,lastname,escaped${os.EOL}Bob,Smith${os.EOL}James,David,"I am a ""quoted"" field"`);
done();

@@ -48,3 +48,3 @@ });

var write = getWriteStream((csv) => {
expect(csv).to.equal(`name|lastname|escaped${os.EOL}Bob|Smith${os.EOL}James|David|I am a ""quoted"" field`);
expect(csv).to.equal(`name|lastname|escaped${os.EOL}Bob|Smith${os.EOL}James|David|"I am a ""quoted"" field"`);
done();

@@ -51,0 +51,0 @@ });

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