# geojson-equality-ts

> Check two valid geojson geometries for equality.

Latest version **1.0.2** (published 2024-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install geojson-equality-ts
pnpm add geojson-equality-ts
yarn add geojson-equality-ts
bun add geojson-equality-ts
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-06-14 |
| First published | 2024-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 39.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | James Beard |
| Maintainers | smallsaucepan |
| Keywords | geojson, equality, equal, assertion |

## Links

- npm: https://www.npmjs.com/package/geojson-equality-ts
- Repository: https://github.com/smallsaucepan/geojson-equality-ts
- Issues: https://github.com/smallsaucepan/geojson-equality-ts/issues
- npm.io page: https://npm.io/package/geojson-equality-ts

## Dependencies (1)

- [@types/geojson](https://npm.io/package/@types/geojson.md) ^7946.0.14

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2024-06-14
- 1.0.1 — 2024-06-14
- 1.0.0 — 2024-06-14

## README

# geojson-equality-ts

Check two valid geojson geometries for equality.

This library is a fork of geojson-equality by Gagan Bansal (@gagan-bansal), ported to Typescript by Samir Shah (@solarissmoke). Published and maintained going forward by James Beard (@smallsaucepan).

## Installation

```
npm install geojson-equality-ts
```

## Usage

Use as either a class or function.

```typescript
import { geojsonEquality, GeojsonEquality } from "geojson-equality";

// ... create g1 and g2 GeoJSON objects

geojsonEquality(g1, g2, { precision: 3 }); // returns boolean

const eq = new GeojsonEquality({ precision: 3 });
eq.compare(g1, g2); // returns boolean
```

In more detail.

```typescript
const GeojsonEquality = require("geojson-equality");
const eq = new GeojsonEquality();

const g1: Polygon = {
    type: "Polygon",
    coordinates: [
      [
        [30, 10],
        [40, 40],
        [20, 40],
        [10, 20],
        [30, 10],
      ],
    ],
  },
  g2: Polygon = {
    type: "Polygon",
    coordinates: [
      [
        [30, 10],
        [40, 40],
        [20, 40],
        [10, 20],
        [30, 10],
      ],
    ],
  };

eq.compare(g1, g2); // returns true
const g3: Polygon = {
  type: "Polygon",
  coordinates: [
    [
      [300, 100],
      [400, 400],
      [200, 400],
      [100, 200],
      [300, 100],
    ],
  ],
};

eq.compare(g1, g3); // returns false
```

## Options

**precision** _number_ floating point precision required. Defualt is **17**.

```typescript
const g1: Point = { type: "Point", coordinates: [30.2, 10] };
const g2: Point = { type: "Point", coordinates: [30.22233, 10] };

geojsonEquality(g1, g2, { precision: 3 }); // returns false

geojsonEquality(g1, g2, { precision: 1 }); // returns true
```

**direction** _boolean_ direction of LineString or Polygon (orientation) is ignored if false. Default is **false**.

```typescript
const g1: LineString = {
    type: "LineString",
    coordinates: [
      [30, 10],
      [10, 30],
      [40, 40],
    ],
  },
  g2: LineString = {
    type: "LineString",
    coordinates: [
      [40, 40],
      [10, 30],
      [30, 10],
    ],
  };

geojsonEquality(g1, g2, { direction: false }); // returns true

geojsonEquality(g1, g2, { direction: true }); // returns false
```

**compareProperties** _boolean_ when comparing features, take their properties into account. Default is true.

```typescript
const g1: Feature<Point> = {
    type: "Feature",
    geometry: {
      type: "Point",
      coordinates: [30, 10],
    },
    properties: { foo: "bar" },
  },
  g2: Feature<Point> = {
    type: "Feature",
    geometry: {
      type: "Point",
      coordinates: [30, 10],
    },
    properties: { foo: "BAZZZZ" },
  };

geojsonEquality(g1, g2); // returns false

geojsonEquality(g1, g2, { compareProperties: false }); // returns true
```

## Contributing

Once you run

`npm install`

then for running test

`npm run test`

to create build

`npm run build`

PRs are welcome.

## License

This project is licensed under the terms of the MIT license.

---
_Source: https://npm.io/package/geojson-equality-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
