From 4923c0dc8d02e67c25f8d9a25f2087b15f4be4fc Mon Sep 17 00:00:00 2001 From: Guillaume Ongenae Date: Thu, 17 Sep 2020 18:08:39 +0200 Subject: [PATCH] [jsonexport] Add new definition for jsonexport (#47678) * Add jsonexport * Remove esModuleInterop config for backward compatibility --- types/jsonexport/index.d.ts | 47 ++++++++++++++++++++++++++++ types/jsonexport/jsonexport-tests.ts | 18 +++++++++++ types/jsonexport/tsconfig.json | 16 ++++++++++ types/jsonexport/tslint.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 types/jsonexport/index.d.ts create mode 100644 types/jsonexport/jsonexport-tests.ts create mode 100644 types/jsonexport/tsconfig.json create mode 100644 types/jsonexport/tslint.json diff --git a/types/jsonexport/index.d.ts b/types/jsonexport/index.d.ts new file mode 100644 index 0000000000..a760d3a6f9 --- /dev/null +++ b/types/jsonexport/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for jsonexport 3.0 +// Project: https://github.com/kaue/jsonexport +// Definitions by: Guillaume Ongenae +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +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; +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; diff --git a/types/jsonexport/jsonexport-tests.ts b/types/jsonexport/jsonexport-tests.ts new file mode 100644 index 0000000000..8fcd246ba1 --- /dev/null +++ b/types/jsonexport/jsonexport-tests.ts @@ -0,0 +1,18 @@ +import jsonexport = require('jsonexport'); +import { Transform } from 'stream'; + +// No user options +const a: Transform = jsonexport(); +const b: Promise = 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 = jsonexport({ key: 'value' }, userOptions); +// $ExpectType void +jsonexport({ key: 'value' }, userOptions, (err: Error, csv: string) => undefined); diff --git a/types/jsonexport/tsconfig.json b/types/jsonexport/tsconfig.json new file mode 100644 index 0000000000..830bb4312b --- /dev/null +++ b/types/jsonexport/tsconfig.json @@ -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"] +} diff --git a/types/jsonexport/tslint.json b/types/jsonexport/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/jsonexport/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }