Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/helpers

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/helpers - npm Package Compare versions

Comparing version 4.5.2 to 4.6.0

37

index.d.ts

@@ -25,2 +25,3 @@ /// <reference types="geojson" />

export type Geoms = GeoJSON.Point | GeoJSON.LineString | GeoJSON.Polygon | GeoJSON.MultiPoint | GeoJSON.MultiLineString | GeoJSON.MultiPolygon;
export type GeometryTypes = 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon';

@@ -31,11 +32,25 @@ export interface FeatureGeometryCollection extends GeoJSON.Feature<any> {

export interface FeatureCollection {
<Geom extends Geoms>(features: Feature<Geom>[], bbox?: BBox): Features<Geom>;
(features: Feature<any>[], bbox?: BBox): Features<any>;
}
export interface Properties {
[key: string]: any
}
/**
* http://turfjs.org/docs/#feature
*/
export function feature<Geom extends GeometryObject>(geometry: Geom, properties?: any): Feature<Geom>;
export function feature<Geom extends GeometryObject>(geometry: Geom, properties?: Properties, bbox?: BBox, id?: string|number): Feature<Geom>;
/**
* http://turfjs.org/docs/#geometry
*/
export function geometry(type: GeometryTypes, coordinates: any[], bbox?: BBox): GeometryObject;
/**
* http://turfjs.org/docs/#point
*/
export function point(coordinates: Position, properties?: any): Point;
export function point(coordinates: Position, properties?: Properties, bbox?: BBox, id?: string|number): Point;

@@ -45,3 +60,3 @@ /**

*/
export function polygon(coordinates: Position[][], properties?: any): Polygon;
export function polygon(coordinates: Position[][], properties?: Properties, bbox?: BBox, id?: string|number): Polygon;

@@ -51,3 +66,3 @@ /**

*/
export function lineString(coordinates: Position[], properties?: any): LineString;
export function lineString(coordinates: Position[], properties?: Properties, bbox?: BBox, id?: string|number): LineString;

@@ -57,7 +72,3 @@ /**

*/
interface featureCollection {
<Geom extends Geoms>(features: Feature<Geom>[]): Features<Geom>;
(features: Feature<any>[]): Features<any>;
}
export const featureCollection: featureCollection;
export const featureCollection: FeatureCollection;

@@ -67,3 +78,3 @@ /**

*/
export function multiLineString(coordinates: Position[][], properties?: any): MultiLineString;
export function multiLineString(coordinates: Position[][], properties?: Properties, bbox?: BBox, id?: string|number): MultiLineString;

@@ -73,3 +84,3 @@ /**

*/
export function multiPoint(coordinates: Position[], properties?: any): MultiPoint;
export function multiPoint(coordinates: Position[], properties?: Properties, bbox?: BBox, id?: string|number): MultiPoint;

@@ -79,3 +90,3 @@ /**

*/
export function multiPolygon(coordinates: Position[][][], properties?: any): MultiPolygon;
export function multiPolygon(coordinates: Position[][][], properties?: Properties, bbox?: BBox, id?: string|number): MultiPolygon;

@@ -85,3 +96,3 @@ /**

*/
export function geometryCollection(geometries: GeometryObject[], properties?: any): FeatureGeometryCollection;
export function geometryCollection(geometries: GeometryObject[], properties?: Properties, bbox?: BBox, id?: string|number): FeatureGeometryCollection;

@@ -88,0 +99,0 @@ /**

@@ -6,3 +6,5 @@ /**

* @param {Geometry} geometry input geometry
* @param {Object} properties properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature} a GeoJSON Feature

@@ -19,6 +21,7 @@ * @example

*/
function feature(geometry, properties) {
if (!geometry) throw new Error('No geometry passed');
function feature(geometry, properties, bbox, id) {
if (geometry === undefined) throw new Error('geometry is required');
if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
return {
var feat = {
type: 'Feature',

@@ -28,5 +31,51 @@ properties: properties || {},

};
if (bbox) {
if (bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
feat.bbox = bbox;
}
if (id) feat.id = id;
return feat;
}
/**
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
* For GeometryCollection type use `helpers.geometryCollection`
*
* @name geometry
* @param {string} type Geometry Type
* @param {Array<number>} coordinates Coordinates
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @returns {Geometry} a GeoJSON Geometry
* @example
* var type = 'Point';
* var coordinates = [110, 50];
*
* var geometry = turf.geometry(type, coordinates);
*
* //=geometry
*/
function geometry(type, coordinates, bbox) {
// Validation
if (!type) throw new Error('type is required');
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
var geom;
switch (type) {
case 'Point': geom = point(coordinates).geometry; break;
case 'LineString': geom = lineString(coordinates).geometry; break;
case 'Polygon': geom = polygon(coordinates).geometry; break;
case 'MultiPoint': geom = multiPoint(coordinates).geometry; break;
case 'MultiLineString': geom = multiLineString(coordinates).geometry; break;
case 'MultiPolygon': geom = multiPolygon(coordinates).geometry; break;
default: throw new Error(type + ' is invalid');
}
if (bbox) {
if (bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
geom.bbox = bbox;
}
return geom;
}
/**
* Takes coordinates and properties (optional) and returns a new {@link Point} feature.

@@ -36,4 +85,5 @@ *

* @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object=} properties an Object that is used as the {@link Feature}'s
* properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<Point>} a Point feature

@@ -45,3 +95,3 @@ * @example

*/
function point(coordinates, properties) {
function point(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -55,3 +105,3 @@ if (coordinates.length === undefined) throw new Error('Coordinates must be an array');

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -64,3 +114,5 @@

* @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
* @param {Object=} properties a properties object
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<Polygon>} a Polygon feature

@@ -80,3 +132,3 @@ * @throws {Error} throw an error if a LinearRing of the polygon has too few positions

*/
function polygon(coordinates, properties) {
function polygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -99,3 +151,3 @@

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -109,3 +161,5 @@

* @param {Array<Array<number>>} coordinates an array of Positions
* @param {Object=} properties an Object of key-value pairs to add as properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<LineString>} a LineString feature

@@ -131,3 +185,3 @@ * @throws {Error} if no coordinates are passed

*/
function lineString(coordinates, properties) {
function lineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -139,3 +193,3 @@ if (coordinates.length < 2) throw new Error('Coordinates must be an array of two or more positions');

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -148,2 +202,3 @@

* @param {Feature[]} features input features
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @returns {FeatureCollection} a FeatureCollection of input features

@@ -161,10 +216,12 @@ * @example

*/
function featureCollection(features) {
function featureCollection(features, bbox) {
if (!features) throw new Error('No features passed');
if (!Array.isArray(features)) throw new Error('features must be an Array');
return {
var fc = {
type: 'FeatureCollection',
features: features
};
if (bbox) fc.bbox = bbox;
return fc;
}

@@ -178,3 +235,5 @@

* @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
* @param {Object=} properties an Object of key-value pairs to add as properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiLineString>} a MultiLineString feature

@@ -187,3 +246,3 @@ * @throws {Error} if no coordinates are passed

*/
function multiLineString(coordinates, properties) {
function multiLineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -194,3 +253,3 @@

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -204,3 +263,5 @@

* @param {Array<Array<number>>} coordinates an array of Positions
* @param {Object=} properties an Object of key-value pairs to add as properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiPoint>} a MultiPoint feature

@@ -213,3 +274,3 @@ * @throws {Error} if no coordinates are passed

*/
function multiPoint(coordinates, properties) {
function multiPoint(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -220,3 +281,3 @@

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -230,3 +291,5 @@

* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
* @param {Object=} properties an Object of key-value pairs to add as properties
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiPolygon>} a multipolygon feature

@@ -240,3 +303,3 @@ * @throws {Error} if no coordinates are passed

*/
function multiPolygon(coordinates, properties) {
function multiPolygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');

@@ -247,3 +310,3 @@

coordinates: coordinates
}, properties);
}, properties, bbox, id);
}

@@ -256,4 +319,6 @@

* @name geometryCollection
* @param {Array<{Geometry}>} geometries an array of GeoJSON Geometries
* @param {Object=} properties an Object of key-value pairs to add as properties
* @param {Array<Geometry>} geometries an array of GeoJSON Geometries
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature

@@ -273,4 +338,5 @@ * @example

*/
function geometryCollection(geometries, properties) {
function geometryCollection(geometries, properties, bbox, id) {
if (!geometries) throw new Error('geometries is required');
if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');

@@ -280,3 +346,3 @@ return feature({

geometries: geometries
}, properties);
}, properties, bbox, id);
}

@@ -321,6 +387,6 @@

* @example
* round(120.4321)
* turf.round(120.4321)
* //=120
*
* round(120.4321, 2)
* turf.round(120.4321, 2)
* //=120.43

@@ -467,2 +533,3 @@ */

feature: feature,
geometry: geometry,
featureCollection: featureCollection,

@@ -469,0 +536,0 @@ geometryCollection: geometryCollection,

{
"name": "@turf/helpers",
"version": "4.5.2",
"version": "4.6.0",
"description": "turf helpers module",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -240,6 +240,6 @@ # @turf/helpers

```javascript
round(120.4321)
turf.round(120.4321)
//=120
round(120.4321, 2)
turf.round(120.4321, 2)
//=120.43

@@ -246,0 +246,0 @@ ```

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