Type file and tests for gsheets (#44035)

This commit is contained in:
Kyle Nazario 2020-04-27 06:46:23 -06:00 committed by GitHub
parent 00e2f3a579
commit 9c865209c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,5 @@
import * as gsheets from 'gsheets';
gsheets.getSpreadsheet(''); // $ExpectType Promise<Spreadsheet>
gsheets.getWorksheet('', ''); // $ExpectType Promise<Worksheet>
gsheets.getWorksheetById('', ''); // $ExpectType Promise<WorksheetFromId>

122
types/gsheets/index.d.ts vendored Normal file
View File

@ -0,0 +1,122 @@
// Type definitions for gsheets 2.0
// Project: https://github.com/interactivethings/gsheets
// Definitions by: Kyle Nazario <https://github.com/kyle-n>
// 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<Worksheet>;
/*
* 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<WorksheetFromId>;
/*
* 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<Spreadsheet>;

View File

@ -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"
]
}

View File

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