Skip to content

Commit

Permalink
CLI: add option --split for CSV input
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Dec 13, 2024
1 parent b978031 commit ec2e314
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

# 0.6.8 - 2024-12-13

- CLI: add option --split for CSV input

# 0.6.7 - 2024-06-06

- Extend HTML display
Expand Down
3 changes: 2 additions & 1 deletion bin/avram.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ cli.usage("avram [options] [validation options] <schema> [<files...>]")
.option("-p, --print print all input records (in JSON)")
.option("-v, --verbose verbose error messages")
.option("-l, --list list supported validation options")
.option("--nullSequence [string] ignore fields with this value in CSV")
.option("--nullSequence [string] ignore fields with this value (CSV only)")
.option("--split [string] split values into lists (CSV only)")
.details(details)
.action(async (args, opt) => {
if (opt.list) {
Expand Down
7 changes: 6 additions & 1 deletion lib/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ const plugins = {
},
"csv-parser": module => {
formats.csv = {
stream(input, options) {
stream(input, options) {
const splitValues = options.split === undefined ? record => record :
(record, delimiter) => record.map(field =>
field.value.split(delimiter).map(value => ({ tag: field.tag, value })),
).flat()
return input.pipe(module.default())
.pipe(recordTransform(Record.fromObject,options))
.pipe(recordTransform(splitValues,options.split))
},
pattern: /\.csv$/,
family: "flat",
Expand Down

0 comments on commit ec2e314

Please sign in to comment.