Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/destination

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/destination - npm Package Compare versions

Comparing version 5.0.0 to 5.0.4

15

index.d.ts

@@ -1,10 +0,13 @@

/// <reference types="geojson" />
import { Feature, Point, Units, Coord } from '@turf/helpers'
import {Units} from '@turf/helpers'
export type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point | number[];
/**
* http://turfjs.org/docs/#destination
*/
export default function destination(origin: Point, distance: number, bearing: number, units?: Units): GeoJSON.Feature<GeoJSON.Point>;
export default function destination(
origin: Coord,
distance: number,
bearing: number,
options?: {
units?: Units
}
): Feature<Point>;

29

index.js
//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html
import { getCoord } from '@turf/invariant';
import { point, distanceToRadians } from '@turf/helpers';
import { point, lengthToRadians, degreesToRadians, radiansToDegrees, isObject } from '@turf/helpers';

@@ -13,3 +13,3 @@ /**

* @param {number} bearing ranging from -180 to 180
* @param {Object} options Optional parameters
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians

@@ -21,5 +21,5 @@ * @returns {Feature<Point>} destination point

* var bearing = 90;
* var units = 'miles';
* var options = {units: 'miles'};
*
* var destination = turf.destination(point, distance, bearing, units);
* var destination = turf.destination(point, distance, bearing, options);
*

@@ -32,14 +32,15 @@ * //addToMap

function destination(origin, distance, bearing, options) {
// Backwards compatible with v4.0
var units = (typeof options === 'object') ? options.units : options;
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var units = options.units;
var degrees2radians = Math.PI / 180;
var radians2degrees = 180 / Math.PI;
// Handle input
var coordinates1 = getCoord(origin);
var longitude1 = degrees2radians * coordinates1[0];
var latitude1 = degrees2radians * coordinates1[1];
var bearing_rad = degrees2radians * bearing;
var longitude1 = degreesToRadians(coordinates1[0]);
var latitude1 = degreesToRadians(coordinates1[1]);
var bearing_rad = degreesToRadians(bearing);
var radians = lengthToRadians(distance, units);
var radians = distanceToRadians(distance, units);
// Main
var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +

@@ -50,5 +51,5 @@ Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));

return point([radians2degrees * longitude2, radians2degrees * latitude2]);
return point([radiansToDegrees(longitude2), radiansToDegrees(latitude2)]);
}
export default destination;

@@ -15,3 +15,4 @@ 'use strict';

* @param {number} bearing ranging from -180 to 180
* @param {string} [units=kilometers] miles, kilometers, degrees, or radians
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
* @returns {Feature<Point>} destination point

@@ -22,5 +23,5 @@ * @example

* var bearing = 90;
* var units = 'miles';
* var options = {units: 'miles'};
*
* var destination = turf.destination(point, distance, bearing, units);
* var destination = turf.destination(point, distance, bearing, options);
*

@@ -32,12 +33,16 @@ * //addToMap

*/
function destination(origin, distance, bearing, units) {
var degrees2radians = Math.PI / 180;
var radians2degrees = 180 / Math.PI;
function destination(origin, distance, bearing, options) {
// Optional parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var units = options.units;
// Handle input
var coordinates1 = invariant.getCoord(origin);
var longitude1 = degrees2radians * coordinates1[0];
var latitude1 = degrees2radians * coordinates1[1];
var bearing_rad = degrees2radians * bearing;
var longitude1 = helpers.degreesToRadians(coordinates1[0]);
var latitude1 = helpers.degreesToRadians(coordinates1[1]);
var bearing_rad = helpers.degreesToRadians(bearing);
var radians = helpers.lengthToRadians(distance, units);
var radians = helpers.distanceToRadians(distance, units);
// Main
var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +

@@ -48,3 +53,3 @@ Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));

return helpers.point([radians2degrees * longitude2, radians2degrees * latitude2]);
return helpers.point([helpers.radiansToDegrees(longitude2), helpers.radiansToDegrees(latitude2)]);
}

@@ -51,0 +56,0 @@

{
"name": "@turf/destination",
"version": "5.0.0",
"version": "5.0.4",
"description": "turf destination module",

@@ -17,3 +17,2 @@ "main": "main",

"test": "node -r @std/esm test.js",
"posttest": "uglifyjs main.js -o main.min.js",
"bench": "node -r @std/esm bench.js"

@@ -40,14 +39,14 @@ },

"devDependencies": {
"@std/esm": "*",
"@turf/truncate": "^5.0.4",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*",
"rollup": "*",
"@std/esm": "*",
"uglify-js": "*"
"write-json-file": "*"
},
"dependencies": {
"@turf/helpers": "5.0.0",
"@turf/invariant": "5.0.0"
"@turf/helpers": "^5.0.4",
"@turf/invariant": "^5.0.4"
},

@@ -54,0 +53,0 @@ "@std/esm": {

@@ -14,3 +14,4 @@ # @turf/destination

- `bearing` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** ranging from -180 to 180
- `units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** miles, kilometers, degrees, or radians (optional, default `kilometers`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** miles, kilometers, degrees, or radians (optional, default `'kilometers'`)

@@ -23,5 +24,5 @@ **Examples**

var bearing = 90;
var units = 'miles';
var options = {units: 'miles'};
var destination = turf.destination(point, distance, bearing, units);
var destination = turf.destination(point, distance, bearing, options);

@@ -28,0 +29,0 @@ //addToMap

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc