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
15 changed files
with
97 additions
and
97 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
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
|
||
import { generate } from 'csv-generate/sync' | ||
import assert from 'assert' | ||
import { generate } from 'csv-generate/sync'; | ||
import assert from 'assert'; | ||
|
||
const records = generate({ | ||
seed: 1, | ||
objectMode: true, | ||
columns: 2, | ||
length: 2 | ||
}) | ||
}); | ||
assert.deepEqual(records, [ | ||
[ 'OMH', 'ONKCHhJmjadoA' ], | ||
[ 'D', 'GeACHiN' ] | ||
]) | ||
]); |
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
19 changes: 9 additions & 10 deletions
19
packages/csv-generate/samples/options.objectmode.stream.js
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
|
||
import { generate } from 'csv-generate' | ||
import assert from 'assert' | ||
import { generate } from 'csv-generate'; | ||
import assert from 'assert'; | ||
|
||
generate({ | ||
seed: 1, | ||
objectMode: true, | ||
columns: 2, | ||
length: 1 | ||
}) | ||
.on('readable', function(){ | ||
let record | ||
while(record = this.read()){ | ||
assert.deepEqual(record, [ | ||
'OMH', 'ONKCHhJmjadoA' | ||
]) | ||
} | ||
}) | ||
.on('readable', function(){ | ||
let record; while((record = this.read()) !== null){ | ||
assert.deepEqual(record, [ | ||
'OMH', 'ONKCHhJmjadoA' | ||
]); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
import { generate } from 'csv-generate' | ||
import { generate } from 'csv-generate'; | ||
|
||
generate({ | ||
columns: ['int', 'bool'], | ||
length: 2 | ||
}) | ||
.pipe(process.stdout) | ||
.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
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
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
|
||
// Import the package main module | ||
import * as csv from '../lib/index.js' | ||
import * as csv from '../lib/index.js'; | ||
|
||
// Run the pipeline | ||
csv | ||
// Generate 20 records | ||
.generate({ | ||
delimiter: '|', | ||
length: 20 | ||
}) | ||
.generate({ | ||
delimiter: '|', | ||
length: 20 | ||
}) | ||
// Transform CSV data into records | ||
.pipe(csv.parse({ | ||
delimiter: '|' | ||
})) | ||
.pipe(csv.parse({ | ||
delimiter: '|' | ||
})) | ||
// Transform each value into uppercase | ||
.pipe(csv.transform((record) => { | ||
return record.map((value) => { | ||
return value.toUpperCase() | ||
}); | ||
})) | ||
.pipe(csv.transform((record) => { | ||
return record.map((value) => { | ||
return value.toUpperCase(); | ||
}); | ||
})) | ||
// Convert objects into a stream | ||
.pipe(csv.stringify({ | ||
quoted: true | ||
})) | ||
.pipe(csv.stringify({ | ||
quoted: true | ||
})) | ||
// Print the CSV stream to stdout | ||
.pipe(process.stdout) | ||
.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
|
||
// Import the package main module | ||
import * as csv from '../lib/index.js' | ||
import * as csv from '../lib/index.js'; | ||
// Use the module | ||
csv.generate ({seed: 1, length: 20}).pipe( | ||
csv.parse ()).pipe( | ||
csv.transform (function(record){ | ||
return record.map(function(value){ | ||
return value.toUpperCase() | ||
})})).pipe( | ||
csv.stringify ()).pipe(process.stdout) | ||
csv.generate ({seed: 1, length: 20}).pipe( | ||
csv.parse ()).pipe( | ||
csv.transform (function(record){ | ||
return record.map(function(value){ | ||
return value.toUpperCase(); | ||
});})).pipe( | ||
csv.stringify ()).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
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