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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mapbox/geojsonhint

v3.3.0

Published

validate and sanity-check geojson files

Downloads

105,684

Readme

Build Status Coverage Status

geojsonhint: complete, fast, standards-based validation for geojson

Important: development of geojsonhint is currently paused. Until development restarts, please refrain from adding non-critical issues or PRs.

A lint tool for the GeoJSON standard. geojsonhint is written to the standard, with no missing or additional opinions about structure.

Thanks to jsonlint-lines, GeoJSON that is also not valid JSON can return informative, line-oriented parsing errors.

Specification

The basis of this tool is the published GeoJSON specification.

API

errors = geojsonhint.hint(string or object, options)

Lint a file, given as a string or object. This call detects all aberrations from the GeoJSON standards and returns them as an array of errors. An example of the output:

[{
  "message": "\"features\" property should be an array, but is an object instead",
  "line": 1
}]

The options argument is optional. It has these options:

noDuplicateMembers.

By default, geojsonhint will treat repeated properties as an error: you can set noDuplicateMembers to false to allow them. For instance:

geojsonhint.hint('{"type":"invalid","type":"Feature","properties":{},"geometry":null}', {
    noDuplicateMembers: false
});

The repeated type property in this input will be ignored with the option, and flagged without it.

precisionWarning.

GeoJSON now recommends six decimal places of accuracy for coordinates (Section 11.2). This option adds a warning message when coordinates contain over 6 decimal places of accuracy, up to 10 coordinates before the warning message is truncated for performance.

geojsonhint.hint('{ "type": "Point", "coordinates": [100.0000000001, 5.0000000001] }', {
    precisionWarning: false
});

With this option enabled, geojsonhint will produce these warnings:

[{
  line: 1,
  level: 'message',
  message: 'precision of coordinates should be reduced'
}, {
  line: 1,
  level: 'message',
  message: 'precision of coordinates should be reduced'
}]

Without this option, this input will pass without errors.

ignoreRightHandRule.

GeoJSON specification defined that linear rings must follow right-hand rule, but also says that for backward compatibility reasons parsers should not rejects polygons wiht incorrect winding order. For that kind of situations geojsonhint has an option ignoreRightHandRule which is false by default. Setting this option to true will cause geojsonhint to skip right-hand rule validation.

geojsonhint.hint(geojsonWithIncorrectWindingOrder, {
  ignoreRightHandRule: true
});

with this option enabled, geojsonhint will not validate winding order.

Line Numbers

Note that the GeoJSON can be given as a string or as an object. Here's how to choose which input to use:

  • string inputs receive line numbers for each error. These make errors easier to track down if the GeoJSON is hand-written.
  • object inputs don't have line numbers but are evaluated faster, by up to 10x. GeoJSONHint is very fast already so unless you have identified it as a bottleneck in your application, don't prematurely optimize based on this fact.

If you're really trying to save space and don't care about JSON validity errors - only GeoJSON errors - you can require('geojsonhint/lib/object') to get a version of this library that bypasses jsonlint-lines and provides only the object interface.

use it

npm (node.js, browserify, webpack, etc)

npm install --save @mapbox/geojsonhint

CDN / script tag

Hit this URL to resolve to the latest pinned version.

https://unpkg.com/@mapbox/geojsonhint@latest/geojsonhint.js

As a command-line utility

Install:

npm install -g @mapbox/geojsonhint
➟ geojsonhint
Usage: geojsonhint FILE.geojson

Options:
  --json  output json-formatted data for hints
➟ geojsonhint test.geojson
line 9, each element in a position must be a number

Development

  • Tests: npm test
  • Building the browser version: npm run build

See Also