@turf/line-chunk 7.3.0 → 7.3.2

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.
@@ -1,29 +1,36 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
2
  var _length = require('@turf/length');
3
3
  var _lineslicealong = require('@turf/line-slice-along');
4
4
  var _meta = require('@turf/meta');
5
5
  var _helpers = require('@turf/helpers');
6
- function lineChunk(geojson, segmentLength, options) {
7
- options = options || {};
6
+ function lineChunk(geojson, segmentLength, options = {}) {
8
7
  if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
9
- var units = options.units;
10
- var reverse = options.reverse;
8
+ const { units = "kilometers", reverse = false } = options;
11
9
  if (!geojson) throw new Error("geojson is required");
12
- if (segmentLength <= 0)
10
+ if (segmentLength <= 0) {
13
11
  throw new Error("segmentLength must be greater than 0");
14
- var results = [];
15
- _meta.flattenEach.call(void 0, geojson, function(feature) {
16
- if (reverse)
12
+ }
13
+ const results = [];
14
+ _meta.flattenEach.call(void 0, geojson, (feature) => {
15
+ if (reverse) {
17
16
  feature.geometry.coordinates = feature.geometry.coordinates.reverse();
18
- sliceLineSegments(feature, segmentLength, units, function(segment) {
19
- results.push(segment);
20
- });
17
+ }
18
+ sliceLineSegments(
19
+ feature,
20
+ segmentLength,
21
+ units,
22
+ (segment) => {
23
+ results.push(segment);
24
+ }
25
+ );
21
26
  });
22
27
  return _helpers.featureCollection.call(void 0, results);
23
28
  }
24
29
  function sliceLineSegments(line, segmentLength, units, callback) {
25
30
  var lineLength = _length.length.call(void 0, line, { units });
26
- if (lineLength <= segmentLength) return callback(line);
31
+ if (lineLength <= segmentLength) {
32
+ return callback(line);
33
+ }
27
34
  var numberOfSegments = lineLength / segmentLength;
28
35
  if (!Number.isInteger(numberOfSegments)) {
29
36
  numberOfSegments = Math.floor(numberOfSegments) + 1;
@@ -35,7 +42,7 @@ function sliceLineSegments(line, segmentLength, units, callback) {
35
42
  segmentLength * (i + 1),
36
43
  { units }
37
44
  );
38
- callback(outline, i);
45
+ callback(outline);
39
46
  }
40
47
  }
41
48
  var index_default = lineChunk;
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-chunk/dist/cjs/index.cjs","../../index.js"],"names":[],"mappings":"AAAA;ACAA,sCAAuB;AACvB,wDAA+B;AAC/B,kCAA4B;AAC5B,wCAA4C;AAqB5C,SAAS,SAAA,CAAU,OAAA,EAAS,aAAA,EAAe,OAAA,EAAS;AAElD,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,GAAA,CAAI,CAAC,+BAAA,OAAgB,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAC5D,EAAA,IAAI,MAAA,EAAQ,OAAA,CAAQ,KAAA;AACpB,EAAA,IAAI,QAAA,EAAU,OAAA,CAAQ,OAAA;AAGtB,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,qBAAqB,CAAA;AACnD,EAAA,GAAA,CAAI,cAAA,GAAiB,CAAA;AACnB,IAAA,MAAM,IAAI,KAAA,CAAM,sCAAsC,CAAA;AAGxD,EAAA,IAAI,QAAA,EAAU,CAAC,CAAA;AAGf,EAAA,+BAAA,OAAY,EAAS,QAAA,CAAU,OAAA,EAAS;AAEtC,IAAA,GAAA,CAAI,OAAA;AACF,MAAA,OAAA,CAAQ,QAAA,CAAS,YAAA,EAAc,OAAA,CAAQ,QAAA,CAAS,WAAA,CAAY,OAAA,CAAQ,CAAA;AAEtE,IAAA,iBAAA,CAAkB,OAAA,EAAS,aAAA,EAAe,KAAA,EAAO,QAAA,CAAU,OAAA,EAAS;AAClE,MAAA,OAAA,CAAQ,IAAA,CAAK,OAAO,CAAA;AAAA,IACtB,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACD,EAAA,OAAO,wCAAA,OAAyB,CAAA;AAClC;AAYA,SAAS,iBAAA,CAAkB,IAAA,EAAM,aAAA,EAAe,KAAA,EAAO,QAAA,EAAU;AAC/D,EAAA,IAAI,WAAA,EAAa,4BAAA,IAAO,EAAM,EAAE,MAAa,CAAC,CAAA;AAG9C,EAAA,GAAA,CAAI,WAAA,GAAc,aAAA,EAAe,OAAO,QAAA,CAAS,IAAI,CAAA;AAErD,EAAA,IAAI,iBAAA,EAAmB,WAAA,EAAa,aAAA;AAGpC,EAAA,GAAA,CAAI,CAAC,MAAA,CAAO,SAAA,CAAU,gBAAgB,CAAA,EAAG;AACvC,IAAA,iBAAA,EAAmB,IAAA,CAAK,KAAA,CAAM,gBAAgB,EAAA,EAAI,CAAA;AAAA,EACpD;AAEA,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,gBAAA,EAAkB,CAAA,EAAA,EAAK;AACzC,IAAA,IAAI,QAAA,EAAU,4CAAA;AAAA,MACZ,IAAA;AAAA,MACA,cAAA,EAAgB,CAAA;AAAA,MAChB,cAAA,EAAA,CAAiB,EAAA,EAAI,CAAA,CAAA;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB,CAAA;AACA,IAAA,QAAA,CAAS,OAAA,EAAS,CAAC,CAAA;AAAA,EACrB;AACF;AAGA,IAAO,cAAA,EAAQ,SAAA;AD9Cf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-chunk/dist/cjs/index.cjs","sourcesContent":[null,"import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk(geojson, segmentLength, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var reverse = options.reverse;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0)\n throw new Error(\"segmentLength must be greater than 0\");\n\n // Container\n var results = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, function (feature) {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse)\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n\n sliceLineSegments(feature, segmentLength, units, function (segment) {\n results.push(segment);\n });\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {Units}[units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(line, segmentLength, units, callback) {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) return callback(line);\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline, i);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-chunk/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACAA,sCAAuB;AACvB,wDAA+B;AAC/B,kCAA4B;AAC5B,wCAAmD;AA4BnD,SAAS,SAAA,CACP,OAAA,EAMA,aAAA,EACA,QAAA,EAGI,CAAC,CAAA,EAC0B;AAE/B,EAAA,GAAA,CAAI,CAAC,+BAAA,OAAgB,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAC5D,EAAA,MAAM,EAAE,MAAA,EAAQ,YAAA,EAAc,QAAA,EAAU,MAAM,EAAA,EAAI,OAAA;AAGlD,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,qBAAqB,CAAA;AACnD,EAAA,GAAA,CAAI,cAAA,GAAiB,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA,CAAM,sCAAsC,CAAA;AAAA,EACxD;AAGA,EAAA,MAAM,QAAA,EAAiC,CAAC,CAAA;AAGxC,EAAA,+BAAA,OAAY,EAAS,CAAC,OAAA,EAAA,GAAwB;AAE5C,IAAA,GAAA,CAAI,OAAA,EAAS;AACX,MAAA,OAAA,CAAQ,QAAA,CAAS,YAAA,EAAc,OAAA,CAAQ,QAAA,CAAS,WAAA,CAAY,OAAA,CAAQ,CAAA;AAAA,IACtE;AAEA,IAAA,iBAAA;AAAA,MACE,OAAA;AAAA,MACA,aAAA;AAAA,MACA,KAAA;AAAA,MACA,CAAC,OAAA,EAAA,GAAY;AACX,QAAA,OAAA,CAAQ,IAAA,CAAK,OAAO,CAAA;AAAA,MACtB;AAAA,IACF,CAAA;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,wCAAA,OAAyB,CAAA;AAClC;AAYA,SAAS,iBAAA,CACP,IAAA,EACA,aAAA,EACA,KAAA,EACA,QAAA,EACM;AACN,EAAA,IAAI,WAAA,EAAa,4BAAA,IAAO,EAAM,EAAE,MAAa,CAAC,CAAA;AAG9C,EAAA,GAAA,CAAI,WAAA,GAAc,aAAA,EAAe;AAC/B,IAAA,OAAO,QAAA,CAAS,IAAI,CAAA;AAAA,EACtB;AAEA,EAAA,IAAI,iBAAA,EAAmB,WAAA,EAAa,aAAA;AAGpC,EAAA,GAAA,CAAI,CAAC,MAAA,CAAO,SAAA,CAAU,gBAAgB,CAAA,EAAG;AACvC,IAAA,iBAAA,EAAmB,IAAA,CAAK,KAAA,CAAM,gBAAgB,EAAA,EAAI,CAAA;AAAA,EACpD;AAEA,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,gBAAA,EAAkB,CAAA,EAAA,EAAK;AACzC,IAAA,IAAI,QAAA,EAAU,4CAAA;AAAA,MACZ,IAAA;AAAA,MACA,cAAA,EAAgB,CAAA;AAAA,MAChB,cAAA,EAAA,CAAiB,EAAA,EAAI,CAAA,CAAA;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB,CAAA;AACA,IAAA,QAAA,CAAS,OAAO,CAAA;AAAA,EAClB;AACF;AAGA,IAAO,cAAA,EAAQ,SAAA;ADtEf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-chunk/dist/cjs/index.cjs","sourcesContent":[null,"import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject, Units } from \"@turf/helpers\";\nimport {\n Feature,\n FeatureCollection,\n GeometryCollection,\n LineString,\n MultiLineString,\n} from \"geojson\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk<T extends LineString | MultiLineString>(\n geojson:\n | Feature<T>\n | FeatureCollection<T>\n | T\n | GeometryCollection\n | Feature<GeometryCollection>,\n segmentLength: number,\n options: {\n units?: Units;\n reverse?: boolean;\n } = {}\n): FeatureCollection<LineString> {\n // Optional parameters\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { units = \"kilometers\", reverse = false } = options;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0) {\n throw new Error(\"segmentLength must be greater than 0\");\n }\n\n // Container\n const results: Feature<LineString>[] = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, (feature: Feature<T>) => {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse) {\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n }\n\n sliceLineSegments(\n feature as Feature<LineString>,\n segmentLength,\n units,\n (segment) => {\n results.push(segment);\n }\n );\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {Units}[units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(\n line: Feature<LineString>,\n segmentLength: number,\n units: Units,\n callback: (feature: Feature<LineString>) => void\n): void {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) {\n return callback(line);\n }\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"]}
@@ -1,21 +1,28 @@
1
- import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
2
1
  import { Units } from '@turf/helpers';
2
+ import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
3
3
 
4
4
  /**
5
- * http://turfjs.org/docs/#lineChunk
5
+ * Divides a {@link LineString} into chunks of a specified length.
6
+ * If the line is shorter than the segment length then the original line is returned.
7
+ *
8
+ * @function
9
+ * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split
10
+ * @param {number} segmentLength how long to make each segment
11
+ * @param {Object} [options={}] Optional parameters
12
+ * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
13
+ * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end
14
+ * @returns {FeatureCollection<LineString>} collection of line segments
15
+ * @example
16
+ * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);
17
+ *
18
+ * var chunk = turf.lineChunk(line, 15, {units: 'miles'});
19
+ *
20
+ * //addToMap
21
+ * var addToMap = [chunk];
6
22
  */
7
- declare function lineChunk<T extends LineString | MultiLineString>(
8
- geojson:
9
- | Feature<T>
10
- | FeatureCollection<T>
11
- | T
12
- | GeometryCollection
13
- | Feature<GeometryCollection>,
14
- segmentLength: number,
15
- options?: {
23
+ declare function lineChunk<T extends LineString | MultiLineString>(geojson: Feature<T> | FeatureCollection<T> | T | GeometryCollection | Feature<GeometryCollection>, segmentLength: number, options?: {
16
24
  units?: Units;
17
25
  reverse?: boolean;
18
- }
19
- ): FeatureCollection<LineString>;
26
+ }): FeatureCollection<LineString>;
20
27
 
21
28
  export { lineChunk as default, lineChunk };
@@ -1,21 +1,28 @@
1
- import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
2
1
  import { Units } from '@turf/helpers';
2
+ import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
3
3
 
4
4
  /**
5
- * http://turfjs.org/docs/#lineChunk
5
+ * Divides a {@link LineString} into chunks of a specified length.
6
+ * If the line is shorter than the segment length then the original line is returned.
7
+ *
8
+ * @function
9
+ * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split
10
+ * @param {number} segmentLength how long to make each segment
11
+ * @param {Object} [options={}] Optional parameters
12
+ * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
13
+ * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end
14
+ * @returns {FeatureCollection<LineString>} collection of line segments
15
+ * @example
16
+ * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);
17
+ *
18
+ * var chunk = turf.lineChunk(line, 15, {units: 'miles'});
19
+ *
20
+ * //addToMap
21
+ * var addToMap = [chunk];
6
22
  */
7
- declare function lineChunk<T extends LineString | MultiLineString>(
8
- geojson:
9
- | Feature<T>
10
- | FeatureCollection<T>
11
- | T
12
- | GeometryCollection
13
- | Feature<GeometryCollection>,
14
- segmentLength: number,
15
- options?: {
23
+ declare function lineChunk<T extends LineString | MultiLineString>(geojson: Feature<T> | FeatureCollection<T> | T | GeometryCollection | Feature<GeometryCollection>, segmentLength: number, options?: {
16
24
  units?: Units;
17
25
  reverse?: boolean;
18
- }
19
- ): FeatureCollection<LineString>;
26
+ }): FeatureCollection<LineString>;
20
27
 
21
28
  export { lineChunk as default, lineChunk };
package/dist/esm/index.js CHANGED
@@ -1,29 +1,36 @@
1
- // index.js
1
+ // index.ts
2
2
  import { length } from "@turf/length";
3
3
  import { lineSliceAlong } from "@turf/line-slice-along";
4
4
  import { flattenEach } from "@turf/meta";
5
5
  import { featureCollection, isObject } from "@turf/helpers";
6
- function lineChunk(geojson, segmentLength, options) {
7
- options = options || {};
6
+ function lineChunk(geojson, segmentLength, options = {}) {
8
7
  if (!isObject(options)) throw new Error("options is invalid");
9
- var units = options.units;
10
- var reverse = options.reverse;
8
+ const { units = "kilometers", reverse = false } = options;
11
9
  if (!geojson) throw new Error("geojson is required");
12
- if (segmentLength <= 0)
10
+ if (segmentLength <= 0) {
13
11
  throw new Error("segmentLength must be greater than 0");
14
- var results = [];
15
- flattenEach(geojson, function(feature) {
16
- if (reverse)
12
+ }
13
+ const results = [];
14
+ flattenEach(geojson, (feature) => {
15
+ if (reverse) {
17
16
  feature.geometry.coordinates = feature.geometry.coordinates.reverse();
18
- sliceLineSegments(feature, segmentLength, units, function(segment) {
19
- results.push(segment);
20
- });
17
+ }
18
+ sliceLineSegments(
19
+ feature,
20
+ segmentLength,
21
+ units,
22
+ (segment) => {
23
+ results.push(segment);
24
+ }
25
+ );
21
26
  });
22
27
  return featureCollection(results);
23
28
  }
24
29
  function sliceLineSegments(line, segmentLength, units, callback) {
25
30
  var lineLength = length(line, { units });
26
- if (lineLength <= segmentLength) return callback(line);
31
+ if (lineLength <= segmentLength) {
32
+ return callback(line);
33
+ }
27
34
  var numberOfSegments = lineLength / segmentLength;
28
35
  if (!Number.isInteger(numberOfSegments)) {
29
36
  numberOfSegments = Math.floor(numberOfSegments) + 1;
@@ -35,7 +42,7 @@ function sliceLineSegments(line, segmentLength, units, callback) {
35
42
  segmentLength * (i + 1),
36
43
  { units }
37
44
  );
38
- callback(outline, i);
45
+ callback(outline);
39
46
  }
40
47
  }
41
48
  var index_default = lineChunk;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"sourcesContent":["import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk(geojson, segmentLength, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var reverse = options.reverse;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0)\n throw new Error(\"segmentLength must be greater than 0\");\n\n // Container\n var results = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, function (feature) {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse)\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n\n sliceLineSegments(feature, segmentLength, units, function (segment) {\n results.push(segment);\n });\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {Units}[units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(line, segmentLength, units, callback) {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) return callback(line);\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline, i);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB,gBAAgB;AAqB5C,SAAS,UAAU,SAAS,eAAe,SAAS;AAElD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,UAAU,QAAQ;AAGtB,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,sCAAsC;AAGxD,MAAI,UAAU,CAAC;AAGf,cAAY,SAAS,SAAU,SAAS;AAEtC,QAAI;AACF,cAAQ,SAAS,cAAc,QAAQ,SAAS,YAAY,QAAQ;AAEtE,sBAAkB,SAAS,eAAe,OAAO,SAAU,SAAS;AAClE,cAAQ,KAAK,OAAO;AAAA,IACtB,CAAC;AAAA,EACH,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAYA,SAAS,kBAAkB,MAAM,eAAe,OAAO,UAAU;AAC/D,MAAI,aAAa,OAAO,MAAM,EAAE,MAAa,CAAC;AAG9C,MAAI,cAAc,cAAe,QAAO,SAAS,IAAI;AAErD,MAAI,mBAAmB,aAAa;AAGpC,MAAI,CAAC,OAAO,UAAU,gBAAgB,GAAG;AACvC,uBAAmB,KAAK,MAAM,gBAAgB,IAAI;AAAA,EACpD;AAEA,WAAS,IAAI,GAAG,IAAI,kBAAkB,KAAK;AACzC,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,gBAAgB;AAAA,MAChB,iBAAiB,IAAI;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB;AACA,aAAS,SAAS,CAAC;AAAA,EACrB;AACF;AAGA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject, Units } from \"@turf/helpers\";\nimport {\n Feature,\n FeatureCollection,\n GeometryCollection,\n LineString,\n MultiLineString,\n} from \"geojson\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @function\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk<T extends LineString | MultiLineString>(\n geojson:\n | Feature<T>\n | FeatureCollection<T>\n | T\n | GeometryCollection\n | Feature<GeometryCollection>,\n segmentLength: number,\n options: {\n units?: Units;\n reverse?: boolean;\n } = {}\n): FeatureCollection<LineString> {\n // Optional parameters\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { units = \"kilometers\", reverse = false } = options;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0) {\n throw new Error(\"segmentLength must be greater than 0\");\n }\n\n // Container\n const results: Feature<LineString>[] = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, (feature: Feature<T>) => {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse) {\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n }\n\n sliceLineSegments(\n feature as Feature<LineString>,\n segmentLength,\n units,\n (segment) => {\n results.push(segment);\n }\n );\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {Units}[units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(\n line: Feature<LineString>,\n segmentLength: number,\n units: Units,\n callback: (feature: Feature<LineString>) => void\n): void {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) {\n return callback(line);\n }\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB,gBAAuB;AA4BnD,SAAS,UACP,SAMA,eACA,UAGI,CAAC,GAC0B;AAE/B,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,EAAE,QAAQ,cAAc,UAAU,MAAM,IAAI;AAGlD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,iBAAiB,GAAG;AACtB,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AAGA,QAAM,UAAiC,CAAC;AAGxC,cAAY,SAAS,CAAC,YAAwB;AAE5C,QAAI,SAAS;AACX,cAAQ,SAAS,cAAc,QAAQ,SAAS,YAAY,QAAQ;AAAA,IACtE;AAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,CAAC,YAAY;AACX,gBAAQ,KAAK,OAAO;AAAA,MACtB;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAYA,SAAS,kBACP,MACA,eACA,OACA,UACM;AACN,MAAI,aAAa,OAAO,MAAM,EAAE,MAAa,CAAC;AAG9C,MAAI,cAAc,eAAe;AAC/B,WAAO,SAAS,IAAI;AAAA,EACtB;AAEA,MAAI,mBAAmB,aAAa;AAGpC,MAAI,CAAC,OAAO,UAAU,gBAAgB,GAAG;AACvC,uBAAmB,KAAK,MAAM,gBAAgB,IAAI;AAAA,EACpD;AAEA,WAAS,IAAI,GAAG,IAAI,kBAAkB,KAAK;AACzC,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,gBAAgB;AAAA,MAChB,iBAAiB,IAAI;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB;AACA,aAAS,OAAO;AAAA,EAClB;AACF;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/line-chunk",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "Divides a LineString into chunks of a specified length.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -54,28 +54,29 @@
54
54
  "bench": "tsx bench.ts",
55
55
  "build": "tsup --config ../../tsup.config.ts",
56
56
  "docs": "tsx ../../scripts/generate-readmes.ts",
57
- "test": "npm-run-all --npm-path npm test:*",
57
+ "test": "pnpm run /test:.*/",
58
58
  "test:tape": "tsx test.ts",
59
59
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
60
60
  },
61
61
  "devDependencies": {
62
- "@turf/truncate": "7.3.0",
62
+ "@turf/truncate": "7.3.2",
63
63
  "@types/benchmark": "^2.1.5",
64
64
  "@types/tape": "^5.8.1",
65
65
  "benchmark": "^2.1.4",
66
66
  "load-json-file": "^7.0.1",
67
- "npm-run-all": "^4.1.5",
68
67
  "tape": "^5.9.0",
69
68
  "tsup": "^8.4.0",
70
69
  "tsx": "^4.19.4",
70
+ "typescript": "^5.8.3",
71
71
  "write-json-file": "^6.0.0"
72
72
  },
73
73
  "dependencies": {
74
- "@turf/helpers": "7.3.0",
75
- "@turf/length": "7.3.0",
76
- "@turf/line-slice-along": "7.3.0",
77
- "@turf/meta": "7.3.0",
78
- "@types/geojson": "^7946.0.10"
74
+ "@turf/helpers": "7.3.2",
75
+ "@turf/length": "7.3.2",
76
+ "@turf/line-slice-along": "7.3.2",
77
+ "@turf/meta": "7.3.2",
78
+ "@types/geojson": "^7946.0.10",
79
+ "tslib": "^2.8.1"
79
80
  },
80
- "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
81
+ "gitHead": "099d9915467bacf45d554be4533fa9998c4efc88"
81
82
  }