@turf/nearest-point 7.2.0 → 7.3.1

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
@@ -15,7 +15,7 @@ is geodesic.
15
15
  * `points` **[FeatureCollection][3]<[Point][1]>** against input point set
16
16
  * `options` **[Object][4]** Optional parameters (optional, default `{}`)
17
17
 
18
- * `options.units` **[string][5]** the units of the numeric result (optional, default `'kilometers'`)
18
+ * `options.units` **Units** the units of the numeric result. Supports all valid Turf [Units][5]. (optional, default `'kilometers'`)
19
19
 
20
20
  ### Examples
21
21
 
@@ -44,7 +44,7 @@ Returns **[Feature][6]<[Point][1]>** the closest point in the set to the referen
44
44
 
45
45
  [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
46
46
 
47
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
47
+ [5]: https://turfjs.org/docs/api/types/Units
48
48
 
49
49
  [6]: https://tools.ietf.org/html/rfc7946#section-3.2
50
50
 
@@ -42,9 +42,9 @@ function nearestPoint(targetPoint, points, options = {}) {
42
42
  })
43
43
  });
44
44
  }
45
- var turf_nearest_point_default = nearestPoint;
45
+ var index_default = nearestPoint;
46
46
 
47
47
 
48
48
 
49
- exports.default = turf_nearest_point_default; exports.nearestPoint = nearestPoint;
49
+ exports.default = index_default; exports.nearestPoint = nearestPoint;
50
50
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-nearest-point/dist/cjs/index.cjs","../../index.ts"],"names":["nearestPoint"],"mappings":"AAAA,6EAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,WAAW,EAAE,MAAM,CAAC,gBAAgB;AACxC,IAAI,kBAAkB,EAAE,MAAM,CAAC,yBAAyB;AACxD,IAAI,oBAAoB,EAAE,MAAM,CAAC,qBAAqB;AACtD,IAAI,aAAa,EAAE,MAAM,CAAC,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C,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"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-nearest-point/dist/cjs/index.cjs","../../index.ts"],"names":["nearestPoint"],"mappings":"AAAA,6EAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,WAAW,EAAE,MAAM,CAAC,gBAAgB;AACxC,IAAI,kBAAkB,EAAE,MAAM,CAAC,yBAAyB;AACxD,IAAI,oBAAoB,EAAE,MAAM,CAAC,qBA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C,CAAA,EACY;AAEjB,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,cAAA,EAAQ,YAAA;AD5Bf;AACE;AACA;AACF,qEAAC","file":"/home/runner/work/turf/turf/packages/turf-nearest-point/dist/cjs/index.cjs","sourcesContent":[null,"import { Feature, FeatureCollection, GeoJsonProperties, 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<P extends GeoJsonProperties = GeoJsonProperties>\n extends Feature<Point> {\n properties: {\n featureIndex: number;\n distanceToPoint: number;\n } & P;\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 {Units} [options.units='kilometers'] the units of the numeric result. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.\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<P extends GeoJsonProperties = GeoJsonProperties>(\n targetPoint: Coord,\n points: FeatureCollection<Point, P>,\n options: {\n units?: Units;\n } = {}\n): NearestPoint<P> {\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,12 +1,11 @@
1
- import { Feature, Point, FeatureCollection } from 'geojson';
1
+ import { GeoJsonProperties, FeatureCollection, Point, Feature } from 'geojson';
2
2
  import { Coord, Units } from '@turf/helpers';
3
3
 
4
- interface NearestPoint extends Feature<Point> {
4
+ interface NearestPoint<P extends GeoJsonProperties = GeoJsonProperties> extends Feature<Point> {
5
5
  properties: {
6
6
  featureIndex: number;
7
7
  distanceToPoint: number;
8
- [key: string]: any;
9
- };
8
+ } & P;
10
9
  }
11
10
  /**
12
11
  * Takes a reference {@link Point|point} and a FeatureCollection of Features
@@ -18,7 +17,7 @@ interface NearestPoint extends Feature<Point> {
18
17
  * @param {Coord} targetPoint the reference point
19
18
  * @param {FeatureCollection<Point>} points against input point set
20
19
  * @param {Object} [options={}] Optional parameters
21
- * @param {string} [options.units='kilometers'] the units of the numeric result
20
+ * @param {Units} [options.units='kilometers'] the units of the numeric result. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.
22
21
  * @returns {Feature<Point>} the closest point in the set to the reference point
23
22
  * @example
24
23
  * var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
@@ -34,8 +33,8 @@ interface NearestPoint extends Feature<Point> {
34
33
  * var addToMap = [targetPoint, points, nearest];
35
34
  * nearest.properties['marker-color'] = '#F00';
36
35
  */
37
- declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
36
+ declare function nearestPoint<P extends GeoJsonProperties = GeoJsonProperties>(targetPoint: Coord, points: FeatureCollection<Point, P>, options?: {
38
37
  units?: Units;
39
- }): NearestPoint;
38
+ }): NearestPoint<P>;
40
39
 
41
40
  export { type NearestPoint, nearestPoint as default, nearestPoint };
@@ -1,12 +1,11 @@
1
- import { Feature, Point, FeatureCollection } from 'geojson';
1
+ import { GeoJsonProperties, FeatureCollection, Point, Feature } from 'geojson';
2
2
  import { Coord, Units } from '@turf/helpers';
3
3
 
4
- interface NearestPoint extends Feature<Point> {
4
+ interface NearestPoint<P extends GeoJsonProperties = GeoJsonProperties> extends Feature<Point> {
5
5
  properties: {
6
6
  featureIndex: number;
7
7
  distanceToPoint: number;
8
- [key: string]: any;
9
- };
8
+ } & P;
10
9
  }
11
10
  /**
12
11
  * Takes a reference {@link Point|point} and a FeatureCollection of Features
@@ -18,7 +17,7 @@ interface NearestPoint extends Feature<Point> {
18
17
  * @param {Coord} targetPoint the reference point
19
18
  * @param {FeatureCollection<Point>} points against input point set
20
19
  * @param {Object} [options={}] Optional parameters
21
- * @param {string} [options.units='kilometers'] the units of the numeric result
20
+ * @param {Units} [options.units='kilometers'] the units of the numeric result. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.
22
21
  * @returns {Feature<Point>} the closest point in the set to the reference point
23
22
  * @example
24
23
  * var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
@@ -34,8 +33,8 @@ interface NearestPoint extends Feature<Point> {
34
33
  * var addToMap = [targetPoint, points, nearest];
35
34
  * nearest.properties['marker-color'] = '#F00';
36
35
  */
37
- declare function nearestPoint(targetPoint: Coord, points: FeatureCollection<Point>, options?: {
36
+ declare function nearestPoint<P extends GeoJsonProperties = GeoJsonProperties>(targetPoint: Coord, points: FeatureCollection<Point, P>, options?: {
38
37
  units?: Units;
39
- }): NearestPoint;
38
+ }): NearestPoint<P>;
40
39
 
41
40
  export { type NearestPoint, nearestPoint as default, nearestPoint };
package/dist/esm/index.js CHANGED
@@ -42,9 +42,9 @@ function nearestPoint(targetPoint, points, options = {}) {
42
42
  })
43
43
  });
44
44
  }
45
- var turf_nearest_point_default = nearestPoint;
45
+ var index_default = nearestPoint;
46
46
  export {
47
- turf_nearest_point_default as default,
47
+ index_default as default,
48
48
  nearestPoint
49
49
  };
50
50
  //# sourceMappingURL=index.js.map
@@ -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 * @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"]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, FeatureCollection, GeoJsonProperties, 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<P extends GeoJsonProperties = GeoJsonProperties>\n extends Feature<Point> {\n properties: {\n featureIndex: number;\n distanceToPoint: number;\n } & P;\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 {Units} [options.units='kilometers'] the units of the numeric result. Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}.\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<P extends GeoJsonProperties = GeoJsonProperties>(\n targetPoint: Coord,\n points: FeatureCollection<Point, P>,\n options: {\n units?: Units;\n } = {}\n): NearestPoint<P> {\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,GACY;AAEjB,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,gBAAQ;","names":["nearestPoint"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/nearest-point",
3
- "version": "7.2.0",
4
- "description": "turf nearest-point module",
3
+ "version": "7.3.1",
4
+ "description": "Finds the nearest point from a FeatureCollection of Features with Point geometries to a given point.",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
7
7
  "bugs": {
@@ -49,29 +49,28 @@
49
49
  "bench": "tsx bench.ts",
50
50
  "build": "tsup --config ../../tsup.config.ts",
51
51
  "docs": "tsx ../../scripts/generate-readmes.ts",
52
- "test": "npm-run-all --npm-path npm test:*",
52
+ "test": "pnpm run /test:.*/",
53
53
  "test:tape": "tsx test.ts",
54
54
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/benchmark": "^2.1.5",
58
- "@types/tape": "^4.13.4",
58
+ "@types/tape": "^5.8.1",
59
59
  "benchmark": "^2.1.4",
60
60
  "load-json-file": "^7.0.1",
61
- "npm-run-all": "^4.1.5",
62
61
  "tape": "^5.9.0",
63
- "tsup": "^8.3.5",
64
- "tsx": "^4.19.2",
65
- "typescript": "^5.5.4",
66
- "write-json-file": "^5.0.0"
62
+ "tsup": "^8.4.0",
63
+ "tsx": "^4.19.4",
64
+ "typescript": "^5.8.3",
65
+ "write-json-file": "^6.0.0"
67
66
  },
68
67
  "dependencies": {
69
- "@turf/clone": "^7.2.0",
70
- "@turf/distance": "^7.2.0",
71
- "@turf/helpers": "^7.2.0",
72
- "@turf/meta": "^7.2.0",
68
+ "@turf/clone": "7.3.1",
69
+ "@turf/distance": "7.3.1",
70
+ "@turf/helpers": "7.3.1",
71
+ "@turf/meta": "7.3.1",
73
72
  "@types/geojson": "^7946.0.10",
74
73
  "tslib": "^2.8.1"
75
74
  },
76
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
75
+ "gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
77
76
  }