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

spreadparser

v1.0.0

Published

Small javaScript module to easily parse data from Google Spreadsheet.

Downloads

10

Readme

Resources

Spreadparser turns a JSON endpoint from Google Spreadsheets into a easier to understand list of objects.

View the Demo on CodePen →

So, using Spreadparser could be useful for some goals such as:

  • ✅ Small web projects
  • ✅ Static generated websites
  • ✅ Projects consuming government generated data
  • ✅ Project prototyping
  • ✅ Generate and share pages for visualizing third party data
  • ✅ Studying project for frontend and backend developers
  • ✅ Small companies online stores
  • ✅ Allow non tech teams to provide data for tech teams
  • ✅ Use Spreadsheet to create and maintain app config files

But it's probably not appropriate for:

  • 🛑 Automatic spreadsheet update
  • 🛑 Complex project based on relational database relations
  • 🛑 Project with a huge amount of data
  • 🛑 Google Spreadsheet data that can't be published to the web

Features

  • 📦 Lightweigth: less than 2kb and zero dependencies
  • 🧰 Versatile: Can be used for ES6/web projects, node project and as script tag
  • 👍 Tested: Highly covered with unit testing, written with typescript
  • 🎯 Understands your data as it is:
    • ➡️ "TRUE", "FALSE" strings and checkboxes become boolean values true and false
    • ➡️ Integers and floats become real numbers like 10 e 0.33
    • ➡️ Repeated title columns are parsed as arrays
    • ➡️ Allow spreadsheet data to be parsed as nested objects with inner properties and value
    • ➡️ Translate your data to your desired pattern like camel case or snake case

Getting Started

Compiled and production-ready code can be found in the dist directory. The src directory contains development code.

Publishing your Google Spreadsheet to web

First of all you need to have a Google Spreadsheet with your data and publish it to the web.

Now that you have your spreadsheet JSON running let's use Spreadparser.

1. Include Spreadparser on your site.

Direct Download

You can download the files directly from GitHub.

<script src="path/to/spreadparser.min.js"></script>

CDN

You can also use the jsDelivr CDN. I recommend linking to a specific version number or version range to prevent major updates from breaking your site. Spreadparser uses semantic versioning.

<!-- Always get the latest version -->
<!-- Not recommended for production sites! -->
<script src="https://cdn.jsdelivr.net/npm/spreadparser/dist/spreadparser.min.js"></script>

<!-- Get minor updates and patch fixes within a major version -->
<script src="https://cdn.jsdelivr.net/npm/spreadparser@1/dist/spreadparser.min.js"></script>

<!-- Get patch fixes within a minor version -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/spreadparser.min.js"></script>

<!-- Get a specific version -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/spreadparser.min.js"></script>

NPM

You can also use yarn (or your favorite package manager).

yarn add spreadparser

2. Add the markup to your HTML.

No extra configuration needed—just standard JavaScript.

fetch(Spreadparser.getSpreadsheetUrl("1Rr2y3ljAJPApYXcPyLXwxLciUCxz8XCu1Q0OnWH1l-U", 2))
    .then(response => response.json())
    .then(json => Spreadparser.parse(json, {titleCase: 'camelCase'}))
    .then(spreadsheet => {
        console.log(spreadsheet.data[0]); // You can see this console.log output bellow
    });

Giving us the following output:

{
   "nome":"Água",
   "hex":"#00FFFF",
   "rgb":{
     "red":0,
     "green":255,
     "blue":255
   },
   "hsv": {
     "hue":"180°",
     "saturation":"100%",
     "value":"100%"
   },
   "nomeWeb":"aqua"
 }

Installation (for web projects)

Install it as a dependency:

yarn add spreadparser # or npm install spreadparser

Now you can import Spreadparser as following:

import Spreadparser from "spreadparser";

Installation (for node projects)

It is possible to use Spreadparser for server side projects using node. For instance you can create a 11ty blog or a command line tool with Spreadparser:

Install it as a dependency:

yarn add spreadparser # or npm install spreadparser

Now you can import Spreadparser as following:

const Spreadparser = require("spreadparser/dist/umd/spreadparser.js");

Using it as a third party library

Spreadparser is available at jsDelivr CDN, for using it all you have to do is add proper url as script src to your HTML page:

<script src="https://unpkg.com/spreadparser">

Spreadparser is also available on unpkg.com

In the next topic we provide live examples of Spreadpaser as thirdy party library combined with other frontend tools.

Live examples

Here are some live examples for Spreadparser:

Documentation: getSpreadsheetUrl method

Spreadparser.getSpreadsheetUrl is a static method that receives two parameters: spreadsheetId and sheetNumber.

| Parameter | Type | Default | Required | |-|-|-|-| |spreadsheetId|string|undefined|true| |sheetNumber|number|1|false|

Sample usage:

Spreadparser.getSpreadsheetUrl("1Rr2y3ljAJPApYXcPyLXwxLciUCxz8XCu1Q0OnWH1l-U")
// https://spreadsheets.google.com/feeds/cells/1Rr2y3ljAJPApYXcPyLXwxLciUCxz8XCu1Q0OnWH1l-U/1/public/full?alt=json

Spreadparser.getSpreadsheetUrl("1Rr2y3ljAJPApYXcPyLXwxLciUCxz8XCu1Q0OnWH1l-U", 2)
// https://spreadsheets.google.com/feeds/cells/1Rr2y3ljAJPApYXcPyLXwxLciUCxz8XCu1Q0OnWH1l-U/2/public/full?alt=json

This method does exists because Spreadparser intentionally doesn't have a method to fetch data. So you can get your Spreadsheet JSON url and fetch data in your own way.

Documentation: parse method

Spreadparser.parse is a static method that receives two parameters: originalData and options.

| Parameter | Type | Required | |-|-|-| |originalData|object|true| |options|object|false|

Right bellow theres documentation for Spreadparser.parse options.

Parse Options

The second parameter for Spreadparse.parse is an object with properties. These properties are described below:

| Option | Type | Default| Description| |-|-|-|-| | separator | string | '__' | String portion used to separate nested objects | | titleCase | string | 'none' | Selected case style for data keys | | headerRow | number | 1 | Row number for title row | | includeEmptyRows | boolean | false | Use to include empty rows as part os data array |

Here are some complete options examples. Let's say we have a Google Spreadsheet as the following, we are going to asume that row column represents a real row number for each row:

|row|Person > Name | Adress > Street > Name | Adress > Street > Number | Hobbies | Hobbies| |-|-|-|-|-|-| |5|Benjamin|Yancy| 32 | Gym | Reading| | | | | | | | |7|Peter|Queens Street| 62| Climb walls | Science |

For the above Google Spreadsheet, the title row is number 4 not 1 as usual. So, using the following options:

const persons = Spreadparser.parse(originalData, {
  separator: '>',
  titleCase: 'camelCase',
  headerRow: 4,
  includeEmptyRows: true
})

The persons.data array will be:

[{
  "row": 5,
  "person": {
    "name": "Benjamin"
  },
  "adress": {
    "street": {
      "name": "Yancy",
      "number": 32
    }
  },
  "hobbies": ["Gym", "Reading"]
}, {}, {
  "row": 7,
  "person": {
    "name": "Peter"
  },
  "adress": {
    "street": {
      "name": "Queens Street",
      "number": 62
    }
  },
  "hobbies": ["Climb Walls", "Science"]
}]

How can you contribute?

  • Give a :star: to this project if you like it
  • Trust it as npm dependency for some of your projects
  • Help this project opening an issue, you may suggest a feature, documentation or share a bug
  • Improve this project by creating a pull request
  • Create a new live example using Spreadparser, maybe using codepen
  • Spread the idea!

License

MIT - Jota Teles - 2021