@turf/centroid 5.0.4 → 6.0.2

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
@@ -9,8 +9,9 @@ This lessens the effect of small islands and artifacts when calculating the cent
9
9
 
10
10
  **Parameters**
11
11
 
12
- - `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** GeoJSON to be centered
13
- - `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object that is used as the [Feature](http://geojson.org/geojson-spec.html#feature-objects)'s properties (optional, default `{}`)
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 `{}`)
14
15
 
15
16
  **Examples**
16
17
 
@@ -23,7 +24,17 @@ var centroid = turf.centroid(polygon);
23
24
  var addToMap = [polygon, centroid]
24
25
  ```
25
26
 
26
- Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** the centroid of the input features
27
+ Returns **[Feature][4]<[Point][5]>** the centroid of the input features
28
+
29
+ [1]: https://tools.ietf.org/html/rfc7946#section-3
30
+
31
+ [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
32
+
33
+ [3]: https://tools.ietf.org/html/rfc7946#section-3.2
34
+
35
+ [4]: https://tools.ietf.org/html/rfc7946#section-3.2
36
+
37
+ [5]: https://tools.ietf.org/html/rfc7946#section-3.1.2
27
38
 
28
39
  <!-- This file is automatically generated. Please don't edit it directly:
29
40
  if you find an error, edit the source file (likely index.js), and re-run
package/index.js CHANGED
@@ -1,13 +1,15 @@
1
- import { coordEach } from '@turf/meta';
2
- import { point } from '@turf/helpers';
3
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var meta_1 = require("@turf/meta");
4
+ var helpers_1 = require("@turf/helpers");
4
5
  /**
5
6
  * Takes one or more features and calculates the centroid using the mean of all vertices.
6
7
  * This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
7
8
  *
8
9
  * @name centroid
9
10
  * @param {GeoJSON} geojson GeoJSON to be centered
10
- * @param {Object} [properties={}] an Object that is used as the {@link Feature}'s properties
11
+ * @param {Object} [options={}] Optional Parameters
12
+ * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
11
13
  * @returns {Feature<Point>} the centroid of the input features
12
14
  * @example
13
15
  * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
@@ -17,16 +19,16 @@ import { point } from '@turf/helpers';
17
19
  * //addToMap
18
20
  * var addToMap = [polygon, centroid]
19
21
  */
20
- function centroid(geojson, properties) {
22
+ function centroid(geojson, options) {
23
+ if (options === void 0) { options = {}; }
21
24
  var xSum = 0;
22
25
  var ySum = 0;
23
26
  var len = 0;
24
- coordEach(geojson, function (coord) {
27
+ meta_1.coordEach(geojson, function (coord) {
25
28
  xSum += coord[0];
26
29
  ySum += coord[1];
27
30
  len++;
28
- }, true);
29
- return point([xSum / len, ySum / len], properties);
31
+ });
32
+ return helpers_1.point([xSum / len, ySum / len], options.properties);
30
33
  }
31
-
32
- export default centroid;
34
+ exports.default = centroid;
package/package.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "name": "@turf/centroid",
3
- "version": "5.0.4",
3
+ "version": "6.0.2",
4
4
  "description": "turf centroid module",
5
- "main": "main",
6
- "module": "index",
7
- "jsnext:main": "index",
5
+ "main": "index",
8
6
  "types": "index.d.ts",
9
7
  "files": [
10
8
  "index.js",
11
- "index.d.ts",
12
- "main.js"
9
+ "index.d.ts"
13
10
  ],
14
11
  "scripts": {
15
- "pretest": "rollup -c ../../rollup.config.js",
16
- "test": "node -r @std/esm test.js",
17
- "bench": "node -r @std/esm bench.js"
12
+ "prepare": "tsc",
13
+ "pretest": "tsc",
14
+ "test": "node test.js",
15
+ "bench": "node bench.js",
16
+ "docs": "node ../../scripts/generate-readmes"
18
17
  },
19
18
  "repository": {
20
19
  "type": "git",
@@ -33,21 +32,18 @@
33
32
  },
34
33
  "homepage": "https://github.com/Turfjs/turf",
35
34
  "devDependencies": {
36
- "@std/esm": "*",
37
35
  "benchmark": "*",
38
36
  "geojson-fixtures": "*",
39
37
  "glob": "*",
40
38
  "load-json-file": "*",
41
- "rollup": "*",
39
+ "typescript": "*",
42
40
  "tape": "*",
43
- "write-json-file": "*"
41
+ "write-json-file": "*",
42
+ "tslint": "*",
43
+ "@types/tape": "*"
44
44
  },
45
45
  "dependencies": {
46
- "@turf/helpers": "^5.0.4",
47
- "@turf/meta": "^5.0.4"
48
- },
49
- "@std/esm": {
50
- "esm": "js",
51
- "cjs": true
46
+ "@turf/helpers": "6.x",
47
+ "@turf/meta": "6.x"
52
48
  }
53
49
  }
package/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { AllGeoJSON, Feature, Point, Properties } from '@turf/helpers';
2
-
3
- /**
4
- * http://turfjs.org/docs/#centroid
5
- */
6
- export default function (
7
- features: AllGeoJSON,
8
- properties?: Properties
9
- ): Feature<Point>;
package/main.js DELETED
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var meta = require('@turf/meta');
4
- var helpers = require('@turf/helpers');
5
-
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.
9
- *
10
- * @name centroid
11
- * @param {GeoJSON} geojson GeoJSON to be centered
12
- * @param {Object} [properties={}] an Object that is used as the {@link Feature}'s properties
13
- * @returns {Feature<Point>} the centroid of the input features
14
- * @example
15
- * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
16
- *
17
- * var centroid = turf.centroid(polygon);
18
- *
19
- * //addToMap
20
- * var addToMap = [polygon, centroid]
21
- */
22
- function centroid(geojson, properties) {
23
- var xSum = 0;
24
- var ySum = 0;
25
- var len = 0;
26
- meta.coordEach(geojson, function (coord) {
27
- xSum += coord[0];
28
- ySum += coord[1];
29
- len++;
30
- }, true);
31
- return helpers.point([xSum / len, ySum / len], properties);
32
- }
33
-
34
- module.exports = centroid;
35
- module.exports.default = centroid;