From 6eed22a050701b5bb174ea4057358af41502a9f1 Mon Sep 17 00:00:00 2001 From: David Worms Date: Sat, 6 Nov 2021 23:18:47 +0100 Subject: [PATCH] docs(csv-parse): to sample --- packages/csv-parse/samples/option.from.js | 9 +++++++-- packages/csv-parse/samples/option.to.js | 24 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 packages/csv-parse/samples/option.to.js diff --git a/packages/csv-parse/samples/option.from.js b/packages/csv-parse/samples/option.from.js index 7b6075cb1..32a127bf5 100644 --- a/packages/csv-parse/samples/option.from.js +++ b/packages/csv-parse/samples/option.from.js @@ -3,16 +3,21 @@ import assert from 'assert'; import { parse } from 'csv-parse'; parse(` -a,b|1,2|3,4 +a,b +1,2 +3,4 +5,6 `.trim(), { columns: true, - record_delimiter: '|', from: 2 }, function(err, records){ assert.deepStrictEqual( records, [{ a: '3', b: '4' + }, { + a: '5', + b: '6' }] ); }); diff --git a/packages/csv-parse/samples/option.to.js b/packages/csv-parse/samples/option.to.js new file mode 100644 index 000000000..9a8c77e47 --- /dev/null +++ b/packages/csv-parse/samples/option.to.js @@ -0,0 +1,24 @@ + +import assert from 'assert'; +import { parse } from 'csv-parse'; + +parse(` +a,b +1,2 +3,4 +5,6 +`.trim(), { + columns: true, + to: 2 +}, function(err, records){ + console.log(err, records) + assert.deepStrictEqual( + records, [{ + a: '1', + b: '2' + }, { + a: '3', + b: '4' + }] + ); +});