About

Air Supply

You need data; Air Supply will get it to you.

Air Supply is a versatile library to handle getting data from multiple sources in a sane way to use in your application build, data analysis, or whatever else requires fetching some data.

npm version github

Why

Air Supply aims to address the need of having to bring in various data sources when making small or mid-size, self-contained projects. Air Supply was originally conceived while working at the Star Tribune where we often create small projects and different, non-dynamic data sources are needed for most of them. Air Supply is essentailly putting together and making a consistent interface for lots of one-off code around getting and parsing data that was written and used for many years.

Pros

  • Can handle many sources of data, such as local files and directories, HTTP(S) sources, Google Docs and Sheets, many SQL sources, AirTable, and more. See Packages.
  • Can easily parse and transform data such as CSV-ish, MS Excel, YAML, Shapefiles, ArchieML, zip files, and more. See parsers
  • Caches by default.
  • Aimed at simple uses by just writing a JSON config, as well as more advanced transformations.
  • Loads dependency modules as needed and allows for overriding.

Cons

  • Not focused on performance (yet). The caching mitigates a lot of issues here, but the goal would be to use streams for everything where possible.
  • Not meant for very complex data pipelines. For instance, if you have to scrape a thousand pages, Air Supply doesn't currently fit well, but could still be used to pull the processed data into your application.

Similar projects

These projects do roughly similar things, but not to the same degree:

Installation

npm install air-supply --save

By default Air Supply only installs the most common dependencies for its packages and parsers. This means, if you need specific more parsers and packages, you will need to install them as well. For instance:

npm install googleapis archieml

Command line use (global)

If you just want to use the command-line tool, install globally like:

npm install -g air-supply

If you plan to use a number of the packages and parsers, it could be easier (though uses more disk-space), to install all the "dev dependencies" which includes all the packages and parser dependences:

NODE_ENV=dev npm install -g air-supply

Usage

Air Supply can be used as a regular Node library, or it can utilize config files that can be run via a command-line tool or as well as through Node.

Basics

Basic usage in Node by defining the Packages when using Air Supply.

const { AirSupply } = require('air-supply');

// Create new AirSupply object and tell it about
// the packages it needs
let air = new AirSupply({
  packages: {
    remoteJSONData: 'http://example.com/data.json',
    // To use Google Sheet package, make sure to install
    // the googleapis module:
    // npm install googleapis
    googleSheetData: {
      source: 'XXXXXXX',
      type: 'google-sheet'
    }
  }
});

// Get the data, caching will happen by default
let data = await air.supply();

// Data will look something like this
{
  remoteJSONData: { ... },
  googleSheetData: [
    { column1: 'abc', column2: 234 },
    ...
  ]
}

Command line

The command line tool will look for configuration in multiple places. See Configuration files below. You can simply call it with:

air-supply

A configuration file, such as a .air-supply.json, will be loaded and run through Air Supply, outputting the fetched and transformed data to the command line (stdout).:

{
  "packages": {
    "cliData": "some-file.yml"
  }
}

You can also point the comand-line tool to a specific file if you want:

air-supply -c air-supply.rc > data.json

Examples

Any AirSupply options are passed down to each Package, so we can define a custom ttl (cache time) to AirSupply and then override for each package.

const { AirSupply } = require("air-supply");
// Since we are using the YAML parser, make sure module is installed
// npm install js-yaml

let air = new AirSupply({
  ttl: 1000 * 60 * 60,
  packages: {
    // This data will probably not change during our project
    unchanging: {
      ttl: 1000 * 60 * 60 * 24 * 30,
      source: "http://example.com/data.json"
    },
    defaultChanging: "https://example/data.yml"
  }
});
await air.supply();

Each Package can be given a transform function to transform data. We can also alter when the caching happens. this can be helpful in this instance so that we don't do an expensive task like parsing HTML.

// Cheerio: https://cheerio.js.org/
const cheerio = require("cheerio");
const { AirSupply } = require("air-supply");

let air = new AirSupply({
  packages: {
    htmlData: {
      // Turn off any parsing, since we will be using cheerio
      parser: false,
      source: "http://example.com/html-table.html",
      // Transform function
      transform(htmlData) {
        $ = cheerio.load(htmlData);
        let data = [];
        $("table.example tbody tr").each(function(i, $tr) {
          data.push({
            column1: $tr.find("td.col1").text(),
            columnNumber: parseInteger($tr.find("td.col2").text(), 10)
          });
        });

        return data;
      },
      // Alter the cachePoint so that AirSupply will cache this
      // after the transform
      cachePoint: "transform"
    }
  }
});
await air.supply();

You can easily read a directory of files. If you just give it a path to a directory, it will assume you mean a glob of **/* in that directory.

const { AirSupply } = require("air-supply");

let air = new AirSupply({
  packages: {
    directoryData: "path/to/directory/"
  }
});
await air.supply();

This might cause problems or otherwise be an issue as it will read every file recursively in that directory. So, it may be helpful to be more specific and define a glob to use. This requires being explicit about the type of Package. We can also use specific parserOptions to define how to parse files.

// In this example we are using the csv and yaml parsers, so make sure to:
// npm install js-yaml csv-parse
const { AirSupply } = require("air-supply");

let air = new AirSupply({
  packages: {
    directoryData: {
      source: "path/to/directory/**/*.{json|yml|csv|custom-ext}",
      type: "directory"
      // The Directory Package type will define the `parser` option as
      // { multiSource: true } which will tell the parser to treat it
      // as an object where each key is a source.  This means, we can
      // define specific options for specific files.
      parserOptions: {
        "file.custom-ext": {
          parser: "yaml"
        }
      }
    }
  }
});
await air.supply();

You can also achieve something similar by just overriding the parser configuration to handle other extensions. Here we will update the YAML matching for another extension.

// In this example we are using the csv and yaml parsers, so make sure to:
// npm install js-yaml csv-parse
const { AirSupply } = require("air-supply");

let air = new AirSupply({
  parserMethods: {
    yaml: {
      match: /(yaml|yml|custom-ext)$/i
    }
  },
  packages: {
    directoryData: {
      source: "path/to/directory/**/*.{json|yml|csv|custom-ext}",
      type: "directory"
    }
  }
});
await air.supply();

Here is an example that gets a shapefile from an FTP source, reprojects and turns it to Topojson:

const { AirSupply } = require("air-supply");

let air = new AirSupply({
  cachePath: defaultCachePath,
  packages: {
    mnCounties: {
      // The FTP Package require the ftp module
      // npm install ftp
      source:
        "ftp://ftp.commissions.leg.state.mn.us/pub/gis/shape/county2010.zip",
      // We need to ensure that the Package will pass the data as a buffer
      fetchOptions: {
        type: "buffer"
      },
      parsers: [
        // The shapefile parser require specific modules
        // npm install shapefile adm-zip
        "shapefile",
        // We then reproject the geo data and need some more modules
        // npm install reproject epsg
        {
          parser: "reproject",
          parserOptions: {
            sourceCrs: "EPSG:26915",
            targetCrs: "EPSG:4326"
          }
        },
        // Finally, we make the data more compact with topojson
        // npm install topojson
        {
          parser: "topojson",
          name: "mnCounties"
        }
      ]
    }
  }
});
await air.supply();

Configuration files

Air Supply will look for a config files based on cosmiconfig rules with a little customization. So, it will read the first of any of these files as it goes up the directory tree:

package.json # An 'air-supply' property
.air-supply
.air-supply.json
.air-supply.json5
.air-supply.yaml
.air-supply.yml
.air-supply.js
air-supply.config.js

Note that any JSON will be read by the json5 module.

Packages

Packages are the methods that define how to get raw data from sources. The following are the available packages; see the full API documentation for all the specific options available.

Packages will get passed any options from the AirSupply object that is using it, as well has some common options and usage.

Note that many packages require specific modules to be installed separately.

AirSupply({
  ttl: 1000 * 60 * 10,
  packages: {
    things: {
      // Type is the kebab case of the package class name, i.e.
      // the package class name here would be PackageName.
      //
      // AirSupply will try to guess this given a source
      type: "package-name",
      // Almost all pcakages use the source option as it's
      // main option to get data
      source: "the main source option for this package",
      // Depending on the package, any options for the
      // fetching of data is ususally managed in fetchOptions
      fetchOptions: {
        fetchEverything: true
      },
      // Can override any defaults from the AirSupply object
      ttl: 1000 * 60 * 60,
      // Parsers are simple functions to transform the raw data.
      // This can be a string definign which parser to use,
      // an object of configuration, or an array of either if
      // you want to do multiple parsers.  The package
      // will guess what kind of parser is needed based on the source.
      parsers: ["zip", { multiSource: true }],
      // Custom transform function that will happen after parsing.
      transform(data) {
        return expensiveAlterFunction(data);
      },
      // Custom transform function that will happen after getting
      // all packages.
      bundle(allPackages) {
        return alterPackages(data);
      },
      // By default, caching will happen after fetching the raw data and
      // any of the built-in parsing.  But, you can cache after the 'transform'
      // or after the 'bundle'.
      //
      // Overall, this is only needed if you have expensive transformations
      cachePoint: "transform",
      // Use the output option to save the fully loaded data
      // to the filesystem.  This is useful if you need to save files
      // that will get loaded into the client (asynchronously).
      output: "things.json"
    }
  }
});
Package Description Docs Dependencies
AirTable Get data from an AirTable table. API npm install airtable
Data Just pass JS data through. API
Directory Read files from a directory and parse each one if can. API
File Read a file from the filesystem. API
Ftp Get a file from an FTP source. API npm install ftp
GoogleDoc Get plain text version of a Google Doc and by default parse with ArchieML. Can be a "Published to the web" URL, or if given an ID will use Google's authentication. API npm install googleapis
GoogleSheet Get tabular data from a Google Sheet and assumes first row is headers by default. Uses Google's authentication; if you want to use a public "Published to the web" CSV, just use the Http package with a CSV parser. API npm install googleapis
Http Get data from an HTTP source. API
Sql Get data from SQL sources as that are supported by sequelize. API npm install sequelize

Parsers

Parsers are simple functions to transform common data; mostly these are used to transform the raw data to more meaningful JSON data.

Note that most parsers require specific modules to be installed separately.

The parsers options can be defined a few different ways:

  • If it is undefined, the package will try to determine which parser to use by looking at the source.
  • If it is false, then no parsing will happen.
  • If it is a string, such as 'csv', then it will use that parser with any default options.
  • If it is a function, then it will simply run the data through that function.
  • If it is an object, it should have a parser key which is the is one of the above options, and optionally a parserOptions that will get passed the parser function. Or it can just be { multiSource: true } which will assume the data coming in is an object where each key is a source.
  • If it is an array, it is assume to be multiple parsers with the above options.

The following parsers are available by default.

Parser Description Source match Docs Dependencies
archieml Uses archieml. /aml$/i API npm install archieml
csv Uses csv-parse. Can be used for any delimited data. /csv$/i API npm install csv-parse
gpx Uses togeojson. /gpx$/i API npm install @mapbox/togeojson
json Uses json5. /json5?$/i API
kml Uses togeojson. /kml$/i API npm install @mapbox/togeojson
reproject Reprojects GeoJSON using reproject. NA API npm install reproject epsg
shapefile Parsers a Shapefile as a .zip or .shp file into GeoJSON using shapefile. /(shp.*zip|shp)$/i API npm install shapefile adm-zip
topojson Transforms GeoJSON to TopoJSON using topojson. /geo.?json$/i API npm install topojson
xlsx Parsers MS Excel and others (.xlsx, .xls, .dbf, .ods) using xlsx. /(xlsx|xls|dbf|ods)$/i API npm install xlsx
yaml Uses js-yaml. /(yml|yaml)$/i API npm install js-yaml
zip Turns a zip file into an object where each key is the file name and the value is the text contents of that file using adm-zip. /zip$/i API npm install adm-zip

API

Full API documentation can be found at zzolo.org/air-supply.

Develop

Documentation

Use npm run docs:preview and open localhost:4001 in a browser.

Test

Run tests with: npm run test

Publish

NPM

  1. Bump version in package.json and run npm install.
  2. Commit.
  3. Tag: git tag X.X.X
  4. Push up: git push origin master --tags
  5. Run npm publish

Docs

Build and publish to Github Pages (after NPM publish): npm run docs:publish

Static Members
PLACEHOLDER see documentationjs/documentation/issues/1113

API Reference

API Reference

The AirSupply class is the main way of collecting data via AirSupply.

Any options given to AirSupply will be provided to packages as defaults before their own default or your specific options.

new AirSupply(options: Object)
Parameters
options (Object) Options object.
Name Description
options.packages Object The object describing each package, in format:
options.ttl Number (default 300000) The global length of cache in milliseconds
options.cachePath String (default '.air-supply-cache') The location of the cache data, defaults to the .air-supply-cache/ directory in the current working path.
options.config String? A specific configuration file
options.noConfig Boolean (default false) If true, will ensure that AirSupply will not look for or load a config file.
options.parserMethods Object? The object describing parsers. This will merge with the default parser configuration. This should be in the format like:
{
  parserName: {
    match: /parser$/,
    parser: (data, options) => { ... }
  }
}

You can also override, specific things, such as changing the matching for a parser:

{
  json: {
    match: /(json|json5|custom-json-ext)$/i
  }
}
options.sharedProtocols Object? The object that will map protocols to other protocols; protocols translate to package classes (i.e. http -> Http package class). Should be similar to:
{
  https: 'http',
  mysql: 'sql'
}
Instance Members
supply(packages)
package(config, key)
guessPackageType(config)
loadConfig(options)

Packages

Packages define ways to get raw data.

Packages

Packages define ways to get raw data.

File package type. Gets data from local files.

new File(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The path to the file.
options.noCache Boolean (default true) Defaults to no caching, since caching is essentially the same. Might be useful to turn on if there is a lot of transforming.
options.fetchOptions (Object | String) (default 'utf-8') Options given to readFileSync
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
import File from 'air-supply/src/packages/File';
let f = new File({ source: 'file.json' });
let data = f.cachedFetch();
Instance Members
fetch()

Directory package type. Gets data from local files in a directory using glob.

new Directory(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The glob path to a directory; for instance to get all files in a directory: directory/*.* .
options.noCache Boolean (default true) Defaults to no caching, since caching is essentially the same. Might be useful to turn on if there is a lot of transforming.
options.parsers Object (default {multiSource:true}) Parser options to default to multiple sources.
options.fetchOptions Object? Options given to glob
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
import Directory from 'air-supply/src/packages/Directory';
let f = new Directory({ source: 'directory/*.csv' });
let data = f.cachedFetch();
Instance Members
fetch()

Http package type. Gets data from an "http://" source via node-fetch.

new Http(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The URI to the file to read data from.
options.fetchOptions Object? node-fetch options.
options.fetchOptions.type String (default 'string') Custom option to handle what kind of response we want from the fetch, can be either buffer , json , or string ; defaults to string .
options.nodeFetch (Object | Function) (default require('node-fetch')) The node-fetch module is installed by default, but you may want to use a specific version or otherwise customize it.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
import Http from 'air-supply/src/packages/Http';
let f = new Http({ source: 'http://example.com/data.json' });
let data = f.cachedFetch();
Instance Members
fetch()

Data package type. Just passes through "source" property.

new Data(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The data that will come through.
options.parsers (Boolean | String | Function | Array | Object) (default false) Explicitly turns parsing off by default.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
import Data from 'air-supply/src/packages/Data';
let f = new Data({ source: [1, 2, 3] });
let data = f.cachedFetch();
Instance Members
fetch()

GoogleDoc package type. Gets data from a Google Doc source via googleapis module. Defaults parser to ArchieML, but if no parser, it will return HTML. The googleapis module is not installed by default, if you need this package, install separately:

npm install googleapis

If you are using Air Supply via the command line, it may make sense to install googleapis globally:

npm install -g googleapis
new GoogleDoc(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! For authenticated requests, simply provide the Google Doc ID (can be found in the URL). For un-authenticated requests via the "Published to the Web" version, provide the full URL.
options.parsers String (default 'archieml') Defaults to use ArchieML parser.
options.authOptions Object? Options to pass to the Google authentication function.
options.googleapis (Object | Function) (default require('googleapis')) The googleapis module is not installed by default. You can either install it normally, i.e. npm install googleapis , or you can provide the module with this option if you need some sort of customization.
options.nodeFetch (Object | Function) (default require('node-fetch')) The node-fetch module is installed by default, but you may want to use a specific version or otherwise customize it.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
// Ensure googleapis module is installed: `npm install googleapis`
import GoogleDoc from 'air-supply/src/packages/GoogleDoc';
let f = new GoogleDoc({ source: 'GOOGLE-DOC-ID' });
let data = f.cachedFetch();
Instance Members
fetch()
getHTMLContents(source, authOptions)
getPublishedToWebContent(url)
htmlParser(text)

GoogleSheet package type. Gets data from a Google Sheet source via googleapis module.

If you want to get the published CSV version, use the package along with the parser.

Note that the googleapis module is not installed by default, if you need this package, install separately:

npm install googleapis

If you are using Air Supply via the command line, it may make sense to install googleapis globally:

npm install -g googleapis
new GoogleSheet(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The Google Doc ID (can be found in the URL).
options.fetchOptions Object? Options for getting sheet data.
options.fetchOptions.headers Boolean (default true) Assumes first row is headers and converts data to object instead of array.
options.fetchOptions.filterEmpty Boolean (default true) Filters any rows that are all empty (null or undefined).
options.fetchOptions.sheet (String | Boolean) (default false) The ID of the specific sheet in the Google Sheet. False to use the first/default.
options.fetchOptions.fieldType String (default 'userEnteredValue') The type of value to get from each field; can be userEnteredValue , effectiveValue , or formattedValue
options.authOptions Object? Options to pass to the Google authentication function.
options.parsers (String | Boolean) (default false) Defaults to not use a parser.
options.googleapis (Object | Function) (default require('googleapis')) The googleapis module is not installed by default. You can either install it normally, i.e. npm install googleapis , or you can provide the module with this option if you need some sort of customization.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
// Ensure googleapis module is installed: `npm install googleapis`
const GoogleSheet = require('air-supply/src/packages/GoogleSheet';
let f = new GoogleSheet({ source: 'GOOGLE-SHEET-ID' });
let data = f.cachedFetch();
Instance Members
fetch()
getRawGrid(source, sheet, fieldType, authOptions)

Airtable package type. Gets data from Airtable. The airtable module is not installed by default, if you need this package, install separately:

npm install airtable

If you are using Air Supply via the command line, it may make sense to install airtable globally:

npm install -g airtable
new Airtable(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The Airtable Base ID.
options.table String! The table ID in the Airtable Base.
options.airtableKey String (default process.env.AIRTABLE_API_KEY) The Airtable API key found at airtable.com/api . Uses the environment variable AIRTABLE_API_KEY by default.
options.parser Boolean (default false) Turns parsing off by default.
options.fetchOptions Object? Options that are passed to the list method of the Airtable NodeJS method. Airtable does not make this linkable, but includes options such as: fields , filterByFormula , maxRecords , pageSize , view , sort (ex. [{field: "ID", direction: "desc"}] ), cellFormat (ex. json or string )
options.Airtable (Object | Function) (default require('airtable')) The airtable module is not installed by default. You can either install it normally, i.e. npm install airtable , or you can provide the module with this option if you need some sort of customization.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
// Ensure airtable module is installed: `npm install airtable`
import Airtable from 'air-supply/src/packages/Airtable';
let f = new Airtable({
  source: 'BASE-ID-XXXX',
  table: 'table-XXXX'
});
let data = f.cachedFetch();
Instance Members
fetch()

SQL package type. Gets data from an SQL database source via sequelize.

Use an URI method to connect to a database.

  • protocol://user:name@host:port/database
  • sqlite://./my-new-db.sql
  • mysql://username:password@localhost/my-database
  • postgres://username:@localhost:1234/my-database

The sequelize module is not installed by default, if you need this package, install separately:

npm install sequelize

You will also need a module to connect to your database, which will depend on what kind of database it is. You will need one of the following:

  • npm install pg pg-hstore
  • npm install mysql2
  • npm install sqlite3
  • npm install tedious (MSSQL)
new Sql(options: Object, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object) Options for package that will override any defaults from the or .
Name Description
options.source String The URI to the the database.
options.query String The SQL select query to run, such as: "SELECT * FROM table".
options.parsers Boolean (default false) Turn parsing off by default.
options.fetchOptions Object? sequelize connection options.
options.Sequelize (Object | Function) (default require('sequelize')) The sequelize module is not installed by default. You can either install it normally, i.e. npm install sequelize , or you can provide the module with this option if you need some sort of customization.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
// Ensure that the "sequelize" module is installed: npm install sequelize
// and at your appropriate database module, for instance: npm install mysql2
import Sql from 'air-supply/src/packages/Sql';
let f = new Sql({
  source: 'mysql://user:name@host/database',
  query: 'SELECT * FROM table'
});
let data = f.cachedFetch();
Instance Members
fetch()

Ftp package type. Gets data from an "ftp://" source via ftp module. The ftp module is not installed by default, if you need this package, install separately:

npm install ftp

If you are using Air Supply via the command line, it may make sense to install ftp globally:

npm install -g ftp
new Ftp(options: Object!, airSupply: Object<AirSupply>?)

Extends BasePackage

Parameters
options (Object!) Options for package that will override any defaults from the or .
Name Description
options.source String! The URI to the file to read data from. Something like ftp://username:[email protected]/path/to/file.json
options.fetchOptions Object? ftp connection options, overriding anything determined from the source .
options.fetchOptions.type String (default 'string') Custom option to handle what kind of response we want from the fetch, can be either buffer or string ; defaults to string .
options.fetchOptions.path String? Custom option for the path to get from the FTP server, if not used in the source URI.
options.Ftp (Object | Function) (default require('ftp')) The ftp module is not installed by default. You can either install it normally, i.e. npm install ftp , or you can provide the module with this option if you need some sort of customization.
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes.
Example
// Ensure ftp module is installed: `npm install ftp`
import Ftp from 'air-supply/src/packages/Ftp';
let f = new Ftp({ source: 'ftp://example.com/data.json' });
let data = f.cachedFetch();
Instance Members
fetch()

The base Package class that is meant to be extended for each Package type class.

Do not use this class directly.

new BasePackage(options: Object, type: String?, airSupply: Object<AirSupply>?, packageDefaults: Object?)
Parameters
options (Object = {}) Options for this package. These options are true for every Package type, though a Package defaults may override these defaults.

More options defaults come in from the AirSupply object, for example options.ttl. See AirSupply.

Name Description
options.keyIdentifiers Array (default ['key','source']) An array of properties in the options that will get used to create the cache key.
options.cachePoint String (default 'fetch') A string the defines when caching will happen; the options are: - fetch: Caching happens after fetch - transform: Caching happens after the transform function is performed - bundle: Caching happens after bundle function is preformed
options.transform Function? A function to transform data after it has been fetched and parsed. The only argument is the data, and this will refer to this package instance. Should return the altered data.
options.bundle Function? A function to alter the data once all packages have been transformed. This is useful if data should be altered based on other packages. The only argument is all transformed package data (not just this one) in the Air Supply bundle, and this will refer to this package instance. Should return only this package data.
options.output String? A file path to save the package data locally. This is the data after any transform or bundle. This is useful if you need your data an asynchronous client call or something.
options.outputJsonStringify (Function | String) (default JSON.stringify) The JSON stringify function to use if the output will be treated like JSON. Defaults to Node's implementation, otherwise a function can be passed, or 'json5' which will use the json5 module's stringify function.
type (String?) This describes the type of package and used in creating the cache path. This is also automatically set by each Package type and should not need to be set manually. For instance the GoogleSheet Package uses 'google-sheet' .
airSupply (Object<AirSupply>?) The AirSupply object useful for referencial purposes and defining defaults.
packageDefaults (Object?) This is used for classes that extend this class, so that they can provid default options.
Instance Members
cachedFetch()
parse(data, options?)
parseData(data, options = {})
parseObject(data, options = {})
transform()
bundle(supplyPackage)
output()
option(optionName)
createId()
setupCache()
setCache(cachePoint)
getCache(cachePoint)
removeCache(silent)
dataFileEncoding(data)
writeFile(filePath, data, fileEncoding?, jsonStringify)

Parsers

Parsers define how to transfrom raw data.

Parsers

Parsers define how to transfrom raw data.

ArchieML parser. Uses archieml module. ArchieML module is not installed by default, if you need this parser, install separately:

npm install archieml

If you are using Air Supply via the command line, it may make sense to install ArchieML globally:

npm install -g archieml
archieml
Parameters
input ((String | Buffer)) Data to parse.
options (Object?) Options, see archieml module for details.
Returns
Object: Parsed data.

CSV (or any delimiter) parser. Uses csv-parse module, specifically the sync method. CSV Parse module is not installed by default, if you need this parser, install separately:

npm install csv-parse

If you are using Air Supply via the command line, it may make sense to install CSV Parse globally:

npm install -g csv-parse
csv
Parameters
input ((String | Buffer)) Data to parse.
options (Object?) Options, see csv-parse for details, though some options are defaulted differently here.
Name Description
options.cast Boolean (default true) Defaults to true.
options.columns Boolean (default true) Defaults to true.
options.trim Boolean (default true) Defaults to true.
Returns
Object: Parsed data.

KML parser. Uses togeojson module. togeojson module is not installed by default, if you need this parser, install separately:

npm install @mapbox/togeojson

If you are using Air Supply via the command line, it may make sense to install togeojson globally:

npm install -g @mapbox/togeojson
gpx
Parameters
input ((String | Buffer)) Data to parse.
options (Object?) Options, see togeojson for details.
Returns
Object: Parsed data.

JSON parser. Uses json5 module.

json
Parameters
input ((String | Buffer)) Data to parse.
options (Function?) Options, see parse method for details.
Returns
Object: Parsed data.

KML parser. Uses togeojson module. togeojson module is not installed by default, if you need this parser, install separately:

npm install @mapbox/togeojson

If you are using Air Supply via the command line, it may make sense to install togeojson globally:

npm install -g @mapbox/togeojson
kml
Parameters
input ((String | Buffer)) Data to parse.
options (Object?) Options, see togeojson for details.
Returns
Object: Parsed data.

Reproject GeoJSON. Uses reproject module. The Reproject and EPSG modules are not installed by default, if you need this parser, install separately:

npm install reproject epsg

If you are using Air Supply via the command line, it may make sense to install Reproject and EPSG globally:

npm install -g reproject epsg
reproject
Parameters
input ((Object | String | Buffer)) Geojson input.
options (Object?) Options to pass to the parser
Name Description
options.sourceCrs String? Target CRS as EPSG definition. Will try to find in geojson, but this is often not set. See epsg module defs for reference.
options.targetCrs String (default 'EPSG:426') Source CRS as EPSG definition. See epsg module defs for reference.
epsgSet (Object = require('epsg')) An object of EPSG lookups, in the format:
{
  'EPSG:4326': 'proj4 def ...'
}
Returns
Object: Reprojected geojson.

Shapefile parser. Will look for any .shp files in a zip file. If multiple .shp files are found, then it will return an object where the key is Uses shapefile and adm-zip modules; these not installed by default, if you need this parser, install separately:

npm install shapefile adm-zip

If you are using Air Supply via the command line, it may make sense to install these modules globally:

npm install -g shapefile adm-zip
shapefile
Parameters
data (Buffer) Buffer to parse; should be either a .zip file or a .shp file.
options (Object?) Options object.
Name Description
options.dbf (Buffer | String)? An optional specific .dbf file to use. Useful if providing shapefile as .shp file. This should be a buffer or file path.
Returns
Object: Parsed data.

Converts GeoJSON to TopoJSON. Uses topojson module. TopoJSON module is not installed by default, if you need this parser, install separately:

npm install topojson

If you are using Air Supply via the command line, it may make sense to install TopoJSON globally:

npm install -g topojson
topojson
Parameters
input ((Object | String | Buffer!)) Geojson input.
options (Object?) Options to pass to the parser
Name Description
options.name String (default 'geojson') Name/key for the geojson data. This is the key to refer to when access the topology, like topojson.objects.KEY .
options.quantization Number (default 100000) Quantization value. See topojson.quantize . Use false to not do quantization.
options.simplifyQuantile Number (default 0.85) Will simplify the topojson based on topojson.quantile . Should be a number between 0 and 1 that represents quantile of weighted points. So, 1 would be no simplification (keeping 100%), while 0 is complete simplification (keeping 0% detail). Use instead of options.simplify . Use false to do not do simplification.
options.simplify Number? If provided, will pass topology to topojson.simplify . Should be a minimum number value, depends on the values, but something like 0.01 will really simplify the topology, while something like 0.00000000001 will not simplify it much. Use instead of options.simplifyQuantile .
Returns
Object: Parsed data.

XLSX (MS Excel) (and other format) parser. Uses xlsx module.

Supports other formats: https://docs.sheetjs.com/#file-formats

Reading options reference: https://docs.sheetjs.com/#parsing-options

XLSX module is not installed by default, if you need this parser, install separately:

npm install xlsx

If you are using Air Supply via the command line, it may make sense to install XLSX globally:

npm install -g xlsx
xlsx
Parameters
input (Buffer) Data to parse.
options (Object?) Options, see parsing options for details, though some options are defaulted differently here.
Name Description
options.sheet Boolean? Custom option to get a specific
options.jsonOptions Boolean? Options to pass to the xlsx json parsing .
Returns
Object: Parsed data.

YAML parser. Uses js-yaml module. YAML module is not installed by default, if you need this parser, install separately:

npm install js-yaml

If you are using Air Supply via the command line, it may make sense to install YAML globally:

npm install -g js-yaml
yaml
Parameters
input ((String | Buffer)) Data to parse.
options (Function?) Options, see safeLoad method for details.
Returns
Object: Parsed data.

Zip archiver. Uses adm-zip module. Produces an object, where each key is the file in the archive and each value is the text of that file. ADM Zip module is not installed by default, if you need this parser, install separately:

npm install adm-zip

If you are using Air Supply via the command line, it may make sense to install ADM Zip globally:

npm install -g adm-zip
zip
Parameters
input (Buffer) Input buffer data.
Returns
Object: Parsed data.

Other

Various other functions.

Other

Various other functions.

googleAuthenticate

src/auth/google.js

Authenticate to Google's API via OAuth on the command line. Will write token to ~/.config/air-supply/google-auth.json by default, and supply token.

The googleapis module is not installed by default, if you need this package, install separately:

npm install googleapis

If you are using Air Supply via the command line, it may make sense to install googleapis globally:

npm install -g googleapis
googleAuthenticate(options: Object?): Object
Parameters
options (Object? = {}) Options to pass.
Name Description
options.clientId String (default process.env.GOOGLE_OAUTH_CLIENT_ID) The Google auth client ID; defaults to the environment variable: GOOGLE_OAUTH_CLIENT_ID .
options.consumerSecret String (default process.env.GOOGLE_OAUTH_CONSUMER_SECRET) The Google auth consumer secret; defaults to the environment variable: GOOGLE_OAUTH_CLIENT_ID .
options.scope Array (default ['https://www.googleapis.com/auth/drive','https://www.googleapis.com/auth/spreadsheets']) The scope of the autentication.
options.localPort Number (default 48080) Port for local server.
options.tokenLocation String (default ~/.config/air-supply/google-auth.json) Where to save the authentication token.
options.forceReAuth Boolean (default false) Force authentication even if tokens are available.
options.timeout Number (default 300000) Timeout (currently doen't work)
options.authenticatedMessage String (default '..[[[LOCATION]]]..') The message to send to the browser when successfully authenticated.
options.openWait Number (default 1) Milliseconds to wait to open authentication browser page.
options.googleapis (Object | Function) (default require('googleapis')) The googleapis module is not installed by default. You can either install it normally, i.e. npm install googleapis , or you can provide the module with this option if you need some sort of customization.
Returns
Object: Authentication object from googleapis module.