Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bertha-client

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bertha-client

A client library for fetching data from [Bertha](https://github.com/ft-interactive/bertha). For use in Node and the browser.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bertha-client CircleCI npm

A client library for fetching data from Bertha. For use in Node and the browser.

Why use this instead of fetching Bertha URLs with fetch or axios?

  • takes care of the URL syntax
  • gives more helpful error messages when things go wrong
  • provides an easy way to transform sheets into objects

Installation

  • yarn add bertha-client or npm install bertha-client

Browser: Use Browserify or Rollup. Requires window.fetch, so make sure this is polyfilled.

Node: Just require or import as usual. No need to polyfill anything – the Node version of bertha-client uses node-fetch internally.

Usage

import * as bertha from 'bertha-client'; // or const bertha = require('bertha-client');

bertha.get(spreadsheetKey, ['someSheet', 'anotherSheet|object']).then((data) => {
  console.log(data);
  // { someSheet: [...], anotherSheet: [...] }
});

API

Currently there is just one method.

bertha.get(spreadsheetKey, sheetNames, [options])

Fetches the sheet and returns a promise for the response data.

spreadsheetKey

String (required). A valid Google spreadsheet key, or a full Google Spreadsheet URL or Bertha URL.

sheetNames

Array of strings (required). The names of the sheets you want to get. A sheet name may be appended with |object to apply the "object" transformation.

// example
const sheetNames = [
  'polls',
  'authors',
  'copy|object', // applies the "object" transformation
]
options

Plain object (optional).

  • republish (default: false) – set to true if you want Bertha to trigger a republish.

Response data

The data is always returned a plain JavaScript object (not an array). The key names correspond with the sheet names.

The |object transformation

If you append a sheet name with |object, that sheet will be transformed into a plain object (instead of an array), using the sheet's name and value columns as key paths and values, respectively. Any other columns are discarded.

Example spreadsheet:

namevalue
foohiya
bar123
someone.age50
someone.name.firstBob
someone.name.lastHoskins
// result of "|object" transform
{
  foo: 'hiya',
  bar: '123',
  someone: {
    age: '50',
    name: {
      first: 'Bob',
      last: 'Hoskins',
    }
  },
}

Development

Local setup

Recommended approach:

  • Clone this repo and run yarn.
  • Run yarn run build -- --watch – this will compile files continually from src to dist using Babel.
  • In another terminal, run yarn run ava -- --watch to run ava continually against files in dist.

Publishing to npm

This module is automatically published to npm via CircleCI whenever the master branch contains a higher version string than the latest published version.

To publish a new version:

  • yarn version (will prompt you to enter a new version)
  • git push && git push --tags

FAQs

Package last updated on 03 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc