@turf/nearest-point 7.0.0-alpha.1 → 7.0.0-alpha.111

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][7]<[Point][4]>** the closest point in the set to the referen
50
50
 
51
51
  [7]: https://tools.ietf.org/html/rfc7946#section-3.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/nearest-point
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,54 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
21
+
22
+ // index.ts
23
+ var _clone = require('@turf/clone');
24
+ var _distance = require('@turf/distance');
25
+ var _meta = require('@turf/meta');
26
+ function nearestPoint(targetPoint, points, options = {}) {
27
+ if (!targetPoint)
28
+ throw new Error("targetPoint is required");
29
+ if (!points)
30
+ throw new Error("points is required");
31
+ let minDist = Infinity;
32
+ let bestFeatureIndex = 0;
33
+ _meta.featureEach.call(void 0, points, (pt, featureIndex) => {
34
+ const distanceToPoint = _distance.distance.call(void 0, targetPoint, pt, options);
35
+ if (distanceToPoint < minDist) {
36
+ bestFeatureIndex = featureIndex;
37
+ minDist = distanceToPoint;
38
+ }
39
+ });
40
+ const nearestPoint2 = _clone.clone.call(void 0, points.features[bestFeatureIndex]);
41
+ return __spreadProps(__spreadValues({}, nearestPoint2), {
42
+ properties: __spreadProps(__spreadValues({}, nearestPoint2.properties), {
43
+ featureIndex: bestFeatureIndex,
44
+ distanceToPoint: minDist
45
+ })
46
+ });
47
+ }
48
+ __name(nearestPoint, "nearestPoint");
49
+ var turf_nearest_point_default = nearestPoint;
50
+
51
+
52
+
53
+ exports.default = turf_nearest_point_default; exports.nearestPoint = nearestPoint;
54
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":["nearestPoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAoC5B,SAAS,aACP,aACA,QACA,UAEI,CAAC,GACS;AAEd,MAAI,CAAC;AAAa,UAAM,IAAI,MAAM,yBAAyB;AAC3D,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AAEjD,MAAI,UAAU;AACd,MAAI,mBAAmB;AACvB,cAAY,QAAQ,CAAC,IAAI,iBAAiB;AACxC,UAAM,kBAAkB,SAAS,aAAa,IAAI,OAAO;AACzD,QAAI,kBAAkB,SAAS;AAC7B,yBAAmB;AACnB,gBAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACD,QAAMA,gBAAe,MAAM,OAAO,SAAS,gBAAgB,CAAC;AAE5D,SAAO,iCACFA,gBADE;AAAA,IAEL,YAAY,iCACPA,cAAa,aADN;AAAA,MAEV,cAAc;AAAA,MACd,iBAAiB;AAAA,IACnB;AAAA,EACF;AACF;AA9BS;AAiCT,IAAO,6BAAQ","sourcesContent":["import { Feature, FeatureCollection, Point } from \"geojson\";\nimport { Coord, Units } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\nimport { distance } from \"@turf/distance\";\nimport { featureEach } from \"@turf/meta\";\n\ninterface NearestPoint extends Feature<Point> {\n properties: {\n featureIndex: number;\n distanceToPoint: number;\n [key: string]: any;\n };\n}\n\n/**\n * Takes a reference {@link Point|point} and a FeatureCollection of Features\n * with Point geometries and returns the\n * point from the FeatureCollection closest to the reference. This calculation\n * is geodesic.\n *\n * @name nearestPoint\n * @param {Coord} targetPoint the reference point\n * @param {FeatureCollection<Point>} points against input point set\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] the units of the numeric result\n * @returns {Feature<Point>} the closest point in the set to the reference point\n * @example\n * var targetPoint = turf.point([28.965797, 41.010086], {\"marker-color\": \"#0F0\"});\n * var points = turf.featureCollection([\n * turf.point([28.973865, 41.011122]),\n * turf.point([28.948459, 41.024204]),\n * turf.point([28.938674, 41.013324])\n * ]);\n *\n * var nearest = turf.nearestPoint(targetPoint, points);\n *\n * //addToMap\n * var addToMap = [targetPoint, points, nearest];\n * nearest.properties['marker-color'] = '#F00';\n */\nfunction nearestPoint(\n targetPoint: Coord,\n points: FeatureCollection<Point>,\n options: {\n units?: Units;\n } = {}\n): NearestPoint {\n // Input validation\n if (!targetPoint) throw new Error(\"targetPoint is required\");\n if (!points) throw new Error(\"points is required\");\n\n let minDist = Infinity;\n let bestFeatureIndex = 0;\n featureEach(points, (pt, featureIndex) => {\n const distanceToPoint = distance(targetPoint, pt, options);\n if (distanceToPoint < minDist) {\n bestFeatureIndex = featureIndex;\n minDist = distanceToPoint;\n }\n });\n const nearestPoint = clone(points.features[bestFeatureIndex]);\n\n return {\n ...nearestPoint,\n properties: {\n ...nearestPoint.properties,\n featureIndex: bestFeatureIndex,\n distanceToPoint: minDist,\n },\n };\n}\n\nexport { nearestPoint, NearestPoint };\nexport default nearestPoint;\n"]}
@@ -1,6 +1,7 @@
1
- import { Feature, FeatureCollection, Point } from "geojson";
2
- import { Coord, Units } from "@turf/helpers";
3
- export interface NearestPoint extends Feature<Point> {
1
+ import { Feature, Point, FeatureCollection } from 'geojson';
2
+ import { Coord, Units } from '@turf/helpers';
3
+
4
+ interface NearestPoint extends Feature<Point> {
4
5
  properties: {
5
6
  featureIndex: number;
6
7
  distanceToPoint: number;
@@ -36,4 +37,5 @@ export interface NearestPoint extends Feature<Point> {
36
37
  declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
37
38
  units?: Units;
38
39
  }): NearestPoint;
39
- export default nearestPoint;
40
+
41
+ export { type NearestPoint, nearestPoint as default, nearestPoint };
@@ -1,6 +1,13 @@
1
- import clone from "@turf/clone";
2
- import distance from "@turf/distance";
3
- import { featureEach } from "@turf/meta";
1
+ import { Feature, Point, FeatureCollection } from 'geojson';
2
+ import { Coord, Units } from '@turf/helpers';
3
+
4
+ interface NearestPoint extends Feature<Point> {
5
+ properties: {
6
+ featureIndex: number;
7
+ distanceToPoint: number;
8
+ [key: string]: any;
9
+ };
10
+ }
4
11
  /**
5
12
  * Takes a reference {@link Point|point} and a FeatureCollection of Features
6
13
  * with Point geometries and returns the
@@ -27,22 +34,8 @@ import { featureEach } from "@turf/meta";
27
34
  * var addToMap = [targetPoint, points, nearest];
28
35
  * nearest.properties['marker-color'] = '#F00';
29
36
  */
30
- function nearestPoint(targetPoint, points, options = {}) {
31
- // Input validation
32
- if (!targetPoint)
33
- throw new Error("targetPoint is required");
34
- if (!points)
35
- throw new Error("points is required");
36
- let minDist = Infinity;
37
- let bestFeatureIndex = 0;
38
- featureEach(points, (pt, featureIndex) => {
39
- const distanceToPoint = distance(targetPoint, pt, options);
40
- if (distanceToPoint < minDist) {
41
- bestFeatureIndex = featureIndex;
42
- minDist = distanceToPoint;
43
- }
44
- });
45
- const nearestPoint = clone(points.features[bestFeatureIndex]);
46
- return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
47
- }
48
- export default nearestPoint;
37
+ declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
38
+ units?: Units;
39
+ }): NearestPoint;
40
+
41
+ export { type NearestPoint, nearestPoint as default, nearestPoint };
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
21
+
22
+ // index.ts
23
+ import { clone } from "@turf/clone";
24
+ import { distance } from "@turf/distance";
25
+ import { featureEach } from "@turf/meta";
26
+ function nearestPoint(targetPoint, points, options = {}) {
27
+ if (!targetPoint)
28
+ throw new Error("targetPoint is required");
29
+ if (!points)
30
+ throw new Error("points is required");
31
+ let minDist = Infinity;
32
+ let bestFeatureIndex = 0;
33
+ featureEach(points, (pt, featureIndex) => {
34
+ const distanceToPoint = distance(targetPoint, pt, options);
35
+ if (distanceToPoint < minDist) {
36
+ bestFeatureIndex = featureIndex;
37
+ minDist = distanceToPoint;
38
+ }
39
+ });
40
+ const nearestPoint2 = clone(points.features[bestFeatureIndex]);
41
+ return __spreadProps(__spreadValues({}, nearestPoint2), {
42
+ properties: __spreadProps(__spreadValues({}, nearestPoint2.properties), {
43
+ featureIndex: bestFeatureIndex,
44
+ distanceToPoint: minDist
45
+ })
46
+ });
47
+ }
48
+ __name(nearestPoint, "nearestPoint");
49
+ var turf_nearest_point_default = nearestPoint;
50
+ export {
51
+ turf_nearest_point_default as default,
52
+ nearestPoint
53
+ };
54
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, FeatureCollection, Point } from \"geojson\";\nimport { Coord, Units } from \"@turf/helpers\";\nimport { clone } from \"@turf/clone\";\nimport { distance } from \"@turf/distance\";\nimport { featureEach } from \"@turf/meta\";\n\ninterface NearestPoint extends Feature<Point> {\n properties: {\n featureIndex: number;\n distanceToPoint: number;\n [key: string]: any;\n };\n}\n\n/**\n * Takes a reference {@link Point|point} and a FeatureCollection of Features\n * with Point geometries and returns the\n * point from the FeatureCollection closest to the reference. This calculation\n * is geodesic.\n *\n * @name nearestPoint\n * @param {Coord} targetPoint the reference point\n * @param {FeatureCollection<Point>} points against input point set\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] the units of the numeric result\n * @returns {Feature<Point>} the closest point in the set to the reference point\n * @example\n * var targetPoint = turf.point([28.965797, 41.010086], {\"marker-color\": \"#0F0\"});\n * var points = turf.featureCollection([\n * turf.point([28.973865, 41.011122]),\n * turf.point([28.948459, 41.024204]),\n * turf.point([28.938674, 41.013324])\n * ]);\n *\n * var nearest = turf.nearestPoint(targetPoint, points);\n *\n * //addToMap\n * var addToMap = [targetPoint, points, nearest];\n * nearest.properties['marker-color'] = '#F00';\n */\nfunction nearestPoint(\n targetPoint: Coord,\n points: FeatureCollection<Point>,\n options: {\n units?: Units;\n } = {}\n): NearestPoint {\n // Input validation\n if (!targetPoint) throw new Error(\"targetPoint is required\");\n if (!points) throw new Error(\"points is required\");\n\n let minDist = Infinity;\n let bestFeatureIndex = 0;\n featureEach(points, (pt, featureIndex) => {\n const distanceToPoint = distance(targetPoint, pt, options);\n if (distanceToPoint < minDist) {\n bestFeatureIndex = featureIndex;\n minDist = distanceToPoint;\n }\n });\n const nearestPoint = clone(points.features[bestFeatureIndex]);\n\n return {\n ...nearestPoint,\n properties: {\n ...nearestPoint.properties,\n featureIndex: bestFeatureIndex,\n distanceToPoint: minDist,\n },\n };\n}\n\nexport { nearestPoint, NearestPoint };\nexport default nearestPoint;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAoC5B,SAAS,aACP,aACA,QACA,UAEI,CAAC,GACS;AAEd,MAAI,CAAC;AAAa,UAAM,IAAI,MAAM,yBAAyB;AAC3D,MAAI,CAAC;AAAQ,UAAM,IAAI,MAAM,oBAAoB;AAEjD,MAAI,UAAU;AACd,MAAI,mBAAmB;AACvB,cAAY,QAAQ,CAAC,IAAI,iBAAiB;AACxC,UAAM,kBAAkB,SAAS,aAAa,IAAI,OAAO;AACzD,QAAI,kBAAkB,SAAS;AAC7B,yBAAmB;AACnB,gBAAU;AAAA,IACZ;AAAA,EACF,CAAC;AACD,QAAMA,gBAAe,MAAM,OAAO,SAAS,gBAAgB,CAAC;AAE5D,SAAO,iCACFA,gBADE;AAAA,IAEL,YAAY,iCACPA,cAAa,aADN;AAAA,MAEV,cAAc;AAAA,MACd,iBAAiB;AAAA,IACnB;AAAA,EACF;AACF;AA9BS;AAiCT,IAAO,6BAAQ;","names":["nearestPoint"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/nearest-point",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.111+08576cb50",
4
4
  "description": "turf nearest-point module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -24,46 +24,51 @@
24
24
  "nearest",
25
25
  "point"
26
26
  ],
27
- "main": "dist/js/index.js",
28
- "module": "dist/es/index.js",
27
+ "type": "commonjs",
28
+ "main": "dist/cjs/index.cjs",
29
+ "module": "dist/esm/index.mjs",
30
+ "types": "dist/cjs/index.d.ts",
29
31
  "exports": {
30
32
  "./package.json": "./package.json",
31
33
  ".": {
32
- "types": "./dist/js/index.d.ts",
33
- "import": "./dist/es/index.js",
34
- "require": "./dist/js/index.js"
34
+ "import": {
35
+ "types": "./dist/esm/index.d.mts",
36
+ "default": "./dist/esm/index.mjs"
37
+ },
38
+ "require": {
39
+ "types": "./dist/cjs/index.d.ts",
40
+ "default": "./dist/cjs/index.cjs"
41
+ }
35
42
  }
36
43
  },
37
- "types": "dist/js/index.d.ts",
38
44
  "sideEffects": false,
39
45
  "files": [
40
46
  "dist"
41
47
  ],
42
48
  "scripts": {
43
- "bench": "tsx bench.js",
44
- "build": "npm-run-all build:*",
45
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
46
- "build:js": "tsc",
47
- "docs": "tsx ../../scripts/generate-readmes",
48
- "test": "npm-run-all test:*",
49
- "test:tape": "tsx test.js",
49
+ "bench": "tsx bench.ts",
50
+ "build": "tsup --config ../../tsup.config.ts",
51
+ "docs": "tsx ../../scripts/generate-readmes.ts",
52
+ "test": "npm-run-all --npm-path npm test:*",
53
+ "test:tape": "tsx test.ts",
50
54
  "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
51
55
  },
52
56
  "devDependencies": {
53
- "@types/tape": "*",
54
- "benchmark": "*",
55
- "npm-run-all": "*",
56
- "tape": "*",
57
- "tslint": "*",
58
- "tsx": "*",
59
- "typescript": "*"
57
+ "@types/benchmark": "^2.1.5",
58
+ "@types/tape": "^4.2.32",
59
+ "benchmark": "^2.1.4",
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"
60
65
  },
61
66
  "dependencies": {
62
- "@turf/clone": "^7.0.0-alpha.1",
63
- "@turf/distance": "^7.0.0-alpha.1",
64
- "@turf/helpers": "^7.0.0-alpha.1",
65
- "@turf/meta": "^7.0.0-alpha.1",
66
- "tslib": "^2.3.0"
67
+ "@turf/clone": "^7.0.0-alpha.111+08576cb50",
68
+ "@turf/distance": "^7.0.0-alpha.111+08576cb50",
69
+ "@turf/helpers": "^7.0.0-alpha.111+08576cb50",
70
+ "@turf/meta": "^7.0.0-alpha.111+08576cb50",
71
+ "tslib": "^2.6.2"
67
72
  },
68
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
73
+ "gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
69
74
  }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const clone_1 = tslib_1.__importDefault(require("@turf/clone"));
5
- const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
6
- const meta_1 = require("@turf/meta");
7
- /**
8
- * Takes a reference {@link Point|point} and a FeatureCollection of Features
9
- * with Point geometries and returns the
10
- * point from the FeatureCollection closest to the reference. This calculation
11
- * is geodesic.
12
- *
13
- * @name nearestPoint
14
- * @param {Coord} targetPoint the reference point
15
- * @param {FeatureCollection<Point>} points against input point set
16
- * @param {Object} [options={}] Optional parameters
17
- * @param {string} [options.units='kilometers'] the units of the numeric result
18
- * @returns {Feature<Point>} the closest point in the set to the reference point
19
- * @example
20
- * var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
21
- * var points = turf.featureCollection([
22
- * turf.point([28.973865, 41.011122]),
23
- * turf.point([28.948459, 41.024204]),
24
- * turf.point([28.938674, 41.013324])
25
- * ]);
26
- *
27
- * var nearest = turf.nearestPoint(targetPoint, points);
28
- *
29
- * //addToMap
30
- * var addToMap = [targetPoint, points, nearest];
31
- * nearest.properties['marker-color'] = '#F00';
32
- */
33
- function nearestPoint(targetPoint, points, options = {}) {
34
- // Input validation
35
- if (!targetPoint)
36
- throw new Error("targetPoint is required");
37
- if (!points)
38
- throw new Error("points is required");
39
- let minDist = Infinity;
40
- let bestFeatureIndex = 0;
41
- meta_1.featureEach(points, (pt, featureIndex) => {
42
- const distanceToPoint = distance_1.default(targetPoint, pt, options);
43
- if (distanceToPoint < minDist) {
44
- bestFeatureIndex = featureIndex;
45
- minDist = distanceToPoint;
46
- }
47
- });
48
- const nearestPoint = clone_1.default(points.features[bestFeatureIndex]);
49
- return Object.assign(Object.assign({}, nearestPoint), { properties: Object.assign(Object.assign({}, nearestPoint.properties), { featureIndex: bestFeatureIndex, distanceToPoint: minDist }) });
50
- }
51
- exports.default = nearestPoint;