@turf/line-segment 6.5.0 → 7.0.0-alpha.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
@@ -4,13 +4,14 @@
4
4
 
5
5
  ## lineSegment
6
6
 
7
- Creates a [FeatureCollection][1] of 2-vertex [LineString][2] segments from a [(Multi)LineString][2] or [(Multi)Polygon][3].
7
+ Creates a [FeatureCollection][1] of 2-vertex [LineString][2] segments from a
8
+ [(Multi)LineString][2] or [(Multi)Polygon][3].
8
9
 
9
- **Parameters**
10
+ ### Parameters
10
11
 
11
- - `geojson` **([Geometry][4] \| [FeatureCollection][5] \| [Feature][6]<([LineString][7] \| [MultiLineString][8] \| [MultiPolygon][9] \| [Polygon][10])>)** GeoJSON Polygon or LineString
12
+ * `geojson` **[GeoJSON][4]** GeoJSON Polygon or LineString
12
13
 
13
- **Examples**
14
+ ### Examples
14
15
 
15
16
  ```javascript
16
17
  var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
@@ -20,7 +21,7 @@ var segments = turf.lineSegment(polygon);
20
21
  var addToMap = [polygon, segments]
21
22
  ```
22
23
 
23
- Returns **[FeatureCollection][5]<[LineString][7]>** 2-vertex line segments
24
+ Returns **[FeatureCollection][5]<[LineString][6]>** 2-vertex line segments
24
25
 
25
26
  [1]: https://tools.ietf.org/html/rfc7946#section-3.3
26
27
 
@@ -28,19 +29,11 @@ Returns **[FeatureCollection][5]&lt;[LineString][7]>** 2-vertex line segments
28
29
 
29
30
  [3]: https://tools.ietf.org/html/rfc7946#section-3.1.6
30
31
 
31
- [4]: https://tools.ietf.org/html/rfc7946#section-3.1
32
+ [4]: https://tools.ietf.org/html/rfc7946#section-3
32
33
 
33
34
  [5]: https://tools.ietf.org/html/rfc7946#section-3.3
34
35
 
35
- [6]: https://tools.ietf.org/html/rfc7946#section-3.2
36
-
37
- [7]: https://tools.ietf.org/html/rfc7946#section-3.1.4
38
-
39
- [8]: https://tools.ietf.org/html/rfc7946#section-3.1.5
40
-
41
- [9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
42
-
43
- [10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
36
+ [6]: https://tools.ietf.org/html/rfc7946#section-3.1.4
44
37
 
45
38
  <!-- This file is automatically generated. Please don't edit it directly:
46
39
  if you find an error, edit the source file (likely index.js), and re-run
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { featureCollection, lineString, } from "@turf/helpers";
1
+ import { featureCollection, lineString } from "@turf/helpers";
2
2
  import { getCoords } from "@turf/invariant";
3
3
  import { flattenEach } from "@turf/meta";
4
4
  /**
@@ -19,8 +19,8 @@ function lineSegment(geojson) {
19
19
  if (!geojson) {
20
20
  throw new Error("geojson is required");
21
21
  }
22
- var results = [];
23
- flattenEach(geojson, function (feature) {
22
+ const results = [];
23
+ flattenEach(geojson, (feature) => {
24
24
  lineSegmentFeature(feature, results);
25
25
  });
26
26
  return featureCollection(results);
@@ -34,8 +34,8 @@ function lineSegment(geojson) {
34
34
  * @returns {void}
35
35
  */
36
36
  function lineSegmentFeature(geojson, results) {
37
- var coords = [];
38
- var geometry = geojson.geometry;
37
+ let coords = [];
38
+ const geometry = geojson.geometry;
39
39
  if (geometry !== null) {
40
40
  switch (geometry.type) {
41
41
  case "Polygon":
@@ -44,9 +44,9 @@ function lineSegmentFeature(geojson, results) {
44
44
  case "LineString":
45
45
  coords = [getCoords(geometry)];
46
46
  }
47
- coords.forEach(function (coord) {
48
- var segments = createSegments(coord, geojson.properties);
49
- segments.forEach(function (segment) {
47
+ coords.forEach((coord) => {
48
+ const segments = createSegments(coord, geojson.properties);
49
+ segments.forEach((segment) => {
50
50
  segment.id = results.length;
51
51
  results.push(segment);
52
52
  });
@@ -62,9 +62,9 @@ function lineSegmentFeature(geojson, results) {
62
62
  * @returns {Array<Feature<LineString>>} line segments
63
63
  */
64
64
  function createSegments(coords, properties) {
65
- var segments = [];
66
- coords.reduce(function (previousCoords, currentCoords) {
67
- var segment = lineString([previousCoords, currentCoords], properties);
65
+ const segments = [];
66
+ coords.reduce((previousCoords, currentCoords) => {
67
+ const segment = lineString([previousCoords, currentCoords], properties);
68
68
  segment.bbox = bbox(previousCoords, currentCoords);
69
69
  segments.push(segment);
70
70
  return currentCoords;
@@ -80,14 +80,14 @@ function createSegments(coords, properties) {
80
80
  * @returns {BBox} [west, south, east, north]
81
81
  */
82
82
  function bbox(coords1, coords2) {
83
- var x1 = coords1[0];
84
- var y1 = coords1[1];
85
- var x2 = coords2[0];
86
- var y2 = coords2[1];
87
- var west = x1 < x2 ? x1 : x2;
88
- var south = y1 < y2 ? y1 : y2;
89
- var east = x1 > x2 ? x1 : x2;
90
- var north = y1 > y2 ? y1 : y2;
83
+ const x1 = coords1[0];
84
+ const y1 = coords1[1];
85
+ const x2 = coords2[0];
86
+ const y2 = coords2[1];
87
+ const west = x1 < x2 ? x1 : x2;
88
+ const south = y1 < y2 ? y1 : y2;
89
+ const east = x1 > x2 ? x1 : x2;
90
+ const north = y1 > y2 ? y1 : y2;
91
91
  return [west, south, east, north];
92
92
  }
93
93
  export default lineSegment;
@@ -1,4 +1,4 @@
1
- import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "@turf/helpers";
1
+ import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "geojson";
2
2
  /**
3
3
  * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
4
4
  * {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
package/dist/js/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var helpers_1 = require("@turf/helpers");
4
- var invariant_1 = require("@turf/invariant");
5
- var meta_1 = require("@turf/meta");
3
+ const helpers_1 = require("@turf/helpers");
4
+ const invariant_1 = require("@turf/invariant");
5
+ const meta_1 = require("@turf/meta");
6
6
  /**
7
7
  * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
8
8
  * {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
@@ -21,8 +21,8 @@ function lineSegment(geojson) {
21
21
  if (!geojson) {
22
22
  throw new Error("geojson is required");
23
23
  }
24
- var results = [];
25
- meta_1.flattenEach(geojson, function (feature) {
24
+ const results = [];
25
+ meta_1.flattenEach(geojson, (feature) => {
26
26
  lineSegmentFeature(feature, results);
27
27
  });
28
28
  return helpers_1.featureCollection(results);
@@ -36,8 +36,8 @@ function lineSegment(geojson) {
36
36
  * @returns {void}
37
37
  */
38
38
  function lineSegmentFeature(geojson, results) {
39
- var coords = [];
40
- var geometry = geojson.geometry;
39
+ let coords = [];
40
+ const geometry = geojson.geometry;
41
41
  if (geometry !== null) {
42
42
  switch (geometry.type) {
43
43
  case "Polygon":
@@ -46,9 +46,9 @@ function lineSegmentFeature(geojson, results) {
46
46
  case "LineString":
47
47
  coords = [invariant_1.getCoords(geometry)];
48
48
  }
49
- coords.forEach(function (coord) {
50
- var segments = createSegments(coord, geojson.properties);
51
- segments.forEach(function (segment) {
49
+ coords.forEach((coord) => {
50
+ const segments = createSegments(coord, geojson.properties);
51
+ segments.forEach((segment) => {
52
52
  segment.id = results.length;
53
53
  results.push(segment);
54
54
  });
@@ -64,9 +64,9 @@ function lineSegmentFeature(geojson, results) {
64
64
  * @returns {Array<Feature<LineString>>} line segments
65
65
  */
66
66
  function createSegments(coords, properties) {
67
- var segments = [];
68
- coords.reduce(function (previousCoords, currentCoords) {
69
- var segment = helpers_1.lineString([previousCoords, currentCoords], properties);
67
+ const segments = [];
68
+ coords.reduce((previousCoords, currentCoords) => {
69
+ const segment = helpers_1.lineString([previousCoords, currentCoords], properties);
70
70
  segment.bbox = bbox(previousCoords, currentCoords);
71
71
  segments.push(segment);
72
72
  return currentCoords;
@@ -82,14 +82,14 @@ function createSegments(coords, properties) {
82
82
  * @returns {BBox} [west, south, east, north]
83
83
  */
84
84
  function bbox(coords1, coords2) {
85
- var x1 = coords1[0];
86
- var y1 = coords1[1];
87
- var x2 = coords2[0];
88
- var y2 = coords2[1];
89
- var west = x1 < x2 ? x1 : x2;
90
- var south = y1 < y2 ? y1 : y2;
91
- var east = x1 > x2 ? x1 : x2;
92
- var north = y1 > y2 ? y1 : y2;
85
+ const x1 = coords1[0];
86
+ const y1 = coords1[1];
87
+ const x2 = coords2[0];
88
+ const y2 = coords2[1];
89
+ const west = x1 < x2 ? x1 : x2;
90
+ const south = y1 < y2 ? y1 : y2;
91
+ const east = x1 > x2 ? x1 : x2;
92
+ const north = y1 > y2 ? y1 : y2;
93
93
  return [west, south, east, north];
94
94
  }
95
95
  exports.default = lineSegment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/line-segment",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf line-segment module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -26,6 +26,7 @@
26
26
  "exports": {
27
27
  "./package.json": "./package.json",
28
28
  ".": {
29
+ "types": "./dist/js/index.d.ts",
29
30
  "import": "./dist/es/index.js",
30
31
  "require": "./dist/js/index.js"
31
32
  }
@@ -36,13 +37,13 @@
36
37
  "dist"
37
38
  ],
38
39
  "scripts": {
39
- "bench": "ts-node bench.js",
40
+ "bench": "tsx bench.js",
40
41
  "build": "npm-run-all build:*",
41
42
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
42
43
  "build:js": "tsc",
43
- "docs": "node ../../scripts/generate-readmes",
44
+ "docs": "tsx ../../scripts/generate-readmes",
44
45
  "test": "npm-run-all test:*",
45
- "test:tape": "ts-node -r esm test.js"
46
+ "test:tape": "tsx test.js"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/tape": "*",
@@ -50,15 +51,16 @@
50
51
  "load-json-file": "*",
51
52
  "npm-run-all": "*",
52
53
  "tape": "*",
53
- "ts-node": "*",
54
54
  "tslint": "*",
55
+ "tsx": "*",
55
56
  "typescript": "*",
56
57
  "write-json-file": "*"
57
58
  },
58
59
  "dependencies": {
59
- "@turf/helpers": "^6.5.0",
60
- "@turf/invariant": "^6.5.0",
61
- "@turf/meta": "^6.5.0"
60
+ "@turf/helpers": "^7.0.0-alpha.1",
61
+ "@turf/invariant": "^7.0.0-alpha.1",
62
+ "@turf/meta": "^7.0.0-alpha.1",
63
+ "tslib": "^2.3.0"
62
64
  },
63
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
65
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
64
66
  }