1 |
|
2 | import { Readable, TransformOptions } from "stream";
|
3 |
|
4 | import JSON2CSVParser = require("./JSON2CSVParser");
|
5 | import JSON2CSVAsyncParser = require("./JSON2CSVAsyncParser");
|
6 | import JSON2CSVTransform = require("./JSON2CSVTransform");
|
7 | import flatten = require("./transforms/flatten");
|
8 | import unwind = require("./transforms/unwind");
|
9 |
|
10 | export as namespace json2csv;
|
11 |
|
12 | export { JSON2CSVAsyncParser as AsyncParser, JSON2CSVParser as Parser, JSON2CSVTransform as Transform };
|
13 |
|
14 |
|
15 | export function parse<T>(data: Readonly<T> | readonly T[], opts?: json2csv.Options<T>): string;
|
16 |
|
17 | export function parseAsync<T>(
|
18 | data: Readonly<T> | readonly T[] | Readable,
|
19 | opts?: json2csv.Options<T>,
|
20 | transformOpts?: TransformOptions,
|
21 | ): Promise<string>;
|
22 |
|
23 | export const transforms: {
|
24 | flatten: typeof flatten;
|
25 | unwind: typeof unwind;
|
26 | };
|
27 |
|
28 | export interface FieldValueCallbackInfo {
|
29 | label: string;
|
30 | default?: string | undefined;
|
31 | }
|
32 |
|
33 | export type FieldValueCallback<T> = FieldValueCallbackWithoutField<T> | FieldValueCallbackWithField<T>;
|
34 |
|
35 | export interface FieldValueCallbackWithoutField<T> {
|
36 | (row: T): any;
|
37 | }
|
38 |
|
39 | export interface FieldValueCallbackWithField<T> {
|
40 | (row: T, field: FieldValueCallbackInfo): any;
|
41 | }
|
42 |
|
43 | export interface FieldInfo<T> {
|
44 | label?: string | undefined;
|
45 | default?: string | undefined;
|
46 | value: string | FieldValueCallback<T>;
|
47 | }
|
48 |
|
49 | export interface NormalizedFieldInfo<T> {
|
50 | label: string;
|
51 | value: FieldValueCallback<T>;
|
52 | }
|
53 |
|
54 | export interface Options<T> {
|
55 | fields?: Array<string | FieldInfo<T>> | undefined;
|
56 | ndjson?: boolean | undefined;
|
57 | defaultValue?: string | undefined;
|
58 | quote?: string | undefined;
|
59 | escapedQuote?: string | undefined;
|
60 | delimiter?: string | undefined;
|
61 | eol?: string | undefined;
|
62 | excelStrings?: boolean | undefined;
|
63 | header?: boolean | undefined;
|
64 | includeEmptyRows?: boolean | undefined;
|
65 | withBOM?: boolean | undefined;
|
66 | transforms?: Array<Json2CsvTransform<any, any>> | undefined;
|
67 | }
|
68 |
|
69 | export interface FlattenOptions {
|
70 | objects?: boolean | undefined;
|
71 | arrays?: boolean | undefined;
|
72 | separator?: string | undefined;
|
73 | }
|
74 |
|
75 | export type Json2CsvTransform<T1, T2> = (item: T1) => T2 | T2[];
|
76 |
|
77 | export interface UnwindOptions {
|
78 | paths?: string[] | undefined;
|
79 | blankOut?: boolean | undefined;
|
80 | }
|