@turf/centroid 6.5.0 → 7.0.0-alpha.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
@@ -4,16 +4,16 @@
4
4
 
5
5
  ## centroid
6
6
 
7
- Takes one or more features and calculates the centroid using the mean of all vertices.
8
- This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
7
+ Computes the centroid as the mean of all vertices within the object.
9
8
 
10
- **Parameters**
9
+ ### Parameters
11
10
 
12
- - `geojson` **[GeoJSON][1]** GeoJSON to be centered
13
- - `options` **[Object][2]** Optional Parameters (optional, default `{}`)
14
- - `options.properties` **[Object][2]** an Object that is used as the [Feature][3]'s properties (optional, default `{}`)
11
+ * `geojson` **[GeoJSON][1]** GeoJSON to be centered
12
+ * `options` **[Object][2]** Optional Parameters (optional, default `{}`)
15
13
 
16
- **Examples**
14
+ * `options.properties` **[Object][2]** an Object that is used as the [Feature][3]'s properties (optional, default `{}`)
15
+
16
+ ### Examples
17
17
 
18
18
  ```javascript
19
19
  var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
@@ -24,7 +24,7 @@ var centroid = turf.centroid(polygon);
24
24
  var addToMap = [polygon, centroid]
25
25
  ```
26
26
 
27
- Returns **[Feature][4]<[Point][5]>** the centroid of the input features
27
+ Returns **[Feature][4]<[Point][5]>** the centroid of the input object
28
28
 
29
29
  [1]: https://tools.ietf.org/html/rfc7946#section-3
30
30
 
package/dist/es/index.js CHANGED
@@ -1,14 +1,13 @@
1
- import { coordEach } from "@turf/meta";
2
1
  import { point } from "@turf/helpers";
2
+ import { coordEach } from "@turf/meta";
3
3
  /**
4
- * Takes one or more features and calculates the centroid using the mean of all vertices.
5
- * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
4
+ * Computes the centroid as the mean of all vertices within the object.
6
5
  *
7
6
  * @name centroid
8
7
  * @param {GeoJSON} geojson GeoJSON to be centered
9
8
  * @param {Object} [options={}] Optional Parameters
10
9
  * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
11
- * @returns {Feature<Point>} the centroid of the input features
10
+ * @returns {Feature<Point>} the centroid of the input object
12
11
  * @example
13
12
  * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
14
13
  *
@@ -17,11 +16,10 @@ import { point } from "@turf/helpers";
17
16
  * //addToMap
18
17
  * var addToMap = [polygon, centroid]
19
18
  */
20
- function centroid(geojson, options) {
21
- if (options === void 0) { options = {}; }
22
- var xSum = 0;
23
- var ySum = 0;
24
- var len = 0;
19
+ function centroid(geojson, options = {}) {
20
+ let xSum = 0;
21
+ let ySum = 0;
22
+ let len = 0;
25
23
  coordEach(geojson, function (coord) {
26
24
  xSum += coord[0];
27
25
  ySum += coord[1];
@@ -1,13 +1,13 @@
1
- import { AllGeoJSON, Feature, Point, Properties } from "@turf/helpers";
1
+ import { Feature, GeoJsonProperties, Point } from "geojson";
2
+ import { AllGeoJSON } from "@turf/helpers";
2
3
  /**
3
- * Takes one or more features and calculates the centroid using the mean of all vertices.
4
- * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
4
+ * Computes the centroid as the mean of all vertices within the object.
5
5
  *
6
6
  * @name centroid
7
7
  * @param {GeoJSON} geojson GeoJSON to be centered
8
8
  * @param {Object} [options={}] Optional Parameters
9
9
  * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
10
- * @returns {Feature<Point>} the centroid of the input features
10
+ * @returns {Feature<Point>} the centroid of the input object
11
11
  * @example
12
12
  * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
13
13
  *
@@ -16,7 +16,7 @@ import { AllGeoJSON, Feature, Point, Properties } from "@turf/helpers";
16
16
  * //addToMap
17
17
  * var addToMap = [polygon, centroid]
18
18
  */
19
- declare function centroid<P = Properties>(geojson: AllGeoJSON, options?: {
19
+ declare function centroid<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
20
20
  properties?: P;
21
21
  }): Feature<Point, P>;
22
22
  export default centroid;
package/dist/js/index.js CHANGED
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var meta_1 = require("@turf/meta");
4
- var helpers_1 = require("@turf/helpers");
3
+ const helpers_1 = require("@turf/helpers");
4
+ const meta_1 = require("@turf/meta");
5
5
  /**
6
- * Takes one or more features and calculates the centroid using the mean of all vertices.
7
- * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
6
+ * Computes the centroid as the mean of all vertices within the object.
8
7
  *
9
8
  * @name centroid
10
9
  * @param {GeoJSON} geojson GeoJSON to be centered
11
10
  * @param {Object} [options={}] Optional Parameters
12
11
  * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
13
- * @returns {Feature<Point>} the centroid of the input features
12
+ * @returns {Feature<Point>} the centroid of the input object
14
13
  * @example
15
14
  * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
16
15
  *
@@ -19,11 +18,10 @@ var helpers_1 = require("@turf/helpers");
19
18
  * //addToMap
20
19
  * var addToMap = [polygon, centroid]
21
20
  */
22
- function centroid(geojson, options) {
23
- if (options === void 0) { options = {}; }
24
- var xSum = 0;
25
- var ySum = 0;
26
- var len = 0;
21
+ function centroid(geojson, options = {}) {
22
+ let xSum = 0;
23
+ let ySum = 0;
24
+ let len = 0;
27
25
  meta_1.coordEach(geojson, function (coord) {
28
26
  xSum += coord[0];
29
27
  ySum += coord[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/centroid",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf centroid module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -44,7 +44,7 @@
44
44
  "docs": "node ../../scripts/generate-readmes",
45
45
  "test": "npm-run-all test:*",
46
46
  "test:tape": "ts-node -r esm test.js",
47
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
47
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/tape": "*",
@@ -60,8 +60,9 @@
60
60
  "write-json-file": "*"
61
61
  },
62
62
  "dependencies": {
63
- "@turf/helpers": "^6.5.0",
64
- "@turf/meta": "^6.5.0"
63
+ "@turf/helpers": "^7.0.0-alpha.0",
64
+ "@turf/meta": "^7.0.0-alpha.0",
65
+ "tslib": "^2.3.0"
65
66
  },
66
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
67
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
67
68
  }