Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 74befad

Browse files
committedMay 13, 2025
docs(csv-parse): on_skip sample
1 parent 987a3a9 commit 74befad

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import assert from "node:assert";
2+
import dedent from "dedent";
3+
import { parse } from "csv-parse";
4+
5+
parse(
6+
dedent`
7+
a,b,c
8+
invalid
9+
d,e,f
10+
`,
11+
{
12+
skip_records_with_error: true,
13+
on_skip: ({ message, code, record }) => {
14+
assert.equal(message, "Invalid Record Length: expect 3, got 1 on line 2");
15+
assert.equal(code, "CSV_RECORD_INCONSISTENT_FIELDS_LENGTH");
16+
assert.deepStrictEqual(record, ["invalid"]);
17+
},
18+
},
19+
function (err, records) {
20+
assert.deepStrictEqual(records, [
21+
["a", "b", "c"],
22+
["d", "e", "f"],
23+
]);
24+
},
25+
);

0 commit comments

Comments
 (0)
Please sign in to comment.