Skip to content

Official javascript library for Data Packages in Node and the browser.

License

Notifications You must be signed in to change notification settings

deanrather/datapackage-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataPackage.js

Gitter

Official javascript library for Data Packages in Node and the browser.

Install

npm coming soon.

For now clone from github!

Usage

var datapacakge = require('datapackage');

// instantiate with a path
var dp = new datapackage.DataPackage('/path/on/disk/to/package/')

// then load datapackage.json info
dp.load()
  .then(function() {
    // all the datapackage.json data is available via the metadata attribute
    // e.g. this will produce 'abc'
    console.log(dp.data.name);
  });


// you can also load direct from JSON object
var dpJson = {
  'name': 'abc'
};
var dp = new datapackage.DataPackage(dpJson);

Resources

var dp = a data package with some resources

// Access the Data Pacakge data resources
var resource = dp.resources[0]

// will return the full path (url or on disk for the resource)
resource.fullPath()

// all data package resource properties are available via metadata attribute
resource.metadata.title

// get the raw data file stream
resource.rawStream()

// get the data stream as set of JS objects (one for each row)
// this only works for tabular data at present
// data is automatically typecast
resource.stream()

csvToSTream

Convenience function to load and convert a CSV to a stream using a JSON Table Schema and CSV Dialect description.

// returns a Node **object** stream
// the csv dialect is optional
var stream = datapackage.csvToStream(rawDataStream, jsonTableSchema, csvDialect)

stream.on('readable', function() {
  while(row = stream.read()) {
    // something like {'col-1': 'abc', 'col-2': 2, ...}
    console.log(row);
  }
});

About

Official javascript library for Data Packages in Node and the browser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%