@turf/nearest-point 7.1.0 → 7.2.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.
@@ -23,10 +23,8 @@ var _clone = require('@turf/clone');
23
23
  var _distance = require('@turf/distance');
24
24
  var _meta = require('@turf/meta');
25
25
  function nearestPoint(targetPoint, points, options = {}) {
26
- if (!targetPoint)
27
- throw new Error("targetPoint is required");
28
- if (!points)
29
- throw new Error("points is required");
26
+ if (!targetPoint) throw new Error("targetPoint is required");
27
+ if (!points) throw new Error("points is required");
30
28
  let minDist = Infinity;
31
29
  let bestFeatureIndex = 0;
32
30
  _meta.featureEach.call(void 0, points, (pt, featureIndex) => {
@@ -1 +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;AAGA,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
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-nearest-point/dist/cjs/index.cjs","../../index.ts"],"names":["nearestPoint"],"mappings":"AAAA,6EAAI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AC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;AACjE;AACA;AClBA,oCAAsB;AACtB,0CAAyB;AACzB,kCAA4B;AAoC5B,SAAS,YAAA,CACP,WAAA,EACA,MAAA,EACA,QAAA,EAEI,CAAC,CAAA,EACS;AAEd,EAAA,GAAA,CAAI,CAAC,WAAA,EAAa,MAAM,IAAI,KAAA,CAAM,yBAAyB,CAAA;AAC3D,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAEjD,EAAA,IAAI,QAAA,EAAU,QAAA;AACd,EAAA,IAAI,iBAAA,EAAmB,CAAA;AACvB,EAAA,+BAAA,MAAY,EAAQ,CAAC,EAAA,EAAI,YAAA,EAAA,GAAiB;AACxC,IAAA,MAAM,gBAAA,EAAkB,gCAAA,WAAS,EAAa,EAAA,EAAI,OAAO,CAAA;AACzD,IAAA,GAAA,CAAI,gBAAA,EAAkB,OAAA,EAAS;AAC7B,MAAA,iBAAA,EAAmB,YAAA;AACnB,MAAA,QAAA,EAAU,eAAA;AAAA,IACZ;AAAA,EACF,CAAC,CAAA;AACD,EAAA,MAAMA,cAAAA,EAAe,0BAAA,MAAM,CAAO,QAAA,CAAS,gBAAgB,CAAC,CAAA;AAE5D,EAAA,OAAO,aAAA,CAAA,cAAA,CAAA,CAAA,CAAA,EACFA,aAAAA,CAAAA,EADE;AAAA,IAEL,UAAA,EAAY,aAAA,CAAA,cAAA,CAAA,CAAA,CAAA,EACPA,aAAAA,CAAa,UAAA,CAAA,EADN;AAAA,MAEV,YAAA,EAAc,gBAAA;AAAA,MACd,eAAA,EAAiB;AAAA,IACnB,CAAA;AAAA,EACF,CAAA,CAAA;AACF;AAGA,IAAO,2BAAA,EAAQ,YAAA;AD5Bf;AACE;AACA;AACF,kFAAC","file":"/home/runner/work/turf/turf/packages/turf-nearest-point/dist/cjs/index.cjs","sourcesContent":[null,"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 * @function\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"]}
@@ -14,7 +14,7 @@ interface NearestPoint extends Feature<Point> {
14
14
  * point from the FeatureCollection closest to the reference. This calculation
15
15
  * is geodesic.
16
16
  *
17
- * @name nearestPoint
17
+ * @function
18
18
  * @param {Coord} targetPoint the reference point
19
19
  * @param {FeatureCollection<Point>} points against input point set
20
20
  * @param {Object} [options={}] Optional parameters
@@ -14,7 +14,7 @@ interface NearestPoint extends Feature<Point> {
14
14
  * point from the FeatureCollection closest to the reference. This calculation
15
15
  * is geodesic.
16
16
  *
17
- * @name nearestPoint
17
+ * @function
18
18
  * @param {Coord} targetPoint the reference point
19
19
  * @param {FeatureCollection<Point>} points against input point set
20
20
  * @param {Object} [options={}] Optional parameters
package/dist/esm/index.js CHANGED
@@ -23,10 +23,8 @@ import { clone } from "@turf/clone";
23
23
  import { distance } from "@turf/distance";
24
24
  import { featureEach } from "@turf/meta";
25
25
  function nearestPoint(targetPoint, points, options = {}) {
26
- if (!targetPoint)
27
- throw new Error("targetPoint is required");
28
- if (!points)
29
- throw new Error("points is required");
26
+ if (!targetPoint) throw new Error("targetPoint is required");
27
+ if (!points) throw new Error("points is required");
30
28
  let minDist = Infinity;
31
29
  let bestFeatureIndex = 0;
32
30
  featureEach(points, (pt, featureIndex) => {
@@ -1 +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;AAGA,IAAO,6BAAQ;","names":["nearestPoint"]}
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 * @function\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,YAAa,OAAM,IAAI,MAAM,yBAAyB;AAC3D,MAAI,CAAC,OAAQ,OAAM,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;AAGA,IAAO,6BAAQ;","names":["nearestPoint"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/nearest-point",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "turf nearest-point module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -55,23 +55,23 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/benchmark": "^2.1.5",
58
- "@types/tape": "^4.2.32",
58
+ "@types/tape": "^4.13.4",
59
59
  "benchmark": "^2.1.4",
60
60
  "load-json-file": "^7.0.1",
61
61
  "npm-run-all": "^4.1.5",
62
- "tape": "^5.7.2",
63
- "tsup": "^8.0.1",
64
- "tsx": "^4.6.2",
65
- "typescript": "^5.2.2",
62
+ "tape": "^5.9.0",
63
+ "tsup": "^8.3.5",
64
+ "tsx": "^4.19.2",
65
+ "typescript": "^5.5.4",
66
66
  "write-json-file": "^5.0.0"
67
67
  },
68
68
  "dependencies": {
69
- "@turf/clone": "^7.1.0",
70
- "@turf/distance": "^7.1.0",
71
- "@turf/helpers": "^7.1.0",
72
- "@turf/meta": "^7.1.0",
69
+ "@turf/clone": "^7.2.0",
70
+ "@turf/distance": "^7.2.0",
71
+ "@turf/helpers": "^7.2.0",
72
+ "@turf/meta": "^7.2.0",
73
73
  "@types/geojson": "^7946.0.10",
74
- "tslib": "^2.6.2"
74
+ "tslib": "^2.8.1"
75
75
  },
76
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
76
+ "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
77
77
  }