@resolute/gsheet
Version:
Simple abstractions for Google Sheets
65 lines (64 loc) • 1.82 kB
TypeScript
import type { sheets_v4 } from '@googleapis/sheets';
export type InputTypes = boolean | string | number | null;
export type RowArray = string[];
export type RowObject = {
[key: string]: string;
};
export type InputRowArray = InputTypes[];
export type InputRowObject = {
[key: string]: InputTypes;
};
export type GoogleAuthInput =
| {
email: string;
key: string;
}
| {
client_email: string;
private_key: string;
};
export interface GSheetOptions {
jwt?: GoogleAuthInput;
spreadsheetId: string;
range: string;
http2?: boolean;
preload?: boolean;
interval?: number;
headerRows?: number;
keyTransform?: Gsheet['keyTransform'];
sanitize?: Gsheet['sanitize'];
filter?: Gsheet['filter'];
}
export declare const gSheetDate: (date?: Date) => string;
export declare const gSheetDateTime: (date?: Date) => string;
export declare const trim: <T extends InputTypes>(arg: T) => string | T;
export declare const noChange: (arg: string) => string;
export declare const noFilter: () => boolean;
export declare class Gsheet {
private client;
private auth;
private spreadsheetId;
private range;
private headerRows;
private keyTransform;
private sanitize;
private filter;
private keptSheet;
private keptColumns;
constructor(options: GSheetOptions);
private getSheet;
private getHeaderRowsOnly;
private getColumnsFromSheetCache;
private getColumns;
columns(): Promise<string[]>;
rows(): Promise<string[][]>;
data(): Promise<RowObject[]>;
private normalizeInputData;
append(
arg: InputRowArray | InputRowObject
): Promise<import('gaxios').GaxiosResponse<sheets_v4.Schema$AppendValuesResponse>>;
refresh(): void;
keepFresh(interval: number): void;
}
export declare const gsheet: (options: GSheetOptions) => Gsheet;
export default gsheet;