1 | var jsonlint = require('jsonlint-lines'),
|
2 | geojsonHintObject = require('./object');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function hint(str, options) {
|
14 |
|
15 | var gj, errors = [];
|
16 |
|
17 | if (typeof str === 'object') {
|
18 | gj = str;
|
19 | } else if (typeof str === 'string') {
|
20 | try {
|
21 | gj = jsonlint.parse(str);
|
22 | } catch(e) {
|
23 | var match = e.message.match(/line (\d+)/),
|
24 | lineNumber = 0;
|
25 | if (match) { lineNumber = parseInt(match[1], 10); }
|
26 | return [{
|
27 | line: lineNumber - 1,
|
28 | message: e.message,
|
29 | error: e
|
30 | }];
|
31 | }
|
32 | } else {
|
33 | return [{
|
34 | message: 'Expected string or object as input',
|
35 | line: 0
|
36 | }];
|
37 | }
|
38 |
|
39 | errors = errors.concat(geojsonHintObject.hint(gj, options));
|
40 |
|
41 | return errors;
|
42 | }
|
43 |
|
44 | module.exports.hint = hint;
|