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