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

simple-sheets-writer

v2.0.4

Published

Provides a simple, promise-based API for writing Google Sheets data.

Downloads

5

Readme

Simple Sheets Writer

This package is deprecated in favor of simple-sheets, which combines this with the simple-sheets-reader API

Writes Google Sheets data, perfect for sheets populated by Google Forms. This is a wrapper for the very powerful-yet-overwhelming official Sheets API.

Authenticates via a Google Service Account by passing in the client_email and private_key values provided by the .json file that Google Service Accounts generate. See service-account-credentials.json for an example.

API

simple-sheets-writer exports an object with two functions, updateRows and addRows. updateRows takes the following arguments:

updateRows(data, options).then();

data is an array of objects, following the following format:

[{
    range: "A2:A",
    values: [
        ["A"],
        ["B"]
    ]
}]

options include:

  • spreadsheetId (required): The ID of the Google sheet, which is the long string in the URL of the page
  • clientEmail (required): The authorized client_email for your service account (remember to add permissions for this email to your sheet!)
  • privateKey (required): the authorized private_key for your service account
  • valueInputOption: Whether input should be taken literally ("RAW"), or as if a user entered them ("USER_ENTERED", default)

It returns a count of modified rows:

{
    updatedRows: 1
}

addRows has the following parameters:

addRows(range, data, options);

range is an A1 range (eg "A2:A") that will be searched to find something table-like to append to the end of.

data is an array of arrays of values to add:

[
    ["column 1", "column 2"],
    ["column 1", "column 2"]
]

options include:

  • spreadsheetId (required): The ID of the Google sheet, which is the long string in the URL of the page
  • clientEmail (required): The authorized client_email for your service account (remember to add permissions for this email to your sheet!)
  • privateKey (required): the authorized private_key for your service account
  • valueInputOption: Whether input should be taken literally ("RAW"), or as if a user entered them ("USER_ENTERED", default)

It returns an object with the count of modified rows:

{
    updatedRows: 1
}

Usage

const {updateRows, addRows} = require("simple-sheets-writer");

updateRows([{
    range: "A2:A",
    values: [["A"], ["B"]]
},{
    range: "Users!A2:B",
    values: [["C", "D"], ["E", "F"]]
}], {
    spreadsheetId: "9wLECuzvVpx8z7Ux5_9if_wdTDwhxXRcJZpJ-xhVeJRs",
    clientEmail: "[email protected]",
    privateKey: PRIVATE_KEY
}).then(console.log) // {updatedRows: 4}
.catch(console.error);

addRows("'Form Responses'!A2:B", [
    ["column 1", "column 2"],
    ["column 1", "column 2"]
], {
    spreadsheetId: "9wLECuzvVpx8z7Ux5_9if_wdTDwhxXRcJZpJ-xhVeJRs",
    clientEmail: "[email protected]",
    privateKey: PRIVATE_KEY
}).then(console.log) // {updatedRows: 2}
.catch(console.error);

Look at the Google Sheets batchUpdate API Docs and the Google Sheets append API Docs for more information.

Tests

npm test

Upgrading to 2.0

  • Credentials need to be passed in, rather than read from the environment