Skip to content

Commit

Permalink
feat(csv-generate): types column option defined as an udf (fix #417)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 27, 2024
1 parent 4d61f49 commit 65f1ace
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/csv-generate/lib/index.d.ts
Expand Up @@ -11,11 +11,24 @@ export class Generator extends stream.Readable {
readonly options: Options;
}

export type ColumnsFunctionArgs = {
options: Options;
state: State;
};
export type ColumnsFunction = (args: ColumnsFunctionArgs) => string;

export type State = {
start_time: number,
fixed_size_buffer: number,
count_written: number,
count_created: number,
}

export interface Options extends stream.ReadableOptions {
/**
* Define the number of generated fields and the generation method.
*/
columns?: number | string[];
columns?: number | (string | ColumnsFunction)[];
/**
* Set the field delimiter.
*/
Expand Down
7 changes: 6 additions & 1 deletion packages/csv-generate/test/api.types.ts
Expand Up @@ -48,7 +48,12 @@ describe('API Types', () => {
it('columns', () => {
const options: Options = {}
options.columns = 8
options.columns = ['ascii', 'bool', 'int']
options.columns = [
"ascii",
"bool",
"int",
({ options, state }) => options.delimiter + "ok" + state.start_time,
];
})

it('delimiter', () => {
Expand Down

0 comments on commit 65f1ace

Please sign in to comment.