Javascript Node module to manage Data Packages especially Simple Data Format Data Packages with tabular data stored in CSV.
npm install datapackage
npm test
The following assume you've required datapackage as follows:
var datapackage = require('datapackage');
All callbacks follow the standard node pattern of (error, data, ...)
.
datapackage.load(urlToDataPackage, callback)
Load a datapackage.json from a URL and normalize it as per the normalize function.
urlToDataPackage
can be either a url to actual datapackage.json or to a base directory.
datapackage.create(info, callback)
info
is an (optional) hash containing data to use for datapackage info most importantly it can contain a url or resource.url pointing to a data file (CSV). This file will be analyzed and used to create the resource entry in the datapackage.json.
datapackage.validate(rawData)
datapackage.validate(url)
Validate a datapackage either provided directly (as a raw string - JSON parse is done in the method) or as a url. This method is synchronous.
Returned object has structure:
{
valid: true | false
errors: [
{
message: ...
... possibly other info ...
},
{
...
}
]
}
var stream = datapackage.createReadStream('pathTo/datapackage', datapackage, resourceName, options);
options
, an object with the following properties:
- objectMode: (true/false) return a stream in objectMode. In case of a JSON array, every row is emmitted separatly.
- coerce: (true/false) coerce the values according to the types specified in schema (implies objectMode)
- ldjsonify: (true/false) JSON.stringify + '\n' (implies objectMode)
- foreignkeys: (true/false) take into account foreignkeys support for SDF (implies objectMode). This option assumes that the
datapackages have been installed by npm (so that the package.json files of the dependecies are in
node_modules/
(see here)).
- #1 - change to name on fields in resource schemas