/
api.types.sync.ts
53 lines (46 loc) · 1.2 KB
/
api.types.sync.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'should'
import {
stringify,
RecordDelimiter, Cast, PlainObject, Input,
ColumnOption, CastingContext,
Options
} from '../lib/sync.js'
describe('API Types', () => {
it('stringify return string', () => {
const input: Input = [[1,2,3]];
const stringifier: string = stringify(input)
stringifier
})
it('Options', () => {
(options: Options) => {
const rd: RecordDelimiter | undefined = options.record_delimiter
const cast = options.cast
const castBoolean : Cast<boolean> | undefined = cast?.boolean
const columns: readonly string[] | PlainObject<string> | readonly ColumnOption[] | undefined = options.columns
return [
rd, castBoolean, columns
]
}
})
it('CastingContext', () => {
const options: Options = {
cast: {
boolean: (value: boolean, context: CastingContext) => {
return `${value} ${context.index}`
}
}
}
return options
})
it('allows cast to return an object', () => {
const options: Options = {
cast: {
boolean: (value: boolean) => ({
value: value.toString(),
delimiter: ';',
quote: false
})
}
}
})
})