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

@komeilm76/km-geojson

v0.1.2

Published

GeoJSON types and validation for RFC 7946 — parse, validate, and construct GeoJSON data.

Readme

@komeilm76/km-geojson

GeoJSON types and validation for RFC 7946 — parse, validate, construct, and query GeoJSON data with full TypeScript inference and Zod runtime schemas.

No rendering, no map engine — just types and pure functions. Works in Node.js ≥ 18, browsers, and edge runtimes.

Install

npm install @komeilm76/km-geojson zod
# or
pnpm add @komeilm76/km-geojson zod

zod (≥ 4.4.0) is a peer dependency — install it alongside.

Quick start

import {
  parseGeoJson,
  featureFromGeometry,
  collectionFromFeatures,
  getGeometryBoundingBox,
} from '@komeilm76/km-geojson';
import type { GeoJsonFeature, GeoJsonPoint } from '@komeilm76/km-geojson';

// Validate untrusted input (returns Result — never throws)
const result = parseGeoJson(JSON.parse(rawString));
if (result.success) {
  console.log(result.data.type); // 'Feature' | 'FeatureCollection' | geometry type
} else {
  console.error(result.error.code, result.error.message);
}

// Build features programmatically
const point: GeoJsonPoint = { type: 'Point', coordinates: [-0.1276, 51.5074] };
const feature = featureFromGeometry(point, { name: 'London' });
const collection = collectionFromFeatures([feature]);

// Query geometry
const bbox = getGeometryBoundingBox(point);
// → [-0.1276, 51.5074, -0.1276, 51.5074]  (west, south, east, north)

API

Parse functions (all return Result<T>, never throw)

| Function | Validates | Returns | |---|---|---| | parseGeoJson(raw: unknown) | Any top-level GeoJSON value | Result<GeoJson> | | parseGeoJsonFeature(raw: unknown) | A single Feature | Result<GeoJsonFeature> | | parseGeoJsonFeatureCollection(raw: unknown) | A FeatureCollection | Result<GeoJsonFeatureCollection> |

On failure, error.code is kebab-case (e.g. 'schema-mismatch') and error.message explains what's wrong.

Type guards

import { isGeoJsonGeometry } from '@komeilm76/km-geojson';

if (isGeoJsonGeometry(value)) {
  // value is narrowed to GeoJsonGeometry
}

Feature builders

| Function | Description | |---|---| | featureFromGeometry(geometry, properties?) | Wrap a geometry into a Feature | | collectionFromFeatures(features) | Wrap features into a FeatureCollection |

Geometry utilities

| Function | Description | |---|---| | getGeometryBoundingBox(geometry) | Compute [west, south, east, north] for any geometry | | flattenGeometryCollection(collection) | Flatten nested GeometryCollections into a flat geometry array |

Types

All RFC 7946 types are exported, fully generic where it matters:

| Type | Shape | |---|---| | Position | [lng, lat] or [lng, lat, alt] | | BoundingBox | [west, south, east, north] (or 3D 6-tuple) | | LinearRing | Closed ring of positions (first = last) | | GeoJsonPoint, GeoJsonMultiPoint, GeoJsonLineString, GeoJsonMultiLineString, GeoJsonPolygon, GeoJsonMultiPolygon | The 6 concrete geometries | | GeoJsonGeometryCollection | { type: 'GeometryCollection', geometries: [...] } | | GeoJsonGeometry | Union of all 7 geometry types | | GeoJsonFeature<G, P> | Generic over geometry and properties — both nullable per RFC 7946 | | GeoJsonFeatureCollection<G, P> | Generic collection | | GeoJson | Top-level union: geometry, feature, or collection |

Example of the generics:

import type { GeoJsonFeature, GeoJsonPolygon } from '@komeilm76/km-geojson';

// A feature that is guaranteed to hold a Polygon with typed properties
type ZoneFeature = GeoJsonFeature<GeoJsonPolygon, { zoneId: string; level: number }>;

Zod schemas

Every type has a matching runtime schema: PositionSchema, BoundingBoxSchema, LinearRingSchema, GeoJsonPointSchema, GeoJsonMultiPointSchema, GeoJsonLineStringSchema, GeoJsonMultiLineStringSchema, GeoJsonPolygonSchema, GeoJsonMultiPolygonSchema, GeoJsonGeometryCollectionSchema, GeoJsonGeometrySchema, GeoJsonFeatureSchema, GeoJsonFeatureCollectionSchema, GeoJsonSchema.

import { GeoJsonFeatureCollectionSchema } from '@komeilm76/km-geojson';

const checked = GeoJsonFeatureCollectionSchema.safeParse(payload);

Schemas use structural types in the public signatures, so this package's declaration files never import Zod (IDE-safe — see the repo's zod_hang.md).

Related packages

| Package | Purpose | |---|---| | @komeilm76/km-geoboard | Umbrella package — this API under the geojson namespace | | @komeilm76/km-svg | Convert SVG shapes into these GeoJSON types | | @komeilm76/km-map | Geographic math over these types (area, bounds, tiles) | | @komeilm76/km-imports / km-exports | Import/export pipelines built on these types |

Full API reference: help.md

License

MIT — komeilm76