npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yuanqing/google-sheets

v0.0.2

Published

An easier interface to read from and write to Google Sheets

Downloads

11

Readme

@yuanqing/google-sheets npm Version Build Status

An easier interface to read from and write to Google Sheets

Quick start

$ yarn add @yuanqing/google-sheets
const { getSpreadsheet } = require('@yuanqing/google-sheets')

async function main () {
  const serviceAccountCredentials = {
    clientEmail: '<client_email>',
    priateKey: '<private_key>'
  }
  const spreadsheetId = '<spreadsheet_id>'
  const sheetName = '<sheet_name>'
  const spreadsheet = await getSpreadsheet(
    serviceAccountCredentials,
    spreadsheetId
  )
  const sheet = await spreadsheet.getSheet(sheetName)
  const rows = await sheet.getAllRows()
  console.log(rows)
}

await main()
  • <client_email> and <private_key> are credentials for a Service Account with edit access to your spreadsheet. See Initial setup.
  • <spreadsheet_id> is the value between /d/ and /edit in your spreadsheet URL.
  • <sheet_name> is the name of the sheet that you want to read from or write to.

Initial setup

  1. Navigate to the Google API Console
  2. Select a project from the drop-down box in the top bar.
  3. Click Credentials (the Key icon) on the left navigation bar.
  4. Click the Create credentials drop-down box, and select Service account key.
  5. Click the Select… drop-down box, and select New service account. Enter a Service account name. For Role, select Project › Editor.
  6. For Key type, select JSON.
  7. Click the Create button. A JSON file with the Service Account credentials will be generated. Note the client_email and private_key values in the generated JSON file.
  1. Navigate to your spreadsheet.
  2. Click the Share button on the top-right corner of the page.
  3. In the Enter names or email addresses… text box, enter the client_email of the Service Account, then click the Send button.

Assumptions

  1. Data is row-based. Each field is stored on a column.
  2. Row 1 of the sheet contains the headers for the data. “Actual” data starts from Row 2.

Google Sheets

Example spreadsheet

API

const { createSpreadsheet, getSpreadsheet } = require('@yuanqing/google-sheets')

Spreadsheet

const spreadsheet = await createSpreadsheet(serviceAccountCredentials)

Creates a new spreadsheet and returns a Promise for it.

  • serviceAccountCredentials is an object literal with the following keys:

    Key | Description :-|:- clientEmail | Email address of the Service Account that has edit access to the spreadsheet. privateKey | Private key of the Service Account.

const spreadsheet = await getSpreadsheet(serviceAccountCredentials, spreadsheetId)

Returns a Promise for an existing spreadsheet.

  • spreadsheetId is the value between /d/ and /edit in the spreadsheet URL.

const sheet = await spreadsheet.createSheet(spreadsheetName, headers)

Creates a new sheet and returns a Promise for it.

  • spreadsheetName is the name of the new sheet.
  • headers is an array of headers for the new sheet.

const sheet = await spreadsheet.getSheet(spreadsheetName)

Returns a Promise for an existing sheet.

Sheet

const rows = await sheet.getAllRows()

Returns a Promise for an array containing all the rows from the sheet.

const rows = await sheet.getRowsByRange(m, n)

Returns a Promise for an array containing rows from the row m to row n of the sheet.

await sheet.addRows(rows)

Appends the given array of rows to the sheet, and returns a Promise that resolves.

Installation

$ yarn add @yuanqing/google-sheets

License

MIT