1 | import {ArrayCsvStringifier} from './csv-stringifiers/array';
|
2 | import {createFieldStringifier} from './field-stringifier';
|
3 | import {ObjectCsvStringifier} from './csv-stringifiers/object';
|
4 | import {ObjectStringifierHeader} from './record';
|
5 |
|
6 | export interface ArrayCsvStringifierParams {
|
7 | header?: string[];
|
8 | fieldDelimiter?: string;
|
9 | recordDelimiter?: string;
|
10 | alwaysQuote?: boolean;
|
11 | }
|
12 |
|
13 | export interface ObjectCsvStringifierParams {
|
14 | header: ObjectStringifierHeader;
|
15 | fieldDelimiter?: string;
|
16 | recordDelimiter?: string;
|
17 | headerIdDelimiter?: string;
|
18 | alwaysQuote?: boolean;
|
19 | }
|
20 |
|
21 | export class CsvStringifierFactory {
|
22 |
|
23 | createArrayCsvStringifier(params: ArrayCsvStringifierParams) {
|
24 | const fieldStringifier = createFieldStringifier(params.fieldDelimiter, params.alwaysQuote);
|
25 | return new ArrayCsvStringifier(fieldStringifier, params.recordDelimiter, params.header);
|
26 | }
|
27 |
|
28 | createObjectCsvStringifier(params: ObjectCsvStringifierParams) {
|
29 | const fieldStringifier = createFieldStringifier(params.fieldDelimiter, params.alwaysQuote);
|
30 | return new ObjectCsvStringifier(fieldStringifier, params.header, params.recordDelimiter, params.headerIdDelimiter);
|
31 | }
|
32 |
|
33 | }
|