@turf/centroid 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
@@ -36,26 +36,21 @@ Returns **[Feature][4]<[Point][5]>** the centroid of the input object
36
36
 
37
37
  [5]: https://tools.ietf.org/html/rfc7946#section-3.1.2
38
38
 
39
- <!-- This file is automatically generated. Please don't edit it directly:
40
- if you find an error, edit the source file (likely index.js), and re-run
41
- ./scripts/generate-readmes in the turf project. -->
39
+ <!-- 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. -->
42
40
 
43
41
  ---
44
42
 
45
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
46
- module collection dedicated to geographic algorithms. It is maintained in the
47
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
48
- PRs and issues.
43
+ 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.
49
44
 
50
45
  ### Installation
51
46
 
52
- Install this module individually:
47
+ Install this single module individually:
53
48
 
54
49
  ```sh
55
50
  $ npm install @turf/centroid
56
51
  ```
57
52
 
58
- Or install the Turf module that includes it as a function:
53
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
59
54
 
60
55
  ```sh
61
56
  $ npm install @turf/turf
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});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
+ function centroid(geojson, options = {}) {
8
+ let xSum = 0;
9
+ let ySum = 0;
10
+ let len = 0;
11
+ _meta.coordEach.call(void 0,
12
+ geojson,
13
+ function(coord) {
14
+ xSum += coord[0];
15
+ ySum += coord[1];
16
+ len++;
17
+ },
18
+ true
19
+ );
20
+ return _helpers.point.call(void 0, [xSum / len, ySum / len], options.properties);
21
+ }
22
+ __name(centroid, "centroid");
23
+ var turf_centroid_default = centroid;
24
+
25
+
26
+
27
+ exports.centroid = centroid; exports.default = turf_centroid_default;
28
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,aAAyB;AAClC,SAAS,iBAAiB;AAkB1B,SAAS,SACP,SACA,UAEI,CAAC,GACc;AACnB,MAAI,OAAO;AACX,MAAI,OAAO;AACX,MAAI,MAAM;AACV;AAAA,IACE;AAAA,IACA,SAAU,OAAO;AACf,cAAQ,MAAM,CAAC;AACf,cAAQ,MAAM,CAAC;AACf;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACA,SAAO,MAAM,CAAC,OAAO,KAAK,OAAO,GAAG,GAAG,QAAQ,UAAU;AAC3D;AAnBS;AAsBT,IAAO,wBAAQ","sourcesContent":["import { Feature, GeoJsonProperties, Point } from \"geojson\";\nimport { point, AllGeoJSON } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\n\n/**\n * Computes the centroid as the mean of all vertices within the object.\n *\n * @name centroid\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties\n * @returns {Feature<Point>} the centroid of the input object\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var centroid = turf.centroid(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, centroid]\n */\nfunction centroid<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n properties?: P;\n } = {}\n): Feature<Point, P> {\n let xSum = 0;\n let ySum = 0;\n let len = 0;\n coordEach(\n geojson,\n function (coord) {\n xSum += coord[0];\n ySum += coord[1];\n len++;\n },\n true\n );\n return point([xSum / len, ySum / len], options.properties);\n}\n\nexport { centroid };\nexport default centroid;\n"]}
@@ -1,5 +1,6 @@
1
- import { point } from "@turf/helpers";
2
- import { coordEach } from "@turf/meta";
1
+ import { GeoJsonProperties, Feature, Point } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Computes the centroid as the mean of all vertices within the object.
5
6
  *
@@ -16,15 +17,8 @@ import { coordEach } from "@turf/meta";
16
17
  * //addToMap
17
18
  * var addToMap = [polygon, centroid]
18
19
  */
19
- function centroid(geojson, options = {}) {
20
- let xSum = 0;
21
- let ySum = 0;
22
- let len = 0;
23
- coordEach(geojson, function (coord) {
24
- xSum += coord[0];
25
- ySum += coord[1];
26
- len++;
27
- }, true);
28
- return point([xSum / len, ySum / len], options.properties);
29
- }
30
- export default centroid;
20
+ declare function centroid<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
21
+ properties?: P;
22
+ }): Feature<Point, P>;
23
+
24
+ export { centroid, centroid as default };
@@ -1,5 +1,6 @@
1
- import { Feature, GeoJsonProperties, Point } from "geojson";
2
- import { AllGeoJSON } from "@turf/helpers";
1
+ import { GeoJsonProperties, Feature, Point } from 'geojson';
2
+ import { AllGeoJSON } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Computes the centroid as the mean of all vertices within the object.
5
6
  *
@@ -16,7 +17,8 @@ import { AllGeoJSON } from "@turf/helpers";
16
17
  * //addToMap
17
18
  * var addToMap = [polygon, centroid]
18
19
  */
19
- declare function centroid<P = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
20
+ declare function centroid<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
20
21
  properties?: P;
21
22
  }): Feature<Point, P>;
22
- export default centroid;
23
+
24
+ export { centroid, centroid as default };
@@ -0,0 +1,28 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { point } from "@turf/helpers";
6
+ import { coordEach } from "@turf/meta";
7
+ function centroid(geojson, options = {}) {
8
+ let xSum = 0;
9
+ let ySum = 0;
10
+ let len = 0;
11
+ coordEach(
12
+ geojson,
13
+ function(coord) {
14
+ xSum += coord[0];
15
+ ySum += coord[1];
16
+ len++;
17
+ },
18
+ true
19
+ );
20
+ return point([xSum / len, ySum / len], options.properties);
21
+ }
22
+ __name(centroid, "centroid");
23
+ var turf_centroid_default = centroid;
24
+ export {
25
+ centroid,
26
+ turf_centroid_default as default
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, GeoJsonProperties, Point } from \"geojson\";\nimport { point, AllGeoJSON } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\n\n/**\n * Computes the centroid as the mean of all vertices within the object.\n *\n * @name centroid\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties\n * @returns {Feature<Point>} the centroid of the input object\n * @example\n * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);\n *\n * var centroid = turf.centroid(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, centroid]\n */\nfunction centroid<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n properties?: P;\n } = {}\n): Feature<Point, P> {\n let xSum = 0;\n let ySum = 0;\n let len = 0;\n coordEach(\n geojson,\n function (coord) {\n xSum += coord[0];\n ySum += coord[1];\n len++;\n },\n true\n );\n return point([xSum / len, ySum / len], options.properties);\n}\n\nexport { centroid };\nexport default centroid;\n"],"mappings":";;;;AACA,SAAS,aAAyB;AAClC,SAAS,iBAAiB;AAkB1B,SAAS,SACP,SACA,UAEI,CAAC,GACc;AACnB,MAAI,OAAO;AACX,MAAI,OAAO;AACX,MAAI,MAAM;AACV;AAAA,IACE;AAAA,IACA,SAAU,OAAO;AACf,cAAQ,MAAM,CAAC;AACf,cAAQ,MAAM,CAAC;AACf;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACA,SAAO,MAAM,CAAC,OAAO,KAAK,OAAO,GAAG,GAAG,QAAQ,UAAU;AAC3D;AAnBS;AAsBT,IAAO,wBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/centroid",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "turf centroid module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -22,48 +22,52 @@
22
22
  "geo",
23
23
  "gis"
24
24
  ],
25
- "main": "dist/js/index.js",
26
- "module": "dist/es/index.js",
25
+ "type": "module",
26
+ "main": "dist/cjs/index.cjs",
27
+ "module": "dist/esm/index.js",
28
+ "types": "dist/esm/index.d.ts",
27
29
  "exports": {
28
30
  "./package.json": "./package.json",
29
31
  ".": {
30
- "types": "./dist/js/index.d.ts",
31
- "import": "./dist/es/index.js",
32
- "require": "./dist/js/index.js"
32
+ "import": {
33
+ "types": "./dist/esm/index.d.ts",
34
+ "default": "./dist/esm/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/cjs/index.d.cts",
38
+ "default": "./dist/cjs/index.cjs"
39
+ }
33
40
  }
34
41
  },
35
- "types": "dist/js/index.d.ts",
36
42
  "sideEffects": false,
37
43
  "files": [
38
44
  "dist"
39
45
  ],
40
46
  "scripts": {
41
- "bench": "tsx bench.js",
42
- "build": "npm-run-all build:*",
43
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
44
- "build:js": "tsc",
45
- "docs": "tsx ../../scripts/generate-readmes",
46
- "test": "npm-run-all test:*",
47
- "test:tape": "tsx test.js",
48
- "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
47
+ "bench": "tsx bench.ts",
48
+ "build": "tsup --config ../../tsup.config.ts",
49
+ "docs": "tsx ../../scripts/generate-readmes.ts",
50
+ "test": "npm-run-all --npm-path npm test:*",
51
+ "test:tape": "tsx test.ts",
52
+ "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
49
53
  },
50
54
  "devDependencies": {
51
- "@types/tape": "*",
52
- "benchmark": "*",
53
- "geojson-fixtures": "*",
54
- "glob": "*",
55
- "load-json-file": "*",
56
- "npm-run-all": "*",
57
- "tape": "*",
58
- "tslint": "*",
59
- "tsx": "*",
60
- "typescript": "*",
61
- "write-json-file": "*"
55
+ "@types/benchmark": "^2.1.5",
56
+ "@types/tape": "^4.2.32",
57
+ "benchmark": "^2.1.4",
58
+ "glob": "^10.3.10",
59
+ "load-json-file": "^7.0.1",
60
+ "npm-run-all": "^4.1.5",
61
+ "tape": "^5.7.2",
62
+ "tsup": "^8.0.1",
63
+ "tsx": "^4.6.2",
64
+ "typescript": "^5.2.2",
65
+ "write-json-file": "^5.0.0"
62
66
  },
63
67
  "dependencies": {
64
- "@turf/helpers": "^7.0.0-alpha.2",
65
- "@turf/meta": "^7.0.0-alpha.2",
66
- "tslib": "^2.3.0"
68
+ "@turf/helpers": "^7.0.0",
69
+ "@turf/meta": "^7.0.0",
70
+ "tslib": "^2.6.2"
67
71
  },
68
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
72
+ "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
69
73
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const helpers_1 = require("@turf/helpers");
4
- const meta_1 = require("@turf/meta");
5
- /**
6
- * Computes the centroid as the mean of all vertices within the object.
7
- *
8
- * @name centroid
9
- * @param {GeoJSON} geojson GeoJSON to be centered
10
- * @param {Object} [options={}] Optional Parameters
11
- * @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
12
- * @returns {Feature<Point>} the centroid of the input object
13
- * @example
14
- * var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
15
- *
16
- * var centroid = turf.centroid(polygon);
17
- *
18
- * //addToMap
19
- * var addToMap = [polygon, centroid]
20
- */
21
- function centroid(geojson, options = {}) {
22
- let xSum = 0;
23
- let ySum = 0;
24
- let len = 0;
25
- meta_1.coordEach(geojson, function (coord) {
26
- xSum += coord[0];
27
- ySum += coord[1];
28
- len++;
29
- }, true);
30
- return helpers_1.point([xSum / len, ySum / len], options.properties);
31
- }
32
- exports.default = centroid;