Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geojsonhint

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojsonhint - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

active.json

74

index.js

@@ -5,3 +5,3 @@ var jsonlint = require('jsonlint-lines');

var errors = [];
var errors = [], gj;

@@ -11,3 +11,3 @@ function root(_) {

errors.push({
message: 'The type member is required and was not found',
message: 'The type property is required and was not found',
line: _.__line__

@@ -25,2 +25,6 @@ });

function everyIs(_, type) {
return _.every(function(x) { return typeof x === 'number'; });
}
function requiredProperty(_, name, type) {

@@ -51,3 +55,6 @@ if (typeof _[name] == 'undefined') {

// http://geojson.org/geojson-spec.html#feature-collection-objects
function FeatureCollection(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'features', 'array')) {

@@ -73,5 +80,3 @@ _.features.forEach(Feature);

}
if (_.some(function(p) {
return (typeof p !== 'number');
})) {
if (!everyIs(_, 'number')) {
return errors.push({

@@ -105,4 +110,39 @@ message: 'each element in a position must be a number',

function crs(_) {
if (!_.crs) return;
if (typeof _.crs === 'object') {
var strErr = requiredProperty(_.crs, 'type', 'string'),
propErr = requiredProperty(_.crs, 'properties', 'object');
if (!strErr && !propErr) {
// http://geojson.org/geojson-spec.html#named-crs
if (_.crs.type == 'name') {
requiredProperty(_.crs.properties, 'name', 'string');
} else if (_.crs.type == 'link') {
requiredProperty(_.crs.properties, 'href', 'string');
}
}
}
}
function bbox(_) {
if (!_.bbox) return;
if (Array.isArray(_.bbox)) {
if (!everyIs(_.bbox, 'number')) {
return errors.push({
message: 'each element in a bbox property must be a number',
line: _.bbox.__line__
});
}
} else {
errors.push({
message: 'bbox property must be an array of numbers, but is a ' + (typeof _.bbox),
line: _.__line__
});
}
}
// http://geojson.org/geojson-spec.html#point
function Point(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -113,3 +153,6 @@ position(_.coordinates);

// http://geojson.org/geojson-spec.html#polygon
function Polygon(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -120,3 +163,6 @@ positionArray(_.coordinates, 2);

// http://geojson.org/geojson-spec.html#multipolygon
function MultiPolygon(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -127,3 +173,6 @@ positionArray(_.coordinates, 3);

// http://geojson.org/geojson-spec.html#linestring
function LineString(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -134,3 +183,6 @@ positionArray(_.coordinates, 1);

// http://geojson.org/geojson-spec.html#multilinestring
function MultiLineString(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -143,2 +195,4 @@ positionArray(_.coordinates, 2);

function MultiPoint(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'coordinates', 'array')) {

@@ -150,2 +204,4 @@ positionArray(_.coordinates, 1);

function GeometryCollection(_) {
crs(_);
bbox(_);
if (!requiredProperty(_, 'geometries', 'array')) {

@@ -157,2 +213,10 @@ _.geometries.forEach(root);

function Feature(_) {
crs(_);
bbox(_);
if (_.type !== 'Feature') {
errors.push({
message: 'GeoJSON features must have a type=feature property',
line: _.__line__
});
}
requiredProperty(_, 'properties', 'object');

@@ -159,0 +223,0 @@ requiredProperty(_, 'geometry', 'object');

2

package.json
{
"name": "geojsonhint",
"version": "0.1.1",
"version": "0.1.2",
"description": "validate and sanity-check geojson files",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -13,13 +13,53 @@ [![Build Status](https://secure.travis-ci.org/tmcw/geojsonhint.png?branch=master)](http://travis-ci.org/tmcw/geojsonhint)

Lint a file - given _as a string_ - with the GeoJSON expectations baked in.
An example of the output:
## install
```json
[{
"message": "\"features\" property should be an array, but is an object instead",
"line": 1
}]
```
# as a binary
npm install -g geojsonhint
## use it
# as a library
as a library
npm install --save geojsonhint
as a web library
curl https://raw.github.com/tmcw/geojsonhint/master/geojsonhint.js > geojsonhint.js
## binary
Install:
npm install -g geojsonhint
```
tmcw➟ geojsonhint
Usage: node /usr/local/share/npm/bin/geojsonhint FILE.geojson
Options:
--json output json-formatted data for hints
```
```
➟ geojsonhint test.geojson
line 9, each element in a position must be a number
```
## developing
Tests:
npm test
Building the browser version:
npm install -g browserify
make
## See Also
[geojsonlint.com](http://geojsonlint.com/) does this server-side

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc