@turf/invariant 6.5.0 → 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -39
- package/dist/es/index.js +5 -6
- package/dist/js/index.d.ts +4 -4
- package/dist/js/index.js +5 -6
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
* `coord` **([Array][1]<[number][2]> | [Geometry][3]<[Point][4]> | [Feature][5]<[Point][4]>)** GeoJSON Point or an Array of numbers
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Examples
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
var pt = turf.point([10, 10]);
|
|
@@ -19,17 +19,17 @@ var coord = turf.getCoord(pt);
|
|
|
19
19
|
//= [10, 10]
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Returns **[Array][1]
|
|
22
|
+
Returns **[Array][1]<[number][2]>** coordinates
|
|
23
23
|
|
|
24
24
|
## getCoords
|
|
25
25
|
|
|
26
26
|
Unwrap coordinates from a Feature, Geometry Object or an Array
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Parameters
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
* `coords` **([Array][1]\<any> | [Geometry][3] | [Feature][5])** Feature, Geometry Object or an Array
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
### Examples
|
|
33
33
|
|
|
34
34
|
```javascript
|
|
35
35
|
var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
|
|
@@ -38,15 +38,15 @@ var coords = turf.getCoords(poly);
|
|
|
38
38
|
//= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Returns **[Array][1]
|
|
41
|
+
Returns **[Array][1]\<any>** coordinates
|
|
42
42
|
|
|
43
43
|
## containsNumber
|
|
44
44
|
|
|
45
45
|
Checks if coordinates contains a number
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
### Parameters
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
* `coordinates` **[Array][1]\<any>** GeoJSON Coordinates
|
|
50
50
|
|
|
51
51
|
Returns **[boolean][6]** true if Array contains a number
|
|
52
52
|
|
|
@@ -54,52 +54,55 @@ Returns **[boolean][6]** true if Array contains a number
|
|
|
54
54
|
|
|
55
55
|
Enforce expectations about types of GeoJSON objects for Turf.
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
### Parameters
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
* `value` **[GeoJSON][7]** any GeoJSON object
|
|
60
|
+
* `type` **[string][8]** expected GeoJSON type
|
|
61
|
+
* `name` **[string][8]** name of calling function
|
|
62
62
|
|
|
63
|
+
<!---->
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
* Throws **[Error][9]** if value is not the expected type.
|
|
65
66
|
|
|
66
67
|
## featureOf
|
|
67
68
|
|
|
68
69
|
Enforce expectations about types of [Feature][10] inputs for Turf.
|
|
69
70
|
Internally this uses [geojsonType][11] to judge geometry types.
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
### Parameters
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
* `feature` **[Feature][5]** a feature with an expected geometry type
|
|
75
|
+
* `type` **[string][8]** expected GeoJSON type
|
|
76
|
+
* `name` **[string][8]** name of calling function
|
|
76
77
|
|
|
78
|
+
<!---->
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
* Throws **[Error][9]** error if value is not the expected type.
|
|
79
81
|
|
|
80
82
|
## collectionOf
|
|
81
83
|
|
|
82
84
|
Enforce expectations about types of [FeatureCollection][12] inputs for Turf.
|
|
83
85
|
Internally this uses [geojsonType][11] to judge geometry types.
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
### Parameters
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
* `featureCollection` **[FeatureCollection][13]** a FeatureCollection for which features will be judged
|
|
90
|
+
* `type` **[string][8]** expected GeoJSON type
|
|
91
|
+
* `name` **[string][8]** name of calling function
|
|
90
92
|
|
|
93
|
+
<!---->
|
|
91
94
|
|
|
92
|
-
|
|
95
|
+
* Throws **[Error][9]** if value is not the expected type.
|
|
93
96
|
|
|
94
97
|
## getGeom
|
|
95
98
|
|
|
96
99
|
Get Geometry from Feature or Geometry Object
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
### Parameters
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
* `geojson` **([Feature][5] | [Geometry][3])** GeoJSON Feature or Geometry Object
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
### Examples
|
|
103
106
|
|
|
104
107
|
```javascript
|
|
105
108
|
var point = {
|
|
@@ -114,26 +117,21 @@ var geom = turf.getGeom(point)
|
|
|
114
117
|
//={"type": "Point", "coordinates": [110, 40]}
|
|
115
118
|
```
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
* Throws **[Error][9]** if geojson is not a Feature or Geometry Object
|
|
118
121
|
|
|
119
122
|
Returns **([Geometry][3] | null)** GeoJSON Geometry Object
|
|
120
123
|
|
|
121
|
-
## getGeomType
|
|
122
|
-
|
|
123
|
-
Get Geometry Type from Feature or Geometry Object
|
|
124
|
-
|
|
125
|
-
- Throws **[Error][9]** **DEPRECATED** in v5.0.0 in favor of getType
|
|
126
|
-
|
|
127
124
|
## getType
|
|
128
125
|
|
|
129
126
|
Get GeoJSON object's type, Geometry type is prioritize.
|
|
130
127
|
|
|
131
|
-
|
|
128
|
+
### Parameters
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
* `geojson` **[GeoJSON][7]** GeoJSON object
|
|
131
|
+
* `_name` **[string][8]?**
|
|
132
|
+
* `name` **[string][8]** name of the variable to display in error message (unused) (optional, default `"geojson"`)
|
|
135
133
|
|
|
136
|
-
|
|
134
|
+
### Examples
|
|
137
135
|
|
|
138
136
|
```javascript
|
|
139
137
|
var point = {
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNumber
|
|
1
|
+
import { isNumber } from "@turf/helpers";
|
|
2
2
|
/**
|
|
3
3
|
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
|
|
4
4
|
*
|
|
@@ -19,17 +19,17 @@ export function getCoord(coord) {
|
|
|
19
19
|
if (coord.type === "Feature" &&
|
|
20
20
|
coord.geometry !== null &&
|
|
21
21
|
coord.geometry.type === "Point") {
|
|
22
|
-
return coord.geometry.coordinates;
|
|
22
|
+
return [...coord.geometry.coordinates];
|
|
23
23
|
}
|
|
24
24
|
if (coord.type === "Point") {
|
|
25
|
-
return coord.coordinates;
|
|
25
|
+
return [...coord.coordinates];
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
if (Array.isArray(coord) &&
|
|
29
29
|
coord.length >= 2 &&
|
|
30
30
|
!Array.isArray(coord[0]) &&
|
|
31
31
|
!Array.isArray(coord[1])) {
|
|
32
|
-
return coord;
|
|
32
|
+
return [...coord];
|
|
33
33
|
}
|
|
34
34
|
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
35
35
|
}
|
|
@@ -152,8 +152,7 @@ export function collectionOf(featureCollection, type, name) {
|
|
|
152
152
|
if (!featureCollection || featureCollection.type !== "FeatureCollection") {
|
|
153
153
|
throw new Error("Invalid input to " + name + ", FeatureCollection required");
|
|
154
154
|
}
|
|
155
|
-
for (
|
|
156
|
-
var feature = _a[_i];
|
|
155
|
+
for (const feature of featureCollection.features) {
|
|
157
156
|
if (!feature || feature.type !== "Feature" || !feature.geometry) {
|
|
158
157
|
throw new Error("Invalid input to " + name + ", Feature with geometry required");
|
|
159
158
|
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Feature, FeatureCollection,
|
|
1
|
+
import { Feature, FeatureCollection, Geometry, LineString, MultiPoint, MultiLineString, MultiPolygon, Point, Polygon } from "geojson";
|
|
2
2
|
/**
|
|
3
3
|
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
|
|
4
4
|
*
|
|
@@ -24,7 +24,7 @@ export declare function getCoord(coord: Feature<Point> | Point | number[]): numb
|
|
|
24
24
|
* var coords = turf.getCoords(poly);
|
|
25
25
|
* //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
|
|
26
26
|
*/
|
|
27
|
-
export declare function getCoords<G extends
|
|
27
|
+
export declare function getCoords<G extends Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>(coords: any[] | Feature<G> | G): any[];
|
|
28
28
|
/**
|
|
29
29
|
* Checks if coordinates contains a number
|
|
30
30
|
*
|
|
@@ -83,7 +83,7 @@ export declare function collectionOf(featureCollection: FeatureCollection<any>,
|
|
|
83
83
|
* var geom = turf.getGeom(point)
|
|
84
84
|
* //={"type": "Point", "coordinates": [110, 40]}
|
|
85
85
|
*/
|
|
86
|
-
export declare function getGeom<G extends
|
|
86
|
+
export declare function getGeom<G extends Geometry>(geojson: Feature<G> | G): G;
|
|
87
87
|
/**
|
|
88
88
|
* Get GeoJSON object's type, Geometry type is prioritize.
|
|
89
89
|
*
|
|
@@ -102,4 +102,4 @@ export declare function getGeom<G extends Geometries | GeometryCollection>(geojs
|
|
|
102
102
|
* var geom = turf.getType(point)
|
|
103
103
|
* //="Point"
|
|
104
104
|
*/
|
|
105
|
-
export declare function getType(geojson: Feature<any> | FeatureCollection<any> |
|
|
105
|
+
export declare function getType(geojson: Feature<any> | FeatureCollection<any> | Geometry, _name?: string): string;
|
package/dist/js/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
4
|
/**
|
|
5
5
|
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
|
|
6
6
|
*
|
|
@@ -21,17 +21,17 @@ function getCoord(coord) {
|
|
|
21
21
|
if (coord.type === "Feature" &&
|
|
22
22
|
coord.geometry !== null &&
|
|
23
23
|
coord.geometry.type === "Point") {
|
|
24
|
-
return coord.geometry.coordinates;
|
|
24
|
+
return [...coord.geometry.coordinates];
|
|
25
25
|
}
|
|
26
26
|
if (coord.type === "Point") {
|
|
27
|
-
return coord.coordinates;
|
|
27
|
+
return [...coord.coordinates];
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (Array.isArray(coord) &&
|
|
31
31
|
coord.length >= 2 &&
|
|
32
32
|
!Array.isArray(coord[0]) &&
|
|
33
33
|
!Array.isArray(coord[1])) {
|
|
34
|
-
return coord;
|
|
34
|
+
return [...coord];
|
|
35
35
|
}
|
|
36
36
|
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
37
37
|
}
|
|
@@ -159,8 +159,7 @@ function collectionOf(featureCollection, type, name) {
|
|
|
159
159
|
if (!featureCollection || featureCollection.type !== "FeatureCollection") {
|
|
160
160
|
throw new Error("Invalid input to " + name + ", FeatureCollection required");
|
|
161
161
|
}
|
|
162
|
-
for (
|
|
163
|
-
var feature = _a[_i];
|
|
162
|
+
for (const feature of featureCollection.features) {
|
|
164
163
|
if (!feature || feature.type !== "Feature" || !feature.geometry) {
|
|
165
164
|
throw new Error("Invalid input to " + name + ", Feature with geometry required");
|
|
166
165
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/invariant",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf invariant module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
"./package.json": "./package.json",
|
|
32
32
|
".": {
|
|
33
|
+
"types": "./dist/js/index.d.ts",
|
|
33
34
|
"import": "./dist/es/index.js",
|
|
34
35
|
"require": "./dist/js/index.js"
|
|
35
36
|
}
|
|
@@ -40,25 +41,26 @@
|
|
|
40
41
|
"dist"
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
43
|
-
"bench": "
|
|
44
|
+
"bench": "tsx bench.js",
|
|
44
45
|
"build": "npm-run-all build:*",
|
|
45
46
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
46
47
|
"build:js": "tsc",
|
|
47
|
-
"docs": "
|
|
48
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
48
49
|
"test": "npm-run-all test:*",
|
|
49
|
-
"test:tape": "
|
|
50
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
50
|
+
"test:tape": "tsx test.js",
|
|
51
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"benchmark": "*",
|
|
54
55
|
"npm-run-all": "*",
|
|
55
56
|
"tape": "*",
|
|
56
|
-
"ts-node": "*",
|
|
57
57
|
"tslint": "*",
|
|
58
|
+
"tsx": "*",
|
|
58
59
|
"typescript": "*"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"@turf/helpers": "^
|
|
62
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
63
|
+
"tslib": "^2.3.0"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
64
66
|
}
|