@turf/invariant 4.5.2 → 4.7.3

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,7 +6,16 @@ Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
6
6
 
7
7
  **Parameters**
8
8
 
9
- - `obj` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<any> | [Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>)** any value
9
+ - `obj` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> | [Geometry](http://geojson.org/geojson-spec.html#geometry)<[Point](http://geojson.org/geojson-spec.html#point)> | [Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>)** Object
10
+
11
+ **Examples**
12
+
13
+ ```javascript
14
+ var pt = turf.point([10, 10]);
15
+
16
+ var coord = turf.getCoord(pt);
17
+ //= [10, 10]
18
+ ```
10
19
 
11
20
  Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
12
21
 
@@ -16,9 +25,18 @@ Unwrap coordinates from a Feature, Geometry Object or an Array of numbers
16
25
 
17
26
  **Parameters**
18
27
 
19
- - `obj` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<any> | [Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** any value
28
+ - `obj` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)> | [Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** Object
20
29
 
21
- Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<any>** coordinates
30
+ **Examples**
31
+
32
+ ```javascript
33
+ var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
34
+
35
+ var coord = turf.getCoords(poly);
36
+ //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
37
+ ```
38
+
39
+ Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** coordinates
22
40
 
23
41
  # containsNumber
24
42
 
@@ -77,7 +95,7 @@ Get Geometry from Feature or Geometry Object
77
95
 
78
96
  **Parameters**
79
97
 
80
- - `geojson` **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<any> | [Geometry](http://geojson.org/geojson-spec.html#geometry)<any>)** GeoJSON Feature or Geometry Object
98
+ - `geojson` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** GeoJSON Feature or Geometry Object
81
99
 
82
100
  **Examples**
83
101
 
@@ -90,13 +108,13 @@ var point = {
90
108
  "coordinates": [110, 40]
91
109
  }
92
110
  }
93
- var geom = invariant.getGeom(point)
111
+ var geom = turf.getGeom(point)
94
112
  //={"type": "Point", "coordinates": [110, 40]}
95
113
  ```
96
114
 
97
115
  - Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if geojson is not a Feature or Geometry Object
98
116
 
99
- Returns **[Geometry](http://geojson.org/geojson-spec.html#geometry)<any>** GeoJSON Geometry Object
117
+ Returns **([Geometry](http://geojson.org/geojson-spec.html#geometry) | null)** GeoJSON Geometry Object
100
118
 
101
119
  # getGeomType
102
120
 
@@ -104,7 +122,7 @@ Get Geometry Type from Feature or Geometry Object
104
122
 
105
123
  **Parameters**
106
124
 
107
- - `geojson` **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<any> | [Geometry](http://geojson.org/geojson-spec.html#geometry)<any>)** GeoJSON Feature or Geometry Object
125
+ - `geojson` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** GeoJSON Feature or Geometry Object
108
126
 
109
127
  **Examples**
110
128
 
@@ -117,7 +135,7 @@ var point = {
117
135
  "coordinates": [110, 40]
118
136
  }
119
137
  }
120
- var geom = invariant.getGeom(point)
138
+ var geom = turf.getGeomType(point)
121
139
  //="Point"
122
140
  ```
123
141
 
package/index.d.ts CHANGED
@@ -38,7 +38,7 @@ export function containsNumber(coordinates: any[]): boolean;
38
38
  /**
39
39
  * http://turfjs.org/docs/
40
40
  */
41
- export function getGeom(geojson: GeometryCollection | GeometryObject | Feature<any>): boolean;
41
+ export function getGeom(geojson: GeometryCollection | GeometryObject | Feature<any>): GeometryObject;
42
42
 
43
43
  /**
44
44
  * http://turfjs.org/docs/
package/index.js CHANGED
@@ -2,11 +2,16 @@
2
2
  * Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
3
3
  *
4
4
  * @name getCoord
5
- * @param {Array<any>|Geometry|Feature<Point>} obj any value
5
+ * @param {Array<number>|Geometry<Point>|Feature<Point>} obj Object
6
6
  * @returns {Array<number>} coordinates
7
+ * @example
8
+ * var pt = turf.point([10, 10]);
9
+ *
10
+ * var coord = turf.getCoord(pt);
11
+ * //= [10, 10]
7
12
  */
8
13
  function getCoord(obj) {
9
- if (!obj) throw new Error('No obj passed');
14
+ if (!obj) throw new Error('obj is required');
10
15
 
11
16
  var coordinates = getCoords(obj);
12
17
 
@@ -24,11 +29,16 @@ function getCoord(obj) {
24
29
  * Unwrap coordinates from a Feature, Geometry Object or an Array of numbers
25
30
  *
26
31
  * @name getCoords
27
- * @param {Array<any>|Geometry|Feature<any>} obj any value
28
- * @returns {Array<any>} coordinates
32
+ * @param {Array<number>|Geometry|Feature} obj Object
33
+ * @returns {Array<number>} coordinates
34
+ * @example
35
+ * var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
36
+ *
37
+ * var coord = turf.getCoords(poly);
38
+ * //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
29
39
  */
30
40
  function getCoords(obj) {
31
- if (!obj) throw new Error('No obj passed');
41
+ if (!obj) throw new Error('obj is required');
32
42
  var coordinates;
33
43
 
34
44
  // Array of numbers
@@ -139,8 +149,8 @@ function collectionOf(featureCollection, type, name) {
139
149
  /**
140
150
  * Get Geometry from Feature or Geometry Object
141
151
  *
142
- * @param {Feature<any>|Geometry<any>} geojson GeoJSON Feature or Geometry Object
143
- * @returns {Geometry<any>} GeoJSON Geometry Object
152
+ * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
153
+ * @returns {Geometry|null} GeoJSON Geometry Object
144
154
  * @throws {Error} if geojson is not a Feature or Geometry Object
145
155
  * @example
146
156
  * var point = {
@@ -151,20 +161,20 @@ function collectionOf(featureCollection, type, name) {
151
161
  * "coordinates": [110, 40]
152
162
  * }
153
163
  * }
154
- * var geom = invariant.getGeom(point)
164
+ * var geom = turf.getGeom(point)
155
165
  * //={"type": "Point", "coordinates": [110, 40]}
156
166
  */
157
167
  function getGeom(geojson) {
158
- if (!geojson) throw new Error('<geojson> is required');
159
- if (geojson.geometry) return geojson.geometry;
168
+ if (!geojson) throw new Error('geojson is required');
169
+ if (geojson.geometry !== undefined) return geojson.geometry;
160
170
  if (geojson.coordinates || geojson.geometries) return geojson;
161
- throw new Error('<geojson> must be a Feature or Geometry Object');
171
+ throw new Error('geojson must be a valid Feature or Geometry Object');
162
172
  }
163
173
 
164
174
  /**
165
175
  * Get Geometry Type from Feature or Geometry Object
166
176
  *
167
- * @param {Feature<any>|Geometry<any>} geojson GeoJSON Feature or Geometry Object
177
+ * @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
168
178
  * @returns {string} GeoJSON Geometry Type
169
179
  * @throws {Error} if geojson is not a Feature or Geometry Object
170
180
  * @example
@@ -176,11 +186,13 @@ function getGeom(geojson) {
176
186
  * "coordinates": [110, 40]
177
187
  * }
178
188
  * }
179
- * var geom = invariant.getGeom(point)
189
+ * var geom = turf.getGeomType(point)
180
190
  * //="Point"
181
191
  */
182
192
  function getGeomType(geojson) {
183
- return getGeom(geojson).type;
193
+ if (!geojson) throw new Error('geojson is required');
194
+ var geom = getGeom(geojson);
195
+ if (geom) return geom.type;
184
196
  }
185
197
 
186
198
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/invariant",
3
- "version": "4.5.2",
3
+ "version": "4.7.3",
4
4
  "description": "turf invariant module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,8 +28,8 @@
28
28
  "url": "https://github.com/Turfjs/turf/issues"
29
29
  },
30
30
  "devDependencies": {
31
- "@turf/helpers": "^4.5.2",
32
- "benchmark": "^2.1.4",
33
- "tape": "^4.6.3"
31
+ "@turf/helpers": "^4.7.3",
32
+ "benchmark": "2.1.4",
33
+ "tape": "4.8.0"
34
34
  }
35
35
  }