# gsheetsts

> Google Apps Script and SheetsAPIv4 wrappers in TypeScript

Latest version **0.3.82** (published 2021-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install gsheetsts
pnpm add gsheetsts
yarn add gsheetsts
bun add gsheetsts
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.82 |
| Published | 2021-06-06 |
| First published | 2018-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 153.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kevin Davis |
| Maintainers | kevincar |
| Keywords | Google, Apps, Script, SheetsAPIv4, TypeScript |

## Links

- npm: https://www.npmjs.com/package/gsheetsts
- Repository: https://github.com/kevincar/GSheetsTS
- Homepage: https://github.com/kevincar/GSheetsTS#readme
- Issues: https://github.com/kevincar/GSheetsTS/issues
- npm.io page: https://npm.io/package/gsheetsts

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.3.82 (latest) — 2021-06-06
- 0.3.81 — 2019-04-25
- 0.3.8 — 2019-04-20
- 0.3.7 — 2019-03-08
- 0.3.6 — 2019-03-03
- 0.3.5 — 2018-07-27
- 0.3.4 — 2018-07-08
- 0.3.32 — 2018-04-28
- 0.3.31 — 2018-04-28
- 0.3.3 — 2018-04-28
- 0.3.22 — 2018-04-28
- 0.3.21 — 2018-04-28
- 0.3.2 — 2018-04-25
- 0.3.1 — 2018-04-24
- 0.3.0 — 2018-04-22
- … 3 more at https://npm.io/package/gsheetsts/versions

## README

[![Build Status](https://travis-ci.org/kevincar/GSheetsTS.svg?branch=master)](https://travis-ci.org/kevincar/GSheetsTS)
[![npm version](https://badge.fury.io/js/gsheetsts.svg)](https://badge.fury.io/js/gsheetsts)

# GSheetsTS

Google Apps Scripts provides two methods for working with and manipulating
data from google spreadsheets:

- SpreadsheetApp
- SheetsAPI

This project merges functionality from both of these interfaces. It also adds
the option to work with data in a spreadsheet as an array of objects rather
than as a two-dimensional array. 

# Usage

```typescript
if(typeof(SheetObject) == 'undefined') {
	eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/kevincar/GSheetsTS/master/index.js').getContentText());
}
```

# Quickstart
 
 Name | Age | Gender
 --- | --- | ---
 Yan | 30 | M 
 Jordan | 25 | F
 Akos | 31 | M
 Natalia | 35 | F
 
1. Each spreadsheet should act as a list of objects Student Table
1. Create your class to model a record in the table
1. Load an array of class objects using the SheetObjectDictionary
1. Do what you want with the data
1. Write it back

```typescript
class Student extends SheetObject {

	name: string;
	age: number;
	gender: number;

	/* 
	 * The constructor is responsible for loading the data
	 * from the spreadsheet into the class. The data parameter
	 * will be an object of a row of data from the spreadsheet.
	 * the key values will match exactly the header values from
	 * the spreadsheet.
	 */
	constructor(data: SheetObjectInstance) {
		super();
		if(!data) return;

		this.name = data["Name"];
		this.age = data["Age"];
		this.gender: data["Gender"];

	}

	/*
	 * the getData method is required for writing data back to the
	 * spreadsheet after modifying data in the class object. The 
	 * key values of the returned object must match the column headers
	 * of the spreadsheet.
	 */
	getData(): SheetObjectInterface {
		return {
			"Name": this.name,
			"Age": this.age,
			"Gender": this.gender
		};
	}

	/*
	 * You can also add a validate function that determiens if the given
	 * row data should be supplied as an object. By Default, empty rows 
	 * are defined as invalid souch that you will not receive an array
	 * of empty objects if all you have is a row header.
	 */
	 validate(data: SheetObjectInstance): boolean {
	 	return true;
	 }
	
}
```

The SheetObjectDictionary class is responsible for taking your sheet and
object and giving back an array of class objects.

```TypeScript
// Get an instance of our google spreadsheet.
// This encapsulates GAS SpreadsheetApp.Spreadsheet
// as well ass SheetAPIv4.Spreadsheets
let spreadsheet: Spreadsheet = new Spreadsheet();

// We give the sheet constructor the name of the sheet
// we are refering to and the spreadsheet that owns it
let sheet: Sheet = new Sheet(spreadsheet, "Students");

// we create our dictionary by telling it what type of
// class objects it should associate with which sheet
let dict = new SheetObjectDictionary(Student, sheet);

let students: Student[] = dict.translate();

// Write them back to the spreadsheet
dict.write(students);
```

---
_Source: https://npm.io/package/gsheetsts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
