# @spatial/invariant

> turf invariant module

Latest version **2.0.0** (published 2020-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @spatial/invariant
pnpm add @spatial/invariant
yarn add @spatial/invariant
bun add @spatial/invariant
```

## Health

**Score 50/100 (C)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score; popular repo.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-09-18 |
| First published | 2019-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10489 |
| Author | Turf Authors |
| Maintainers | normanbreau, tpnormanbreau |
| Keywords | turf, invariant, expectations |

## Links

- npm: https://www.npmjs.com/package/@spatial/invariant
- Repository: https://github.com/Turfjs/turf
- Issues: https://github.com/Turfjs/turf/issues
- npm.io page: https://npm.io/package/@spatial/invariant

## Dependencies (1)

- [@spatial/helpers](https://npm.io/package/@spatial/helpers.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2020-09-18
- 1.0.5 — 2019-08-09
- 1.0.4 — 2019-05-21
- 1.0.3 — 2019-05-21

## README

# @spatial/invariant

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## getCoord

Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.

### Parameters

-   `obj` **([Array][1]&lt;[number][2]> | [Geometry][3]&lt;[Point][4]> | [Feature][5]&lt;[Point][4]>)** Object

### Examples

```javascript
var pt = turf.point([10, 10]);

var coord = turf.getCoord(pt);
//= [10, 10]
```

Returns **[Array][1]&lt;[number][2]>** coordinates

## getCoords

Unwrap coordinates from a Feature, Geometry Object or an Array of numbers

### Parameters

-   `obj` **([Array][1]&lt;[number][2]> | [Geometry][3] \| [Feature][5])** Object

### Examples

```javascript
var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);

var coord = turf.getCoords(poly);
//= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
```

Returns **[Array][1]&lt;[number][2]>** coordinates

## containsNumber

Checks if coordinates contains a number

### Parameters

-   `coordinates` **[Array][1]&lt;any>** GeoJSON Coordinates

Returns **[boolean][6]** true if Array contains a number

## geojsonType

Enforce expectations about types of GeoJSON objects for Turf.

### Parameters

-   `value` **[GeoJSON][7]** any GeoJSON object
-   `type` **[string][8]** expected GeoJSON type
-   `name` **[string][8]** name of calling function


-   Throws **[Error][9]** if value is not the expected type.

## featureOf

Enforce expectations about types of [Feature][10] inputs for Turf.
Internally this uses [geojsonType][11] to judge geometry types.

### Parameters

-   `feature` **[Feature][5]** a feature with an expected geometry type
-   `type` **[string][8]** expected GeoJSON type
-   `name` **[string][8]** name of calling function


-   Throws **[Error][9]** error if value is not the expected type.

## collectionOf

Enforce expectations about types of [FeatureCollection][12] inputs for Turf.
Internally this uses [geojsonType][11] to judge geometry types.

### Parameters

-   `featureCollection` **[FeatureCollection][13]** a FeatureCollection for which features will be judged
-   `type` **[string][8]** expected GeoJSON type
-   `name` **[string][8]** name of calling function


-   Throws **[Error][9]** if value is not the expected type.

## getGeom

Get Geometry from Feature or Geometry Object

### Parameters

-   `geojson` **([Feature][5] \| [Geometry][3])** GeoJSON Feature or Geometry Object

### Examples

```javascript
var point = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [110, 40]
  }
}
var geom = turf.getGeom(point)
//={"type": "Point", "coordinates": [110, 40]}
```

-   Throws **[Error][9]** if geojson is not a Feature or Geometry Object

Returns **([Geometry][3] | null)** GeoJSON Geometry Object

## getGeomType

Get Geometry Type from Feature or Geometry Object

-   Throws **[Error][9]** **DEPRECATED** in v5.0.0 in favor of getType

## getType

Get GeoJSON object's type, Geometry type is prioritize.

### Parameters

-   `geojson` **[GeoJSON][7]** GeoJSON object
-   `name` **[string][8]?** name of the variable to display in error message

### Examples

```javascript
var point = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [110, 40]
  }
}
var geom = turf.getType(point)
//="Point"
```

Returns **[string][8]** GeoJSON type

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[3]: https://tools.ietf.org/html/rfc7946#section-3.1

[4]: https://tools.ietf.org/html/rfc7946#section-3.1.2

[5]: https://tools.ietf.org/html/rfc7946#section-3.2

[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[7]: https://tools.ietf.org/html/rfc7946#section-3

[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error

[10]: https://tools.ietf.org/html/rfc7946#section-3.2

[11]: #geojsontype

[12]: https://tools.ietf.org/html/rfc7946#section-3.3

[13]: https://tools.ietf.org/html/rfc7946#section-3.3

<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->

---

This module is part of the [Turfjs project](http://turfjs.org/), an open source
module collection dedicated to geographic algorithms. It is maintained in the
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
PRs and issues.

### Installation

Install this module individually:

```sh
$ npm install @spatial/invariant
```

Or install the Turf module that includes it as a function:

```sh
$ npm install @turf/turf
```

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