@turf/invariant 6.4.0 → 7.0.0-alpha.0

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 CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `coord` **([Array][1]<[number][2]> | [Geometry][3]<[Point][4]> | [Feature][5]<[Point][4]>)** GeoJSON Point or an Array of numbers
11
+ * `coord` **([Array][1]<[number][2]> | [Geometry][3]<[Point][4]> | [Feature][5]<[Point][4]>)** GeoJSON Point or an Array of numbers
12
12
 
13
- **Examples**
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]&lt;[number][2]>** coordinates
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
- **Parameters**
28
+ ### Parameters
29
29
 
30
- - `coords` **([Array][1]&lt;any> | [Geometry][3] \| [Feature][5])** Feature, Geometry Object or an Array
30
+ * `coords` **([Array][1]\<any> | [Geometry][3] | [Feature][5])** Feature, Geometry Object or an Array
31
31
 
32
- **Examples**
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]&lt;any>** coordinates
41
+ Returns **[Array][1]\<any>** coordinates
42
42
 
43
43
  ## containsNumber
44
44
 
45
45
  Checks if coordinates contains a number
46
46
 
47
- **Parameters**
47
+ ### Parameters
48
48
 
49
- - `coordinates` **[Array][1]&lt;any>** GeoJSON Coordinates
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
- **Parameters**
57
+ ### Parameters
58
58
 
59
- - `value` **[GeoJSON][7]** any GeoJSON object
60
- - `type` **[string][8]** expected GeoJSON type
61
- - `name` **[string][8]** name of calling function
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
- - Throws **[Error][9]** if value is not the expected type.
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
- **Parameters**
72
+ ### Parameters
72
73
 
73
- - `feature` **[Feature][5]** a feature with an expected geometry type
74
- - `type` **[string][8]** expected GeoJSON type
75
- - `name` **[string][8]** name of calling function
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
- - Throws **[Error][9]** error if value is not the expected type.
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
- **Parameters**
87
+ ### Parameters
86
88
 
87
- - `featureCollection` **[FeatureCollection][13]** a FeatureCollection for which features will be judged
88
- - `type` **[string][8]** expected GeoJSON type
89
- - `name` **[string][8]** name of calling function
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
- - Throws **[Error][9]** if value is not the expected type.
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
- **Parameters**
101
+ ### Parameters
99
102
 
100
- - `geojson` **([Feature][5] \| [Geometry][3])** GeoJSON Feature or Geometry Object
103
+ * `geojson` **([Feature][5] | [Geometry][3])** GeoJSON Feature or Geometry Object
101
104
 
102
- **Examples**
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
- - Throws **[Error][9]** if geojson is not a Feature or Geometry Object
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
- **Parameters**
128
+ ### Parameters
132
129
 
133
- - `geojson` **[GeoJSON][7]** GeoJSON object
134
- - `name` **[string][8]** name of the variable to display in error message (optional, default `"geojson"`)
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
- **Examples**
134
+ ### Examples
137
135
 
138
136
  ```javascript
139
137
  var point = {
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isNumber, } from "@turf/helpers";
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 (var _i = 0, _a = featureCollection.features; _i < _a.length; _i++) {
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
  }
@@ -1,4 +1,4 @@
1
- import { Feature, FeatureCollection, Geometries, GeometryCollection, Point } from "@turf/helpers";
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 Geometries>(coords: any[] | Feature<G> | G): any[];
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 Geometries | GeometryCollection>(geojson: Feature<G> | G): G;
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> | Geometries | GeometryCollection, _name?: string): string;
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
- var helpers_1 = require("@turf/helpers");
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 (var _i = 0, _a = featureCollection.features; _i < _a.length; _i++) {
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": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf invariant module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -16,6 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git://github.com/Turfjs/turf.git"
18
18
  },
19
+ "funding": "https://opencollective.com/turf",
19
20
  "publishConfig": {
20
21
  "access": "public"
21
22
  },
@@ -46,7 +47,7 @@
46
47
  "docs": "node ../../scripts/generate-readmes",
47
48
  "test": "npm-run-all test:*",
48
49
  "test:tape": "ts-node -r esm test.js",
49
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
50
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
50
51
  },
51
52
  "devDependencies": {
52
53
  "benchmark": "*",
@@ -57,7 +58,8 @@
57
58
  "typescript": "*"
58
59
  },
59
60
  "dependencies": {
60
- "@turf/helpers": "^6.4.0"
61
+ "@turf/helpers": "^7.0.0-alpha.0",
62
+ "tslib": "^2.3.0"
61
63
  },
62
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
64
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
63
65
  }