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

luft

v0.2.1

Published

[![npm version](https://img.shields.io/npm/v/luft)](https://www.npmjs.com/package/luft)

Downloads

2

Readme

npm version

💨 luft

An extremely simple Airtable client for JavaScript.

WARNING!

⚠️ This library is highly experimental, UNTESTED and likely to have breaking changes. It is not recommended to use it for anything serious. Unserious and mischievious use is encouraged.

Install

yarn add luft

// or

npm install luft

Usage example

An example that utilizes most options:

import { initialize, get } from 'luft';

initialize({
  baseId: '<your base id>',
  apiKey: '<your api key>',
});

const getUpcomingShows = async () => {
  let records;
  try {
    records = await get('Shows', {
      sort: [{ field: 'Date', direction: 'desc' }],
      populate: [
        {
          path: 'Venue',
          from: 'Venues',
          multi: false,
          fields: ['Address', 'City', 'Name'],
        },
        {
          path: 'With',
          from: 'Bands',
          multi: true,
          fields: ['Name']
        },
      ],
      filter: 'IS_AFTER({Date}, NOW())',
      toObject: true,
    });
  } catch (err) {
    // Error handling
  }
  return records;
};

Documentation

luft is a simplifying wrapper around airtable.js - the aim is not to reinvent the wheel but to simplify some things to allow for lightweight more implementations. You can use getBase as an escape hatch if necessary to use the full raw functionality.

Common parameters

All record getXYZ functions take the table name as the first param and support the following optional params:

  • fields - an array of fieldnames to select
  • sort - a list of sort objects with a field and optional direction keys (see api docs)
  • filter - a filter formula (see the Formula field reference and api docs)
  • populate - an array of population specs, see Population
  • toObject - boolean, return raw airtable.js records or plain objects with all keys converted to camelCase - default false

To start initialize the connection

Initializes your Airtable instance. Only one base is supported.

import { initialize } from 'luft';

initialize({
  baseId: '<your base id>',
  apiKey: '<your api key>',
});

// Now do things, see below

Visit your account page to get your API key.
It's recommended to use environment variables here for security and flexibility.

Then get some docs

import { get } from 'luft';

// initialize...

const shows = await get('Shows', {
  // See common parameters
});

And getById one doc by its id

import { getById } from 'luft';

// initialize...

const shows = await getById('Shows', {
  recordId: 'abc123',
  // See common parameters
});

Or getByKey one doc by a key field of your choice

For example to use Airtable as a rudimentary CMS:

import { getByKey } from 'luft';

// initialize...

const homepageContent = await getById('Content', {
  key: 'home',
  field: 'page',
  // See common parameters
});

(protip: the rich text field type is Markdown)

Populate linked fields

This is where luft really goes 💨.
Pass an array of population specs to population to get linked fields from other tables.

Example:

import { getByKey } from 'luft';

// initialize...

await get('Shows', {
  populate: [
    {
      path: 'Venue',
      from: 'Venues',
      multi: false,
      fields: ['Address', 'City', 'Name'],
    },
    {
      path: 'With',
      from: 'Bands',
      multi: true,
      fields: ['Name']
    },
  ],
  // See common parameters, toObject will convert the populated fields as well
});

A population spec has:

  • path - the field that you want to populate
  • from - the table to get it from
  • multi - whether to get one or multiple records (we can't tell this from the record sadly), you can safely leave this to true when in doubt to always get an array of results
  • fields - an array of fieldnames to select in the target record

It is currently only possible to populate one level deep. (create an issue of you need more)

Escape hatch

luft uses airtable.js under the hood, you can get the raw base to write your own logic:

import { getBase } from 'luft';

// initialize...

const base = getBase()

base('Shows').destroy(['rec123ABC'])

Local Development

yarn dev

Runs the project in development/watch mode. The project will be rebuilt upon changes.

yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

yarn test

Runs the test watcher (Jest) in an interactive mode.

Notes

This project was bootstrapped with TSDX.

Some inspiration taken from https://github.com/Arro/airtable-json