@turf/intersect 7.0.0-alpha.1 → 7.0.0-alpha.110

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
@@ -59,26 +59,21 @@ Returns **([Feature][7] | null)** returns a feature representing the area they s
59
59
 
60
60
  [7]: https://tools.ietf.org/html/rfc7946#section-3.2
61
61
 
62
- <!-- This file is automatically generated. Please don't edit it directly:
63
- if you find an error, edit the source file (likely index.js), and re-run
64
- ./scripts/generate-readmes in the turf project. -->
62
+ <!-- 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. -->
65
63
 
66
64
  ---
67
65
 
68
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
69
- module collection dedicated to geographic algorithms. It is maintained in the
70
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
71
- PRs and issues.
66
+ 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.
72
67
 
73
68
  ### Installation
74
69
 
75
- Install this module individually:
70
+ Install this single module individually:
76
71
 
77
72
  ```sh
78
73
  $ npm install @turf/intersect
79
74
  ```
80
75
 
81
- Or install the Turf module that includes it as a function:
76
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
82
77
 
83
78
  ```sh
84
79
  $ npm install @turf/turf
@@ -0,0 +1,32 @@
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 _helpers = require('@turf/helpers');
6
+ var _meta = require('@turf/meta');
7
+ var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
8
+ function intersect(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 specify at least 2 geometries");
15
+ }
16
+ const intersection = _polygonclipping2.default.intersection(
17
+ geoms[0],
18
+ ...geoms.slice(1)
19
+ );
20
+ if (intersection.length === 0)
21
+ return null;
22
+ if (intersection.length === 1)
23
+ return _helpers.polygon.call(void 0, intersection[0], options.properties);
24
+ return _helpers.multiPolygon.call(void 0, intersection, options.properties);
25
+ }
26
+ __name(intersect, "intersect");
27
+ var turf_intersect_default = intersect;
28
+
29
+
30
+
31
+ exports.default = turf_intersect_default; exports.intersect = intersect;
32
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAOA,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAqC5B,SAAS,UACP,UACA,UAEI,CAAC,GACsC;AAC3C,QAAM,QAAgC,CAAC;AAEvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,QAAM,eAAe,gBAAgB;AAAA,IACnC,MAAM,CAAC;AAAA,IACP,GAAG,MAAM,MAAM,CAAC;AAAA,EAClB;AACA,MAAI,aAAa,WAAW;AAAG,WAAO;AACtC,MAAI,aAAa,WAAW;AAC1B,WAAO,QAAQ,aAAa,CAAC,GAAG,QAAQ,UAAU;AACpD,SAAO,aAAa,cAAc,QAAQ,UAAU;AACtD;AAvBS;AA0BT,IAAO,yBAAQ","sourcesContent":["import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @name intersect\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polygonClipping.intersection(\n geoms[0],\n ...geoms.slice(1)\n );\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"]}
@@ -1,4 +1,5 @@
1
- import { Feature, GeoJsonProperties, MultiPolygon, Polygon, FeatureCollection } from "geojson";
1
+ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
+
2
3
  /**
3
4
  * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
4
5
  * finds their polygonal intersection. If they don't intersect, returns null.
@@ -34,6 +35,8 @@ import { Feature, GeoJsonProperties, MultiPolygon, Polygon, FeatureCollection }
34
35
  * //addToMap
35
36
  * var addToMap = [poly1, poly2, intersection];
36
37
  */
37
- export default function intersect<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
38
+ declare function intersect<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
38
39
  properties?: P;
39
40
  }): Feature<Polygon | MultiPolygon, P> | null;
41
+
42
+ export { intersect as default, intersect };
@@ -1,6 +1,5 @@
1
- import { multiPolygon, polygon } from "@turf/helpers";
2
- import { geomEach } from "@turf/meta";
3
- import polygonClipping from "polygon-clipping";
1
+ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
2
+
4
3
  /**
5
4
  * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
6
5
  * finds their polygonal intersection. If they don't intersect, returns null.
@@ -36,18 +35,8 @@ import polygonClipping from "polygon-clipping";
36
35
  * //addToMap
37
36
  * var addToMap = [poly1, poly2, intersection];
38
37
  */
39
- export default function intersect(features, options = {}) {
40
- const geoms = [];
41
- geomEach(features, (geom) => {
42
- geoms.push(geom.coordinates);
43
- });
44
- if (geoms.length < 2) {
45
- throw new Error("Must specify at least 2 geometries");
46
- }
47
- const intersection = polygonClipping.intersection(geoms[0], ...geoms.slice(1));
48
- if (intersection.length === 0)
49
- return null;
50
- if (intersection.length === 1)
51
- return polygon(intersection[0], options.properties);
52
- return multiPolygon(intersection, options.properties);
53
- }
38
+ declare function intersect<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: {
39
+ properties?: P;
40
+ }): Feature<Polygon | MultiPolygon, P> | null;
41
+
42
+ export { intersect as default, intersect };
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { multiPolygon, polygon } from "@turf/helpers";
6
+ import { geomEach } from "@turf/meta";
7
+ import polygonClipping from "polygon-clipping";
8
+ function intersect(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 specify at least 2 geometries");
15
+ }
16
+ const intersection = polygonClipping.intersection(
17
+ geoms[0],
18
+ ...geoms.slice(1)
19
+ );
20
+ if (intersection.length === 0)
21
+ return null;
22
+ if (intersection.length === 1)
23
+ return polygon(intersection[0], options.properties);
24
+ return multiPolygon(intersection, options.properties);
25
+ }
26
+ __name(intersect, "intersect");
27
+ var turf_intersect_default = intersect;
28
+ export {
29
+ turf_intersect_default as default,
30
+ intersect
31
+ };
32
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @name intersect\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polygonClipping.intersection(\n geoms[0],\n ...geoms.slice(1)\n );\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"],"mappings":";;;;AAOA,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAqC5B,SAAS,UACP,UACA,UAEI,CAAC,GACsC;AAC3C,QAAM,QAAgC,CAAC;AAEvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,QAAM,eAAe,gBAAgB;AAAA,IACnC,MAAM,CAAC;AAAA,IACP,GAAG,MAAM,MAAM,CAAC;AAAA,EAClB;AACA,MAAI,aAAa,WAAW;AAAG,WAAO;AACtC,MAAI,aAAa,WAAW;AAC1B,WAAO,QAAQ,aAAa,CAAC,GAAG,QAAQ,UAAU;AACpD,SAAO,aAAa,cAAc,QAAQ,UAAU;AACtD;AAvBS;AA0BT,IAAO,yBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/intersect",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.110+1411d63a7",
4
4
  "description": "turf intersect module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -21,48 +21,53 @@
21
21
  "gis",
22
22
  "intersect"
23
23
  ],
24
- "main": "dist/js/index.js",
25
- "module": "dist/es/index.js",
24
+ "type": "commonjs",
25
+ "main": "dist/cjs/index.cjs",
26
+ "module": "dist/esm/index.mjs",
27
+ "types": "dist/cjs/index.d.ts",
26
28
  "exports": {
27
29
  "./package.json": "./package.json",
28
30
  ".": {
29
- "types": "./dist/js/index.d.ts",
30
- "import": "./dist/es/index.js",
31
- "require": "./dist/js/index.js"
31
+ "import": {
32
+ "types": "./dist/esm/index.d.mts",
33
+ "default": "./dist/esm/index.mjs"
34
+ },
35
+ "require": {
36
+ "types": "./dist/cjs/index.d.ts",
37
+ "default": "./dist/cjs/index.cjs"
38
+ }
32
39
  }
33
40
  },
34
- "types": "dist/js/index.d.ts",
35
41
  "sideEffects": false,
36
42
  "files": [
37
43
  "dist"
38
44
  ],
39
45
  "scripts": {
40
- "bench": "tsx bench.js",
41
- "build": "npm-run-all build:*",
42
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
43
- "build:js": "tsc",
44
- "docs": "tsx ../../scripts/generate-readmes",
45
- "test": "npm-run-all test:*",
46
- "test:tape": "tsx test.js",
46
+ "bench": "tsx bench.ts",
47
+ "build": "tsup --config ../../tsup.config.ts",
48
+ "docs": "tsx ../../scripts/generate-readmes.ts",
49
+ "test": "npm-run-all --npm-path npm test:*",
50
+ "test:tape": "tsx test.ts",
47
51
  "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
48
52
  },
49
53
  "devDependencies": {
50
- "@types/tape": "*",
51
- "benchmark": "*",
52
- "glob": "*",
53
- "load-json-file": "*",
54
- "npm-run-all": "*",
55
- "tape": "*",
56
- "tslint": "*",
57
- "tsx": "*",
58
- "typescript": "*",
59
- "write-json-file": "*"
54
+ "@types/benchmark": "^2.1.5",
55
+ "@types/tape": "^4.2.32",
56
+ "benchmark": "^2.1.4",
57
+ "glob": "^10.3.10",
58
+ "load-json-file": "^7.0.1",
59
+ "npm-run-all": "^4.1.5",
60
+ "tape": "^5.7.2",
61
+ "tsup": "^8.0.1",
62
+ "tsx": "^4.6.2",
63
+ "typescript": "^5.2.2",
64
+ "write-json-file": "^5.0.0"
60
65
  },
61
66
  "dependencies": {
62
- "@turf/helpers": "^7.0.0-alpha.1",
63
- "@turf/meta": "^7.0.0-alpha.1",
67
+ "@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
68
+ "@turf/meta": "^7.0.0-alpha.110+1411d63a7",
64
69
  "polygon-clipping": "^0.15.3",
65
- "tslib": "^2.3.0"
70
+ "tslib": "^2.6.2"
66
71
  },
67
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
72
+ "gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
68
73
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const helpers_1 = require("@turf/helpers");
5
- const meta_1 = require("@turf/meta");
6
- const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping"));
7
- /**
8
- * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
9
- * finds their polygonal intersection. If they don't intersect, returns null.
10
- *
11
- * @name intersect
12
- * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
13
- * @param {Object} [options={}] Optional Parameters
14
- * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
15
- * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
16
- * {@link MultiPolygon}). If they do not share any area, returns `null`.
17
- * @example
18
- * var poly1 = turf.polygon([[
19
- * [-122.801742, 45.48565],
20
- * [-122.801742, 45.60491],
21
- * [-122.584762, 45.60491],
22
- * [-122.584762, 45.48565],
23
- * [-122.801742, 45.48565]
24
- * ]]);
25
- *
26
- * var poly2 = turf.polygon([[
27
- * [-122.520217, 45.535693],
28
- * [-122.64038, 45.553967],
29
- * [-122.720031, 45.526554],
30
- * [-122.669906, 45.507309],
31
- * [-122.723464, 45.446643],
32
- * [-122.532577, 45.408574],
33
- * [-122.487258, 45.477466],
34
- * [-122.520217, 45.535693]
35
- * ]]);
36
- *
37
- * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));
38
- *
39
- * //addToMap
40
- * var addToMap = [poly1, poly2, intersection];
41
- */
42
- function intersect(features, options = {}) {
43
- const geoms = [];
44
- meta_1.geomEach(features, (geom) => {
45
- geoms.push(geom.coordinates);
46
- });
47
- if (geoms.length < 2) {
48
- throw new Error("Must specify at least 2 geometries");
49
- }
50
- const intersection = polygon_clipping_1.default.intersection(geoms[0], ...geoms.slice(1));
51
- if (intersection.length === 0)
52
- return null;
53
- if (intersection.length === 1)
54
- return helpers_1.polygon(intersection[0], options.properties);
55
- return helpers_1.multiPolygon(intersection, options.properties);
56
- }
57
- exports.default = intersect;