@turf/convex 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
@@ -58,26 +58,21 @@ Returns **[Feature][9]<[Polygon][10]>** a convex hull
58
58
 
59
59
  [10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
60
60
 
61
- <!-- This file is automatically generated. Please don't edit it directly:
62
- if you find an error, edit the source file (likely index.js), and re-run
63
- ./scripts/generate-readmes in the turf project. -->
61
+ <!-- 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. -->
64
62
 
65
63
  ---
66
64
 
67
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
68
- module collection dedicated to geographic algorithms. It is maintained in the
69
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
70
- PRs and issues.
65
+ 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.
71
66
 
72
67
  ### Installation
73
68
 
74
- Install this module individually:
69
+ Install this single module individually:
75
70
 
76
71
  ```sh
77
72
  $ npm install @turf/convex
78
73
  ```
79
74
 
80
- Or install the Turf module that includes it as a function:
75
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
81
76
 
82
77
  ```sh
83
78
  $ npm install @turf/turf
@@ -0,0 +1,29 @@
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 _concaveman = require('concaveman'); var _concaveman2 = _interopRequireDefault(_concaveman);
8
+ function convex(geojson, options = {}) {
9
+ options.concavity = options.concavity || Infinity;
10
+ const points = [];
11
+ _meta.coordEach.call(void 0, geojson, (coord) => {
12
+ points.push([coord[0], coord[1]]);
13
+ });
14
+ if (!points.length) {
15
+ return null;
16
+ }
17
+ const convexHull = _concaveman2.default.call(void 0, points, options.concavity);
18
+ if (convexHull.length > 3) {
19
+ return _helpers.polygon.call(void 0, [convexHull]);
20
+ }
21
+ return null;
22
+ }
23
+ __name(convex, "convex");
24
+ var turf_convex_default = convex;
25
+
26
+
27
+
28
+ exports.convex = convex; exports.default = turf_convex_default;
29
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAqB,eAAe;AACpC,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AA8BvB,SAAS,OACP,SACA,UAGI,CAAC,GACuB;AAE5B,UAAQ,YAAY,QAAQ,aAAa;AAGzC,QAAM,SAAqB,CAAC;AAG5B,YAAU,SAAS,CAAC,UAAU;AAC5B,WAAO,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAAA,EAClC,CAAC;AACD,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,WAAW,QAAQ,QAAQ,SAAS;AAGvD,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,QAAQ,CAAC,UAAU,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;AA5BS;AA+BT,IAAO,sBAAQ","sourcesContent":["import { Feature, GeoJsonProperties, Polygon } from \"geojson\";\nimport { AllGeoJSON, polygon } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\nimport concaveman from \"concaveman\";\n\n/**\n * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.\n *\n * Internally this uses\n * the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a\n * [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).\n *\n * @name convex\n * @param {GeoJSON} geojson input Feature or FeatureCollection\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.\n * @param {Object} [options.properties={}] Translate Properties to Feature\n * @returns {Feature<Polygon>} a convex hull\n * @example\n * var points = turf.featureCollection([\n * turf.point([10.195312, 43.755225]),\n * turf.point([10.404052, 43.8424511]),\n * turf.point([10.579833, 43.659924]),\n * turf.point([10.360107, 43.516688]),\n * turf.point([10.14038, 43.588348]),\n * turf.point([10.195312, 43.755225])\n * ]);\n *\n * var hull = turf.convex(points);\n *\n * //addToMap\n * var addToMap = [points, hull]\n */\nfunction convex<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n concavity?: number;\n properties?: P;\n } = {}\n): Feature<Polygon, P> | null {\n // Default parameters\n options.concavity = options.concavity || Infinity;\n\n // Container\n const points: number[][] = [];\n\n // Convert all points to flat 2D coordinate Array\n coordEach(geojson, (coord) => {\n points.push([coord[0], coord[1]]);\n });\n if (!points.length) {\n return null;\n }\n\n const convexHull = concaveman(points, options.concavity);\n\n // Convex hull should have at least 3 different vertices in order to create a valid polygon\n if (convexHull.length > 3) {\n return polygon([convexHull]);\n }\n return null;\n}\n\nexport { convex };\nexport default convex;\n"]}
@@ -1,6 +1,6 @@
1
- import { polygon } from "@turf/helpers";
2
- import { coordEach } from "@turf/meta";
3
- import concaveman from "concaveman";
1
+ import { GeoJsonProperties, Feature, Polygon } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
4
4
  /**
5
5
  * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
6
6
  *
@@ -29,22 +29,9 @@ import concaveman from "concaveman";
29
29
  * //addToMap
30
30
  * var addToMap = [points, hull]
31
31
  */
32
- export default function convex(geojson, options = {}) {
33
- // Default parameters
34
- options.concavity = options.concavity || Infinity;
35
- // Container
36
- const points = [];
37
- // Convert all points to flat 2D coordinate Array
38
- coordEach(geojson, (coord) => {
39
- points.push([coord[0], coord[1]]);
40
- });
41
- if (!points.length) {
42
- return null;
43
- }
44
- const convexHull = concaveman(points, options.concavity);
45
- // Convex hull should have at least 3 different vertices in order to create a valid polygon
46
- if (convexHull.length > 3) {
47
- return polygon([convexHull]);
48
- }
49
- return null;
50
- }
32
+ declare function convex<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
33
+ concavity?: number;
34
+ properties?: P;
35
+ }): Feature<Polygon, P> | null;
36
+
37
+ export { convex, convex as default };
@@ -1,5 +1,6 @@
1
- import { Feature, GeoJsonProperties, Polygon } from "geojson";
2
- import { AllGeoJSON } from "@turf/helpers";
1
+ import { GeoJsonProperties, Feature, Polygon } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
5
6
  *
@@ -28,7 +29,9 @@ import { AllGeoJSON } from "@turf/helpers";
28
29
  * //addToMap
29
30
  * var addToMap = [points, hull]
30
31
  */
31
- export default function convex<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
32
+ declare function convex<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
32
33
  concavity?: number;
33
34
  properties?: P;
34
35
  }): Feature<Polygon, P> | null;
36
+
37
+ export { convex, convex as default };
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { polygon } from "@turf/helpers";
6
+ import { coordEach } from "@turf/meta";
7
+ import concaveman from "concaveman";
8
+ function convex(geojson, options = {}) {
9
+ options.concavity = options.concavity || Infinity;
10
+ const points = [];
11
+ coordEach(geojson, (coord) => {
12
+ points.push([coord[0], coord[1]]);
13
+ });
14
+ if (!points.length) {
15
+ return null;
16
+ }
17
+ const convexHull = concaveman(points, options.concavity);
18
+ if (convexHull.length > 3) {
19
+ return polygon([convexHull]);
20
+ }
21
+ return null;
22
+ }
23
+ __name(convex, "convex");
24
+ var turf_convex_default = convex;
25
+ export {
26
+ convex,
27
+ turf_convex_default as default
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, GeoJsonProperties, Polygon } from \"geojson\";\nimport { AllGeoJSON, polygon } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\nimport concaveman from \"concaveman\";\n\n/**\n * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.\n *\n * Internally this uses\n * the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a\n * [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).\n *\n * @name convex\n * @param {GeoJSON} geojson input Feature or FeatureCollection\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.\n * @param {Object} [options.properties={}] Translate Properties to Feature\n * @returns {Feature<Polygon>} a convex hull\n * @example\n * var points = turf.featureCollection([\n * turf.point([10.195312, 43.755225]),\n * turf.point([10.404052, 43.8424511]),\n * turf.point([10.579833, 43.659924]),\n * turf.point([10.360107, 43.516688]),\n * turf.point([10.14038, 43.588348]),\n * turf.point([10.195312, 43.755225])\n * ]);\n *\n * var hull = turf.convex(points);\n *\n * //addToMap\n * var addToMap = [points, hull]\n */\nfunction convex<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n concavity?: number;\n properties?: P;\n } = {}\n): Feature<Polygon, P> | null {\n // Default parameters\n options.concavity = options.concavity || Infinity;\n\n // Container\n const points: number[][] = [];\n\n // Convert all points to flat 2D coordinate Array\n coordEach(geojson, (coord) => {\n points.push([coord[0], coord[1]]);\n });\n if (!points.length) {\n return null;\n }\n\n const convexHull = concaveman(points, options.concavity);\n\n // Convex hull should have at least 3 different vertices in order to create a valid polygon\n if (convexHull.length > 3) {\n return polygon([convexHull]);\n }\n return null;\n}\n\nexport { convex };\nexport default convex;\n"],"mappings":";;;;AACA,SAAqB,eAAe;AACpC,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AA8BvB,SAAS,OACP,SACA,UAGI,CAAC,GACuB;AAE5B,UAAQ,YAAY,QAAQ,aAAa;AAGzC,QAAM,SAAqB,CAAC;AAG5B,YAAU,SAAS,CAAC,UAAU;AAC5B,WAAO,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAAA,EAClC,CAAC;AACD,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,WAAW,QAAQ,QAAQ,SAAS;AAGvD,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,QAAQ,CAAC,UAAU,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;AA5BS;AA+BT,IAAO,sBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/convex",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "turf convex module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -20,48 +20,53 @@
20
20
  "turf",
21
21
  "gis"
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"
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"
46
50
  },
47
51
  "devDependencies": {
48
- "@types/concaveman": "^1.1.3",
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": "*"
52
+ "@types/benchmark": "^2.1.5",
53
+ "@types/concaveman": "^1.1.6",
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
  "concaveman": "^1.2.1",
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,54 +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 concaveman_1 = tslib_1.__importDefault(require("concaveman"));
7
- /**
8
- * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
9
- *
10
- * Internally this uses
11
- * the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a
12
- * [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).
13
- *
14
- * @name convex
15
- * @param {GeoJSON} geojson input Feature or FeatureCollection
16
- * @param {Object} [options={}] Optional parameters
17
- * @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.
18
- * @param {Object} [options.properties={}] Translate Properties to Feature
19
- * @returns {Feature<Polygon>} a convex hull
20
- * @example
21
- * var points = turf.featureCollection([
22
- * turf.point([10.195312, 43.755225]),
23
- * turf.point([10.404052, 43.8424511]),
24
- * turf.point([10.579833, 43.659924]),
25
- * turf.point([10.360107, 43.516688]),
26
- * turf.point([10.14038, 43.588348]),
27
- * turf.point([10.195312, 43.755225])
28
- * ]);
29
- *
30
- * var hull = turf.convex(points);
31
- *
32
- * //addToMap
33
- * var addToMap = [points, hull]
34
- */
35
- function convex(geojson, options = {}) {
36
- // Default parameters
37
- options.concavity = options.concavity || Infinity;
38
- // Container
39
- const points = [];
40
- // Convert all points to flat 2D coordinate Array
41
- meta_1.coordEach(geojson, (coord) => {
42
- points.push([coord[0], coord[1]]);
43
- });
44
- if (!points.length) {
45
- return null;
46
- }
47
- const convexHull = concaveman_1.default(points, options.concavity);
48
- // Convex hull should have at least 3 different vertices in order to create a valid polygon
49
- if (convexHull.length > 3) {
50
- return helpers_1.polygon([convexHull]);
51
- }
52
- return null;
53
- }
54
- exports.default = convex;