Skip to content

Commit 9aeec33

Browse files
authored
Merge pull request #107 from GabrielCastro/feat/typescript-typings
feat: Add typescript typings
2 parents 94aa267 + e3cf14f commit 9aeec33

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"csv2json": "./bin/csv2json.js"
1919
},
2020
"main": "./src/converter.js",
21+
"types": "./src/converter.d.ts",
2122
"scripts": {
2223
"test": "./node_modules/.bin/mocha test/tests.js",
2324
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -R spec",

src/converter.d.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export interface ReadOptions {
2+
/**
3+
* Specifies the different types of delimiters
4+
*/
5+
delimiter?: {
6+
/** @default ',' */
7+
field?: string;
8+
/** @default '"' */
9+
wrap?: string;
10+
/** @default '\n' */
11+
eol?: string;
12+
};
13+
14+
/**
15+
* Should a unicode character be prepended to allow Excel to open
16+
* a UTF-8 encoded file with non-ASCII characters present
17+
* @default false
18+
*/
19+
excelBOM?: boolean;
20+
/**
21+
* Specify the keys (as strings) that should be converted
22+
*
23+
* * If you have a nested object (ie. {info : {name: 'Mike'}}), then set this to ['info.name']
24+
* * If you want all keys to be converted, then specify null or don't specify the option to utilize the default.
25+
*/
26+
keys?: string[];
27+
/**
28+
* Should the header fields be trimmed
29+
* @default false
30+
*/
31+
trimHeaderFields?: boolean;
32+
/**
33+
* Should the field values be trimmed? (in development)
34+
* @default false
35+
*/
36+
trimFieldValues?: boolean;
37+
}
38+
39+
export interface WriteOptions extends ReadOptions {
40+
/**
41+
* Should all documents have the same schema?
42+
* @default false
43+
*/
44+
checkSchemaDifferences?: boolean;
45+
46+
/**
47+
* Value that, if specified, will be substituted in for field values
48+
* that are undefined, null, or an empty string
49+
*/
50+
emptyFieldValue?: any;
51+
52+
/**
53+
* Should objects in array values be deep-converted to CSV
54+
* @default false
55+
*/
56+
expandArrayObjects?: boolean;
57+
58+
/**
59+
* Should the auto-generated header be prepended as the first line in the CSV
60+
* @default true
61+
*/
62+
prependHeader?: boolean;
63+
/**
64+
* Should the header keys be sorted in alphabetical order
65+
* @default false
66+
*/
67+
sortHeader?: boolean;
68+
69+
}
70+
71+
export function json2csv(data: object[], callback: (err?: Error, csv?: string) => void, options?: WriteOptions): void;
72+
73+
export function json2csvAsync(data: object[], options?: WriteOptions): Promise<string>;
74+
75+
export function csv2json(csv: string, callback: (err?: Error, data?: unknown[]) => void, options?: ReadOptions): void;
76+
77+
export function csv2jsonAsync(csv: string, options?: ReadOptions): Promise<unknown[]>;

0 commit comments

Comments
 (0)