[jsonexport] Add new definition for jsonexport (#47678)

* Add jsonexport

* Remove esModuleInterop config for backward compatibility
This commit is contained in:
Guillaume Ongenae 2020-09-17 18:08:39 +02:00 committed by GitHub
parent 252becaa9f
commit 4923c0dc8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 0 deletions

47
types/jsonexport/index.d.ts vendored Normal file
View File

@ -0,0 +1,47 @@
// Type definitions for jsonexport 3.0
// Project: https://github.com/kaue/jsonexport
// Definitions by: Guillaume Ongenae <https://github.com/g-ongenae>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { Transform } from 'stream';
declare namespace jsonexport {
interface UserOptions {
headers?: string[];
rename?: string[];
headerPathString?: string;
rowDelimiter?: string;
textDelimiter?: string;
arrayPathString?: string;
undefinedString?: string;
endOfLine?: string;
mainPathItem?: string;
booleanTrueString?: string;
booleanFalseString?: string;
includeHeaders?: boolean;
fillGaps?: boolean;
verticalOutput?: boolean;
forceTextDelimiter?: boolean;
}
}
/**
* Main declare function that converts json to csv
*
* @param json - object or array to convert
* @param options - csv options
* @param callback(err, csv) - Callback declare function
* if error, returning error in call back.
* if csv is created successfully, returning csv output to callback.
*/
declare function jsonexport(userOptions?: jsonexport.UserOptions): Transform;
declare function jsonexport(json: object | object[], userOptions?: jsonexport.UserOptions): Promise<string>;
declare function jsonexport(json: object | object[], cb: (err: Error, csv: string) => void): void;
declare function jsonexport(
json: object | object[],
userOptions: jsonexport.UserOptions,
cb: (err: Error, csv: string) => void,
): void;
export = jsonexport;

View File

@ -0,0 +1,18 @@
import jsonexport = require('jsonexport');
import { Transform } from 'stream';
// No user options
const a: Transform = jsonexport();
const b: Promise<string> = jsonexport({ key: 'value' });
// $ExpectType void
jsonexport({ key: 'value' }, (err: Error, csv: string) => undefined);
// With user options
const userOptions: jsonexport.UserOptions = {
textDelimiter: ';',
};
const c: Transform = jsonexport(userOptions);
const d: Promise<string> = jsonexport({ key: 'value' }, userOptions);
// $ExpectType void
jsonexport({ key: 'value' }, userOptions, (err: Error, csv: string) => undefined);

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "jsonexport-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }