Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename option separator to delimiter

  • Loading branch information...
commit b82fdc18a859b927edfadb4229e339b2576f03a8 1 parent c253672
@wdavidw authored
View
20 lib/csv.js
@@ -33,9 +33,9 @@ module.exports = function(){
flags: 'r',
encoding: 'utf8',
bufferSize: 8 * 1024 * 1024,
- separator: ',',
- escape: '"',
- quote: '"'
+ delimiter: ',',
+ quote: '"',
+ escape: '"'
};
this.writeOptions = {
bufferSize: null,
@@ -149,10 +149,10 @@ module.exports = function(){
break;
}
if (state.quoted) {
- // Make sure a closing quote is followed by a separator
+ // Make sure a closing quote is followed by a delimiter
var nextChar = chars.charAt(i + 1);
- if (nextChar && nextChar != '\r' && nextChar != '\n' && nextChar !== csv.readOptions.separator) {
- throw new Error('Invalid closing quote; found "' + nextChar + '" instead of separator "' + csv.readOptions.separator + '"');
+ if (nextChar && nextChar != '\r' && nextChar != '\n' && nextChar !== csv.readOptions.delimiter) {
+ throw new Error('Invalid closing quote; found "' + nextChar + '" instead of delimiter "' + csv.readOptions.delimiter + '"');
}
state.quoted = false;
} else if (state.field === '') {
@@ -160,7 +160,7 @@ module.exports = function(){
}
}
break;
- case csv.readOptions.separator:
+ case csv.readOptions.delimiter:
if( state.commented ) break;
if( state.quoted ) {
state.field += c;
@@ -200,17 +200,17 @@ module.exports = function(){
if(line instanceof Array){
var newLine = '';
line.forEach(function(field,i){
- var containsSeparator = field.indexOf(csv.writeOptions.separator||csv.readOptions.separator)>=0;
+ var containsdelimiter = field.indexOf(csv.writeOptions.delimiter||csv.readOptions.delimiter)>=0;
var containsQuote = field.indexOf(csv.writeOptions.quote||csv.readOptions.quote)>=0;
if(containsQuote){
field = field.replace(csv.writeOptions.quote||csv.readOptions.quote,(csv.writeOptions.escape||csv.readOptions.escape)+(csv.writeOptions.quote||csv.readOptions.quote));
}
- if(containsQuote||containsSeparator){
+ if(containsQuote||containsdelimiter){
field = (csv.writeOptions.quote||csv.readOptions.quote)+field+(csv.writeOptions.quote||csv.readOptions.quote);
}
newLine += field;
if(i!==line.length-1){
- newLine += (csv.writeOptions.separator||csv.readOptions.separator)
+ newLine += (csv.writeOptions.delimiter||csv.readOptions.delimiter)
}
});
line = newLine+csv.writeOptions.lineBreaks;
View
12 test/quotes.js
@@ -20,18 +20,18 @@ module.exports = {
fs.unlink(__dirname+'/quotes/regular.tmp');
});
},
- 'Test quotes with separator': function(assert){
+ 'Test quotes with delimiter': function(assert){
csv()
- .fromPath(__dirname+'/quotes/separator.in',{
+ .fromPath(__dirname+'/quotes/delimiter.in',{
})
- .toPath(__dirname+'/quotes/separator.tmp',{
+ .toPath(__dirname+'/quotes/delimiter.tmp',{
})
.on('end',function(){
assert.equal(
- fs.readFileSync(__dirname+'/quotes/separator.out').toString(),
- fs.readFileSync(__dirname+'/quotes/separator.tmp').toString()
+ fs.readFileSync(__dirname+'/quotes/delimiter.out').toString(),
+ fs.readFileSync(__dirname+'/quotes/delimiter.tmp').toString()
);
- fs.unlink(__dirname+'/quotes/separator.tmp');
+ fs.unlink(__dirname+'/quotes/delimiter.tmp');
});
},
'Test quotes inside field': function(assert){
View
0  test/quotes/separator.in → test/quotes/delimiter.in
File renamed without changes
View
0  test/quotes/separator.out → test/quotes/delimiter.out
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.