@turf/difference 4.6.0 → 4.7.4

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
@@ -39,17 +39,7 @@ var difference = turf.difference(polygon1, polygon2);
39
39
  var addToMap = [polygon1, polygon2, difference];
40
40
  ```
41
41
 
42
- Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | [undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `undefined`)
43
-
44
- # removeEmptyPolygon
45
-
46
- Detect Empty Polygon
47
-
48
- **Parameters**
49
-
50
- - `geom` **[Geometry](http://geojson.org/geojson-spec.html#geometry)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>** Geometry Object
51
-
52
- Returns **([Geometry](http://geojson.org/geojson-spec.html#geometry)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | [undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))** removed any polygons with no areas
42
+ Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null))** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
53
43
 
54
44
  <!-- This file is automatically generated. Please don't edit it directly:
55
45
  if you find an error, edit the source file (likely index.js), and re-run
package/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import {Polygon, MultiPolygon, Feature} from '@turf/meta'
4
4
 
5
5
  type Input = Feature<Polygon|MultiPolygon> | Polygon | MultiPolygon;
6
- type Output = Feature<Polygon|MultiPolygon> | undefined;
6
+ type Output = Feature<Polygon|MultiPolygon> | null;
7
7
 
8
8
  /**
9
9
  * http://turfjs.org/docs/#difference
package/index.js CHANGED
@@ -11,7 +11,7 @@ var flattenEach = require('@turf/meta').flattenEach;
11
11
  * @name difference
12
12
  * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature
13
13
  * @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1
14
- * @returns {Feature<Polygon|MultiPolygon>|undefined} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `undefined`)
14
+ * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
15
15
  * @example
16
16
  * var polygon1 = turf.polygon([[
17
17
  * [128, -26],
@@ -47,7 +47,7 @@ module.exports = function (polygon1, polygon2) {
47
47
  // Issue #721 - JSTS can't handle empty polygons
48
48
  geom1 = removeEmptyPolygon(geom1);
49
49
  geom2 = removeEmptyPolygon(geom2);
50
- if (!geom1) return undefined;
50
+ if (!geom1) return null;
51
51
  if (!geom2) return feature(geom1, properties);
52
52
 
53
53
  // JSTS difference operation
@@ -55,7 +55,7 @@ module.exports = function (polygon1, polygon2) {
55
55
  var a = reader.read(geom1);
56
56
  var b = reader.read(geom2);
57
57
  var differenced = a.difference(b);
58
- if (differenced.isEmpty()) return undefined;
58
+ if (differenced.isEmpty()) return null;
59
59
  var writer = new jsts.io.GeoJSONWriter();
60
60
  var geom = writer.write(differenced);
61
61
 
@@ -65,14 +65,15 @@ module.exports = function (polygon1, polygon2) {
65
65
  /**
66
66
  * Detect Empty Polygon
67
67
  *
68
+ * @private
68
69
  * @param {Geometry<Polygon|MultiPolygon>} geom Geometry Object
69
- * @returns {Geometry<Polygon|MultiPolygon>|undefined} removed any polygons with no areas
70
+ * @returns {Geometry<Polygon|MultiPolygon>|null} removed any polygons with no areas
70
71
  */
71
72
  function removeEmptyPolygon(geom) {
72
73
  switch (geom.type) {
73
74
  case 'Polygon':
74
75
  if (area(geom) > 1) return geom;
75
- return undefined;
76
+ return null;
76
77
  case 'MultiPolygon':
77
78
  var coordinates = [];
78
79
  flattenEach(geom, function (feature) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/difference",
3
- "version": "4.6.0",
3
+ "version": "4.7.4",
4
4
  "description": "turf difference module",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -34,10 +34,10 @@
34
34
  "write-json-file": "^2.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@turf/area": "^4.6.0",
38
- "@turf/helpers": "^4.6.0",
39
- "@turf/invariant": "^4.6.0",
40
- "@turf/meta": "^4.6.0",
37
+ "@turf/area": "^4.7.3",
38
+ "@turf/helpers": "^4.7.3",
39
+ "@turf/invariant": "^4.7.3",
40
+ "@turf/meta": "^4.7.3",
41
41
  "jsts": "1.3.0"
42
42
  }
43
43
  }