Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/openknowledge-archive/datapackage-validate-js

[DEPRECATED] Replacement: https://github.com/frictionlessdata/datapackage-js
https://github.com/openknowledge-archive/datapackage-validate-js

Last synced: 13 days ago
JSON representation

[DEPRECATED] Replacement: https://github.com/frictionlessdata/datapackage-js

Awesome Lists containing this project

README

        

datapackage-validate
====================

Validate [Data Package][] datapackage.json files.

[Data Package]: http://data.okfn.org/doc/data-package

# Installation

[![NPM](https://nodei.co/npm/datapackage-validate.png)](https://nodei.co/npm/datapackage-validate/)

```
npm install datapackage-validate
```

# Usage

Following assume you've imported the module as follows:

```
var validator = require('datapackage-validate');
```

## validate

Validate the provided object or string as a Data Package.

```
validator.validate(raw, schema)
```

* `raw`: datapackage.json string or object to validate (note method will
take care of parsing the string and checking it is valid JSON if it is not
parsed already)
* `schema`: A schema to validate `raw` against, or, a string that is the unique identifier for a schema in the [Data Package Registry](https://github.com/dataprotocols/registry), which is used to retrieve the matching schema

Note the method is asynchronous and returns a Promise (implemented with [bluebird](https://www.npmjs.com/package/bluebird)).
The Promise resolves with following structure:

```
{
valid: true | false,
errors: [
{
// every error has a message
message: 'Invalid JSON: ...'
// JSON errors come from json-lint and will also have
line:
},
{
message: 'Array is too short (0), minimum 1',
// schema errors come from schema validator and include additiona
// path in input JSON
dataPath: '/resources',
// path in schema
schemaPath: '/properties/resources/minItems',
},
...
]
warnings: [
{
message: 'No title field'
},
...
]
};
```

# Changelog

* v0.3.0:
* Adds support for any Profile in the [Data Package Registry](https://github.com/dataprotocols/registry)
* API is now async using bluebird Promises
* Removes hardcoded schemas
* Removes validateUrl
* v0.2.0: #1, #2, #4 (jsonlint, much better schema validation using official schemas)
* v0.1.0: first working release