@turf/union 7.0.0-alpha.2 → 7.0.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
@@ -51,26 +51,21 @@ Returns **[Feature][3]<([Polygon][4] | [MultiPolygon][5])>** a combined [Polygon
51
51
 
52
52
  [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
53
53
 
54
- <!-- This file is automatically generated. Please don't edit it directly:
55
- if you find an error, edit the source file (likely index.js), and re-run
56
- ./scripts/generate-readmes in the turf project. -->
54
+ <!-- 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. -->
57
55
 
58
56
  ---
59
57
 
60
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
61
- module collection dedicated to geographic algorithms. It is maintained in the
62
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
63
- PRs and issues.
58
+ 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.
64
59
 
65
60
  ### Installation
66
61
 
67
- Install this module individually:
62
+ Install this single module individually:
68
63
 
69
64
  ```sh
70
65
  $ npm install @turf/union
71
66
  ```
72
67
 
73
- Or install the Turf module that includes it as a function:
68
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
74
69
 
75
70
  ```sh
76
71
  $ 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 union(features, options = {}) {
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 2 geometries");
15
+ }
16
+ const unioned = _polygonclipping2.default.union(geoms[0], ...geoms.slice(1));
17
+ if (unioned.length === 0)
18
+ return null;
19
+ if (unioned.length === 1)
20
+ return _helpers.polygon.call(void 0, unioned[0], options.properties);
21
+ else
22
+ return _helpers.multiPolygon.call(void 0, unioned, options.properties);
23
+ }
24
+ __name(union, "union");
25
+ var turf_union_default = union;
26
+
27
+
28
+
29
+ exports.default = turf_union_default; exports.union = union;
30
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAAA,OAAO,qBAAqB;AAC5B,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AAsCzB,SAAS,MACP,UACA,UAA8B,CAAC,GACY;AAC3C,QAAM,QAAgC,CAAC;AACvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,UAAU,gBAAgB,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACjE,MAAI,QAAQ,WAAW;AAAG,WAAO;AACjC,MAAI,QAAQ,WAAW;AAAG,WAAO,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;AAAA;AAClE,WAAO,aAAa,SAAS,QAAQ,UAAU;AACtD;AAjBS;AAoBT,IAAO,qBAAQ","sourcesContent":["import polygonClipping from \"polygon-clipping\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport {\n FeatureCollection,\n Feature,\n Polygon,\n MultiPolygon,\n GeoJsonProperties,\n} from \"geojson\";\n\n/**\n * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.\n *\n * @name union\n * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate Properties to output Feature\n * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty\n * @example\n * var poly1 = turf.polygon([[\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087]\n * ]], {\"fill\": \"#0f0\"});\n * var poly2 = turf.polygon([[\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153]\n * ]], {\"fill\": \"#00f\"});\n *\n * var union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, union];\n */\nfunction union<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: { properties?: P } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1));\n if (unioned.length === 0) return null;\n if (unioned.length === 1) return polygon(unioned[0], options.properties);\n else return multiPolygon(unioned, options.properties);\n}\n\nexport { union };\nexport default union;\n"]}
@@ -1,6 +1,5 @@
1
- import polygonClipping from "polygon-clipping";
2
- import { multiPolygon, polygon } from "@turf/helpers";
3
- import { geomEach } from "@turf/meta";
1
+ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
+
4
3
  /**
5
4
  * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
6
5
  *
@@ -30,20 +29,8 @@ import { geomEach } from "@turf/meta";
30
29
  * //addToMap
31
30
  * var addToMap = [poly1, poly2, union];
32
31
  */
33
- function union(features, options = {}) {
34
- const geoms = [];
35
- geomEach(features, (geom) => {
36
- geoms.push(geom.coordinates);
37
- });
38
- if (geoms.length < 2) {
39
- throw new Error("Must have at least 2 geometries");
40
- }
41
- const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1));
42
- if (unioned.length === 0)
43
- return null;
44
- if (unioned.length === 1)
45
- return polygon(unioned[0], options.properties);
46
- else
47
- return multiPolygon(unioned, options.properties);
48
- }
49
- export default union;
32
+ declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
33
+ properties?: P;
34
+ }): Feature<Polygon | MultiPolygon, P> | null;
35
+
36
+ export { union as default, union };
@@ -1,4 +1,5 @@
1
- import { FeatureCollection, Feature, Polygon, MultiPolygon, GeoJsonProperties } from "geojson";
1
+ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
+
2
3
  /**
3
4
  * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
4
5
  *
@@ -28,7 +29,8 @@ import { FeatureCollection, Feature, Polygon, MultiPolygon, GeoJsonProperties }
28
29
  * //addToMap
29
30
  * var addToMap = [poly1, poly2, union];
30
31
  */
31
- declare function union<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
32
+ declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
32
33
  properties?: P;
33
34
  }): Feature<Polygon | MultiPolygon, P> | null;
34
- export default union;
35
+
36
+ export { union as default, union };
@@ -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 { multiPolygon, polygon } from "@turf/helpers";
7
+ import { geomEach } from "@turf/meta";
8
+ function union(features, options = {}) {
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 2 geometries");
15
+ }
16
+ const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1));
17
+ if (unioned.length === 0)
18
+ return null;
19
+ if (unioned.length === 1)
20
+ return polygon(unioned[0], options.properties);
21
+ else
22
+ return multiPolygon(unioned, options.properties);
23
+ }
24
+ __name(union, "union");
25
+ var turf_union_default = union;
26
+ export {
27
+ turf_union_default as default,
28
+ union
29
+ };
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import polygonClipping from \"polygon-clipping\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport {\n FeatureCollection,\n Feature,\n Polygon,\n MultiPolygon,\n GeoJsonProperties,\n} from \"geojson\";\n\n/**\n * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.\n *\n * @name union\n * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate Properties to output Feature\n * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty\n * @example\n * var poly1 = turf.polygon([[\n * [-82.574787, 35.594087],\n * [-82.574787, 35.615581],\n * [-82.545261, 35.615581],\n * [-82.545261, 35.594087],\n * [-82.574787, 35.594087]\n * ]], {\"fill\": \"#0f0\"});\n * var poly2 = turf.polygon([[\n * [-82.560024, 35.585153],\n * [-82.560024, 35.602602],\n * [-82.52964, 35.602602],\n * [-82.52964, 35.585153],\n * [-82.560024, 35.585153]\n * ]], {\"fill\": \"#00f\"});\n *\n * var union = turf.union(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, union];\n */\nfunction union<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: { properties?: P } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least 2 geometries\");\n }\n\n const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1));\n if (unioned.length === 0) return null;\n if (unioned.length === 1) return polygon(unioned[0], options.properties);\n else return multiPolygon(unioned, options.properties);\n}\n\nexport { union };\nexport default union;\n"],"mappings":";;;;AAAA,OAAO,qBAAqB;AAC5B,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AAsCzB,SAAS,MACP,UACA,UAA8B,CAAC,GACY;AAC3C,QAAM,QAAgC,CAAC;AACvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,UAAU,gBAAgB,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACjE,MAAI,QAAQ,WAAW;AAAG,WAAO;AACjC,MAAI,QAAQ,WAAW;AAAG,WAAO,QAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;AAAA;AAClE,WAAO,aAAa,SAAS,QAAQ,UAAU;AACtD;AAjBS;AAoBT,IAAO,qBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/union",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "turf union module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -20,48 +20,53 @@
20
20
  "turf",
21
21
  "gif"
22
22
  ],
23
- "main": "dist/js/index.js",
24
- "module": "dist/es/index.js",
23
+ "type": "module",
24
+ "main": "dist/cjs/index.cjs",
25
+ "module": "dist/esm/index.js",
26
+ "types": "dist/esm/index.d.ts",
25
27
  "exports": {
26
28
  "./package.json": "./package.json",
27
29
  ".": {
28
- "types": "./dist/js/index.d.ts",
29
- "import": "./dist/es/index.js",
30
- "require": "./dist/js/index.js"
30
+ "import": {
31
+ "types": "./dist/esm/index.d.ts",
32
+ "default": "./dist/esm/index.js"
33
+ },
34
+ "require": {
35
+ "types": "./dist/cjs/index.d.cts",
36
+ "default": "./dist/cjs/index.cjs"
37
+ }
31
38
  }
32
39
  },
33
- "types": "dist/js/index.d.ts",
34
40
  "sideEffects": false,
35
41
  "files": [
36
42
  "dist"
37
43
  ],
38
44
  "scripts": {
39
- "bench": "tsx bench.js",
40
- "build": "npm-run-all build:*",
41
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
42
- "build:js": "tsc",
43
- "docs": "tsx ../../scripts/generate-readmes",
44
- "test": "npm-run-all test:*",
45
- "test:tape": "tsx test.js",
46
- "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
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",
50
+ "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
47
51
  },
48
52
  "devDependencies": {
49
- "@types/tape": "*",
50
- "benchmark": "*",
51
- "glob": "*",
52
- "load-json-file": "*",
53
- "npm-run-all": "*",
54
- "tape": "*",
55
- "tslint": "*",
56
- "tsx": "*",
57
- "typescript": "*",
58
- "write-json-file": "*"
53
+ "@types/benchmark": "^2.1.5",
54
+ "@types/tape": "^4.2.32",
55
+ "benchmark": "^2.1.4",
56
+ "glob": "^10.3.10",
57
+ "load-json-file": "^7.0.1",
58
+ "npm-run-all": "^4.1.5",
59
+ "tape": "^5.7.2",
60
+ "tsup": "^8.0.1",
61
+ "tsx": "^4.6.2",
62
+ "typescript": "^5.2.2",
63
+ "write-json-file": "^5.0.0"
59
64
  },
60
65
  "dependencies": {
61
- "@turf/helpers": "^7.0.0-alpha.2",
62
- "@turf/meta": "^7.0.0-alpha.2",
66
+ "@turf/helpers": "^7.0.0",
67
+ "@turf/meta": "^7.0.0",
63
68
  "polygon-clipping": "^0.15.3",
64
- "tslib": "^2.3.0"
69
+ "tslib": "^2.6.2"
65
70
  },
66
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
71
+ "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
67
72
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping"));
5
- const helpers_1 = require("@turf/helpers");
6
- const meta_1 = require("@turf/meta");
7
- /**
8
- * Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature.
9
- *
10
- * @name union
11
- * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features
12
- * @param {Object} [options={}] Optional Parameters
13
- * @param {Object} [options.properties={}] Translate Properties to output Feature
14
- * @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty
15
- * @example
16
- * var poly1 = turf.polygon([[
17
- * [-82.574787, 35.594087],
18
- * [-82.574787, 35.615581],
19
- * [-82.545261, 35.615581],
20
- * [-82.545261, 35.594087],
21
- * [-82.574787, 35.594087]
22
- * ]], {"fill": "#0f0"});
23
- * var poly2 = turf.polygon([[
24
- * [-82.560024, 35.585153],
25
- * [-82.560024, 35.602602],
26
- * [-82.52964, 35.602602],
27
- * [-82.52964, 35.585153],
28
- * [-82.560024, 35.585153]
29
- * ]], {"fill": "#00f"});
30
- *
31
- * var union = turf.union(turf.featureCollection([poly1, poly2]));
32
- *
33
- * //addToMap
34
- * var addToMap = [poly1, poly2, union];
35
- */
36
- function union(features, options = {}) {
37
- const geoms = [];
38
- meta_1.geomEach(features, (geom) => {
39
- geoms.push(geom.coordinates);
40
- });
41
- if (geoms.length < 2) {
42
- throw new Error("Must have at least 2 geometries");
43
- }
44
- const unioned = polygon_clipping_1.default.union(geoms[0], ...geoms.slice(1));
45
- if (unioned.length === 0)
46
- return null;
47
- if (unioned.length === 1)
48
- return helpers_1.polygon(unioned[0], options.properties);
49
- else
50
- return helpers_1.multiPolygon(unioned, options.properties);
51
- }
52
- exports.default = union;