Skip to content

Module for reading datapackage.json files with defaults, normalization and more

Notifications You must be signed in to change notification settings

openknowledge-archive/datapackage-read-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

datapackage-read

This is a module that reads datapackage.json files. It validates some stuff, and loads some default things.

Installation

NPM

npm install datapackage-read

Usage

The following assume you've required datapackage as follows:

var datapackage = require('datapackage-read');

load

datapackage.load(path, callback)
  • path {String} The path to the Data Package directory or the datapackage.json file

Load a datapackage.json from a file and normalize it as per the normalize function. Will search for README at README.md in same directory as datapackage.json.

loadUrl

datapackage.loadUrl(urlToDataPackage, callback)

Load a datapackage.json from a URL, related files (e.g. README.md) and normalize it

normalize

datapackage.normalize(datapackage, url)
  • datapackage: datapackage.json object (already parsed from JSON)
  • url: [optional] url to datapackage.json or the root directory in which it is contained online. Used to help auto-generate things homepage

Normalize a DataPackage DataPackage.json in various ways, for example:

  • Setting a description if missing (from readme)
  • Setting a url for resources
  • Guessing a homepage

parseSpecString

datapackage.parseSpecString(specString)

Parse a Data Package Spec string to a Spec object/dictionary. (See below for more on Data Package Specs).

Data Package Spec (Specifier)

A Data Package "Spec" is a small Object/Hash which describing the identify and location of a Data Package. Its structure is like:

{
  url: ...
  name: ...
  version: ...
}

It can be parsed (and less importantly) serialized to a simple string. Spec strings will be frequently used on e.g. the command line to identify a data package.

A spec string can be:

  • A direct URL to a datapackage e.g.

     http://mywebsite.com/mydatapackage/
     // or with the datapackage.json
     http://mywebsite.com/mydatapackage/datapackage.json
    
  • A github URL

     http://github.com/datasets/gold-prices
    
  • A single name

     gold-prices
    

    In this case the data package must be in the core datasets in the primary registry.

Tests

Run the tests with:

npm test

About

Module for reading datapackage.json files with defaults, normalization and more

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published