From 8bc60d4de59ef475240509c96e5f1b181702f29f Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 01:11:47 +0800 Subject: [PATCH 1/7] add node-xlsx .d.ts --- types/node-xlsx/index.d.ts | 31 ++++++++++++++++++++++++++++++ types/node-xlsx/node-xlsx-tests.ts | 8 ++++++++ types/node-xlsx/tsconfig.json | 22 +++++++++++++++++++++ types/node-xlsx/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/node-xlsx/index.d.ts create mode 100644 types/node-xlsx/node-xlsx-tests.ts create mode 100644 types/node-xlsx/tsconfig.json create mode 100644 types/node-xlsx/tslint.json diff --git a/types/node-xlsx/index.d.ts b/types/node-xlsx/index.d.ts new file mode 100644 index 0000000000..6840f90592 --- /dev/null +++ b/types/node-xlsx/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for node-xlsx 0.12 +// Project: https://github.com/mgcrea/node-xlsx#readme +// Definitions by: chenc +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * parsing a xlsx from file/buffer, outputs an object of worksheets + * @param mixed file or buffer + * @param options options is for xlsx + * @returns worksheets data, like: [{ name, data: [] }] + */ +export declare function parse( + mixed: any, + options?: {} + ): { + name: string; + data: {}[]; + }[]; + + /** + * building a xlsx + * @param worksheets worksheets data, like:[[1,2,3],['1', '2','word']] + * @param options spannig multiple rows A1:A4 + * @returns returns a buffer of worksheets + */ + export declare function build(worksheets: any, options?: {}): any; + declare const _default: { + parse: typeof parse; + build: typeof build; + }; + export default _default; diff --git a/types/node-xlsx/node-xlsx-tests.ts b/types/node-xlsx/node-xlsx-tests.ts new file mode 100644 index 0000000000..f9dffcad47 --- /dev/null +++ b/types/node-xlsx/node-xlsx-tests.ts @@ -0,0 +1,8 @@ +import { build } from 'node-xlsx'; +const data = [ + [1, 2, 3], + [true, false, null, 'sheetjs'], + ['foo', 'bar', new Date('2014-02-19T14:30Z'), '0.3'], + ['baz', null, 'qux'], +]; +const buffer = build([{ name: 'mySheetName', data }]); diff --git a/types/node-xlsx/tsconfig.json b/types/node-xlsx/tsconfig.json new file mode 100644 index 0000000000..355898caaf --- /dev/null +++ b/types/node-xlsx/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-xlsx-tests.ts" + ] +} diff --git a/types/node-xlsx/tslint.json b/types/node-xlsx/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/node-xlsx/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 75a42d225ed54157a90278e62359501ed68792ec Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 01:52:47 +0800 Subject: [PATCH 2/7] change tsconfig.js --- types/node-xlsx/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/node-xlsx/tsconfig.json b/types/node-xlsx/tsconfig.json index 355898caaf..168c454276 100644 --- a/types/node-xlsx/tsconfig.json +++ b/types/node-xlsx/tsconfig.json @@ -13,7 +13,8 @@ ], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": false }, "files": [ "index.d.ts", From 517fcb3e2d464ac7961007988b6bffcce5686779 Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 01:55:07 +0800 Subject: [PATCH 3/7] Use 'Array' to instead T[] --- types/node-xlsx/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/node-xlsx/index.d.ts b/types/node-xlsx/index.d.ts index 6840f90592..9f447202bf 100644 --- a/types/node-xlsx/index.d.ts +++ b/types/node-xlsx/index.d.ts @@ -12,10 +12,10 @@ export declare function parse( mixed: any, options?: {} - ): { + ): Array<{ name: string; data: {}[]; - }[]; + }>; /** * building a xlsx From bfc5ff013be07248bd779ad4b04542a965e1b0d9 Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 01:59:30 +0800 Subject: [PATCH 4/7] fix lint error --- types/node-xlsx/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/node-xlsx/index.d.ts b/types/node-xlsx/index.d.ts index 9f447202bf..1262be153b 100644 --- a/types/node-xlsx/index.d.ts +++ b/types/node-xlsx/index.d.ts @@ -2,19 +2,20 @@ // Project: https://github.com/mgcrea/node-xlsx#readme // Definitions by: chenc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 /** * parsing a xlsx from file/buffer, outputs an object of worksheets * @param mixed file or buffer * @param options options is for xlsx - * @returns worksheets data, like: [{ name, data: [] }] + * @returns worksheets data, like: [{ name, data: [[]] }] */ export declare function parse( mixed: any, options?: {} ): Array<{ name: string; - data: {}[]; + data: Array<[]>; }>; /** From 61b4e9d8537c8baaccf6c6100f4e2843dee0d3d2 Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 02:06:01 +0800 Subject: [PATCH 5/7] set strictFunctionTypes to true --- types/node-xlsx/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node-xlsx/tsconfig.json b/types/node-xlsx/tsconfig.json index 168c454276..915d266284 100644 --- a/types/node-xlsx/tsconfig.json +++ b/types/node-xlsx/tsconfig.json @@ -14,7 +14,7 @@ "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true, - "strictFunctionTypes": false + "strictFunctionTypes": true }, "files": [ "index.d.ts", From f6d46c5dac36366f90e3ca7e199f0bd2214070ad Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 02:23:24 +0800 Subject: [PATCH 6/7] Add comments and improve return values --- types/node-xlsx/index.d.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/types/node-xlsx/index.d.ts b/types/node-xlsx/index.d.ts index 1262be153b..45c1173be3 100644 --- a/types/node-xlsx/index.d.ts +++ b/types/node-xlsx/index.d.ts @@ -6,27 +6,30 @@ /** * parsing a xlsx from file/buffer, outputs an object of worksheets - * @param mixed file or buffer + * @param mixed file path or buffer * @param options options is for xlsx - * @returns worksheets data, like: [{ name, data: [[]] }] + * @returns worksheets data, like: { name: 'worksheets', data: [[1,2,3],['1', '2','word']] } */ export declare function parse( - mixed: any, + mixed: string | ArrayBuffer, options?: {} - ): Array<{ +): Array<{ name: string; data: Array<[]>; - }>; +}>; - /** - * building a xlsx - * @param worksheets worksheets data, like:[[1,2,3],['1', '2','word']] - * @param options spannig multiple rows A1:A4 - * @returns returns a buffer of worksheets - */ - export declare function build(worksheets: any, options?: {}): any; - declare const _default: { +/** + * building a xlsx + * @param worksheets worksheets data, like:{ name: 'worksheets', data: [[1,2,3],['1', '2','word']] } + * @param options spannig multiple rows A1:A4 + * @returns returns a buffer of worksheets + */ +export declare function build( + worksheets: Array<{ name: string; data: Array }>, + options?: {} +): ArrayBuffer; +declare const _default: { parse: typeof parse; build: typeof build; - }; - export default _default; +}; +export default _default; From 1aba60e3f7b2b3209ab6b7fbae7b0ef64d3f76e4 Mon Sep 17 00:00:00 2001 From: chenc Date: Tue, 8 Jan 2019 02:25:35 +0800 Subject: [PATCH 7/7] fix lint err --- types/node-xlsx/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node-xlsx/index.d.ts b/types/node-xlsx/index.d.ts index 45c1173be3..bd500d8a4e 100644 --- a/types/node-xlsx/index.d.ts +++ b/types/node-xlsx/index.d.ts @@ -25,7 +25,7 @@ export declare function parse( * @returns returns a buffer of worksheets */ export declare function build( - worksheets: Array<{ name: string; data: Array }>, + worksheets: Array<{ name: string; data: any[][] }>, options?: {} ): ArrayBuffer; declare const _default: {