diff --git a/types/gsheets/gsheets-tests.ts b/types/gsheets/gsheets-tests.ts new file mode 100644 index 0000000000..1f6d2dcf17 --- /dev/null +++ b/types/gsheets/gsheets-tests.ts @@ -0,0 +1,5 @@ +import * as gsheets from 'gsheets'; + +gsheets.getSpreadsheet(''); // $ExpectType Promise +gsheets.getWorksheet('', ''); // $ExpectType Promise +gsheets.getWorksheetById('', ''); // $ExpectType Promise diff --git a/types/gsheets/index.d.ts b/types/gsheets/index.d.ts new file mode 100644 index 0000000000..9da40ed1fa --- /dev/null +++ b/types/gsheets/index.d.ts @@ -0,0 +1,122 @@ +// Type definitions for gsheets 2.0 +// Project: https://github.com/interactivethings/gsheets +// Definitions by: Kyle Nazario +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/* + * - Numeric cells are converted to numbers + * - Empty cells are converted to `null` + * - Beware of cells formatted as dates! Their values will be returned as Excel-style + * [DATEVALUE](http://office.microsoft.com/en-001/excel-help/datevalue-function-HP010062284.aspx) numbers (i.e. + * based on the number of days since January 1, 1900) + */ +export interface Row { + [headerColName: string]: string | number | null; +} + +/* + * - Empty rows are omitted + * - `updated` is an ISO-formatted date string + */ +export interface Worksheet { + updated: string; + title: string; + data: Row[] | null; +} + +/* + * - Empty rows are omitted + * - `updated` is an ISO-formatted date string + */ +export interface WorksheetFromId extends Worksheet { + data: Row[]; +} + +/* + * - `updated` is an ISO-formatted date string + */ +export interface Spreadsheet { + updated: string; + title: string; + worksheets: Array<{ + id: string; + title: string; + }>; +} + +/* + * Returns the contents of a worksheet, specified by its title. Note that this generates + * **two** requests (to resolve a worksheet's title). If you know a worksheet's ID (e.g. via a previous call to + * `getSpreadsheet`), use `getWorksheetById`. + * + * For empty worksheets `data` is `null`. + * + * --- + * + * Example response: + * + * ``` + * { + * "updated": "2014-11-19T10:20:18.068Z", + * "title": "foobar", + * "data": [ + * { + * "foo": "bar", + * "baz": 42, + * "boing": null + * }, + * // more rows ... + * ] + * } + * ``` + */ +export function getWorksheet(spreadsheetId: string, worksheetTitle: string): Promise; + +/* + * Returns the contents of a worksheet, specified by its ID. + * + * For empty worksheets `data` is `[]`. + * + * --- + * + * Example response: + * + * ``` + * { + * "updated": "2014-11-19T10:20:18.068Z", + * "title": "foobar", + * "data": [ + * { + * "foo": "bar", + * "baz": 42, + * "boing": null + * }, + * // more rows ... + * ] + * } + * ``` + */ +export function getWorksheetById(spreadsheetId: string, worksheetId: string): Promise; + +/* + * Returns information about a spreadsheet including a list of worksheets. + * + * --- + * + * Example response: + * + * ``` + * { + * "updated": "2014-11-19T10:20:18.068Z", + * "title": "My Awesome Spreadsheet", + * "worksheets": [ + * { + * "id": "od6", + * "title": "foobar" + * }, + * // more worksheets ... + * ] + * } + * ``` + */ +export function getSpreadsheet(spreadsheetId: string): Promise; diff --git a/types/gsheets/tsconfig.json b/types/gsheets/tsconfig.json new file mode 100644 index 0000000000..9b08376173 --- /dev/null +++ b/types/gsheets/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "gsheets-tests.ts" + ] +} diff --git a/types/gsheets/tslint.json b/types/gsheets/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/gsheets/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }