@turf/along 7.0.0-alpha.2 → 7.1.0-alpha.7

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
@@ -44,26 +44,21 @@ Returns **[Feature][3]<[Point][8]>** Point `distance` `units` along the line
44
44
 
45
45
  [8]: https://tools.ietf.org/html/rfc7946#section-3.1.2
46
46
 
47
- <!-- This file is automatically generated. Please don't edit it directly:
48
- if you find an error, edit the source file (likely index.js), and re-run
49
- ./scripts/generate-readmes in the turf project. -->
47
+ <!-- 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. -->
50
48
 
51
49
  ---
52
50
 
53
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
54
- module collection dedicated to geographic algorithms. It is maintained in the
55
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
56
- PRs and issues.
51
+ 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.
57
52
 
58
53
  ### Installation
59
54
 
60
- Install this module individually:
55
+ Install this single module individually:
61
56
 
62
57
  ```sh
63
58
  $ npm install @turf/along
64
59
  ```
65
60
 
66
- Or install the Turf module that includes it as a function:
61
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
67
62
 
68
63
  ```sh
69
64
  $ npm install @turf/turf
@@ -0,0 +1,39 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var _bearing = require('@turf/bearing');
3
+ var _destination = require('@turf/destination');
4
+ var _distance = require('@turf/distance');
5
+ var _helpers = require('@turf/helpers');
6
+ var _invariant = require('@turf/invariant');
7
+ function along(line, distance, options = {}) {
8
+ const geom = _invariant.getGeom.call(void 0, line);
9
+ const coords = geom.coordinates;
10
+ let travelled = 0;
11
+ for (let i = 0; i < coords.length; i++) {
12
+ if (distance >= travelled && i === coords.length - 1) {
13
+ break;
14
+ } else if (travelled >= distance) {
15
+ const overshot = distance - travelled;
16
+ if (!overshot) {
17
+ return _helpers.point.call(void 0, coords[i]);
18
+ } else {
19
+ const direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
20
+ const interpolated = _destination.destination.call(void 0,
21
+ coords[i],
22
+ overshot,
23
+ direction,
24
+ options
25
+ );
26
+ return interpolated;
27
+ }
28
+ } else {
29
+ travelled += _distance.distance.call(void 0, coords[i], coords[i + 1], options);
30
+ }
31
+ }
32
+ return _helpers.point.call(void 0, coords[coords.length - 1]);
33
+ }
34
+ var turf_along_default = along;
35
+
36
+
37
+
38
+ exports.along = along; exports.default = turf_along_default;
39
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,uBAAuB;AAC5C,SAAS,aAAoB;AAC7B,SAAS,eAAe;AAoBxB,SAAS,MACP,MACA,UACA,UAA6B,CAAC,GACd;AAEhB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,KAAK;AACpB,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,YAAY,aAAa,MAAM,OAAO,SAAS,GAAG;AACpD;AAAA,IACF,WAAW,aAAa,UAAU;AAChC,YAAM,WAAW,WAAW;AAC5B,UAAI,CAAC,UAAU;AACb,eAAO,MAAM,OAAO,CAAC,CAAC;AAAA,MACxB,OAAO;AACL,cAAM,YAAY,QAAQ,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,IAAI;AACtD,cAAM,eAAe;AAAA,UACnB,OAAO,CAAC;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AACL,mBAAa,gBAAgB,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,EACF;AACA,SAAO,MAAM,OAAO,OAAO,SAAS,CAAC,CAAC;AACxC;AAGA,IAAO,qBAAQ","sourcesContent":["import { Feature, LineString, Point } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { destination } from \"@turf/destination\";\nimport { distance as measureDistance } from \"@turf/distance\";\nimport { point, Units } from \"@turf/helpers\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.\n *\n * @name along\n * @param {Feature<LineString>} line input line\n * @param {number} distance distance along the line\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} Point `distance` `units` along the line\n * @example\n * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);\n * var options = {units: 'miles'};\n *\n * var along = turf.along(line, 200, options);\n *\n * //addToMap\n * var addToMap = [along, line]\n */\nfunction along(\n line: Feature<LineString> | LineString,\n distance: number,\n options: { units?: Units } = {}\n): Feature<Point> {\n // Get Coords\n const geom = getGeom(line);\n const coords = geom.coordinates;\n let travelled = 0;\n for (let i = 0; i < coords.length; i++) {\n if (distance >= travelled && i === coords.length - 1) {\n break;\n } else if (travelled >= distance) {\n const overshot = distance - travelled;\n if (!overshot) {\n return point(coords[i]);\n } else {\n const direction = bearing(coords[i], coords[i - 1]) - 180;\n const interpolated = destination(\n coords[i],\n overshot,\n direction,\n options\n );\n return interpolated;\n }\n } else {\n travelled += measureDistance(coords[i], coords[i + 1], options);\n }\n }\n return point(coords[coords.length - 1]);\n}\n\nexport { along };\nexport default along;\n"]}
@@ -0,0 +1,26 @@
1
+ import { Feature, LineString, Point } from 'geojson';
2
+ import { Units } from '@turf/helpers';
3
+
4
+ /**
5
+ * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
6
+ *
7
+ * @name along
8
+ * @param {Feature<LineString>} line input line
9
+ * @param {number} distance distance along the line
10
+ * @param {Object} [options] Optional parameters
11
+ * @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
12
+ * @returns {Feature<Point>} Point `distance` `units` along the line
13
+ * @example
14
+ * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
15
+ * var options = {units: 'miles'};
16
+ *
17
+ * var along = turf.along(line, 200, options);
18
+ *
19
+ * //addToMap
20
+ * var addToMap = [along, line]
21
+ */
22
+ declare function along(line: Feature<LineString> | LineString, distance: number, options?: {
23
+ units?: Units;
24
+ }): Feature<Point>;
25
+
26
+ export { along, along as default };
@@ -1,5 +1,6 @@
1
- import { Feature, LineString, Point } from "geojson";
2
- import { Units } from "@turf/helpers";
1
+ import { Feature, LineString, Point } from 'geojson';
2
+ import { Units } from '@turf/helpers';
3
+
3
4
  /**
4
5
  * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
5
6
  *
@@ -18,6 +19,8 @@ import { Units } from "@turf/helpers";
18
19
  * //addToMap
19
20
  * var addToMap = [along, line]
20
21
  */
21
- export default function along(line: Feature<LineString> | LineString, distance: number, options?: {
22
+ declare function along(line: Feature<LineString> | LineString, distance: number, options?: {
22
23
  units?: Units;
23
24
  }): Feature<Point>;
25
+
26
+ export { along, along as default };
@@ -0,0 +1,39 @@
1
+ // index.ts
2
+ import { bearing } from "@turf/bearing";
3
+ import { destination } from "@turf/destination";
4
+ import { distance as measureDistance } from "@turf/distance";
5
+ import { point } from "@turf/helpers";
6
+ import { getGeom } from "@turf/invariant";
7
+ function along(line, distance, options = {}) {
8
+ const geom = getGeom(line);
9
+ const coords = geom.coordinates;
10
+ let travelled = 0;
11
+ for (let i = 0; i < coords.length; i++) {
12
+ if (distance >= travelled && i === coords.length - 1) {
13
+ break;
14
+ } else if (travelled >= distance) {
15
+ const overshot = distance - travelled;
16
+ if (!overshot) {
17
+ return point(coords[i]);
18
+ } else {
19
+ const direction = bearing(coords[i], coords[i - 1]) - 180;
20
+ const interpolated = destination(
21
+ coords[i],
22
+ overshot,
23
+ direction,
24
+ options
25
+ );
26
+ return interpolated;
27
+ }
28
+ } else {
29
+ travelled += measureDistance(coords[i], coords[i + 1], options);
30
+ }
31
+ }
32
+ return point(coords[coords.length - 1]);
33
+ }
34
+ var turf_along_default = along;
35
+ export {
36
+ along,
37
+ turf_along_default as default
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, LineString, Point } from \"geojson\";\nimport { bearing } from \"@turf/bearing\";\nimport { destination } from \"@turf/destination\";\nimport { distance as measureDistance } from \"@turf/distance\";\nimport { point, Units } from \"@turf/helpers\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.\n *\n * @name along\n * @param {Feature<LineString>} line input line\n * @param {number} distance distance along the line\n * @param {Object} [options] Optional parameters\n * @param {string} [options.units=\"kilometers\"] can be degrees, radians, miles, or kilometers\n * @returns {Feature<Point>} Point `distance` `units` along the line\n * @example\n * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);\n * var options = {units: 'miles'};\n *\n * var along = turf.along(line, 200, options);\n *\n * //addToMap\n * var addToMap = [along, line]\n */\nfunction along(\n line: Feature<LineString> | LineString,\n distance: number,\n options: { units?: Units } = {}\n): Feature<Point> {\n // Get Coords\n const geom = getGeom(line);\n const coords = geom.coordinates;\n let travelled = 0;\n for (let i = 0; i < coords.length; i++) {\n if (distance >= travelled && i === coords.length - 1) {\n break;\n } else if (travelled >= distance) {\n const overshot = distance - travelled;\n if (!overshot) {\n return point(coords[i]);\n } else {\n const direction = bearing(coords[i], coords[i - 1]) - 180;\n const interpolated = destination(\n coords[i],\n overshot,\n direction,\n options\n );\n return interpolated;\n }\n } else {\n travelled += measureDistance(coords[i], coords[i + 1], options);\n }\n }\n return point(coords[coords.length - 1]);\n}\n\nexport { along };\nexport default along;\n"],"mappings":";AACA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,uBAAuB;AAC5C,SAAS,aAAoB;AAC7B,SAAS,eAAe;AAoBxB,SAAS,MACP,MACA,UACA,UAA6B,CAAC,GACd;AAEhB,QAAM,OAAO,QAAQ,IAAI;AACzB,QAAM,SAAS,KAAK;AACpB,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,QAAI,YAAY,aAAa,MAAM,OAAO,SAAS,GAAG;AACpD;AAAA,IACF,WAAW,aAAa,UAAU;AAChC,YAAM,WAAW,WAAW;AAC5B,UAAI,CAAC,UAAU;AACb,eAAO,MAAM,OAAO,CAAC,CAAC;AAAA,MACxB,OAAO;AACL,cAAM,YAAY,QAAQ,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,IAAI;AACtD,cAAM,eAAe;AAAA,UACnB,OAAO,CAAC;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AACL,mBAAa,gBAAgB,OAAO,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,EACF;AACA,SAAO,MAAM,OAAO,OAAO,SAAS,CAAC,CAAC;AACxC;AAGA,IAAO,qBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/along",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf along module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -23,47 +23,52 @@
23
23
  "turf",
24
24
  "distance"
25
25
  ],
26
- "main": "dist/js/index.js",
27
- "module": "dist/es/index.js",
26
+ "type": "module",
27
+ "main": "dist/cjs/index.cjs",
28
+ "module": "dist/esm/index.js",
29
+ "types": "dist/esm/index.d.ts",
28
30
  "exports": {
29
31
  "./package.json": "./package.json",
30
32
  ".": {
31
- "types": "./dist/js/index.d.ts",
32
- "import": "./dist/es/index.js",
33
- "require": "./dist/js/index.js"
33
+ "import": {
34
+ "types": "./dist/esm/index.d.ts",
35
+ "default": "./dist/esm/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/cjs/index.d.cts",
39
+ "default": "./dist/cjs/index.cjs"
40
+ }
34
41
  }
35
42
  },
36
- "types": "dist/js/index.d.ts",
37
43
  "sideEffects": false,
38
44
  "files": [
39
45
  "dist"
40
46
  ],
41
47
  "scripts": {
42
- "bench": "tsx bench.js",
43
- "build": "npm-run-all build:*",
44
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
45
- "build:js": "tsc",
46
- "docs": "tsx ../../scripts/generate-readmes",
47
- "test": "npm-run-all test:*",
48
- "test:tape": "tsx test.js"
48
+ "bench": "tsx bench.ts",
49
+ "build": "tsup --config ../../tsup.config.ts",
50
+ "docs": "tsx ../../scripts/generate-readmes.ts",
51
+ "test": "npm-run-all --npm-path npm test:*",
52
+ "test:tape": "tsx test.ts"
49
53
  },
50
54
  "devDependencies": {
51
- "@types/tape": "*",
52
- "benchmark": "*",
53
- "load-json-file": "*",
54
- "npm-run-all": "*",
55
- "tape": "*",
56
- "tslint": "*",
57
- "tsx": "*",
58
- "typescript": "*"
55
+ "@types/benchmark": "^2.1.5",
56
+ "@types/tape": "^4.2.32",
57
+ "benchmark": "^2.1.4",
58
+ "load-json-file": "^7.0.1",
59
+ "npm-run-all": "^4.1.5",
60
+ "tape": "^5.7.2",
61
+ "tsup": "^8.0.1",
62
+ "tsx": "^4.6.2",
63
+ "typescript": "^5.2.2"
59
64
  },
60
65
  "dependencies": {
61
- "@turf/bearing": "^7.0.0-alpha.2",
62
- "@turf/destination": "^7.0.0-alpha.2",
63
- "@turf/distance": "^7.0.0-alpha.2",
64
- "@turf/helpers": "^7.0.0-alpha.2",
65
- "@turf/invariant": "^7.0.0-alpha.2",
66
- "tslib": "^2.3.0"
66
+ "@turf/bearing": "^7.1.0-alpha.7+0ce6ecca0",
67
+ "@turf/destination": "^7.1.0-alpha.7+0ce6ecca0",
68
+ "@turf/distance": "^7.1.0-alpha.7+0ce6ecca0",
69
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
70
+ "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
71
+ "tslib": "^2.6.2"
67
72
  },
68
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
73
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
69
74
  }
package/dist/es/index.js DELETED
@@ -1,49 +0,0 @@
1
- import bearing from "@turf/bearing";
2
- import destination from "@turf/destination";
3
- import measureDistance from "@turf/distance";
4
- import { point } from "@turf/helpers";
5
- import { getGeom } from "@turf/invariant";
6
- /**
7
- * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
8
- *
9
- * @name along
10
- * @param {Feature<LineString>} line input line
11
- * @param {number} distance distance along the line
12
- * @param {Object} [options] Optional parameters
13
- * @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
14
- * @returns {Feature<Point>} Point `distance` `units` along the line
15
- * @example
16
- * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
17
- * var options = {units: 'miles'};
18
- *
19
- * var along = turf.along(line, 200, options);
20
- *
21
- * //addToMap
22
- * var addToMap = [along, line]
23
- */
24
- export default function along(line, distance, options = {}) {
25
- // Get Coords
26
- const geom = getGeom(line);
27
- const coords = geom.coordinates;
28
- let travelled = 0;
29
- for (let i = 0; i < coords.length; i++) {
30
- if (distance >= travelled && i === coords.length - 1) {
31
- break;
32
- }
33
- else if (travelled >= distance) {
34
- const overshot = distance - travelled;
35
- if (!overshot) {
36
- return point(coords[i]);
37
- }
38
- else {
39
- const direction = bearing(coords[i], coords[i - 1]) - 180;
40
- const interpolated = destination(coords[i], overshot, direction, options);
41
- return interpolated;
42
- }
43
- }
44
- else {
45
- travelled += measureDistance(coords[i], coords[i + 1], options);
46
- }
47
- }
48
- return point(coords[coords.length - 1]);
49
- }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const bearing_1 = tslib_1.__importDefault(require("@turf/bearing"));
5
- const destination_1 = tslib_1.__importDefault(require("@turf/destination"));
6
- const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
7
- const helpers_1 = require("@turf/helpers");
8
- const invariant_1 = require("@turf/invariant");
9
- /**
10
- * Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
11
- *
12
- * @name along
13
- * @param {Feature<LineString>} line input line
14
- * @param {number} distance distance along the line
15
- * @param {Object} [options] Optional parameters
16
- * @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
17
- * @returns {Feature<Point>} Point `distance` `units` along the line
18
- * @example
19
- * var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
20
- * var options = {units: 'miles'};
21
- *
22
- * var along = turf.along(line, 200, options);
23
- *
24
- * //addToMap
25
- * var addToMap = [along, line]
26
- */
27
- function along(line, distance, options = {}) {
28
- // Get Coords
29
- const geom = invariant_1.getGeom(line);
30
- const coords = geom.coordinates;
31
- let travelled = 0;
32
- for (let i = 0; i < coords.length; i++) {
33
- if (distance >= travelled && i === coords.length - 1) {
34
- break;
35
- }
36
- else if (travelled >= distance) {
37
- const overshot = distance - travelled;
38
- if (!overshot) {
39
- return helpers_1.point(coords[i]);
40
- }
41
- else {
42
- const direction = bearing_1.default(coords[i], coords[i - 1]) - 180;
43
- const interpolated = destination_1.default(coords[i], overshot, direction, options);
44
- return interpolated;
45
- }
46
- }
47
- else {
48
- travelled += distance_1.default(coords[i], coords[i + 1], options);
49
- }
50
- }
51
- return helpers_1.point(coords[coords.length - 1]);
52
- }
53
- exports.default = along;