Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
The GeoJSON.js is designed to build and validate GeoJSON feature collections.
To get started with the GeoJSON.js, install geojsonjs
package to your project.
npm i geojsonjs
yarn add geojsonjs
const geom = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
],
};
import { getFeatureCollection, validate } from 'geojsonjs';
const featureCollection = getFeatureCollection(geom);
const result = validate(featureCollection);
// TypeScript
import {
getFeatureCollection,
validate,
FeatureCollection,
ValidationResult,
} from 'geojsonjs';
const featureCollection: FeatureCollection = getFeatureCollection(geom);
const result: ValidationResult = validate(featureCollection);
Name | Returns | |
---|---|---|
parse | FeatureCollection | More info |
getGeometries | Geometry[] | More info |
getFeatures | Feature[] | More info |
getFeatureCollection | FeatureCollection | More info |
Accepts array or object of type
, coordinates
and properties
(optional)
Returns feature collection
Example:
import { parse } from 'geojsonjs';
const featureCollection = parse({ type: 'Point', coordinates: [11, 22] });
const featureCollection2 = parse([
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } },
]);
// TypeScript
import { parse, FeatureCollection } from 'geojsonjs';
const featureCollection: FeatureCollection = parse({
type: 'Point',
coordinates: [11, 22],
});
const featureCollection2: FeatureCollection = parse([
{ type: 'Point', coordinates: [11, 22], properties: { prop1: 'prop1' } },
]);
Finds and returns all geometries from data.
Supports all geometry types.
Returns array of geometries
Example:
import { getGeometries } from 'geojson';
const geometries = getGeometries(geom);
// TypeScript
import { getGeometries, Geometry } from 'geojson';
const geometries: Geometry[] = getGeometries(geom);
Finds and returns all features from data.
Supports all geometry types.
Returns array of features
Example:
import { getFeatures } from 'geojson';
const features = getFeatures(geom);
// TypeScript
import { getFeatures, Feature } from 'geojson';
const features: Feature[] = getFeatures(geom);
Finds and returns feature collection from data.
Supports all geometry types.
Returns feature collection
Example:
import { getFeatureCollection } from 'geojson';
const featureCollection = getFeatureCollection(geom);
// TypeScript
import { getFeatureCollection, FeatureCollection } from 'geojson';
const featureCollection: FeatureCollection = getFeatureCollection(geom);
Each validation returns Validation Result response
Name | Params | |
---|---|---|
validate | geom: AllTypes | More info |
validateCoordinates | type: string, coordinates: CoordinatesTypes | More info |
validateGeometry | geometry: Geometry | More info |
validateFeature | feature: Feature | More info |
validateFeatures | features: Feature[] | More info |
validateFeatureCollection | collection: FeatureCollection | More info |
validateGeometryTypes | types: string | string [], geom: AllTypes | More info |
Supports all geometry types.
Example:
import { validate } from 'geojsonjs';
const result = validate(geom);
// TypeScript
import { validate, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validate(geom);
Accepts type
and coordinates
.
Example:
import { validateCoordinates } from 'geojsonjs';
const result = validateCoordinates('Point', [11, 12]);
// TypeScript
import { validateCoordinates, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateCoordinates('Point', [11, 12]);
Accepts geometry
Example:
const geometry = { type: 'Point', coordinates: [11, 22] };
import { validateGeometry } from 'geojsonjs';
const result = validateGeometry(geometry);
// TypeScript
import { validateGeometry, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateGeometry(geometry);
Accepts feature
Example:
const feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
};
import { validateFeature } from 'geojsonjs';
const result = validateFeature(feature);
// TypeScript
import { validateFeature, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeature(feature);
Accepts features array
Example:
const features = [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
];
import { validateFeatures } from 'geojsonjs';
const result = validateFeatures(features);
// TypeScript
import { validateFeatures, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeatures(features);
Accepts feature collection
Example:
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
],
};
import { validateFeatureCollection } from 'geojsonjs';
const result = validateFeatureCollection(featureCollection);
// TypeScript
import { validateFeatureCollection, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validateFeatureCollection(featureCollection);
Example: Accepts geometry type OR array of geometry types and feature collection
const featureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [11, 22],
},
},
],
};
import { GeometryType, validateGeometryTypes } from 'geojsonjs';
const result = validateGeometryTypes([GeometryType.POINT], featureCollection);
// TypeScript
import {
GeometryType,
validateGeometryTypes,
ValidationResult,
} from 'geojsonjs';
const result: ValidationResult = validateGeometryTypes(
GeometryType.POINT,
featureCollection
);
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
]
}
[
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
]
},
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [33, 44]
}
}
]
}
]
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
}
[
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [11, 22]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [33, 44]
}
}
]
{
"type": "Point",
"coordinates": [11, 22]
}
[
{
"type": "Point",
"coordinates": [11, 22]
},
{
"type": "Point",
"coordinates": [33, 44]
}
]
import { GeometryType } from 'geojsonjs';
GeometryType.POINT; // Point
GeometryType.MULTI_POINT; // MultiPoint
GeometryType.LINE_STRING; // LineString
GeometryType.MULTI_LINE_STRING; // MultiLineString
GeometryType.POLYGON; // Polygon
GeometryType.MULTI_POLYGON; // MultiPolygon
Valid example:
{
"valid": true
}
Invalid example:
{
"valid": false,
"error": "INVALID_TYPE",
"data": {
"type": "Pointt"
}
}
import { ValidationError } from 'geojsonjs';
ValidationError.EMTPY; // EMTPY
ValidationError.EMPTY_FEATURES; // EMPTY_FEATURES
ValidationError.EMPTY_COORDINATES; // INVALID_COORDINATES
ValidationError.EMPTY_TYPE; // EMPTY_TYPE
ValidationError.INVALID_TYPE; // INVALID_TYPE
ValidationError.INVALID_FEATURES; // INVALID_FEATURES
ValidationError.INVALID_COORDINATES; // INVALID_COORDINATES
ValidationError.INVALID_PROPERTIES; // INVALID_PROPERTIES
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request. For more information, see the contribution guidelines.
This project is licensed under the MIT License.
FAQs
Build and validate GeoJSON
The npm package geojsonjs receives a total of 55 weekly downloads. As such, geojsonjs popularity was classified as not popular.
We found that geojsonjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.