forked from koles/ya-csv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var csv = require('../lib/ya-csv'), | ||
stream = require('stream'), | ||
assert = require('assert'); | ||
|
||
// create a really simple writable stream | ||
var writeStream = new stream.Stream(); | ||
writeStream.writable = true; | ||
writeStream.data = ''; | ||
writeStream.write = function(data) { | ||
// this csv writer doesn't allow commas since there is no | ||
// quote or escape character. We're writing this for a really | ||
// piss-poor csv implementation. | ||
this.data += data.replace(/,/g, ''); | ||
}; | ||
writeStream.end = function() { | ||
// nothing to do | ||
}; | ||
|
||
// create csv writer with empty string options | ||
var csvWriter = csv.createCsvStreamWriter(writeStream, { | ||
separator: ',', // must remove in writeStream.write() | ||
quote: '', | ||
escape: '' | ||
}); | ||
|
||
var csvRecord = ['John Smith', 'Customer 999', 'United States']; | ||
csvWriter.writeRecord(csvRecord); | ||
|
||
var expected = "John Smith,Customer 999,United States\r\n"; | ||
assert.strictEqual(writeStream.data, expected); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters