Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Expose columns in info object #317

Open
moroine opened this issue Apr 21, 2021 · 3 comments
Open

Expose columns in info object #317

moroine opened this issue Apr 21, 2021 · 3 comments

Comments

@moroine
Copy link

moroine commented Apr 21, 2021

Is your feature request related to a problem? Please describe.

When using column: true option, we need to get the columns and it would be useful to have them as part as info object.

Describe the solution you'd like

Currently, I'm doing parser.options.columns because I saw in the code that options.columns is updated when reading the header line.

Thanks for this amazing CSV parser ❤️

@wdavidw
Copy link
Member

wdavidw commented May 20, 2021

I just push a commit which expose columns inside the info/context object with the cast, info and on_record options. I don't wish to enrich state with columns because I am sort of planning to remove state in the next major release and merge its properties inside state.

Could you have a look at #81c5c8798de8d44446f69b210674fd74c7fe3d7a, in particular the test which illustrate its access and let me know if that works for you. If this is the case, I'll release a new minor version.

@moroine
Copy link
Author

moroine commented May 24, 2021

Yeah, that's perfect thanks 👌

@obones
Copy link

obones commented Jun 24, 2021

Thanks for this, it's nice to have.

However, I'm interesting in having the information about columns before starting the for await of loop. Here is what I would like to do:

const parser = sourceStream.pipe(csv_parse({ columns: true, info: true }));
if (expectedColumnsAreFound(parser))
    for await (const {record, info} of parser)
    {
        // process records
    }

Of course, I could move the columns validity test inside the loop, but it would be tested for all records which is a waste of computation time in huge files.
Any suggestion is most welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants