This module serves the JSON schema definitions for GeoJSON and a validator extended from the
NPM module jsonschema.
It serves declaration files for TypeScript.
First you have to install this library from npm:
npm install --save @yaga/geojson-schema
# OR
yarn add @yaga/geojson-schemaYou will find the schema definitions as single json files in the subfolder schema or while
Use this module with TypeScript:
import { GeoJSONValidator, validate, schemas } from "@yaga/geojson-schema";
const point = {
type: "Point",
coordinates: [1, 2],
};
// With an instance of a class
const aNewValidator = new GeoJSONValidator();
console.log(
"Validation results:",
aNewValidator.validate(point, schemas.point),
);
// With a factory function
console.log(
"Validation results:",
validate(point, schemas.point),
);Use the module with JavaScript:
const { GeoJSONValidator, validate, schemas } = require('@yaga/geojson-schema');
const point = {
type: "Point",
coordinates: [1, 2],
};
// With an instance of a class
const aNewValidator = new GeoJSONValidator();
console.log(
"Validation results:",
aNewValidator.validate(point, schemas.point),
);
// With a factory function
console.log(
"Validation results:",
validate(point, schemas.point),
);The module provides the following schemas:
import { schemas } from "@yaga/geojson-schema";
// The namespace schemas includes the following schemas:geometryTypes:http://geojson.org/schema/geometry-typesgeoJSONTypes:http://geojson.org/schema/geojson-typesbbox:http://geojson.org/schema/bboxgeoJSONObject:http://geojson.org/schema/geojson-objectgeometryObject:http://geojson.org/schema/geometry-objectposition:http://geojson.org/schema/positionpoint:http://geojson.org/schema/pointmultiPoint:http://geojson.org/schema/multi-pointlineString:http://geojson.org/schema/line-stringmultiLineString:http://geojson.org/schema/multi-line-stringpolygon:http://geojson.org/schema/polygonmultiPolygon:http://geojson.org/schema/multi-polygongeometryCollection:http://geojson.org/schema/geometry-collectionanyGeometry:http://geojson.org/schema/any-geometryfeature:http://geojson.org/schema/featurefeatureCollection:http://geojson.org/schema/feature-collection
The list represents the key followed by the schema-id
For further information look at the GeoJSON specification or the TypeScript TypeDefinition for GeoJSON.
Scripts registered in package.json:
transpile: Transpile TypeScript Code to JavaScript.lint: Use the linter for TypeScript Code.test: Run software-tests in node.dist: Make everything ready for a release.
This library is released under the ISC License.