UNPKG

1.21 kBPlain TextView Raw
1import {ArrayCsvStringifier} from './csv-stringifiers/array';
2import {createFieldStringifier} from './field-stringifier';
3import {ObjectCsvStringifier} from './csv-stringifiers/object';
4import {ObjectStringifierHeader} from './record';
5
6export interface ArrayCsvStringifierParams {
7 header?: string[];
8 fieldDelimiter?: string;
9 recordDelimiter?: string;
10 alwaysQuote?: boolean;
11}
12
13export interface ObjectCsvStringifierParams {
14 header: ObjectStringifierHeader;
15 fieldDelimiter?: string;
16 recordDelimiter?: string;
17 headerIdDelimiter?: string;
18 alwaysQuote?: boolean;
19}
20
21export 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}