npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

geojsonjs

v0.1.2

Published

Build and validate GeoJSON

Readme

Build and validate GeoJSON with Node.js

License GitHub issues GitHub stars

Table of Contents

About the Project

The GeoJSON.js is designed to build and validate GeoJSON feature collections.

Getting Started

To get started with the GeoJSON.js, install geojsonjs package to your project.

npm i geojsonjs
yarn add geojsonjs

Usage

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);

Documentation

Global functions

| Name | Returns | | | ---------------------- | ------------------- | ---------------------------------- | | parse | FeatureCollection | More info | | getGeometries | Geometry[] | More info | | getFeatures | Feature[] | More info | | getFeatureCollection | FeatureCollection | More info |

parse

Accepts array or object of type, coordinates and properties (optional).

Also you can parse GeometryCollection (object or array of objects). In that case instead of coordinates and properties it uses geometries.

Returns feature collection

Example:

import { parse } from 'geojsonjs';

const point1 = { type: 'Point', coordinates: [11, 22] };
const point2 = {
  type: 'Point',
  coordinates: [11, 22],
  properties: { prop1: 'prop1' },
};
const geometryCollection = {
  type: 'GeometryCollection',
  geometries: [{ type: 'Point', coordinates: [11, 22] }],
};

const featureCollection = parse(point1);
const featureCollection2 = parse([point1, point2]);
const featureCollection3 = parse(geometryCollection);

// TypeScript
import { parse, FeatureCollection } from 'geojsonjs';

const featureCollection: FeatureCollection = parse(point1);
const featureCollection2: FeatureCollection = parse([point1, point2]);
const featureCollection3: FeatureCollection = parse(geometryCollection);

getGeometries

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);

getFeatures

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);

getFeatureCollection

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);

Validation

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 |

validate

Supports all geometry types.

Example:

import { validate } from 'geojsonjs';
const result = validate(geom);

// TypeScript
import { validate, ValidationResult } from 'geojsonjs';
const result: ValidationResult = validate(geom);

validateCoordinates

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]);

validateGeometry

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);

validateFeature

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);

validateFeatures

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);

validateFeatureCollection

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);

validateGeometryTypes

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
);

Types

Feature Collection

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [11, 22]
      }
    }
  ]
}

Feature Collections (array)

[
  {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Point",
          "coordinates": [11, 22]
        }
      }
    ]
  },
  {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Point",
          "coordinates": [33, 44]
        }
      }
    ]
  }
]

Feature

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [11, 22]
  }
}

Features (array)

[
  {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [11, 22]
    }
  },
  {
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": [33, 44]
    }
  }
]

Geometry

{
  "type": "Point",
  "coordinates": [11, 22]
}

Geometries (array)

[
  {
    "type": "Point",
    "coordinates": [11, 22]
  },
  {
    "type": "Point",
    "coordinates": [33, 44]
  }
]

Geometry Collection

{
  "type": "GeometryCollection",
  "geometries": [
    { "type": "Point", "coordinates": [11, 22] },
    {
      "type": "LineString",
      "coordinates": [
        [11, 22],
        [22, 33]
      ]
    }
  ]
}

Geometry Collections (array)

[
  {
    "type": "GeometryCollection",
    "geometries": [{ "type": "Point", "coordinates": [11, 22] }]
  },
  {
    "type": "GeometryCollection",
    "geometries": [
      {
        "type": "LineString",
        "coordinates": [
          [11, 22],
          [22, 33]
        ]
      }
    ]
  }
]

Geometry types

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

Validation Result˝

Valid example:

{
  "valid": true
}

Invalid example:

{
  "valid": false,
  "error": "INVALID_TYPE",
  "data": {
    "type": "Pointt"
  }
}

Validation Errors

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

Contributing

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.

License

This project is licensed under the MIT License.