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

@turf/line-offset

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/line-offset - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

lib/intersection.js

18

index.d.ts

@@ -1,14 +0,12 @@

/// <reference types="geojson" />
import { Units, Feature, LineString, MultiLineString } from '@turf/helpers';
import {Units} from '@turf/helpers';
type GeometryObject = GeoJSON.GeometryObject;
type Feature<Geom extends GeometryObject> = GeoJSON.Feature<Geom>;
type Geoms = GeoJSON.LineString | GeoJSON.MultiLineString;
/**
* http://turfjs.org/docs/#lineoffset
*/
declare function lineOffset<Geom extends Geoms>(line: Feature<Geom> | Geom, distance: number, units?: Units): Feature<Geom>;
declare namespace lineOffset { }
export = lineOffset;
export default function lineOffset<T extends LineString | MultiLineString>(
line: Feature<T> | T,
distance: number,
options?: {
units?: Units
}
): Feature<T>;

@@ -1,9 +0,5 @@

var meta = require('@turf/meta');
var helpers = require('@turf/helpers');
var getCoords = require('@turf/invariant').getCoords;
var intersection = require('./intersection');
var flattenEach = meta.flattenEach;
var lineString = helpers.lineString;
var multiLineString = helpers.multiLineString;
var distanceToDegrees = helpers.distanceToDegrees;
import { flattenEach } from '@turf/meta';
import { getCoords, getType } from '@turf/invariant';
import { isObject, lineString, multiLineString, lengthToDegrees } from '@turf/helpers';
import intersection from './lib/intersection';

@@ -16,3 +12,4 @@ /**

* @param {number} distance distance to offset the line (can be of negative value)
* @param {string} [units=kilometers] can be degrees, radians, miles, kilometers, inches, yards, meters
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, kilometers, inches, yards, meters
* @returns {Feature<LineString|MultiLineString>} Line offset from the input line

@@ -22,3 +19,3 @@ * @example

*
* var offsetLine = turf.lineOffset(line, 2, "miles");
* var offsetLine = turf.lineOffset(line, 2, {units: 'miles'});
*

@@ -29,6 +26,13 @@ * //addToMap

*/
module.exports = function (geojson, distance, units) {
function lineOffset(geojson, distance, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var units = options.units;
// Valdiation
if (!geojson) throw new Error('geojson is required');
if (distance === undefined || distance === null || isNaN(distance)) throw new Error('distance is required');
var type = (geojson.type === 'Feature') ? geojson.geometry.type : geojson.type;
var type = getType(geojson);
var properties = geojson.properties;

@@ -38,7 +42,7 @@

case 'LineString':
return lineOffset(geojson, distance, units);
return lineOffsetFeature(geojson, distance, units);
case 'MultiLineString':
var coords = [];
flattenEach(geojson, function (feature) {
coords.push(lineOffset(feature, distance, units).geometry.coordinates);
coords.push(lineOffsetFeature(feature, distance, units).geometry.coordinates);
});

@@ -49,3 +53,3 @@ return multiLineString(coords, properties);

}
};
}

@@ -61,5 +65,5 @@ /**

*/
function lineOffset(line, distance, units) {
function lineOffsetFeature(line, distance, units) {
var segments = [];
var offsetDegrees = distanceToDegrees(distance, units);
var offsetDegrees = lengthToDegrees(distance, units);
var coords = getCoords(line);

@@ -116,1 +120,3 @@ var finalCoords = [];

}
export default lineOffset;
{
"name": "@turf/line-offset",
"version": "4.7.3",
"version": "5.0.4",
"description": "turf line-offset module",
"main": "index.js",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",

@@ -10,7 +12,9 @@ "files": [

"index.d.ts",
"intersection.js"
"main.js",
"lib"
],
"scripts": {
"test": "node test.js",
"bench": "node bench.js"
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
},

@@ -39,13 +43,19 @@ "repository": {

"devDependencies": {
"@turf/truncate": "^4.7.3",
"benchmark": "^2.1.4",
"load-json-file": "^2.0.0",
"tape": "^4.6.3",
"write-json-file": "^2.0.0"
"@std/esm": "*",
"@turf/truncate": "^5.0.4",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/helpers": "^4.7.3",
"@turf/invariant": "^4.7.3",
"@turf/meta": "^4.7.3"
"@turf/helpers": "^5.0.4",
"@turf/invariant": "^5.0.4",
"@turf/meta": "^5.0.4"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}
# @turf/line-offset
# lineOffset
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## lineOffset
Takes a [line](http://geojson.org/geojson-spec.html#linestring) and returns a [line](http://geojson.org/geojson-spec.html#linestring) at offset by the specified distance.

@@ -11,3 +13,4 @@

- `distance` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance to offset the line (can be of negative value)
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** can be degrees, radians, miles, kilometers, inches, yards, meters (optional, default `kilometers`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** can be degrees, radians, miles, kilometers, inches, yards, meters (optional, default `'kilometers'`)

@@ -19,3 +22,3 @@ **Examples**

var offsetLine = turf.lineOffset(line, 2, "miles");
var offsetLine = turf.lineOffset(line, 2, {units: 'miles'});

@@ -29,12 +32,2 @@ //addToMap

# ab
<https://github.com/rook2pawn/node-intersection>
Author @rook2pawn
**Parameters**
- `segment`
<!-- This file is automatically generated. Please don't edit it directly:

@@ -41,0 +34,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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