bartoszgolebiowski / zod-csv

The library with utils function for validating csv content
MIT License
13 stars 0 forks source link

Option to skip header #1

Closed nerdstep closed 1 year ago

nerdstep commented 1 year ago

@bartoszgolebiowski would it be possible to support an option to skip reading the header?

my current use-case is reading a file stream line by line and wanting to parse each line individually.

nerdstep commented 1 year ago

that said, maybe what I'm really asking for is the ability to parse a file stream... but perhaps that is outside of the scope for what you intend this project to do?

bartoszgolebiowski commented 1 year ago

@nerdstep Streaming is an amazing missing feature for sure, but I am not sure how to do it for both node and browser. This is an interesting implementation of how to split CSV files. I think I would do something similar here. https://github.com/alex-murashkin/csv-split-stream#readme

bartoszgolebiowski commented 1 year ago

Maybe to resolve this issue we should consider adding a new method to check if row is valid against schema. What do you think, is it sufficient for you @nerdstep

nerdstep commented 1 year ago

@bartoszgolebiowski -- I think streaming can be achieved in both node and browser, since the browser also supports a Streams API. The Papa Parse library does this too.

That said, if you wanted to keep this library small and avoid those implementation details, then a row validation method would make sense.

bartoszgolebiowski commented 1 year ago

https://github.com/bartoszgolebiowski/zod-csv/pull/2

This is a draft, I am open to naming, typing, and other suggestions!

bartoszgolebiowski commented 1 year ago

I introduced a new method: https://github.com/bartoszgolebiowski/zod-csv/blob/main/src/csv.ts#L173 Here is some basic usage: https://github.com/bartoszgolebiowski/zod-csv/blob/main/src/csv.test.ts#L390

nerdstep commented 1 year ago

nice work and thanks for the quick turnaround!