jsonexport
Advanced tools
Comparing version 2.0.9 to 2.0.10
## 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 @@ } |
{ | ||
"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 @@ }); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
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
49003
22
973