0.1.0
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.
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.
These projects do roughly similar things, but not to the same degree:
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
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
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.
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 },
...
]
}
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
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();
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 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 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:
undefined
, the package will try to determine which parser to use by looking at the source
.false
, then no parsing will happen.'csv'
, then it will use that parser with any default options.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.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 |
Full API documentation can be found at zzolo.org/air-supply.
Use npm run docs:preview
and open localhost:4001 in a browser.
Run tests with: npm run test
package.json
and run npm install
.git tag X.X.X
git push origin master --tags
npm publish
Build and publish to Github Pages (after NPM publish): npm run docs:publish
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.
(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'
}
|
Bundles all the package data. This will use the options.packages provided to AirSupply as well as any provided options.
(Object?
= {}
)
An object describing packages. This is the same
as the constructor option, but will not get attached to the AirSupply object
for future reference.
Promise<Object>
:
The compiled data.
Given a config, gets a package instance.
(Object!)
An object for defining the package. This will be the options
passed to the package object, plus the following necessary properties.
Name | Description |
---|---|
config.type (String | Function!)
|
This is either the package class name as a string, or directly passed the package class. |
config.key String!
|
The package key that helps assign the package to the bundled supply package. |
(any)
Object
:
The instantiated package.
Load config via cosmiconfig.
Packages define ways to get raw data.
Packages define ways to get raw data.
File package type. Gets data from local files.
Extends BasePackage
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 |
import File from 'air-supply/src/packages/File';
let f = new File({ source: 'file.json' });
let data = f.cachedFetch();
Directory package type. Gets data from local files in a directory using glob.
Extends BasePackage
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 |
import Directory from 'air-supply/src/packages/Directory';
let f = new Directory({ source: 'directory/*.csv' });
let data = f.cachedFetch();
Http package type. Gets data from an "http://" source via node-fetch.
Extends BasePackage
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. |
import Http from 'air-supply/src/packages/Http';
let f = new Http({ source: 'http://example.com/data.json' });
let data = f.cachedFetch();
Fetch implementation. Utilizes node-fetch.
Object
:
The fetched data.
Data package type. Just passes through "source" property.
Extends BasePackage
import Data from 'air-supply/src/packages/Data';
let f = new Data({ source: [1, 2, 3] });
let data = f.cachedFetch();
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
Extends BasePackage
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. |
// 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();
Fetch implementation. Uses googleapis module
Object
:
The fetched data.
HTML parser From: https://github.com/bradoyler/googledoc-to-json/blob/master/index.js
(String)
HTML test to parse
String
:
Parsed content.
GoogleSheet package type. Gets data from a Google Sheet source via googleapis module.
If you want to get the published CSV version, use the
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
Extends BasePackage
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.
|
// 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();
Fetch implementation. Uses googleapis module
Object
:
The fetched data.
Get the basic grid content from the sheet. Reference: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#SheetProperties
(String)
The Google Sheet ID.
(String
= 'userEnteredValue'
)
The type of value to
get from each field; can be
userEnteredValue
,
effectiveValue
,
or
formattedValue
.
(any
= {}
)
Object
:
Sheet content.
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
Extends BasePackage
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.
|
// 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();
Fetch implementation. Utilizes the Airtable NodeJS library to read data from Airtable.
Object
:
The fetched data.
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)Extends BasePackage
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.
|
// 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();
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
Extends BasePackage
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.
|
// 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();
The base Package class that is meant to be extended for each Package type class.
Do not use this class directly.
(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.
|
(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'
.
(Object?)
This is used for classes that extend this class, so
that they can provid default options.
Wrapper around the implemented fetch method. This will cache the result if needed, and perform the transform method if needed as well.
any
:
The fetched data.
Run data through multiple parsers.
(any)
The data to parse.
((Array | Object | String | Boolean)?)
The options for each
parser. Can be a number of things:
undefined
: The package will try to determine which parser to
use by looking at the source.false
: No parsing will happen.{String}
: Example 'csv'. It will use that parser with any
default options.{Function}
: It will simply run the data through that function.{Object}
: 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.
See BasePackage#parseObject{Array}
: For multiple parsers, use an array with any
of the above options.any
:
The parsed data.
Run data through single parser
(any)
The data to parse.
((Array | Object | String | Boolean)?
= {}
)
The options for each
parser. Can be a number of things. See:
BasePackage#parse
any
:
The parsed data.
Goes through an object and runs this.parse
on each one, using the
key as the source
property.
(Object)
The to parse; should be an Object.
(Object?
= {}
)
An object where each key matches the
key from the data, and the value is passed to
this.parse
.
See:
BasePackage#parse
any
:
The parsed data.
parseObject({
'yaml-file.yaml': 'yaml: "data"',
'json-file.json': '{ "yaml": "data" }'
}, {
'yaml-file.yaml': "yaml",
'json-file.json': ["json", customParserFunction]
});
Save fully bundle(d) output to disk if options.output
is provided.
any
:
Self
Sets cache data to this.cacheData
then saves the data in the file
defined in this.cacheFiles
.
Object
:
This instance.
Gets cache for a specific cache point. Specifically sets data
in this.cacheData
if the cache data is still valid.
Object
:
This instance.
Wrapper around writeFileSync that looks at what kind of data it is and sets appropriately.
(String)
The path to the file
(any)
Data to save
(String?)
Specific string to determine
how to encode this data. Will use
dataFileEncoding
if
not specified.
See
BasePackage#dataFileEncoding
(Function
= json5.stringify
)
Function
to use when encoding json data. Defaults to json5 module.
String
:
The type of formatting that was used,
can be
string
,
json
, or
buffer
Parsers define how to transfrom raw data.
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
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
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
Object
:
Parsed data.
JSON parser. Uses json5 module.
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
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
(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. |
(Object
= require('epsg')
)
An object of EPSG lookups, in the format:
{
'EPSG:4326': 'proj4 def ...'
}
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
(Buffer)
Buffer to parse; should be either a .zip file or a .shp file.
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
(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
.
|
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
(Buffer)
Data to parse.
(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 . |
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
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
(Buffer)
Input buffer data.
Object
:
Parsed data.
Various other functions.
Various other functions.
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
(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.
|
Object
:
Authentication object from
googleapis
module.