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

spreadsheet2json

v0.3.3

Published

Converts spreadsheet to JSON with validation, it is easy and fast. You just need to specify `client_id`, `client_secret` and `spreadsheet_id`.

Downloads

14

Readme

spreadsheet2json

Converts spreadsheet to JSON with validation, it is easy and fast. You just need to specify client_id, client_secret and spreadsheet_id.

Usage

$ npm i spreadsheet2json
const Spreadsheet = require('spreadsheet2json');

const tokenpath = '<token path>';

// configuration
const config = {
  client_id: '<client id>',
  client_secret: '<client secret>',
  scope: ['https://spreadsheets.google.com/feeds'],
  redirect_url: '<reidrect url>',
  port: '<port>',
  token: fs.existsSync(tokenpath) && require(tokenpath),
};
Spreadsheet.configure(config);

// define title, validation and first line of data
const spreadsheet = new Spreadsheet({ spreadsheet_id: '<spreadsheet id>' })
  .defineTitle(1)
  .defineValidation(2)
  .defineFirstData(3);

if (!config.token) {
  const token = await spreadsheet.authorize();
  fs.writeFileSync(tokenpath, JSON.stringify(token));
}

// get all sheets
const sheetMap = await spreadsheet.getSheetMap();

// get a sheet
const sheet = await spreadsheet.getSheet('<sheet name>');

// get speficied sheets
const sheetMap = await spreadsheet.getSheetMap(['sheet1', 'sheet3']);

Example

First, you need to create a Spreadsheet on Google Drive. If You define like this table, it will convert to JSON as below.

|ID|Name|Type|Order| |---|---|---|---| |int|string|string|int| |1|test1|test_type_1|1| |2|test2|test_type_1|2| |3|test3|test_type_1|3| |4|test4|test_type_2|4|

// generated json
[
  {
    "ID": 1,
    "Name": "test1",
    "Type": "test_type_1",
    "Order": 1
  },
  {
    "ID": 2,
    "Name": "test2",
    "Type": "test_type_1",
    "Order": 2
  },
  {
    "ID": 3,
    "Name": "test2",
    "Type": "test_type_1",
    "Order": 3 },
  {
    "ID": 4,
    "Name": "test4",
    "Type": "test_type_1",
    "Order": 4
  }
]

APIs

Spreadsheet.configure({ client_id, client_secret, [scope], [redirect_url], [port], [token] })

Spreadsheet.defineTitle([line=1], { [vartical=false], [sort=false] })

The defined line will be used for object keys. (vartical is not supported yet.) If sort is true, the key will be sorted by JavaScript comparision.

Spreadsheet.defineValidation([line=2])

The defined line will be used for validation. The validation types are as below. If it is not included, you can define own validations. See Speadsheet#getSheet

|types|description| |---|---| |int/integer|| |number/float/double|| |string|| |boolean||

Spreadsheet.defineFirstData([line=3])

The defined line will be first data line.

Spreadsheet({ spreadsheet_id })

Create a Spreadsheet instance with spreadsheet_id, you could speficy configulation as well.

async Spreadsheet#getSheet(sheetName, { [validator], [formatter], [range], [object=true] })

Get a sheet by specified name. The range will be resolved automatically, it doesn't need to be specified. \n If auto validation or default formatter is not enough, you can define them. \n If object is false, it will return a Sheet instance. You need to use 2D information, you need to call Sheet#getMatrix.

async Spreadsheet#getSheetMap([sheetNames], { [validators], [formatters], [ranges], [object=true] })

Get sheets by specified names. If sheetNames is not defined, it will return all sheets.

async Spreadsheet#getInfo()

Return spreadsheet information.