node-csv icon indicating copy to clipboard operation
node-csv copied to clipboard

User-defined value generation

Open itstueben opened this issue 1 year ago • 4 comments

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

itstueben avatar Feb 08 '24 14:02 itstueben

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

wdavidw avatar Feb 08 '24 15:02 wdavidw

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.

itstueben avatar Feb 09 '24 07:02 itstueben

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

wdavidw avatar Feb 09 '24 12:02 wdavidw

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

itstueben avatar Feb 09 '24 14:02 itstueben

Version 4.4.0 hopefully fixes your issue.

wdavidw avatar Feb 27 '24 15:02 wdavidw