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

@financial-times/sheet-reader

v2.0.1

Published

![Node.js CI](https://github.com/Financial-Times/dj-sheet-reader/workflows/Node.js%20CI/badge.svg)

Downloads

6

Readme

dj-sheet-reader

Node.js CI

Provides the core spreadsheet processing functionality inside Bertha.

What does it do?

  • Fetches data from a google spreadsheet
  • transforms all the cells values to types (eg booleans, numbers and arrays)
  • outputs the result as an object.

Bertha wraps this functionality into a service, providing also a cache and a background queue for that helps managing large spreadsheets and frequent edits.

Installation

$ npm install @financial-times/sheet-reader

Usage

First, you'll need a Google API Service Account email and key. A service account reads/writes data from the Google API on behalf of a Google user/email. See the auth configuration options below.

const SheetReader = require('@financial-times/sheet-reader')

const auth = {
	key: process.env.KEY,
	email: process.env.EMAIL,
	subject: process.env.SUBJECT,
	scopes: ['https://www.googleapis.com/auth/example.scope'],
}

const spreadsheetId = '__your__sheet__id__'
const sheetNames = ['Sheet1', '+my Optional Sheet']

const data = await SheetReader({ auth }).fetchSheet(spreadsheetId, sheetNames)

process.stdout.write(JSON.stringify(data))

API

SheetReader(options: object):SheetReaderInstance

options:

  • auth.email: is the Email/ID of the service account. It looks like 367017482409-ki8573gid665t1ee2m8t2omwvj3dbt2mj@developer.gserviceaccount.com
  • auth.key: is a key that's generated for the service account that's used authenticate with the Google API
  • auth.subject: a Google Email account (e.g a person or email group) who is the subject of the API request and is used for authorisation. This package will be making requests to the Google API on behalf of this user and can only fetch data for a spreadsheet when the subject has read access.
  • auth.scopes: An optional array of scopes that have been setup for the key when connecting to the Spreadsheet API in Google Cloud console . The default scopes (show below) are the most common configuation.
scopes: [
	'https://www.googleapis.com/auth/drive.readonly',
	'https://www.googleapis.com/auth/spreadsheets.readonly'
],

fetchSheet(spreadsheetId: string, sheetNames: string[], options: object):Promise<object>

  • spreadsheetId: The ID of the Google Spreadsheet
  • sheetNames: An array of sheet names (as they appear on the tabbed sheets)
    • It's possible for sheets to be optional
  • options
    • reserved for future use.

fetchSheetWithCallback(spreadsheetId: string, sheetNames: string[], options: object, callback: Function(error, data)):SheetReaderInstance

Same as fetchSheet but uses the older callback pattern, rather than returning a promise.

SheetReader({ auth }).fetchSheet(spreadsheetId, sheetNames, {}, function (error, data) {
	if (error) {
		console.error(error)
		return
	}
	process.stdout.write(JSON.stringify(data))
})

refreshAuth():void

Refreshes the JWT token in case it's expired.

Licence

This software is published by the Financial Times under the MIT licence.