Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Commit

Permalink
Add API docs. Fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jan 25, 2015
1 parent c9f0e8a commit 06747a4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
30 changes: 30 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### `validate(str)`

Validate a Mapbox GL Style given as a string of JSON. Returns an array
that can contain any number of objects representing errors. Each
object has members `line` (number) and `message` (string).

This expects the style to be given as a string, rather than an object,
so that it can return accurate line numbers for errors. If you happen to
have an object, you'll need to use JSON.stringify() to convert it to a string
first.


### Parameters

| parameter | type | description |
| --------- | ------ | ----------------------------- |
| `str` | string | a Mapbox GL Style as a string |


### Example

```js
var fs = require('fs');
var validate = require('mapbox-gl-style-lint');
var style = fs.readFileSync('./style.json', 'utf8');
var errors = validate(style);
```


**Returns** `Array.<Object>`, an array of error objects
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ $ gl-style-validate style.json
Will validate the given style JSON and print errors to stdout. Provide a
`--json` flag to get JSON output.

### [API](API.md)

### Migrations

This repo contains scripts for migrating GL styles of any version to the latest version
Expand Down
19 changes: 19 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ var reference = require('mapbox-gl-style-spec/reference/v6');
var parseCSSColor = require('csscolorparser').parseCSSColor;
var format = require('util').format;

/**
* Validate a Mapbox GL Style given as a string of JSON. Returns an array
* that can contain any number of objects representing errors. Each
* object has members `line` (number) and `message` (string).
*
* This expects the style to be given as a string, rather than an object,
* so that it can return accurate line numbers for errors. If you happen to
* have an object, you'll need to use JSON.stringify() to convert it to a string
* first.
*
* @alias validate
* @param {string} str a Mapbox GL Style as a string
* @returns {Array<Object>} an array of error objects
* @example
* var fs = require('fs');
* var validate = require('mapbox-gl-style-lint');
* var style = fs.readFileSync('./style.json', 'utf8');
* var errors = validate(style);
*/
module.exports = function(str) {
var style;

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"scripts": {
"test": "jshint lib/*.js migrations/*.js && tape test/*.js test/migrations/*.js",
"doc": "dox -r < lib/validate.js | doxme",
"cov": "istanbul cover ./node_modules/.bin/tape test/*.js test/migrations/*.js && coveralls < ./coverage/lcov.info"
},
"repository": {
Expand All @@ -18,12 +19,14 @@
},
"license": "ISC",
"devDependencies": {
"tape": "^2.12.1",
"jshint": "^2.5.0",
"coveralls": "~2.10.0",
"coverify": "~1.0.7",
"dox": "^0.6.1",
"doxme": "^1.4.2",
"istanbul": "~0.2.11",
"coveralls": "~2.10.0",
"mapbox-gl-styles": "git+https://github.com/mapbox/mapbox-gl-styles.git#mb-pages"
"jshint": "^2.5.0",
"mapbox-gl-styles": "git+https://github.com/mapbox/mapbox-gl-styles.git#mb-pages",
"tape": "^2.12.1"
},
"dependencies": {
"csscolorparser": "~1.0.2",
Expand Down

0 comments on commit 06747a4

Please sign in to comment.