This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
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
9 changed files
with
84 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
## Trunk | ||
|
||
* samples: update syntax | ||
package: improve ignore files | ||
|
||
## Version 3.0.0 | ||
|
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,13 @@ | ||
|
||
const parse = require('../lib') | ||
const assert = require('assert') | ||
|
||
const input = '#Welcome\n"1","2","3","4"\n"a","b","c","d"' | ||
parse(input, { | ||
comment: '#' | ||
}, function(err, output){ | ||
assert.deepEqual( | ||
output, | ||
[ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ] | ||
) | ||
}) |
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,19 @@ | ||
|
||
const parse = require('..') | ||
const generate = require('csv-generate') | ||
const transform = require('stream-transform') | ||
|
||
const parser = parse({ | ||
delimiter: ':' | ||
}) | ||
const input = generate({ | ||
length: 20 | ||
}) | ||
const transformer = transform(function(record, callback){ | ||
setTimeout(function(){ | ||
callback(null, record.join(' ')+'\n') | ||
}, 500) | ||
}, { | ||
parallel: 5 | ||
}) | ||
input.pipe(parser).pipe(transformer).pipe(process.stdout) |
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,35 @@ | ||
|
||
const parse = require('../lib') | ||
const assert = require('assert') | ||
|
||
const output = [] | ||
// Create the parser | ||
const parser = parse({ | ||
delimiter: ':' | ||
}) | ||
// Write data to the stream | ||
parser.write("root:x:0:0:root:/root:/bin/bash\n") | ||
parser.write("someone:x:1022:1022::/home/someone:/bin/bash\n") | ||
// Close the readable stream | ||
parser.end() | ||
// Use the writable stream api | ||
parser.on('readable', function(){ | ||
let record | ||
while (record = parser.read()) { | ||
output.push(record) | ||
} | ||
}) | ||
// Catch any error | ||
parser.on('error', function(err){ | ||
console.error(err.message) | ||
}) | ||
// When we are done, test that the parsed output matched what expected | ||
parser.on('end', function(){ | ||
assert.deepEqual( | ||
output, | ||
[ | ||
[ 'root','x','0','0','root','/root','/bin/bash' ], | ||
[ 'someone','x','1022','1022','','/home/someone','/bin/bash' ] | ||
] | ||
) | ||
}) |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
|
||
// The package "should" must be installed: | ||
// `npm install should` | ||
|
||
const parse = require('../lib/sync') | ||
const assert = require('assert') | ||
|
||
const input = ` | ||
"key_1","key_2" | ||
"value 1","value 2" | ||
` | ||
const records = parse(input, { | ||
columns: true, | ||
skip_empty_lines: true | ||
}) | ||
assert.deepEqual(records, [{ key_1: 'value 1', key_2: 'value 2' }]) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.