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

mozaik-ext-sheets

v0.6.0

Published

Mozaïk extension for listing data from Google Sheets

Downloads

6

Readme

mozaik-ext-sheets

List rows from Google Sheets in Mozaïk dashboard. The extension can be handy for various use cases where data is maintained in Google Sheets:

  • List events (including dates etc)
  • Show game results
  • Show event participants, company vacation listing
  • Etc.

preview

  • The widget tries to provide a generic but easy-to-use way to show content in dashboard.
  • You can also utilise the Sheets functions as the outcome is shown in widget
  • Use format functions to format some cell data
  • Use filter function to leave out some results

Setup

  • Install module

    npm install --save mozaik-ext-sheets
  • Create a project and service account in Google Developer Console

  • Enable API: Drive API

  • Collect service email and .p12 file

  • Convert .p12 file into .PEM

  • Configure service key and .PEM file into dashboard config.js file and environment variables / .env file:

    api: {
      sheets: {
        googleServiceEmail: process.env.GOOGLE_SERVICE_EMAIL,
        googleServiceKeypath: process.env.GOOGLE_SERVICE_KEYPATH
      }
    }
  • Done.

Widget: List

Show cell contents in a listing. Use dashboard theme to customize the outcome to match with your requirements.

parameters

key | required | description --------------|----------|--------------- documentId | yes | Sheets document id, taken form web UI sheetNo | no | Sheet order number, starting from 0. Defaults to first: 0 range | no | Range from where to list data. Example: A2:C10 or A2:. Defaults to full sheet style | no | Show results as bullet list or table-like. Valid values: list (default) or table styles | no | *Inline style defintions in React supported style format. Sub-elements: list, listItem* fields | no | *Columns to list, using advanced formatting*random | no | *Pick and show random number entries, defined by the value. Zero means no random is used (Default). Example:random: 1* fontSize | no | *Use default (``), fixed (12px) or auto scaled fontsize (auto)* format | no | *Custom formating functions in object, where key is name of the formatter and used like {COLUMNLETTER!formatter}. See usage for examples*filter` | no | Filter some rows out of the outcome by implementing the function. See usage for examples

usage

Imaginary example of Google Sheet document cells:

    |      A     |       B       |       C       |  D  |
 1  | 2015-01-28 | React.js Conf | Facebook HQ   |     |
 2  | 2015-07-02 | ReactEurope   | Paris, France |     |

One widget in dashboard config:

// widget in config.js
{
  type: 'sheets.list',
  // You can find the documentId in sheet URL
  documentId: 'abasdfsdfafsd123123',
  range: 'A1:D10',
  // Use either 'list' or 'table'
  // Table shows every other row with different bg color
  style: 'list',
  fontSize: 'auto', // Use default, fixed or auto-scaled font size
  // Customize the list or list item styles
  styles: {
    list: {
      listStyle: 'none'
    },
    listItem: {
      textAlign: 'center'
    }
  },
  // Values (cells) to show on each row. Use one or multiple column letters:
  // Uses https://www.npmjs.com/package/string-format for formatting
  // NOTE: The both `['{A} {B} {C}']` and `['{A}', '{B}', '{C}']` work, but
  // latter makes it possible to style each field / show the values in different
  // cells in table format
  fields: [
    'Event date: {A!date}',
    '{B!uppercase}',
    '{C} {D}'
  ],
  // Show two random entries (after optional filtering)
  // Handy for picking random quote of the day etc.
  random: 2,
  // Custom formatter functions, name must match with the usage: !method
  // NOTE: Call method.toString() to every function!
  // NOTE: `moment` is available
  format: {
    // !date formatter
    date: function(s){
      return new moment(s).format('YYYY-MM-DD');
    }.toString(),
    // !uppercase formatter
    uppercase: function(s) {
      return s.toUpperCase();
    }.toString()
  },
  // Custom function to filter some results rows
  // If defined, each row is processed through it.
  // Return `false` if you want to filter the row out and `true`
  // for inclusion.
  // NOTE: Only one variable is passed, containing all columns from current row
  // NOTE: Variable `columns` does not contain the columns out of the range
  // NOTE: Call method.toString() to every function!
  filter: function(columns, index){
    // Filter out first two lines
    if (index < 2) {
      return false;
    }

    // Filter out the results that are in past
    var eventStart = moment(columns.B, ['YYYY-MM-DD']);
    if (eventStart.isBefore(new moment())) {
      return false;
    }

    // Otherwise show the fields from that row
    return true;
  }.toString(),
  columns: 1, rows: 2,
  x: 0, y: 0
}

Changelog

Release 0.6.0

  • Added support showing random number (0-n) of entries
  • Added support for styling elements with widget arguments

Release 0.5.0

  • Added support for table -styled listing

Release 0.4.1

  • Fixed missing module: src/client

Release 0.4.0

  • Replaced Gulp + Karma with Ava testing
  • Started using Eslint
  • Fixed dependencies
  • Fixed format support

Release 0.3.0

  • Updated support to Mozaik 1.4

Release 0.2.0

  • Added support for filtering

Release 0.1.0

  • Initial release

License

Module is MIT -licensed

Credit

Module is backed by: SC5