@turf/center-mean 7.0.0-alpha.2 → 7.1.0-alpha.7

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
@@ -50,26 +50,21 @@ Returns **[Feature][6]<[Point][7]>** a Point feature at the mean center point of
50
50
 
51
51
  [7]: https://tools.ietf.org/html/rfc7946#section-3.1.2
52
52
 
53
- <!-- This file is automatically generated. Please don't edit it directly:
54
- if you find an error, edit the source file (likely index.js), and re-run
55
- ./scripts/generate-readmes in the turf project. -->
53
+ <!-- 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. -->
56
54
 
57
55
  ---
58
56
 
59
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
60
- module collection dedicated to geographic algorithms. It is maintained in the
61
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
62
- PRs and issues.
57
+ 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.
63
58
 
64
59
  ### Installation
65
60
 
66
- Install this module individually:
61
+ Install this single module individually:
67
62
 
68
63
  ```sh
69
64
  $ npm install @turf/center-mean
70
65
  ```
71
66
 
72
- Or install the Turf module that includes it as a function:
67
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
73
68
 
74
69
  ```sh
75
70
  $ npm install @turf/turf
@@ -0,0 +1,31 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var _meta = require('@turf/meta');
3
+ var _helpers = require('@turf/helpers');
4
+ function centerMean(geojson, options = {}) {
5
+ let sumXs = 0;
6
+ let sumYs = 0;
7
+ let sumNs = 0;
8
+ _meta.geomEach.call(void 0, geojson, function(geom, featureIndex, properties) {
9
+ let weight = options.weight ? properties == null ? void 0 : properties[options.weight] : void 0;
10
+ weight = weight === void 0 || weight === null ? 1 : weight;
11
+ if (!_helpers.isNumber.call(void 0, weight))
12
+ throw new Error(
13
+ "weight value must be a number for feature index " + featureIndex
14
+ );
15
+ weight = Number(weight);
16
+ if (weight > 0) {
17
+ _meta.coordEach.call(void 0, geom, function(coord) {
18
+ sumXs += coord[0] * weight;
19
+ sumYs += coord[1] * weight;
20
+ sumNs += weight;
21
+ });
22
+ }
23
+ });
24
+ return _helpers.point.call(void 0, [sumXs / sumNs, sumYs / sumNs], options.properties, options);
25
+ }
26
+ var turf_center_mean_default = centerMean;
27
+
28
+
29
+
30
+ exports.centerMean = centerMean; exports.default = turf_center_mean_default;
31
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,UAAU,iBAAiB;AACpC,SAAS,UAAU,aAAiB;AA4BpC,SAAS,WACP,SACA,UAAqE,CAAC,GACnD;AACnB,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,WAAS,SAAS,SAAU,MAAM,cAAc,YAAY;AAC1D,QAAI,SAAS,QAAQ,SAAS,yCAAa,QAAQ,UAAU;AAC7D,aAAS,WAAW,UAAa,WAAW,OAAO,IAAI;AACvD,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI;AAAA,QACR,qDAAqD;AAAA,MACvD;AACF,aAAS,OAAO,MAAM;AACtB,QAAI,SAAS,GAAG;AACd,gBAAU,MAAM,SAAU,OAAO;AAC/B,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACD,SAAO,MAAM,CAAC,QAAQ,OAAO,QAAQ,KAAK,GAAG,QAAQ,YAAY,OAAO;AAC1E;AAGA,IAAO,2BAAQ","sourcesContent":["import { BBox, Feature, Point, GeoJsonProperties } from \"geojson\";\nimport { geomEach, coordEach } from \"@turf/meta\";\nimport { isNumber, point, Id } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.\n *\n * @name centerMean\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point\n * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point\n * @param {Object} [options.id={}] Translate GeoJSON Id to Point\n * @param {string} [options.weight] the property name used to weight the center\n * @returns {Feature<Point>} a Point feature at the mean center point of all input features\n * @example\n * var features = turf.featureCollection([\n * turf.point([-97.522259, 35.4691], {value: 10}),\n * turf.point([-97.502754, 35.463455], {value: 3}),\n * turf.point([-97.508269, 35.463245], {value: 5})\n * ]);\n *\n * var options = {weight: \"value\"}\n * var mean = turf.centerMean(features, options);\n *\n * //addToMap\n * var addToMap = [features, mean]\n * mean.properties['marker-size'] = 'large';\n * mean.properties['marker-color'] = '#000';\n */\nfunction centerMean<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: any, // To-Do include Typescript AllGeoJSON\n options: { properties?: P; bbox?: BBox; id?: Id; weight?: string } = {}\n): Feature<Point, P> {\n let sumXs = 0;\n let sumYs = 0;\n let sumNs = 0;\n geomEach(geojson, function (geom, featureIndex, properties) {\n let weight = options.weight ? properties?.[options.weight] : undefined;\n weight = weight === undefined || weight === null ? 1 : weight;\n if (!isNumber(weight))\n throw new Error(\n \"weight value must be a number for feature index \" + featureIndex\n );\n weight = Number(weight);\n if (weight > 0) {\n coordEach(geom, function (coord) {\n sumXs += coord[0] * weight;\n sumYs += coord[1] * weight;\n sumNs += weight;\n });\n }\n });\n return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);\n}\n\nexport { centerMean };\nexport default centerMean;\n"]}
@@ -1,5 +1,6 @@
1
- import { geomEach, coordEach } from "@turf/meta";
2
- import { isNumber, point } from "@turf/helpers";
1
+ import { GeoJsonProperties, BBox, Feature, Point } from 'geojson';
2
+ import { Id } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
5
6
  *
@@ -26,25 +27,12 @@ import { isNumber, point } from "@turf/helpers";
26
27
  * mean.properties['marker-size'] = 'large';
27
28
  * mean.properties['marker-color'] = '#000';
28
29
  */
29
- function centerMean(geojson, // To-Do include Typescript AllGeoJSON
30
- options = {}) {
31
- let sumXs = 0;
32
- let sumYs = 0;
33
- let sumNs = 0;
34
- geomEach(geojson, function (geom, featureIndex, properties) {
35
- let weight = options.weight ? properties === null || properties === void 0 ? void 0 : properties[options.weight] : undefined;
36
- weight = weight === undefined || weight === null ? 1 : weight;
37
- if (!isNumber(weight))
38
- throw new Error("weight value must be a number for feature index " + featureIndex);
39
- weight = Number(weight);
40
- if (weight > 0) {
41
- coordEach(geom, function (coord) {
42
- sumXs += coord[0] * weight;
43
- sumYs += coord[1] * weight;
44
- sumNs += weight;
45
- });
46
- }
47
- });
48
- return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
49
- }
50
- export default centerMean;
30
+ declare function centerMean<P extends GeoJsonProperties = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
31
+ options?: {
32
+ properties?: P;
33
+ bbox?: BBox;
34
+ id?: Id;
35
+ weight?: string;
36
+ }): Feature<Point, P>;
37
+
38
+ export { centerMean, centerMean as default };
@@ -1,5 +1,6 @@
1
- import { BBox, Feature, Point, GeoJsonProperties } from "geojson";
2
- import { Id } from "@turf/helpers";
1
+ import { GeoJsonProperties, BBox, Feature, Point } from 'geojson';
2
+ import { Id } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
5
6
  *
@@ -26,11 +27,12 @@ import { Id } from "@turf/helpers";
26
27
  * mean.properties['marker-size'] = 'large';
27
28
  * mean.properties['marker-color'] = '#000';
28
29
  */
29
- declare function centerMean<P = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
30
+ declare function centerMean<P extends GeoJsonProperties = GeoJsonProperties>(geojson: any, // To-Do include Typescript AllGeoJSON
30
31
  options?: {
31
32
  properties?: P;
32
33
  bbox?: BBox;
33
34
  id?: Id;
34
35
  weight?: string;
35
36
  }): Feature<Point, P>;
36
- export default centerMean;
37
+
38
+ export { centerMean, centerMean as default };
@@ -0,0 +1,31 @@
1
+ // index.ts
2
+ import { geomEach, coordEach } from "@turf/meta";
3
+ import { isNumber, point } from "@turf/helpers";
4
+ function centerMean(geojson, options = {}) {
5
+ let sumXs = 0;
6
+ let sumYs = 0;
7
+ let sumNs = 0;
8
+ geomEach(geojson, function(geom, featureIndex, properties) {
9
+ let weight = options.weight ? properties == null ? void 0 : properties[options.weight] : void 0;
10
+ weight = weight === void 0 || weight === null ? 1 : weight;
11
+ if (!isNumber(weight))
12
+ throw new Error(
13
+ "weight value must be a number for feature index " + featureIndex
14
+ );
15
+ weight = Number(weight);
16
+ if (weight > 0) {
17
+ coordEach(geom, function(coord) {
18
+ sumXs += coord[0] * weight;
19
+ sumYs += coord[1] * weight;
20
+ sumNs += weight;
21
+ });
22
+ }
23
+ });
24
+ return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
25
+ }
26
+ var turf_center_mean_default = centerMean;
27
+ export {
28
+ centerMean,
29
+ turf_center_mean_default as default
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { BBox, Feature, Point, GeoJsonProperties } from \"geojson\";\nimport { geomEach, coordEach } from \"@turf/meta\";\nimport { isNumber, point, Id } from \"@turf/helpers\";\n\n/**\n * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.\n *\n * @name centerMean\n * @param {GeoJSON} geojson GeoJSON to be centered\n * @param {Object} [options={}] Optional parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point\n * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point\n * @param {Object} [options.id={}] Translate GeoJSON Id to Point\n * @param {string} [options.weight] the property name used to weight the center\n * @returns {Feature<Point>} a Point feature at the mean center point of all input features\n * @example\n * var features = turf.featureCollection([\n * turf.point([-97.522259, 35.4691], {value: 10}),\n * turf.point([-97.502754, 35.463455], {value: 3}),\n * turf.point([-97.508269, 35.463245], {value: 5})\n * ]);\n *\n * var options = {weight: \"value\"}\n * var mean = turf.centerMean(features, options);\n *\n * //addToMap\n * var addToMap = [features, mean]\n * mean.properties['marker-size'] = 'large';\n * mean.properties['marker-color'] = '#000';\n */\nfunction centerMean<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: any, // To-Do include Typescript AllGeoJSON\n options: { properties?: P; bbox?: BBox; id?: Id; weight?: string } = {}\n): Feature<Point, P> {\n let sumXs = 0;\n let sumYs = 0;\n let sumNs = 0;\n geomEach(geojson, function (geom, featureIndex, properties) {\n let weight = options.weight ? properties?.[options.weight] : undefined;\n weight = weight === undefined || weight === null ? 1 : weight;\n if (!isNumber(weight))\n throw new Error(\n \"weight value must be a number for feature index \" + featureIndex\n );\n weight = Number(weight);\n if (weight > 0) {\n coordEach(geom, function (coord) {\n sumXs += coord[0] * weight;\n sumYs += coord[1] * weight;\n sumNs += weight;\n });\n }\n });\n return point([sumXs / sumNs, sumYs / sumNs], options.properties, options);\n}\n\nexport { centerMean };\nexport default centerMean;\n"],"mappings":";AACA,SAAS,UAAU,iBAAiB;AACpC,SAAS,UAAU,aAAiB;AA4BpC,SAAS,WACP,SACA,UAAqE,CAAC,GACnD;AACnB,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,WAAS,SAAS,SAAU,MAAM,cAAc,YAAY;AAC1D,QAAI,SAAS,QAAQ,SAAS,yCAAa,QAAQ,UAAU;AAC7D,aAAS,WAAW,UAAa,WAAW,OAAO,IAAI;AACvD,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI;AAAA,QACR,qDAAqD;AAAA,MACvD;AACF,aAAS,OAAO,MAAM;AACtB,QAAI,SAAS,GAAG;AACd,gBAAU,MAAM,SAAU,OAAO;AAC/B,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS,MAAM,CAAC,IAAI;AACpB,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACD,SAAO,MAAM,CAAC,QAAQ,OAAO,QAAQ,KAAK,GAAG,QAAQ,YAAY,OAAO;AAC1E;AAGA,IAAO,2BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/center-mean",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf center-mean module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -28,50 +28,55 @@
28
28
  "geo",
29
29
  "turf"
30
30
  ],
31
- "main": "dist/js/index.js",
32
- "module": "dist/es/index.js",
31
+ "type": "module",
32
+ "main": "dist/cjs/index.cjs",
33
+ "module": "dist/esm/index.js",
34
+ "types": "dist/esm/index.d.ts",
33
35
  "exports": {
34
36
  "./package.json": "./package.json",
35
37
  ".": {
36
- "types": "./dist/js/index.d.ts",
37
- "import": "./dist/es/index.js",
38
- "require": "./dist/js/index.js"
38
+ "import": {
39
+ "types": "./dist/esm/index.d.ts",
40
+ "default": "./dist/esm/index.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/cjs/index.d.cts",
44
+ "default": "./dist/cjs/index.cjs"
45
+ }
39
46
  }
40
47
  },
41
- "types": "dist/js/index.d.ts",
42
48
  "sideEffects": false,
43
49
  "files": [
44
50
  "dist"
45
51
  ],
46
52
  "scripts": {
47
- "bench": "tsx bench.js",
48
- "build": "npm-run-all build:*",
49
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
50
- "build:js": "tsc",
51
- "docs": "tsx ../../scripts/generate-readmes",
52
- "test": "npm-run-all test:*",
53
- "test:tape": "tsx test.js",
54
- "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
53
+ "bench": "tsx bench.ts",
54
+ "build": "tsup --config ../../tsup.config.ts",
55
+ "docs": "tsx ../../scripts/generate-readmes.ts",
56
+ "test": "npm-run-all --npm-path npm test:*",
57
+ "test:tape": "tsx test.ts",
58
+ "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
55
59
  },
56
60
  "devDependencies": {
57
- "@turf/center": "^7.0.0-alpha.2",
58
- "@turf/truncate": "^7.0.0-alpha.2",
59
- "@types/tape": "*",
60
- "benchmark": "*",
61
- "glob": "*",
62
- "load-json-file": "*",
63
- "npm-run-all": "*",
64
- "tape": "*",
65
- "tslint": "*",
66
- "tsx": "*",
67
- "typescript": "*",
68
- "write-json-file": "*"
61
+ "@turf/center": "^7.1.0-alpha.7+0ce6ecca0",
62
+ "@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
63
+ "@types/benchmark": "^2.1.5",
64
+ "@types/tape": "^4.2.32",
65
+ "benchmark": "^2.1.4",
66
+ "glob": "^10.3.10",
67
+ "load-json-file": "^7.0.1",
68
+ "npm-run-all": "^4.1.5",
69
+ "tape": "^5.7.2",
70
+ "tsup": "^8.0.1",
71
+ "tsx": "^4.6.2",
72
+ "typescript": "^5.2.2",
73
+ "write-json-file": "^5.0.0"
69
74
  },
70
75
  "dependencies": {
71
- "@turf/bbox": "^7.0.0-alpha.2",
72
- "@turf/helpers": "^7.0.0-alpha.2",
73
- "@turf/meta": "^7.0.0-alpha.2",
74
- "tslib": "^2.3.0"
76
+ "@turf/bbox": "^7.1.0-alpha.7+0ce6ecca0",
77
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
78
+ "@turf/meta": "^7.1.0-alpha.7+0ce6ecca0",
79
+ "tslib": "^2.6.2"
75
80
  },
76
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
81
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
77
82
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const meta_1 = require("@turf/meta");
4
- const helpers_1 = require("@turf/helpers");
5
- /**
6
- * Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
7
- *
8
- * @name centerMean
9
- * @param {GeoJSON} geojson GeoJSON to be centered
10
- * @param {Object} [options={}] Optional parameters
11
- * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point
12
- * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point
13
- * @param {Object} [options.id={}] Translate GeoJSON Id to Point
14
- * @param {string} [options.weight] the property name used to weight the center
15
- * @returns {Feature<Point>} a Point feature at the mean center point of all input features
16
- * @example
17
- * var features = turf.featureCollection([
18
- * turf.point([-97.522259, 35.4691], {value: 10}),
19
- * turf.point([-97.502754, 35.463455], {value: 3}),
20
- * turf.point([-97.508269, 35.463245], {value: 5})
21
- * ]);
22
- *
23
- * var options = {weight: "value"}
24
- * var mean = turf.centerMean(features, options);
25
- *
26
- * //addToMap
27
- * var addToMap = [features, mean]
28
- * mean.properties['marker-size'] = 'large';
29
- * mean.properties['marker-color'] = '#000';
30
- */
31
- function centerMean(geojson, // To-Do include Typescript AllGeoJSON
32
- options = {}) {
33
- let sumXs = 0;
34
- let sumYs = 0;
35
- let sumNs = 0;
36
- meta_1.geomEach(geojson, function (geom, featureIndex, properties) {
37
- let weight = options.weight ? properties === null || properties === void 0 ? void 0 : properties[options.weight] : undefined;
38
- weight = weight === undefined || weight === null ? 1 : weight;
39
- if (!helpers_1.isNumber(weight))
40
- throw new Error("weight value must be a number for feature index " + featureIndex);
41
- weight = Number(weight);
42
- if (weight > 0) {
43
- meta_1.coordEach(geom, function (coord) {
44
- sumXs += coord[0] * weight;
45
- sumYs += coord[1] * weight;
46
- sumNs += weight;
47
- });
48
- }
49
- });
50
- return helpers_1.point([sumXs / sumNs, sumYs / sumNs], options.properties, options);
51
- }
52
- exports.default = centerMean;