New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/line-chunk

Package Overview
Dependencies
Maintainers
6
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/line-chunk - npm Package Compare versions

Comparing version 6.2.0-alpha.2 to 6.2.0-alpha.3

dist/es/package.json

67

dist/es/index.js

@@ -26,25 +26,27 @@ import length from '@turf/length';

function lineChunk(geojson, segmentLength, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var units = options.units;
var reverse = options.reverse;
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error("options is invalid");
var units = options.units;
var reverse = options.reverse;
// Validation
if (!geojson) throw new Error('geojson is required');
if (segmentLength <= 0) throw new Error('segmentLength must be greater than 0');
// Validation
if (!geojson) throw new Error("geojson is required");
if (segmentLength <= 0)
throw new Error("segmentLength must be greater than 0");
// Container
var results = [];
// Container
var results = [];
// Flatten each feature to simple LineString
flattenEach(geojson, function (feature) {
// reverses coordinates to start the first chunked segment at the end
if (reverse) feature.geometry.coordinates = feature.geometry.coordinates.reverse();
// Flatten each feature to simple LineString
flattenEach(geojson, function (feature) {
// reverses coordinates to start the first chunked segment at the end
if (reverse)
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
sliceLineSegments(feature, segmentLength, units, function (segment) {
results.push(segment);
});
sliceLineSegments(feature, segmentLength, units, function (segment) {
results.push(segment);
});
return featureCollection(results);
});
return featureCollection(results);
}

@@ -63,20 +65,25 @@

function sliceLineSegments(line, segmentLength, units, callback) {
var lineLength = length(line, {units: units});
var lineLength = length(line, { units: units });
// If the line is shorter than the segment length then the orginal line is returned.
if (lineLength <= segmentLength) return callback(line);
// If the line is shorter than the segment length then the orginal line is returned.
if (lineLength <= segmentLength) return callback(line);
var numberOfSegments = lineLength / segmentLength;
var numberOfSegments = lineLength / segmentLength;
// If numberOfSegments is integer, no need to plus 1
if (!Number.isInteger(numberOfSegments)) {
numberOfSegments = Math.floor(numberOfSegments) + 1;
}
// If numberOfSegments is integer, no need to plus 1
if (!Number.isInteger(numberOfSegments)) {
numberOfSegments = Math.floor(numberOfSegments) + 1;
}
for (var i = 0; i < numberOfSegments; i++) {
var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units});
callback(outline, i);
}
for (var i = 0; i < numberOfSegments; i++) {
var outline = lineSliceAlong(
line,
segmentLength * i,
segmentLength * (i + 1),
{ units: units }
);
callback(outline, i);
}
}
export default lineChunk;

@@ -30,25 +30,27 @@ 'use strict';

function lineChunk(geojson, segmentLength, options) {
// Optional parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var units = options.units;
var reverse = options.reverse;
// Optional parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var units = options.units;
var reverse = options.reverse;
// Validation
if (!geojson) throw new Error('geojson is required');
if (segmentLength <= 0) throw new Error('segmentLength must be greater than 0');
// Validation
if (!geojson) throw new Error("geojson is required");
if (segmentLength <= 0)
throw new Error("segmentLength must be greater than 0");
// Container
var results = [];
// Container
var results = [];
// Flatten each feature to simple LineString
meta.flattenEach(geojson, function (feature) {
// reverses coordinates to start the first chunked segment at the end
if (reverse) feature.geometry.coordinates = feature.geometry.coordinates.reverse();
// Flatten each feature to simple LineString
meta.flattenEach(geojson, function (feature) {
// reverses coordinates to start the first chunked segment at the end
if (reverse)
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
sliceLineSegments(feature, segmentLength, units, function (segment) {
results.push(segment);
});
sliceLineSegments(feature, segmentLength, units, function (segment) {
results.push(segment);
});
return helpers.featureCollection(results);
});
return helpers.featureCollection(results);
}

@@ -67,21 +69,25 @@

function sliceLineSegments(line, segmentLength, units, callback) {
var lineLength = length(line, {units: units});
var lineLength = length(line, { units: units });
// If the line is shorter than the segment length then the orginal line is returned.
if (lineLength <= segmentLength) return callback(line);
// If the line is shorter than the segment length then the orginal line is returned.
if (lineLength <= segmentLength) return callback(line);
var numberOfSegments = lineLength / segmentLength;
var numberOfSegments = lineLength / segmentLength;
// If numberOfSegments is integer, no need to plus 1
if (!Number.isInteger(numberOfSegments)) {
numberOfSegments = Math.floor(numberOfSegments) + 1;
}
// If numberOfSegments is integer, no need to plus 1
if (!Number.isInteger(numberOfSegments)) {
numberOfSegments = Math.floor(numberOfSegments) + 1;
}
for (var i = 0; i < numberOfSegments; i++) {
var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units});
callback(outline, i);
}
for (var i = 0; i < numberOfSegments; i++) {
var outline = lineSliceAlong(
line,
segmentLength * i,
segmentLength * (i + 1),
{ units: units }
);
callback(outline, i);
}
}
module.exports = lineChunk;
module.exports.default = lineChunk;
import {
LineString,
MultiLineString,
GeometryCollection,
Units,
Feature,
FeatureCollection,
} from '@turf/helpers'
LineString,
MultiLineString,
GeometryCollection,
Units,
Feature,
FeatureCollection,
} from "@turf/helpers";

@@ -14,8 +14,13 @@ /**

export default function lineChunk<T extends LineString | MultiLineString>(
geojson: Feature<T> | FeatureCollection<T> | T | GeometryCollection| Feature<GeometryCollection>,
segmentLength: number,
options?: {
units?: Units,
reverse?: boolean
}
geojson:
| Feature<T>
| FeatureCollection<T>
| T
| GeometryCollection
| Feature<GeometryCollection>,
segmentLength: number,
options?: {
units?: Units;
reverse?: boolean;
}
): FeatureCollection<LineString>;
{
"name": "@turf/line-chunk",
"version": "6.2.0-alpha.2",
"version": "6.2.0-alpha.3",
"description": "turf line-chunk module",

@@ -33,2 +33,6 @@ "author": "Turf Authors",

"module": "dist/es/index.js",
"exports": {
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
},
"types": "index.d.ts",

@@ -41,13 +45,12 @@ "sideEffects": false,

"scripts": {
"bench": "npm-run-all prepare bench:run",
"bench:run": "node bench.js",
"bench": "node -r esm bench.js",
"build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
"docs": "node ../../scripts/generate-readmes",
"posttest": "node -r esm ../../scripts/validate-es5-dependencies.js",
"prepare": "rollup -c ../../rollup.config.js",
"test": "npm-run-all prepare test:*",
"test": "npm-run-all test:*",
"test:tape": "node -r esm test.js",
"test:types": "tsc --noEmit types.ts"
"test:types": "tsc --esModuleInterop --noEmit types.ts"
},
"devDependencies": {
"@turf/truncate": "^6.2.0-alpha.2",
"@turf/truncate": "^6.2.0-alpha.3",
"benchmark": "*",

@@ -61,8 +64,8 @@ "load-json-file": "*",

"dependencies": {
"@turf/helpers": "^6.2.0-alpha.2",
"@turf/length": "^6.2.0-alpha.2",
"@turf/line-slice-along": "^6.2.0-alpha.2",
"@turf/meta": "^6.2.0-alpha.2"
"@turf/helpers": "^6.2.0-alpha.3",
"@turf/length": "^6.2.0-alpha.3",
"@turf/line-slice-along": "^6.2.0-alpha.3",
"@turf/meta": "^6.2.0-alpha.3"
},
"gitHead": "23d5cb91d77e0c1e2e903a2252f525797f1d0d09"
"gitHead": "dce9edfc705352e8cb9e0083c9330ba0e8d77409"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc