@turf/bearing 7.0.0-alpha.2 → 7.0.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.
package/README.md CHANGED
@@ -42,26 +42,21 @@ Returns **[number][5]** bearing in decimal degrees, between -180 and 180 degrees
42
42
 
43
43
  [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
44
44
 
45
- <!-- This file is automatically generated. Please don't edit it directly:
46
- if you find an error, edit the source file (likely index.js), and re-run
47
- ./scripts/generate-readmes in the turf project. -->
45
+ <!-- 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. -->
48
46
 
49
47
  ---
50
48
 
51
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
52
- module collection dedicated to geographic algorithms. It is maintained in the
53
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
54
- PRs and issues.
49
+ 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.
55
50
 
56
51
  ### Installation
57
52
 
58
- Install this module individually:
53
+ Install this single module individually:
59
54
 
60
55
  ```sh
61
56
  $ npm install @turf/bearing
62
57
  ```
63
58
 
64
- Or install the Turf module that includes it as a function:
59
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
65
60
 
66
61
  ```sh
67
62
  $ npm install @turf/turf
@@ -0,0 +1,33 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ var _helpers = require('@turf/helpers');
6
+ var _invariant = require('@turf/invariant');
7
+ function bearing(start, end, options = {}) {
8
+ if (options.final === true) {
9
+ return calculateFinalBearing(start, end);
10
+ }
11
+ const coordinates1 = _invariant.getCoord.call(void 0, start);
12
+ const coordinates2 = _invariant.getCoord.call(void 0, end);
13
+ const lon1 = _helpers.degreesToRadians.call(void 0, coordinates1[0]);
14
+ const lon2 = _helpers.degreesToRadians.call(void 0, coordinates2[0]);
15
+ const lat1 = _helpers.degreesToRadians.call(void 0, coordinates1[1]);
16
+ const lat2 = _helpers.degreesToRadians.call(void 0, coordinates2[1]);
17
+ const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
18
+ const b = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
19
+ return _helpers.radiansToDegrees.call(void 0, Math.atan2(a, b));
20
+ }
21
+ __name(bearing, "bearing");
22
+ function calculateFinalBearing(start, end) {
23
+ let bear = bearing(end, start);
24
+ bear = (bear + 180) % 360;
25
+ return bear;
26
+ }
27
+ __name(calculateFinalBearing, "calculateFinalBearing");
28
+ var turf_bearing_default = bearing;
29
+
30
+
31
+
32
+ exports.bearing = bearing; exports.default = turf_bearing_default;
33
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AAAA,SAAgB,kBAAkB,wBAAwB;AAC1D,SAAS,gBAAgB;AA2BzB,SAAS,QACP,OACA,KACA,UAEI,CAAC,GACG;AAER,MAAI,QAAQ,UAAU,MAAM;AAC1B,WAAO,sBAAsB,OAAO,GAAG;AAAA,EACzC;AAEA,QAAM,eAAe,SAAS,KAAK;AACnC,QAAM,eAAe,SAAS,GAAG;AAEjC,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,IAAI,KAAK,IAAI,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI;AAC/C,QAAM,IACJ,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAC9B,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,OAAO,IAAI;AAExD,SAAO,iBAAiB,KAAK,MAAM,GAAG,CAAC,CAAC;AAC1C;AAzBS;AAmCT,SAAS,sBAAsB,OAAc,KAAY;AAEvD,MAAI,OAAO,QAAQ,KAAK,KAAK;AAC7B,UAAQ,OAAO,OAAO;AACtB,SAAO;AACT;AALS;AAQT,IAAO,uBAAQ","sourcesContent":["import { Coord, degreesToRadians, radiansToDegrees } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Haversine_formula\n// http://www.movable-type.co.uk/scripts/latlong.html\n\n/**\n * Takes two {@link Point|points} and finds the geographic bearing between them,\n * i.e. the angle measured in degrees from the north line (0 degrees)\n *\n * @name bearing\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.final=false] calculates the final bearing if true\n * @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)\n * @example\n * var point1 = turf.point([-75.343, 39.984]);\n * var point2 = turf.point([-75.534, 39.123]);\n *\n * var bearing = turf.bearing(point1, point2);\n *\n * //addToMap\n * var addToMap = [point1, point2]\n * point1.properties['marker-color'] = '#f00'\n * point2.properties['marker-color'] = '#0f0'\n * point1.properties.bearing = bearing\n */\nfunction bearing(\n start: Coord,\n end: Coord,\n options: {\n final?: boolean;\n } = {}\n): number {\n // Reverse calculation\n if (options.final === true) {\n return calculateFinalBearing(start, end);\n }\n\n const coordinates1 = getCoord(start);\n const coordinates2 = getCoord(end);\n\n const lon1 = degreesToRadians(coordinates1[0]);\n const lon2 = degreesToRadians(coordinates2[0]);\n const lat1 = degreesToRadians(coordinates1[1]);\n const lat2 = degreesToRadians(coordinates2[1]);\n const a = Math.sin(lon2 - lon1) * Math.cos(lat2);\n const b =\n Math.cos(lat1) * Math.sin(lat2) -\n Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);\n\n return radiansToDegrees(Math.atan2(a, b));\n}\n\n/**\n * Calculates Final Bearing\n *\n * @private\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @returns {number} bearing\n */\nfunction calculateFinalBearing(start: Coord, end: Coord) {\n // Swap start & end\n let bear = bearing(end, start);\n bear = (bear + 180) % 360;\n return bear;\n}\n\nexport { bearing };\nexport default bearing;\n"]}
@@ -0,0 +1,29 @@
1
+ import { Coord } from '@turf/helpers';
2
+
3
+ /**
4
+ * Takes two {@link Point|points} and finds the geographic bearing between them,
5
+ * i.e. the angle measured in degrees from the north line (0 degrees)
6
+ *
7
+ * @name bearing
8
+ * @param {Coord} start starting Point
9
+ * @param {Coord} end ending Point
10
+ * @param {Object} [options={}] Optional parameters
11
+ * @param {boolean} [options.final=false] calculates the final bearing if true
12
+ * @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
13
+ * @example
14
+ * var point1 = turf.point([-75.343, 39.984]);
15
+ * var point2 = turf.point([-75.534, 39.123]);
16
+ *
17
+ * var bearing = turf.bearing(point1, point2);
18
+ *
19
+ * //addToMap
20
+ * var addToMap = [point1, point2]
21
+ * point1.properties['marker-color'] = '#f00'
22
+ * point2.properties['marker-color'] = '#0f0'
23
+ * point1.properties.bearing = bearing
24
+ */
25
+ declare function bearing(start: Coord, end: Coord, options?: {
26
+ final?: boolean;
27
+ }): number;
28
+
29
+ export { bearing, bearing as default };
@@ -1,4 +1,5 @@
1
- import { Coord } from "@turf/helpers";
1
+ import { Coord } from '@turf/helpers';
2
+
2
3
  /**
3
4
  * Takes two {@link Point|points} and finds the geographic bearing between them,
4
5
  * i.e. the angle measured in degrees from the north line (0 degrees)
@@ -21,6 +22,8 @@ import { Coord } from "@turf/helpers";
21
22
  * point2.properties['marker-color'] = '#0f0'
22
23
  * point1.properties.bearing = bearing
23
24
  */
24
- export default function bearing(start: Coord, end: Coord, options?: {
25
+ declare function bearing(start: Coord, end: Coord, options?: {
25
26
  final?: boolean;
26
27
  }): number;
28
+
29
+ export { bearing, bearing as default };
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { degreesToRadians, radiansToDegrees } from "@turf/helpers";
6
+ import { getCoord } from "@turf/invariant";
7
+ function bearing(start, end, options = {}) {
8
+ if (options.final === true) {
9
+ return calculateFinalBearing(start, end);
10
+ }
11
+ const coordinates1 = getCoord(start);
12
+ const coordinates2 = getCoord(end);
13
+ const lon1 = degreesToRadians(coordinates1[0]);
14
+ const lon2 = degreesToRadians(coordinates2[0]);
15
+ const lat1 = degreesToRadians(coordinates1[1]);
16
+ const lat2 = degreesToRadians(coordinates2[1]);
17
+ const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
18
+ const b = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
19
+ return radiansToDegrees(Math.atan2(a, b));
20
+ }
21
+ __name(bearing, "bearing");
22
+ function calculateFinalBearing(start, end) {
23
+ let bear = bearing(end, start);
24
+ bear = (bear + 180) % 360;
25
+ return bear;
26
+ }
27
+ __name(calculateFinalBearing, "calculateFinalBearing");
28
+ var turf_bearing_default = bearing;
29
+ export {
30
+ bearing,
31
+ turf_bearing_default as default
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Coord, degreesToRadians, radiansToDegrees } from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\n\n// http://en.wikipedia.org/wiki/Haversine_formula\n// http://www.movable-type.co.uk/scripts/latlong.html\n\n/**\n * Takes two {@link Point|points} and finds the geographic bearing between them,\n * i.e. the angle measured in degrees from the north line (0 degrees)\n *\n * @name bearing\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.final=false] calculates the final bearing if true\n * @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)\n * @example\n * var point1 = turf.point([-75.343, 39.984]);\n * var point2 = turf.point([-75.534, 39.123]);\n *\n * var bearing = turf.bearing(point1, point2);\n *\n * //addToMap\n * var addToMap = [point1, point2]\n * point1.properties['marker-color'] = '#f00'\n * point2.properties['marker-color'] = '#0f0'\n * point1.properties.bearing = bearing\n */\nfunction bearing(\n start: Coord,\n end: Coord,\n options: {\n final?: boolean;\n } = {}\n): number {\n // Reverse calculation\n if (options.final === true) {\n return calculateFinalBearing(start, end);\n }\n\n const coordinates1 = getCoord(start);\n const coordinates2 = getCoord(end);\n\n const lon1 = degreesToRadians(coordinates1[0]);\n const lon2 = degreesToRadians(coordinates2[0]);\n const lat1 = degreesToRadians(coordinates1[1]);\n const lat2 = degreesToRadians(coordinates2[1]);\n const a = Math.sin(lon2 - lon1) * Math.cos(lat2);\n const b =\n Math.cos(lat1) * Math.sin(lat2) -\n Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);\n\n return radiansToDegrees(Math.atan2(a, b));\n}\n\n/**\n * Calculates Final Bearing\n *\n * @private\n * @param {Coord} start starting Point\n * @param {Coord} end ending Point\n * @returns {number} bearing\n */\nfunction calculateFinalBearing(start: Coord, end: Coord) {\n // Swap start & end\n let bear = bearing(end, start);\n bear = (bear + 180) % 360;\n return bear;\n}\n\nexport { bearing };\nexport default bearing;\n"],"mappings":";;;;AAAA,SAAgB,kBAAkB,wBAAwB;AAC1D,SAAS,gBAAgB;AA2BzB,SAAS,QACP,OACA,KACA,UAEI,CAAC,GACG;AAER,MAAI,QAAQ,UAAU,MAAM;AAC1B,WAAO,sBAAsB,OAAO,GAAG;AAAA,EACzC;AAEA,QAAM,eAAe,SAAS,KAAK;AACnC,QAAM,eAAe,SAAS,GAAG;AAEjC,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,OAAO,iBAAiB,aAAa,CAAC,CAAC;AAC7C,QAAM,IAAI,KAAK,IAAI,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI;AAC/C,QAAM,IACJ,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAC9B,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,OAAO,IAAI;AAExD,SAAO,iBAAiB,KAAK,MAAM,GAAG,CAAC,CAAC;AAC1C;AAzBS;AAmCT,SAAS,sBAAsB,OAAc,KAAY;AAEvD,MAAI,OAAO,QAAQ,KAAK,KAAK;AAC7B,UAAQ,OAAO,OAAO;AACtB,SAAO;AACT;AALS;AAQT,IAAO,uBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/bearing",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "turf bearing module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -20,45 +20,50 @@
20
20
  "turf",
21
21
  "bearing"
22
22
  ],
23
- "main": "dist/js/index.js",
24
- "module": "dist/es/index.js",
23
+ "type": "module",
24
+ "main": "dist/cjs/index.cjs",
25
+ "module": "dist/esm/index.js",
26
+ "types": "dist/esm/index.d.ts",
25
27
  "exports": {
26
28
  "./package.json": "./package.json",
27
29
  ".": {
28
- "types": "./dist/js/index.d.ts",
29
- "import": "./dist/es/index.js",
30
- "require": "./dist/js/index.js"
30
+ "import": {
31
+ "types": "./dist/esm/index.d.ts",
32
+ "default": "./dist/esm/index.js"
33
+ },
34
+ "require": {
35
+ "types": "./dist/cjs/index.d.cts",
36
+ "default": "./dist/cjs/index.cjs"
37
+ }
31
38
  }
32
39
  },
33
- "types": "dist/js/index.d.ts",
34
40
  "sideEffects": false,
35
41
  "files": [
36
42
  "dist"
37
43
  ],
38
44
  "scripts": {
39
- "bench": "tsx bench.js",
40
- "build": "npm-run-all build:*",
41
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
42
- "build:js": "tsc",
43
- "docs": "tsx ../../scripts/generate-readmes",
44
- "test": "npm-run-all test:*",
45
- "test:tape": "tsx test.js"
45
+ "bench": "tsx bench.ts",
46
+ "build": "tsup --config ../../tsup.config.ts",
47
+ "docs": "tsx ../../scripts/generate-readmes.ts",
48
+ "test": "npm-run-all --npm-path npm test:*",
49
+ "test:tape": "tsx test.ts"
46
50
  },
47
51
  "devDependencies": {
48
- "@turf/destination": "^7.0.0-alpha.2",
49
- "@types/tape": "*",
50
- "benchmark": "*",
51
- "npm-run-all": "*",
52
- "tape": "*",
53
- "tslint": "*",
54
- "tsx": "*",
55
- "typescript": "*",
56
- "write-json-file": "*"
52
+ "@turf/destination": "^7.0.0",
53
+ "@types/benchmark": "^2.1.5",
54
+ "@types/tape": "^4.2.32",
55
+ "benchmark": "^2.1.4",
56
+ "npm-run-all": "^4.1.5",
57
+ "tape": "^5.7.2",
58
+ "tsup": "^8.0.1",
59
+ "tsx": "^4.6.2",
60
+ "typescript": "^5.2.2",
61
+ "write-json-file": "^5.0.0"
57
62
  },
58
63
  "dependencies": {
59
- "@turf/helpers": "^7.0.0-alpha.2",
60
- "@turf/invariant": "^7.0.0-alpha.2",
61
- "tslib": "^2.3.0"
64
+ "@turf/helpers": "^7.0.0",
65
+ "@turf/invariant": "^7.0.0",
66
+ "tslib": "^2.6.2"
62
67
  },
63
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
68
+ "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
64
69
  }
package/dist/es/index.js DELETED
@@ -1,56 +0,0 @@
1
- import { degreesToRadians, radiansToDegrees } from "@turf/helpers";
2
- import { getCoord } from "@turf/invariant";
3
- // http://en.wikipedia.org/wiki/Haversine_formula
4
- // http://www.movable-type.co.uk/scripts/latlong.html
5
- /**
6
- * Takes two {@link Point|points} and finds the geographic bearing between them,
7
- * i.e. the angle measured in degrees from the north line (0 degrees)
8
- *
9
- * @name bearing
10
- * @param {Coord} start starting Point
11
- * @param {Coord} end ending Point
12
- * @param {Object} [options={}] Optional parameters
13
- * @param {boolean} [options.final=false] calculates the final bearing if true
14
- * @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
15
- * @example
16
- * var point1 = turf.point([-75.343, 39.984]);
17
- * var point2 = turf.point([-75.534, 39.123]);
18
- *
19
- * var bearing = turf.bearing(point1, point2);
20
- *
21
- * //addToMap
22
- * var addToMap = [point1, point2]
23
- * point1.properties['marker-color'] = '#f00'
24
- * point2.properties['marker-color'] = '#0f0'
25
- * point1.properties.bearing = bearing
26
- */
27
- export default function bearing(start, end, options = {}) {
28
- // Reverse calculation
29
- if (options.final === true) {
30
- return calculateFinalBearing(start, end);
31
- }
32
- const coordinates1 = getCoord(start);
33
- const coordinates2 = getCoord(end);
34
- const lon1 = degreesToRadians(coordinates1[0]);
35
- const lon2 = degreesToRadians(coordinates2[0]);
36
- const lat1 = degreesToRadians(coordinates1[1]);
37
- const lat2 = degreesToRadians(coordinates2[1]);
38
- const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
39
- const b = Math.cos(lat1) * Math.sin(lat2) -
40
- Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
41
- return radiansToDegrees(Math.atan2(a, b));
42
- }
43
- /**
44
- * Calculates Final Bearing
45
- *
46
- * @private
47
- * @param {Coord} start starting Point
48
- * @param {Coord} end ending Point
49
- * @returns {number} bearing
50
- */
51
- function calculateFinalBearing(start, end) {
52
- // Swap start & end
53
- let bear = bearing(end, start);
54
- bear = (bear + 180) % 360;
55
- return bear;
56
- }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const helpers_1 = require("@turf/helpers");
4
- const invariant_1 = require("@turf/invariant");
5
- // http://en.wikipedia.org/wiki/Haversine_formula
6
- // http://www.movable-type.co.uk/scripts/latlong.html
7
- /**
8
- * Takes two {@link Point|points} and finds the geographic bearing between them,
9
- * i.e. the angle measured in degrees from the north line (0 degrees)
10
- *
11
- * @name bearing
12
- * @param {Coord} start starting Point
13
- * @param {Coord} end ending Point
14
- * @param {Object} [options={}] Optional parameters
15
- * @param {boolean} [options.final=false] calculates the final bearing if true
16
- * @returns {number} bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
17
- * @example
18
- * var point1 = turf.point([-75.343, 39.984]);
19
- * var point2 = turf.point([-75.534, 39.123]);
20
- *
21
- * var bearing = turf.bearing(point1, point2);
22
- *
23
- * //addToMap
24
- * var addToMap = [point1, point2]
25
- * point1.properties['marker-color'] = '#f00'
26
- * point2.properties['marker-color'] = '#0f0'
27
- * point1.properties.bearing = bearing
28
- */
29
- function bearing(start, end, options = {}) {
30
- // Reverse calculation
31
- if (options.final === true) {
32
- return calculateFinalBearing(start, end);
33
- }
34
- const coordinates1 = invariant_1.getCoord(start);
35
- const coordinates2 = invariant_1.getCoord(end);
36
- const lon1 = helpers_1.degreesToRadians(coordinates1[0]);
37
- const lon2 = helpers_1.degreesToRadians(coordinates2[0]);
38
- const lat1 = helpers_1.degreesToRadians(coordinates1[1]);
39
- const lat2 = helpers_1.degreesToRadians(coordinates2[1]);
40
- const a = Math.sin(lon2 - lon1) * Math.cos(lat2);
41
- const b = Math.cos(lat1) * Math.sin(lat2) -
42
- Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
43
- return helpers_1.radiansToDegrees(Math.atan2(a, b));
44
- }
45
- exports.default = bearing;
46
- /**
47
- * Calculates Final Bearing
48
- *
49
- * @private
50
- * @param {Coord} start starting Point
51
- * @param {Coord} end ending Point
52
- * @returns {number} bearing
53
- */
54
- function calculateFinalBearing(start, end) {
55
- // Swap start & end
56
- let bear = bearing(end, start);
57
- bear = (bear + 180) % 360;
58
- return bear;
59
- }