geojsonhint
Advanced tools
Comparing version 0.0.0 to 0.1.0
63
index.js
@@ -8,4 +8,15 @@ var jsonlint = require('jsonlint-lines'); | ||
function root(_) { | ||
if (!_.type) return 'The type member is required and was not found'; | ||
types[_.type](_); | ||
if (!_.type) { | ||
errors.push({ | ||
message: 'The type member is required and was not found', | ||
line: _.__line__ | ||
}); | ||
} else if (!types[_.type]) { | ||
errors.push({ | ||
message: 'The type ' + _.type + ' is unknown', | ||
line: _.__line__ | ||
}); | ||
} else { | ||
types[_.type](_); | ||
} | ||
} | ||
@@ -45,3 +56,3 @@ | ||
// http://geojson.org/geojson-spec.html#positions | ||
function position(_) { | ||
function position(_, line) { | ||
if (!Array.isArray(_)) { | ||
@@ -51,3 +62,3 @@ return errors.push({ | ||
' instead', | ||
line: _.__line__ | ||
line: _.__line__ || line | ||
}); | ||
@@ -58,3 +69,3 @@ } else { | ||
message: 'position must have 2 or more elements', | ||
line: _.__line__ | ||
line: _.__line__ || line | ||
}); | ||
@@ -67,3 +78,3 @@ } | ||
message: 'each element in a position must be a number', | ||
line: _.__line__ | ||
line: _.__line__ || line | ||
}); | ||
@@ -74,2 +85,22 @@ } | ||
function positionArray(coords, depth, line) { | ||
if (line === undefined && coords.__line__ !== undefined) { | ||
line = coords.__line__; | ||
} | ||
if (depth === 0) { | ||
return position(coords, line); | ||
} else { | ||
if (!Array.isArray(coords)) { | ||
return errors.push({ | ||
message: 'coordinates should be an array, are an ' + (typeof coords) + | ||
'instead', | ||
line: line | ||
}); | ||
} | ||
coords.forEach(function(c) { | ||
positionArray(c, depth - 1, c.__line__ || line); | ||
}); | ||
} | ||
} | ||
// http://geojson.org/geojson-spec.html#point | ||
@@ -83,15 +114,23 @@ function Point(_) { | ||
function Polygon(_) { | ||
requiredProperty(_, 'coordinates', 'array'); | ||
if (!requiredProperty(_, 'coordinates', 'array')) { | ||
positionArray(_.coordinates, 2); | ||
} | ||
} | ||
function MultiPolygon(_) { | ||
requiredProperty(_, 'coordinates', 'array'); | ||
if (!requiredProperty(_, 'coordinates', 'array')) { | ||
positionArray(_.coordinates, 3); | ||
} | ||
} | ||
function LineString(_) { | ||
requiredProperty(_, 'coordinates', 'array'); | ||
if (!requiredProperty(_, 'coordinates', 'array')) { | ||
positionArray(_.coordinates, 1); | ||
} | ||
} | ||
function MultiLineString(_) { | ||
requiredProperty(_, 'coordinates', 'array'); | ||
if (!requiredProperty(_, 'coordinates', 'array')) { | ||
positionArray(_.coordinates, 2); | ||
} | ||
} | ||
@@ -101,3 +140,5 @@ | ||
function MultiPoint(_) { | ||
requiredProperty(_, 'coordinates', 'array'); | ||
if (!requiredProperty(_, 'coordinates', 'array')) { | ||
positionArray(_.coordinates, 1); | ||
} | ||
} | ||
@@ -104,0 +145,0 @@ |
{ | ||
"name": "geojsonhint", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "validate and sanity-check geojson files", | ||
@@ -14,2 +14,5 @@ "main": "index.js", | ||
}, | ||
"bin": { | ||
"geojsonhint": "./bin/geojsonhint" | ||
}, | ||
"scripts": { | ||
@@ -32,4 +35,6 @@ "test": "mocha -R spec" | ||
"dependencies": { | ||
"jsonlint-lines": "~1.6.0" | ||
"jsonlint-lines": "~1.6.0", | ||
"optimist": "~0.6.0", | ||
"colors": "~0.6.0-1" | ||
} | ||
} |
@@ -16,6 +16,10 @@ [![Build Status](https://secure.travis-ci.org/tmcw/geojsonhint.png?branch=master)](http://travis-ci.org/tmcw/geojsonhint) | ||
npm install geojsonhint | ||
# as a binary | ||
npm install -g geojsonhint | ||
# as a library | ||
npm install --save geojsonhint | ||
## See Also | ||
[geojsonlint.com](http://geojsonlint.com/) does this server-side |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10521
32
180
25
3
2
+ Addedcolors@~0.6.0-1
+ Addedoptimist@~0.6.0
+ Addedcolors@0.6.2(transitive)
+ Addedminimist@0.0.10(transitive)
+ Addedoptimist@0.6.1(transitive)
+ Addedwordwrap@0.0.3(transitive)