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

geojson-validation

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-validation - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

app.js
var gjVal = require("./index.js");
gj = {type: "MultiPoint", coordinates: [[2,3],[5,6]]};
gjVal.isMultiPoint(gj);
var validGeoCollection = {

@@ -5,0 +8,0 @@ "type": "GeometryCollection",

155

index.js

@@ -103,3 +103,3 @@ /**

* @method isPosition
* @param position {Object}
* @param position {Array}
* @param [cb] {Function} the callback

@@ -224,2 +224,30 @@ * @return {Boolean}

/**
* Determines if an array can be interperted as coordinates for a MultiPoint
* @method isMultiPointCoor
* @param coordinates {Array}
* @param [cb] {Function} the callback
* @return {Boolean}
*/
exports.isMultiPointCoor = function(coordinates, cb) {
var errors = [];
if(Array.isArray(coordinates)){
coordinates.forEach(function(val, index){
exports.isPosition(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
return _done(cb, errors);
}
/**
* Determines if an object is a MultiPoint or not

@@ -251,16 +279,7 @@ * @method isMultiPoint

if('coordinates' in multiPoint){
if(Array.isArray(multiPoint.coordinates)){
multiPoint.coordinates.forEach(function(val, index){
exports.isPosition(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
exports.isMultiPointCoor(multiPoint.coordinates, function(valid, err){
if(!valid){
errors = errors.concat(err);
}
});
}else{

@@ -277,10 +296,9 @@ errors.push("must have a member with the name 'coordinates'");

/**
* Determines if an object is a MultiPoint or not
* @method _lineStringCoor
* @private
* @param coordinates {Object}
* Determines if an array can be interperted as coordinates for a lineString
* @method isLineStringCoor
* @param coordinates {Array}
* @param [cb] {Function} the callback
* @return {Boolean}
*/
function _lineStringCoor(coordinates, cb) {
exports.isLineStringCoor = function(coordinates, cb) {

@@ -338,3 +356,3 @@ var errors = [];

if('coordinates' in lineString){
_lineStringCoor(lineString.coordinates, function(valid, err){
exports.isLineStringCoor(lineString.coordinates, function(valid, err){
if(!valid){

@@ -355,2 +373,28 @@ errors = errors.concat(err);

/**
* Determines if an array can be interperted as coordinates for a MultiLineString
* @method isMultiLineStringCoor
* @param coordinates {Array}
* @param [cb] {Function} the callback
* @return {Boolean}
*/
exports.isMultiLineStringCoor = function(coordinates, cb) {
var errors = [];
if(Array.isArray(coordinates)){
coordinates.forEach(function(val, index){
exports.isLineStringCoor(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
_done(cb, errors);
}
/**
* Determines if an object is a MultiLine String or not

@@ -383,16 +427,7 @@ * @method isMultiLineString

if('coordinates' in multilineString){
if(Array.isArray(multilineString.coordinates)){
multilineString.coordinates.forEach(function(val, index){
_lineStringCoor(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
exports.isMultiLineStringCoor(multilineString.coordinates, function(valid, err){
if(!valid){
errors = errors.concat(err);
}
});
}else{

@@ -457,3 +492,3 @@ errors.push("must have a member with the name 'coordinates'");

*/
function _polygonCoor(coordinates, cb){
exports.isPolygonCoor = function (coordinates, cb){

@@ -507,3 +542,3 @@ var errors = [];

if('coordinates' in polygon){
_polygonCoor(polygon.coordinates, function(valid, err) {
exports.isPolygonCoor(polygon.coordinates, function(valid, err) {
if(!valid){

@@ -524,2 +559,29 @@ errors = errors.concat(err);

/**
* Determines if an array can be interperted as coordinates for a MultiPolygon
* @method isMultiPolygonCoor
* @param coordinates {Array}
* @param [cb] {Function} the callback
* @return {Boolean}
*/
exports.isMultiPolygonCoor = function(coordinates, cb) {
var errors = [];
if(Array.isArray(coordinates)){
coordinates.forEach(function(val, index){
exports.isPolygonCoor(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
_done(cb, errors);
}
/**
* Determines if an object is a valid MultiPolygon

@@ -552,16 +614,7 @@ * @method isMultiPolygon

if('coordinates' in multiPolygon){
if(Array.isArray(multiPolygon.coordinates)){
multiPolygon.coordinates.forEach(function(val, index){
_polygonCoor(val, function(valid, err){
if(!valid){
//modify the err msg from "isPosition" to note the element number
err[0] = "at "+ index+ ": ".concat(err[0]);
//build a list of invalide positions
errors = errors.concat(err);
}
});
});
}else{
errors.push("coordinates must be an array");
}
exports.isMultiPolygonCoor(multiPolygon.coordinates, function(valid, err){
if(!valid){
errors = errors.concat(err);
}
});
}else{

@@ -568,0 +621,0 @@ errors.push("must have a member with the name 'coordinates'");

{
"name": "geojson-validation",
"version": "0.1.2",
"version": "0.1.3",
"description": "A GeoJSON Validation Library",

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

@@ -11,3 +11,3 @@ GeoJSON-Validation

## Functions
All Function return a boolean and take a JSON object that will be evalatued to see if it is a GeoJSON object, with the exception of `define`.
All Function return a boolean and take a JSON object that will be evalatued to see if it is a GeoJSON object, with the exception of [define](#definetype-function).

@@ -25,23 +25,38 @@ **Arguments**

### isGeometryObject(geoJSON, callback)
Checks if an object is a [Geometry Object](http://geojson.org/geojson-spec.html#geometry-objects)
### isPosition(array, callback)
Checks if an array is a [Position](http://geojson.org/geojson-spec.html#positions)
### isGeometryObject(geoJSON, callback)
Checks if an object is a [Geometry Object](http://geojson.org/geojson-spec.html#geometry-objects)
### isPoint(geoJSON, callback)
Checks if an object is a [Point](http://geojson.org/geojson-spec.html#point)
### isMultiPointCoor(array, callback)
Checks if an array can be interperted as coordinates for a MultiPoint
### isMultiPoint(geoJSON, callback)
Checks if an object is a [MultiPoint](http://geojson.org/geojson-spec.html#multipoint)
### isLineStringCoor(array, callback)
Checks if an array can be interperted as coordinates for a LineString
### isLineString(geoJSON, callback)
Checks if an object is a [Line String](http://geojson.org/geojson-spec.html#linestring)
### isMultiLineStringCoor(array, callback)
Checks if an array can be interperted as coordinates for a MultiLineString
### isMultiLineString(geoJSON, callback)
Checks if an object is a [MultiLine String](http://geojson.org/geojson-spec.html#multilinestring)
### isPolygonCoor(array, callback)
Checks an array can be interperted as coordinates for a Polygon
### isPolygon(geoJSON, callback)
Checks if an object is a [Polygon](http://geojson.org/geojson-spec.html#polygon)
### isMultiPolygonCoor(array, callback)
Checks if an array can be interperted as coordinates for a MultiPolygon
### isMultiPolygon(geoJSON, callback)

@@ -63,5 +78,6 @@ Checks if an object is a [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon)

### Define(type, function)
Define a Custom Validation for the give `type`. Type can "Feature", "FeatureCollection", "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Bbox", "Position", "GeoJSON", "GeometryObject".
The `function` is passed the `object` being validated and should return a `string` or an `array` of strings repesenting errors. If there are no errors then the function should not return anything or an empty array. See the [example](#define-example) for more.
Define a Custom Validation for the give `type`. `type` can be "Feature", "FeatureCollection", "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Bbox", "Position", "GeoJSON" or "GeometryObject".
The `function` is passed the `object` being validated and should return a `string` or an `array` of strings representing errors. If there are no errors then the function should not return anything or an empty array. See the [example](#define-example) for more.
## Example

@@ -124,4 +140,3 @@ ```javascript

## Define Example
Shout out to @VitoLau for the code
Shout out to [@VitoLau](https://github.com/VitoLau>) for the code! Thanks!
```javascript

@@ -131,4 +146,2 @@ GJV = require("geojson-validation");

GJV.define("Position", function(position){
//Shout out to @VitoLau <https://github.com/VitoLau> for the code
//the postion must be valid point on the earth, x between -180 and 180

@@ -147,3 +160,4 @@ errors = [];

gj = {type: "Point", coordinates: [-200,3]};
//returns false
GJV.isPoint(gj);
```

@@ -150,0 +164,0 @@

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