adaltas / node-csv

Full featured CSV parser with simple api and tested against large datasets.
https://csv.js.org
MIT License
4.05k stars 267 forks source link

User-defined value generation #417

Closed itstueben closed 8 months ago

itstueben commented 9 months ago

How to generate user defined values

I'dont find how to add user definded values to the generator. How can i add my own calue gerators some like faker.js?

Please help out. Thx

wdavidw commented 9 months ago

With the column options, maybe this test will help you.

itstueben commented 9 months ago

Thanks for the hint but it seems that is not support (anymore). The Typescript types are not supporting a function in the coulmuns array(see). I use the following code and get the message:

TypeError [ERR_INVALID_ARG_TYPE]: The "buf" argument must be an instance of Buffer, TypedArray, or DataView. Received an instance of Array

 generate({
        columns: [() => 'mydata'],
        encoding: 'utf-8',
        objectMode: true,
        length: args.count,
      }).pipe(process.stdout);

if i ignore typescript errors and use "objectMode:false" this will run as aspected.

wdavidw commented 9 months ago

Please reproduce and share a full sample with minimal code. I will enrich the tests and update the definition file accordingly.

itstueben commented 9 months ago

i have a mini sample repo here

In the Typescript File the types are wrong. I hope this helps what is wrong with the types

wdavidw commented 8 months ago

Version 4.4.0 hopefully fixes your issue.