Skip to content

Commit 60efa78

Browse files
authored
fix(csv-stringify): update TS types to allow cast to return an object (#339)
1 parent 23f6260 commit 60efa78

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ import * as stream from "stream";
44

55
export type Callback = (err: Error | undefined, output: string) => void
66
export type RecordDelimiter = string | Buffer | 'auto' | 'unix' | 'mac' | 'windows' | 'ascii' | 'unicode'
7-
export type Cast<T> = (value: T, context: CastingContext) => string
7+
8+
export type CastReturnObject = { value: string } & Pick<
9+
Options,
10+
| 'delimiter'
11+
| 'escape'
12+
| 'quote'
13+
| 'quoted'
14+
| 'quoted_empty'
15+
| 'quoted_string'
16+
| 'quoted_match'
17+
| 'record_delimiter'
18+
>
19+
20+
export type Cast<T> = (
21+
value: T,
22+
context: CastingContext
23+
) => string | CastReturnObject;
24+
825
export type PlainObject<T> = Record<string, T>
926
export type Input = any[]
1027
export interface ColumnOption {

packages/csv-stringify/test/api.types.sync.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ describe('API Types', () => {
3737
}
3838
return options
3939
})
40+
41+
it('allows cast to return an object', () => {
42+
const options: Options = {
43+
cast: {
44+
boolean: (value: boolean) => ({
45+
value: value.toString(),
46+
delimiter: ';',
47+
quote: false
48+
})
49+
}
50+
}
51+
})
4052

4153
})

0 commit comments

Comments
 (0)