@turf/difference 7.0.0-alpha.1 → 7.0.0-alpha.111

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
@@ -52,26 +52,21 @@ Returns **([Feature][5]<([Polygon][3] | [MultiPolygon][4])> | null)** a Polygon
52
52
 
53
53
  [5]: https://tools.ietf.org/html/rfc7946#section-3.2
54
54
 
55
- <!-- This file is automatically generated. Please don't edit it directly:
56
- if you find an error, edit the source file (likely index.js), and re-run
57
- ./scripts/generate-readmes in the turf project. -->
55
+ <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
58
56
 
59
57
  ---
60
58
 
61
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
62
- module collection dedicated to geographic algorithms. It is maintained in the
63
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
64
- PRs and issues.
59
+ This module is part of the [Turfjs project](https://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.
65
60
 
66
61
  ### Installation
67
62
 
68
- Install this module individually:
63
+ Install this single module individually:
69
64
 
70
65
  ```sh
71
66
  $ npm install @turf/difference
72
67
  ```
73
68
 
74
- Or install the Turf module that includes it as a function:
69
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
75
70
 
76
71
  ```sh
77
72
  $ npm install @turf/turf
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
6
+ var _helpers = require('@turf/helpers');
7
+ var _meta = require('@turf/meta');
8
+ function difference(features) {
9
+ const geoms = [];
10
+ _meta.geomEach.call(void 0, features, (geom) => {
11
+ geoms.push(geom.coordinates);
12
+ });
13
+ if (geoms.length < 2) {
14
+ throw new Error("Must have at least two features");
15
+ }
16
+ const properties = features.features[0].properties || {};
17
+ const differenced = _polygonclipping2.default.difference(geoms[0], ...geoms.slice(1));
18
+ if (differenced.length === 0)
19
+ return null;
20
+ if (differenced.length === 1)
21
+ return _helpers.polygon.call(void 0, differenced[0], properties);
22
+ return _helpers.multiPolygon.call(void 0, differenced, properties);
23
+ }
24
+ __name(difference, "difference");
25
+ var turf_difference_default = difference;
26
+
27
+
28
+
29
+ exports.default = turf_difference_default; exports.difference = difference;
30
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,OAAO,qBAA+B;AACtC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AAmCzB,SAAS,WACP,UACwC;AACxC,QAAM,QAAqB,CAAC;AAE5B,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmB;AAAA,EACrC,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,aAAa,SAAS,SAAS,CAAC,EAAE,cAAc,CAAC;AAEvD,QAAM,cAAc,gBAAgB,WAAW,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AAC1E,MAAI,YAAY,WAAW;AAAG,WAAO;AACrC,MAAI,YAAY,WAAW;AAAG,WAAO,QAAQ,YAAY,CAAC,GAAG,UAAU;AACvE,SAAO,aAAa,aAAa,UAAU;AAC7C;AAnBS;AAsBT,IAAO,0BAAQ","sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @name difference\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<Geom> = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"]}
@@ -1,6 +1,4 @@
1
- import polygonClipping from 'polygon-clipping';
2
- import { polygon, multiPolygon } from '@turf/helpers';
3
- import { geomEach } from '@turf/meta';
1
+ import { FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
4
2
 
5
3
  /**
6
4
  * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.
@@ -35,23 +33,6 @@ import { geomEach } from '@turf/meta';
35
33
  * //addToMap
36
34
  * var addToMap = [polygon1, polygon2, difference];
37
35
  */
38
- function difference(features) {
39
- const geoms = [];
36
+ declare function difference(features: FeatureCollection<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon> | null;
40
37
 
41
- geomEach(features, (geom) => {
42
- geoms.push(geom.coordinates);
43
- });
44
-
45
- if (geoms.length < 2) {
46
- throw new Error("Must have at least two features");
47
- }
48
-
49
- var properties = features.features[0].properties || {};
50
-
51
- var differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));
52
- if (differenced.length === 0) return null;
53
- if (differenced.length === 1) return polygon(differenced[0], properties);
54
- return multiPolygon(differenced, properties);
55
- }
56
-
57
- export default difference;
38
+ export { difference as default, difference };
@@ -0,0 +1,38 @@
1
+ import { FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
+
3
+ /**
4
+ * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.
5
+ *
6
+ * @name difference
7
+ * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features
8
+ * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
9
+ * @example
10
+ * var polygon1 = turf.polygon([[
11
+ * [128, -26],
12
+ * [141, -26],
13
+ * [141, -21],
14
+ * [128, -21],
15
+ * [128, -26]
16
+ * ]], {
17
+ * "fill": "#F00",
18
+ * "fill-opacity": 0.1
19
+ * });
20
+ * var polygon2 = turf.polygon([[
21
+ * [126, -28],
22
+ * [140, -28],
23
+ * [140, -20],
24
+ * [126, -20],
25
+ * [126, -28]
26
+ * ]], {
27
+ * "fill": "#00F",
28
+ * "fill-opacity": 0.1
29
+ * });
30
+ *
31
+ * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));
32
+ *
33
+ * //addToMap
34
+ * var addToMap = [polygon1, polygon2, difference];
35
+ */
36
+ declare function difference(features: FeatureCollection<Polygon | MultiPolygon>): Feature<Polygon | MultiPolygon> | null;
37
+
38
+ export { difference as default, difference };
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import polygonClipping from "polygon-clipping";
6
+ import { polygon, multiPolygon } from "@turf/helpers";
7
+ import { geomEach } from "@turf/meta";
8
+ function difference(features) {
9
+ const geoms = [];
10
+ geomEach(features, (geom) => {
11
+ geoms.push(geom.coordinates);
12
+ });
13
+ if (geoms.length < 2) {
14
+ throw new Error("Must have at least two features");
15
+ }
16
+ const properties = features.features[0].properties || {};
17
+ const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));
18
+ if (differenced.length === 0)
19
+ return null;
20
+ if (differenced.length === 1)
21
+ return polygon(differenced[0], properties);
22
+ return multiPolygon(differenced, properties);
23
+ }
24
+ __name(difference, "difference");
25
+ var turf_difference_default = difference;
26
+ export {
27
+ turf_difference_default as default,
28
+ difference
29
+ };
30
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @name difference\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<Geom> = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"],"mappings":";;;;AACA,OAAO,qBAA+B;AACtC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AAmCzB,SAAS,WACP,UACwC;AACxC,QAAM,QAAqB,CAAC;AAE5B,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmB;AAAA,EACrC,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,aAAa,SAAS,SAAS,CAAC,EAAE,cAAc,CAAC;AAEvD,QAAM,cAAc,gBAAgB,WAAW,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AAC1E,MAAI,YAAY,WAAW;AAAG,WAAO;AACrC,MAAI,YAAY,WAAW;AAAG,WAAO,QAAQ,YAAY,CAAC,GAAG,UAAU;AACvE,SAAO,aAAa,aAAa,UAAU;AAC7C;AAnBS;AAsBT,IAAO,0BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/difference",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.111+08576cb50",
4
4
  "description": "turf difference module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -20,43 +20,52 @@
20
20
  "turf",
21
21
  "gis"
22
22
  ],
23
- "main": "dist/js/index.js",
24
- "module": "dist/es/index.js",
23
+ "type": "commonjs",
24
+ "main": "dist/cjs/index.cjs",
25
+ "module": "dist/esm/index.mjs",
26
+ "types": "dist/cjs/index.d.ts",
25
27
  "exports": {
26
28
  "./package.json": "./package.json",
27
29
  ".": {
28
- "types": "./index.d.ts",
29
- "import": "./dist/es/index.js",
30
- "require": "./dist/js/index.js"
30
+ "import": {
31
+ "types": "./dist/esm/index.d.mts",
32
+ "default": "./dist/esm/index.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/cjs/index.d.ts",
36
+ "default": "./dist/cjs/index.cjs"
37
+ }
31
38
  }
32
39
  },
33
- "types": "index.d.ts",
34
40
  "sideEffects": false,
35
41
  "files": [
36
- "dist",
37
- "index.d.ts"
42
+ "dist"
38
43
  ],
39
44
  "scripts": {
40
- "bench": "tsx bench.js",
41
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
42
- "docs": "tsx ../../scripts/generate-readmes",
43
- "test": "npm-run-all test:*",
44
- "test:tape": "tsx test.js"
45
+ "bench": "tsx bench.ts",
46
+ "build": "tsup --config ../../tsup.config.ts",
47
+ "docs": "tsx ../../scripts/generate-readmes.ts",
48
+ "test": "npm-run-all --npm-path npm test:*",
49
+ "test:tape": "tsx test.ts"
45
50
  },
46
51
  "devDependencies": {
47
- "benchmark": "*",
48
- "glob": "*",
49
- "load-json-file": "*",
50
- "npm-run-all": "*",
51
- "rollup": "*",
52
- "tape": "*",
53
- "tsx": "*",
54
- "write-json-file": "*"
52
+ "@types/benchmark": "^2.1.5",
53
+ "@types/tape": "^4.2.32",
54
+ "benchmark": "^2.1.4",
55
+ "glob": "^10.3.10",
56
+ "load-json-file": "^7.0.1",
57
+ "npm-run-all": "^4.1.5",
58
+ "tape": "^5.7.2",
59
+ "tsup": "^8.0.1",
60
+ "tsx": "^4.6.2",
61
+ "typescript": "^5.2.2",
62
+ "write-json-file": "^5.0.0"
55
63
  },
56
64
  "dependencies": {
57
- "@turf/helpers": "^7.0.0-alpha.1",
58
- "@turf/meta": "^7.0.0-alpha.1",
59
- "polygon-clipping": "^0.15.3"
65
+ "@turf/helpers": "^7.0.0-alpha.111+08576cb50",
66
+ "@turf/meta": "^7.0.0-alpha.111+08576cb50",
67
+ "polygon-clipping": "^0.15.3",
68
+ "tslib": "^2.6.2"
60
69
  },
61
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
70
+ "gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
62
71
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,64 +0,0 @@
1
- 'use strict';
2
-
3
- var polygonClipping = require('polygon-clipping');
4
- var helpers = require('@turf/helpers');
5
- var meta = require('@turf/meta');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var polygonClipping__default = /*#__PURE__*/_interopDefaultLegacy(polygonClipping);
10
-
11
- /**
12
- * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.
13
- *
14
- * @name difference
15
- * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features
16
- * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
17
- * @example
18
- * var polygon1 = turf.polygon([[
19
- * [128, -26],
20
- * [141, -26],
21
- * [141, -21],
22
- * [128, -21],
23
- * [128, -26]
24
- * ]], {
25
- * "fill": "#F00",
26
- * "fill-opacity": 0.1
27
- * });
28
- * var polygon2 = turf.polygon([[
29
- * [126, -28],
30
- * [140, -28],
31
- * [140, -20],
32
- * [126, -20],
33
- * [126, -28]
34
- * ]], {
35
- * "fill": "#00F",
36
- * "fill-opacity": 0.1
37
- * });
38
- *
39
- * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));
40
- *
41
- * //addToMap
42
- * var addToMap = [polygon1, polygon2, difference];
43
- */
44
- function difference(features) {
45
- const geoms = [];
46
-
47
- meta.geomEach(features, (geom) => {
48
- geoms.push(geom.coordinates);
49
- });
50
-
51
- if (geoms.length < 2) {
52
- throw new Error("Must have at least two features");
53
- }
54
-
55
- var properties = features.features[0].properties || {};
56
-
57
- var differenced = polygonClipping__default['default'].difference(geoms[0], ...geoms.slice(1));
58
- if (differenced.length === 0) return null;
59
- if (differenced.length === 1) return helpers.polygon(differenced[0], properties);
60
- return helpers.multiPolygon(differenced, properties);
61
- }
62
-
63
- module.exports = difference;
64
- module.exports.default = difference;
package/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Polygon, MultiPolygon, Feature, FeatureCollection } from "geojson";
2
-
3
- /**
4
- * http://turfjs.org/docs/#difference
5
- */
6
- export default function difference(
7
- features: FeatureCollection<Polygon | MultiPolygon>
8
- ): Feature<Polygon | MultiPolygon> | null;