Skip to content

Commit 65f1ace

Browse files
committed
feat(csv-generate): types column option defined as an udf (fix #417)
1 parent 4d61f49 commit 65f1ace

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/csv-generate/lib/index.d.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,24 @@ export class Generator extends stream.Readable {
1111
readonly options: Options;
1212
}
1313

14+
export type ColumnsFunctionArgs = {
15+
options: Options;
16+
state: State;
17+
};
18+
export type ColumnsFunction = (args: ColumnsFunctionArgs) => string;
19+
20+
export type State = {
21+
start_time: number,
22+
fixed_size_buffer: number,
23+
count_written: number,
24+
count_created: number,
25+
}
26+
1427
export interface Options extends stream.ReadableOptions {
1528
/**
1629
* Define the number of generated fields and the generation method.
1730
*/
18-
columns?: number | string[];
31+
columns?: number | (string | ColumnsFunction)[];
1932
/**
2033
* Set the field delimiter.
2134
*/

packages/csv-generate/test/api.types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ describe('API Types', () => {
4848
it('columns', () => {
4949
const options: Options = {}
5050
options.columns = 8
51-
options.columns = ['ascii', 'bool', 'int']
51+
options.columns = [
52+
"ascii",
53+
"bool",
54+
"int",
55+
({ options, state }) => options.delimiter + "ok" + state.start_time,
56+
];
5257
})
5358

5459
it('delimiter', () => {

0 commit comments

Comments
 (0)