@turf/line-slice 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
@@ -48,26 +48,21 @@ Returns **[Feature][4]<[LineString][5]>** sliced line
48
48
 
49
49
  [5]: https://tools.ietf.org/html/rfc7946#section-3.1.4
50
50
 
51
- <!-- This file is automatically generated. Please don't edit it directly:
52
- if you find an error, edit the source file (likely index.js), and re-run
53
- ./scripts/generate-readmes in the turf project. -->
51
+ <!-- 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. -->
54
52
 
55
53
  ---
56
54
 
57
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
58
- module collection dedicated to geographic algorithms. It is maintained in the
59
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
60
- PRs and issues.
55
+ 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.
61
56
 
62
57
  ### Installation
63
58
 
64
- Install this module individually:
59
+ Install this single module individually:
65
60
 
66
61
  ```sh
67
62
  $ npm install @turf/line-slice
68
63
  ```
69
64
 
70
- Or install the Turf module that includes it as a function:
65
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
71
66
 
72
67
  ```sh
73
68
  $ npm install @turf/turf
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
2
+ var _invariant = require('@turf/invariant');
3
+ var _helpers = require('@turf/helpers');
4
+ var _nearestpointonline = require('@turf/nearest-point-on-line');
5
+ function lineSlice(startPt, stopPt, line) {
6
+ var coords = _invariant.getCoords.call(void 0, line);
7
+ if (_invariant.getType.call(void 0, line) !== "LineString")
8
+ throw new Error("line must be a LineString");
9
+ var startVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, startPt);
10
+ var stopVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, stopPt);
11
+ var ends;
12
+ if (startVertex.properties.index <= stopVertex.properties.index) {
13
+ ends = [startVertex, stopVertex];
14
+ } else {
15
+ ends = [stopVertex, startVertex];
16
+ }
17
+ var clipCoords = [ends[0].geometry.coordinates];
18
+ for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
19
+ clipCoords.push(coords[i]);
20
+ }
21
+ clipCoords.push(ends[1].geometry.coordinates);
22
+ return _helpers.lineString.call(void 0, clipCoords, line.properties);
23
+ }
24
+ var turf_line_slice_default = lineSlice;
25
+
26
+
27
+
28
+ exports.default = turf_line_slice_default; exports.lineSlice = lineSlice;
29
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"names":[],"mappings":";AAAA,SAAS,WAAW,eAAe;AACnC,SAAS,cAAc,kBAAkB;AACzC,SAAS,0BAA0B;AA+BnC,SAAS,UAAU,SAAS,QAAQ,MAAM;AAExC,MAAI,SAAS,UAAU,IAAI;AAC3B,MAAI,QAAQ,IAAI,MAAM;AACpB,UAAM,IAAI,MAAM,2BAA2B;AAE7C,MAAI,cAAc,mBAAmB,MAAM,OAAO;AAClD,MAAI,aAAa,mBAAmB,MAAM,MAAM;AAChD,MAAI;AACJ,MAAI,YAAY,WAAW,SAAS,WAAW,WAAW,OAAO;AAC/D,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC,OAAO;AACL,WAAO,CAAC,YAAY,WAAW;AAAA,EACjC;AACA,MAAI,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,WAAW;AAC9C,WACM,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GACnC,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GAC/B,KACA;AACA,eAAW,KAAK,OAAO,CAAC,CAAC;AAAA,EAC3B;AACA,aAAW,KAAK,KAAK,CAAC,EAAE,SAAS,WAAW;AAC5C,SAAO,WAAW,YAAY,KAAK,UAAU;AAC/C;AAGA,IAAO,0BAAQ","sourcesContent":["import { getCoords, getType } from \"@turf/invariant\";\nimport { lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @name lineSlice\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(startPt, stopPt, line) {\n // Validation\n var coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n var startVertex = nearestPointOnLine(line, startPt);\n var stopVertex = nearestPointOnLine(line, stopPt);\n var ends;\n if (startVertex.properties.index <= stopVertex.properties.index) {\n ends = [startVertex, stopVertex];\n } else {\n ends = [stopVertex, startVertex];\n }\n var clipCoords = [ends[0].geometry.coordinates];\n for (\n var i = ends[0].properties.index + 1;\n i < ends[1].properties.index + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.properties);\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"]}
@@ -0,0 +1,13 @@
1
+ import { Feature, LineString } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
3
+
4
+ /**
5
+ * http://turfjs.org/docs/#lineslice
6
+ */
7
+ declare function lineSlice(
8
+ startPt: Coord,
9
+ stopPt: Coord,
10
+ line: Feature<LineString> | LineString
11
+ ): Feature<LineString>;
12
+
13
+ export { lineSlice as default, lineSlice };
@@ -0,0 +1,13 @@
1
+ import { Feature, LineString } from 'geojson';
2
+ import { Coord } from '@turf/helpers';
3
+
4
+ /**
5
+ * http://turfjs.org/docs/#lineslice
6
+ */
7
+ declare function lineSlice(
8
+ startPt: Coord,
9
+ stopPt: Coord,
10
+ line: Feature<LineString> | LineString
11
+ ): Feature<LineString>;
12
+
13
+ export { lineSlice as default, lineSlice };
@@ -0,0 +1,29 @@
1
+ // index.js
2
+ import { getCoords, getType } from "@turf/invariant";
3
+ import { lineString as linestring } from "@turf/helpers";
4
+ import { nearestPointOnLine } from "@turf/nearest-point-on-line";
5
+ function lineSlice(startPt, stopPt, line) {
6
+ var coords = getCoords(line);
7
+ if (getType(line) !== "LineString")
8
+ throw new Error("line must be a LineString");
9
+ var startVertex = nearestPointOnLine(line, startPt);
10
+ var stopVertex = nearestPointOnLine(line, stopPt);
11
+ var ends;
12
+ if (startVertex.properties.index <= stopVertex.properties.index) {
13
+ ends = [startVertex, stopVertex];
14
+ } else {
15
+ ends = [stopVertex, startVertex];
16
+ }
17
+ var clipCoords = [ends[0].geometry.coordinates];
18
+ for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
19
+ clipCoords.push(coords[i]);
20
+ }
21
+ clipCoords.push(ends[1].geometry.coordinates);
22
+ return linestring(clipCoords, line.properties);
23
+ }
24
+ var turf_line_slice_default = lineSlice;
25
+ export {
26
+ turf_line_slice_default as default,
27
+ lineSlice
28
+ };
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"sourcesContent":["import { getCoords, getType } from \"@turf/invariant\";\nimport { lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @name lineSlice\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(startPt, stopPt, line) {\n // Validation\n var coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n var startVertex = nearestPointOnLine(line, startPt);\n var stopVertex = nearestPointOnLine(line, stopPt);\n var ends;\n if (startVertex.properties.index <= stopVertex.properties.index) {\n ends = [startVertex, stopVertex];\n } else {\n ends = [stopVertex, startVertex];\n }\n var clipCoords = [ends[0].geometry.coordinates];\n for (\n var i = ends[0].properties.index + 1;\n i < ends[1].properties.index + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.properties);\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"],"mappings":";AAAA,SAAS,WAAW,eAAe;AACnC,SAAS,cAAc,kBAAkB;AACzC,SAAS,0BAA0B;AA+BnC,SAAS,UAAU,SAAS,QAAQ,MAAM;AAExC,MAAI,SAAS,UAAU,IAAI;AAC3B,MAAI,QAAQ,IAAI,MAAM;AACpB,UAAM,IAAI,MAAM,2BAA2B;AAE7C,MAAI,cAAc,mBAAmB,MAAM,OAAO;AAClD,MAAI,aAAa,mBAAmB,MAAM,MAAM;AAChD,MAAI;AACJ,MAAI,YAAY,WAAW,SAAS,WAAW,WAAW,OAAO;AAC/D,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC,OAAO;AACL,WAAO,CAAC,YAAY,WAAW;AAAA,EACjC;AACA,MAAI,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,WAAW;AAC9C,WACM,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GACnC,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GAC/B,KACA;AACA,eAAW,KAAK,OAAO,CAAC,CAAC;AAAA,EAC3B;AACA,aAAW,KAAK,KAAK,CAAC,EAAE,SAAS,WAAW;AAC5C,SAAO,WAAW,YAAY,KAAK,UAAU;AAC/C;AAGA,IAAO,0BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/line-slice",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf line-slice module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -25,43 +25,50 @@
25
25
  "line",
26
26
  "distance"
27
27
  ],
28
- "main": "dist/js/index.js",
29
- "module": "dist/es/index.js",
28
+ "type": "module",
29
+ "main": "dist/cjs/index.cjs",
30
+ "module": "dist/esm/index.js",
31
+ "types": "dist/esm/index.d.ts",
30
32
  "exports": {
31
33
  "./package.json": "./package.json",
32
34
  ".": {
33
- "types": "./index.d.ts",
34
- "import": "./dist/es/index.js",
35
- "require": "./dist/js/index.js"
35
+ "import": {
36
+ "types": "./dist/esm/index.d.ts",
37
+ "default": "./dist/esm/index.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/cjs/index.d.cts",
41
+ "default": "./dist/cjs/index.cjs"
42
+ }
36
43
  }
37
44
  },
38
- "types": "index.d.ts",
39
45
  "sideEffects": false,
40
46
  "files": [
41
- "dist",
42
- "index.d.ts"
47
+ "dist"
43
48
  ],
44
49
  "scripts": {
45
- "bench": "tsx bench.js",
46
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
47
- "docs": "tsx ../../scripts/generate-readmes",
48
- "test": "npm-run-all test:*",
49
- "test:tape": "tsx test.js"
50
+ "bench": "tsx bench.ts",
51
+ "build": "tsup --config ../../tsup.config.ts",
52
+ "docs": "tsx ../../scripts/generate-readmes.ts",
53
+ "test": "npm-run-all --npm-path npm test:*",
54
+ "test:tape": "tsx test.ts"
50
55
  },
51
56
  "devDependencies": {
52
- "@turf/truncate": "^7.0.0-alpha.2",
53
- "benchmark": "*",
54
- "load-json-file": "*",
55
- "npm-run-all": "*",
56
- "rollup": "*",
57
- "tape": "*",
58
- "tsx": "*",
59
- "write-json-file": "*"
57
+ "@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
58
+ "@types/benchmark": "^2.1.5",
59
+ "@types/tape": "^4.2.32",
60
+ "benchmark": "^2.1.4",
61
+ "load-json-file": "^7.0.1",
62
+ "npm-run-all": "^4.1.5",
63
+ "tape": "^5.7.2",
64
+ "tsup": "^8.0.1",
65
+ "tsx": "^4.6.2",
66
+ "write-json-file": "^5.0.0"
60
67
  },
61
68
  "dependencies": {
62
- "@turf/helpers": "^7.0.0-alpha.2",
63
- "@turf/invariant": "^7.0.0-alpha.2",
64
- "@turf/nearest-point-on-line": "^7.0.0-alpha.2"
69
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
70
+ "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
71
+ "@turf/nearest-point-on-line": "^7.1.0-alpha.7+0ce6ecca0"
65
72
  },
66
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
73
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
67
74
  }
package/dist/es/index.js DELETED
@@ -1,60 +0,0 @@
1
- import { getCoords, getType } from '@turf/invariant';
2
- import { lineString } from '@turf/helpers';
3
- import nearestPointOnLine from '@turf/nearest-point-on-line';
4
-
5
- /**
6
- * Takes a {@link LineString|line}, a start {@link Point}, and a stop point
7
- * and returns a subsection of the line in-between those points.
8
- * The start & stop points don't need to fall exactly on the line.
9
- *
10
- * This can be useful for extracting only the part of a route between waypoints.
11
- *
12
- * @name lineSlice
13
- * @param {Coord} startPt starting point
14
- * @param {Coord} stopPt stopping point
15
- * @param {Feature<LineString>|LineString} line line to slice
16
- * @returns {Feature<LineString>} sliced line
17
- * @example
18
- * var line = turf.lineString([
19
- * [-77.031669, 38.878605],
20
- * [-77.029609, 38.881946],
21
- * [-77.020339, 38.884084],
22
- * [-77.025661, 38.885821],
23
- * [-77.021884, 38.889563],
24
- * [-77.019824, 38.892368]
25
- * ]);
26
- * var start = turf.point([-77.029609, 38.881946]);
27
- * var stop = turf.point([-77.021884, 38.889563]);
28
- *
29
- * var sliced = turf.lineSlice(start, stop, line);
30
- *
31
- * //addToMap
32
- * var addToMap = [start, stop, line]
33
- */
34
- function lineSlice(startPt, stopPt, line) {
35
- // Validation
36
- var coords = getCoords(line);
37
- if (getType(line) !== "LineString")
38
- throw new Error("line must be a LineString");
39
-
40
- var startVertex = nearestPointOnLine(line, startPt);
41
- var stopVertex = nearestPointOnLine(line, stopPt);
42
- var ends;
43
- if (startVertex.properties.index <= stopVertex.properties.index) {
44
- ends = [startVertex, stopVertex];
45
- } else {
46
- ends = [stopVertex, startVertex];
47
- }
48
- var clipCoords = [ends[0].geometry.coordinates];
49
- for (
50
- var i = ends[0].properties.index + 1;
51
- i < ends[1].properties.index + 1;
52
- i++
53
- ) {
54
- clipCoords.push(coords[i]);
55
- }
56
- clipCoords.push(ends[1].geometry.coordinates);
57
- return lineString(clipCoords, line.properties);
58
- }
59
-
60
- export default lineSlice;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,67 +0,0 @@
1
- 'use strict';
2
-
3
- var invariant = require('@turf/invariant');
4
- var helpers = require('@turf/helpers');
5
- var nearestPointOnLine = require('@turf/nearest-point-on-line');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var nearestPointOnLine__default = /*#__PURE__*/_interopDefaultLegacy(nearestPointOnLine);
10
-
11
- /**
12
- * Takes a {@link LineString|line}, a start {@link Point}, and a stop point
13
- * and returns a subsection of the line in-between those points.
14
- * The start & stop points don't need to fall exactly on the line.
15
- *
16
- * This can be useful for extracting only the part of a route between waypoints.
17
- *
18
- * @name lineSlice
19
- * @param {Coord} startPt starting point
20
- * @param {Coord} stopPt stopping point
21
- * @param {Feature<LineString>|LineString} line line to slice
22
- * @returns {Feature<LineString>} sliced line
23
- * @example
24
- * var line = turf.lineString([
25
- * [-77.031669, 38.878605],
26
- * [-77.029609, 38.881946],
27
- * [-77.020339, 38.884084],
28
- * [-77.025661, 38.885821],
29
- * [-77.021884, 38.889563],
30
- * [-77.019824, 38.892368]
31
- * ]);
32
- * var start = turf.point([-77.029609, 38.881946]);
33
- * var stop = turf.point([-77.021884, 38.889563]);
34
- *
35
- * var sliced = turf.lineSlice(start, stop, line);
36
- *
37
- * //addToMap
38
- * var addToMap = [start, stop, line]
39
- */
40
- function lineSlice(startPt, stopPt, line) {
41
- // Validation
42
- var coords = invariant.getCoords(line);
43
- if (invariant.getType(line) !== "LineString")
44
- throw new Error("line must be a LineString");
45
-
46
- var startVertex = nearestPointOnLine__default['default'](line, startPt);
47
- var stopVertex = nearestPointOnLine__default['default'](line, stopPt);
48
- var ends;
49
- if (startVertex.properties.index <= stopVertex.properties.index) {
50
- ends = [startVertex, stopVertex];
51
- } else {
52
- ends = [stopVertex, startVertex];
53
- }
54
- var clipCoords = [ends[0].geometry.coordinates];
55
- for (
56
- var i = ends[0].properties.index + 1;
57
- i < ends[1].properties.index + 1;
58
- i++
59
- ) {
60
- clipCoords.push(coords[i]);
61
- }
62
- clipCoords.push(ends[1].geometry.coordinates);
63
- return helpers.lineString(clipCoords, line.properties);
64
- }
65
-
66
- module.exports = lineSlice;
67
- module.exports.default = lineSlice;
package/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Feature, LineString } from "geojson";
2
- import { Coord } from "@turf/helpers";
3
-
4
- /**
5
- * http://turfjs.org/docs/#lineslice
6
- */
7
- export default function lineSlice(
8
- startPt: Coord,
9
- stopPt: Coord,
10
- line: Feature<LineString> | LineString
11
- ): Feature<LineString>;