@turf/helpers
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -10,13 +10,15 @@ /** | ||
*/ | ||
export var earthRadius = 6371008.8; | ||
export const earthRadius = 6371008.8; | ||
/** | ||
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius. | ||
* | ||
* Keys are the name of the unit, values are the number of that unit in a single radian | ||
* | ||
* @memberof helpers | ||
* @type {Object} | ||
*/ | ||
export var factors = { | ||
export const factors = { | ||
centimeters: earthRadius * 100, | ||
centimetres: earthRadius * 100, | ||
degrees: earthRadius / 111325, | ||
degrees: 360 / (2 * Math.PI), | ||
feet: earthRadius * 3.28084, | ||
@@ -36,25 +38,3 @@ inches: earthRadius * 39.37, | ||
/** | ||
* Units of measurement factors based on 1 meter. | ||
* | ||
* @memberof helpers | ||
* @type {Object} | ||
*/ | ||
export var unitsFactors = { | ||
centimeters: 100, | ||
centimetres: 100, | ||
degrees: 1 / 111325, | ||
feet: 3.28084, | ||
inches: 39.37, | ||
kilometers: 1 / 1000, | ||
kilometres: 1 / 1000, | ||
meters: 1, | ||
metres: 1, | ||
miles: 1 / 1609.344, | ||
millimeters: 1000, | ||
millimetres: 1000, | ||
nauticalmiles: 1 / 1852, | ||
radians: 1 / earthRadius, | ||
yards: 1.0936133, | ||
}; | ||
/** | ||
* Area of measurement factors based on 1 square meter. | ||
@@ -65,3 +45,3 @@ * | ||
*/ | ||
export var areaFactors = { | ||
export const areaFactors = { | ||
acres: 0.000247105, | ||
@@ -102,5 +82,4 @@ centimeters: 10000, | ||
*/ | ||
export function feature(geom, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var feat = { type: "Feature" }; | ||
export function feature(geom, properties, options = {}) { | ||
const feat = { type: "Feature" }; | ||
if (options.id === 0 || options.id) { | ||
@@ -131,4 +110,3 @@ feat.id = options.id; | ||
*/ | ||
export function geometry(type, coordinates, _options) { | ||
if (_options === void 0) { _options = {}; } | ||
export function geometry(type, coordinates, _options = {}) { | ||
switch (type) { | ||
@@ -166,4 +144,3 @@ case "Point": | ||
*/ | ||
export function point(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
export function point(coordinates, properties, options = {}) { | ||
if (!coordinates) { | ||
@@ -181,5 +158,5 @@ throw new Error("coordinates is required"); | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "Point", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -208,5 +185,4 @@ return feature(geom, properties, options); | ||
*/ | ||
export function points(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
export function points(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return point(coords, properties); | ||
@@ -230,10 +206,11 @@ }), options); | ||
*/ | ||
export function polygon(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) { | ||
var ring = coordinates_1[_i]; | ||
export function polygon(coordinates, properties, options = {}) { | ||
for (const ring of coordinates) { | ||
if (ring.length < 4) { | ||
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions."); | ||
} | ||
for (var j = 0; j < ring[ring.length - 1].length; j++) { | ||
if (ring[ring.length - 1].length !== ring[0].length) { | ||
throw new Error("First and last Position are not equivalent."); | ||
} | ||
for (let j = 0; j < ring[ring.length - 1].length; j++) { | ||
// Check if first point of Polygon contains two numbers | ||
@@ -245,5 +222,5 @@ if (ring[ring.length - 1][j] !== ring[0][j]) { | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "Polygon", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -270,5 +247,4 @@ return feature(geom, properties, options); | ||
*/ | ||
export function polygons(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
export function polygons(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return polygon(coords, properties); | ||
@@ -294,10 +270,9 @@ }), options); | ||
*/ | ||
export function lineString(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
export function lineString(coordinates, properties, options = {}) { | ||
if (coordinates.length < 2) { | ||
throw new Error("coordinates must be an array of two or more positions"); | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "LineString", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -325,5 +300,4 @@ return feature(geom, properties, options); | ||
*/ | ||
export function lineStrings(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
export function lineStrings(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return lineString(coords, properties); | ||
@@ -354,5 +328,4 @@ }), options); | ||
*/ | ||
export function featureCollection(features, options) { | ||
if (options === void 0) { options = {}; } | ||
var fc = { type: "FeatureCollection" }; | ||
export function featureCollection(features, options = {}) { | ||
const fc = { type: "FeatureCollection" }; | ||
if (options.id) { | ||
@@ -384,7 +357,6 @@ fc.id = options.id; | ||
*/ | ||
export function multiLineString(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
export function multiLineString(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiLineString", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -410,7 +382,6 @@ return feature(geom, properties, options); | ||
*/ | ||
export function multiPoint(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
export function multiPoint(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiPoint", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -437,7 +408,6 @@ return feature(geom, properties, options); | ||
*/ | ||
export function multiPolygon(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
export function multiPolygon(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiPolygon", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -464,7 +434,6 @@ return feature(geom, properties, options); | ||
*/ | ||
export function geometryCollection(geometries, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
export function geometryCollection(geometries, properties, options = {}) { | ||
const geom = { | ||
type: "GeometryCollection", | ||
geometries: geometries, | ||
geometries, | ||
}; | ||
@@ -486,8 +455,7 @@ return feature(geom, properties, options); | ||
*/ | ||
export function round(num, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
export function round(num, precision = 0) { | ||
if (precision && !(precision >= 0)) { | ||
throw new Error("precision must be a positive number"); | ||
} | ||
var multiplier = Math.pow(10, precision || 0); | ||
const multiplier = Math.pow(10, precision || 0); | ||
return Math.round(num * multiplier) / multiplier; | ||
@@ -505,5 +473,4 @@ } | ||
*/ | ||
export function radiansToLength(radians, units) { | ||
if (units === void 0) { units = "kilometers"; } | ||
var factor = factors[units]; | ||
export function radiansToLength(radians, units = "kilometers") { | ||
const factor = factors[units]; | ||
if (!factor) { | ||
@@ -524,5 +491,4 @@ throw new Error(units + " units is invalid"); | ||
*/ | ||
export function lengthToRadians(distance, units) { | ||
if (units === void 0) { units = "kilometers"; } | ||
var factor = factors[units]; | ||
export function lengthToRadians(distance, units = "kilometers") { | ||
const factor = factors[units]; | ||
if (!factor) { | ||
@@ -555,3 +521,3 @@ throw new Error(units + " units is invalid"); | ||
export function bearingToAzimuth(bearing) { | ||
var angle = bearing % 360; | ||
let angle = bearing % 360; | ||
if (angle < 0) { | ||
@@ -570,3 +536,3 @@ angle += 360; | ||
export function radiansToDegrees(radians) { | ||
var degrees = radians % (2 * Math.PI); | ||
const degrees = radians % (2 * Math.PI); | ||
return (degrees * 180) / Math.PI; | ||
@@ -582,3 +548,3 @@ } | ||
export function degreesToRadians(degrees) { | ||
var radians = degrees % 360; | ||
const radians = degrees % 360; | ||
return (radians * Math.PI) / 180; | ||
@@ -595,5 +561,3 @@ } | ||
*/ | ||
export function convertLength(length, originalUnit, finalUnit) { | ||
if (originalUnit === void 0) { originalUnit = "kilometers"; } | ||
if (finalUnit === void 0) { finalUnit = "kilometers"; } | ||
export function convertLength(length, originalUnit = "kilometers", finalUnit = "kilometers") { | ||
if (!(length >= 0)) { | ||
@@ -612,13 +576,11 @@ throw new Error("length must be a positive number"); | ||
*/ | ||
export function convertArea(area, originalUnit, finalUnit) { | ||
if (originalUnit === void 0) { originalUnit = "meters"; } | ||
if (finalUnit === void 0) { finalUnit = "kilometers"; } | ||
export function convertArea(area, originalUnit = "meters", finalUnit = "kilometers") { | ||
if (!(area >= 0)) { | ||
throw new Error("area must be a positive number"); | ||
} | ||
var startFactor = areaFactors[originalUnit]; | ||
const startFactor = areaFactors[originalUnit]; | ||
if (!startFactor) { | ||
throw new Error("invalid original units"); | ||
} | ||
var finalFactor = areaFactors[finalUnit]; | ||
const finalFactor = areaFactors[finalUnit]; | ||
if (!finalFactor) { | ||
@@ -647,3 +609,3 @@ throw new Error("invalid final units"); | ||
* @param {*} input variable to validate | ||
* @returns {boolean} true/false | ||
* @returns {boolean} true/false, including false for Arrays and Functions | ||
* @example | ||
@@ -656,3 +618,3 @@ * turf.isObject({elevation: 10}) | ||
export function isObject(input) { | ||
return !!input && input.constructor === Object; | ||
return input !== null && typeof input === "object" && !Array.isArray(input); | ||
} | ||
@@ -665,3 +627,3 @@ /** | ||
* @returns {void} | ||
* @throws Error if BBox is not valid | ||
* @throws {Error} if BBox is not valid | ||
* @example | ||
@@ -691,3 +653,3 @@ * validateBBox([-180, -40, 110, 50]) | ||
} | ||
bbox.forEach(function (num) { | ||
bbox.forEach((num) => { | ||
if (!isNumber(num)) { | ||
@@ -704,3 +666,3 @@ throw new Error("bbox must only contain numbers"); | ||
* @returns {void} | ||
* @throws Error if Id is not valid | ||
* @throws {Error} if Id is not valid | ||
* @example | ||
@@ -707,0 +669,0 @@ * validateId([-180, -40, 110, 50]) |
@@ -1,5 +0,6 @@ | ||
import { BBox, CollectionTypes, Feature, FeatureCollection, GeoJSONObject, Geometries, Geometry, GeometryCollection, GeometryObject, GeometryTypes, Id, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Position, Properties, Types } from "./lib/geojson"; | ||
export { Id, Properties, BBox, Position, Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryObject, GeoJSONObject, GeometryCollection, Geometry, GeometryTypes, Types, CollectionTypes, Geometries, Feature, FeatureCollection, }; | ||
import { BBox, Feature, FeatureCollection, Geometry, GeometryCollection, GeometryObject, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon, Position, GeoJsonProperties } from "geojson"; | ||
import { Id } from "./lib/geojson"; | ||
export * from "./lib/geojson"; | ||
export declare type Coord = Feature<Point> | Point | Position; | ||
export declare type Units = "meters" | "millimeters" | "centimeters" | "kilometers" | "acres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees" | "hectares"; | ||
export declare type Units = "meters" | "metres" | "millimeters" | "millimetres" | "centimeters" | "centimetres" | "kilometers" | "kilometres" | "acres" | "miles" | "nauticalmiles" | "inches" | "yards" | "feet" | "radians" | "degrees" | "hectares"; | ||
export declare type Grid = "point" | "square" | "hex" | "triangle"; | ||
@@ -18,14 +19,17 @@ export declare type Corners = "sw" | "se" | "nw" | "ne" | "center" | "centroid"; | ||
*/ | ||
export declare let earthRadius: number; | ||
export declare const earthRadius = 6371008.8; | ||
/** | ||
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius. | ||
* | ||
* Keys are the name of the unit, values are the number of that unit in a single radian | ||
* | ||
* @memberof helpers | ||
* @type {Object} | ||
*/ | ||
export declare let factors: { | ||
export declare const factors: { | ||
[key: string]: number; | ||
}; | ||
/** | ||
* Units of measurement factors based on 1 meter. | ||
* Area of measurement factors based on 1 square meter. | ||
* | ||
@@ -35,13 +39,6 @@ * @memberof helpers | ||
*/ | ||
export declare let unitsFactors: { | ||
export declare const areaFactors: { | ||
[key: string]: number; | ||
}; | ||
/** | ||
* Area of measurement factors based on 1 square meter. | ||
* | ||
* @memberof helpers | ||
* @type {Object} | ||
*/ | ||
export declare let areaFactors: any; | ||
/** | ||
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}. | ||
@@ -66,3 +63,3 @@ * | ||
*/ | ||
export declare function feature<G = Geometry, P = Properties>(geom: G, properties?: P, options?: { | ||
export declare function feature<G extends GeometryObject = Geometry, P = GeoJsonProperties>(geom: G | null, properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -86,3 +83,3 @@ id?: Id; | ||
*/ | ||
export declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon; | ||
export declare function geometry(type: "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon", coordinates: any[], _options?: Record<string, never>): Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon; | ||
/** | ||
@@ -103,3 +100,3 @@ * Creates a {@link Point} {@link Feature} from a Position. | ||
*/ | ||
export declare function point<P = Properties>(coordinates: Position, properties?: P, options?: { | ||
export declare function point<P = GeoJsonProperties>(coordinates: Position, properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -128,3 +125,3 @@ id?: Id; | ||
*/ | ||
export declare function points<P = Properties>(coordinates: Position[], properties?: P, options?: { | ||
export declare function points<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -148,3 +145,3 @@ id?: Id; | ||
*/ | ||
export declare function polygon<P = Properties>(coordinates: Position[][], properties?: P, options?: { | ||
export declare function polygon<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -171,3 +168,3 @@ id?: Id; | ||
*/ | ||
export declare function polygons<P = Properties>(coordinates: Position[][][], properties?: P, options?: { | ||
export declare function polygons<P = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -193,3 +190,3 @@ id?: Id; | ||
*/ | ||
export declare function lineString<P = Properties>(coordinates: Position[], properties?: P, options?: { | ||
export declare function lineString<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -217,3 +214,3 @@ id?: Id; | ||
*/ | ||
export declare function lineStrings<P = Properties>(coordinates: Position[][], properties?: P, options?: { | ||
export declare function lineStrings<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -244,3 +241,3 @@ id?: Id; | ||
*/ | ||
export declare function featureCollection<G = Geometry, P = Properties>(features: Array<Feature<G, P>>, options?: { | ||
export declare function featureCollection<G extends GeometryObject = Geometry, P = GeoJsonProperties>(features: Array<Feature<G, P>>, options?: { | ||
bbox?: BBox; | ||
@@ -266,3 +263,3 @@ id?: Id; | ||
*/ | ||
export declare function multiLineString<P = Properties>(coordinates: Position[][], properties?: P, options?: { | ||
export declare function multiLineString<P = GeoJsonProperties>(coordinates: Position[][], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -288,3 +285,3 @@ id?: Id; | ||
*/ | ||
export declare function multiPoint<P = Properties>(coordinates: Position[], properties?: P, options?: { | ||
export declare function multiPoint<P = GeoJsonProperties>(coordinates: Position[], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -311,3 +308,3 @@ id?: Id; | ||
*/ | ||
export declare function multiPolygon<P = Properties>(coordinates: Position[][][], properties?: P, options?: { | ||
export declare function multiPolygon<P = GeoJsonProperties>(coordinates: Position[][][], properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -334,3 +331,3 @@ id?: Id; | ||
*/ | ||
export declare function geometryCollection<P = Properties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: { | ||
export declare function geometryCollection<P = GeoJsonProperties>(geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>, properties?: P, options?: { | ||
bbox?: BBox; | ||
@@ -446,3 +443,3 @@ id?: Id; | ||
* @param {*} input variable to validate | ||
* @returns {boolean} true/false | ||
* @returns {boolean} true/false, including false for Arrays and Functions | ||
* @example | ||
@@ -461,3 +458,3 @@ * turf.isObject({elevation: 10}) | ||
* @returns {void} | ||
* @throws Error if BBox is not valid | ||
* @throws {Error} if BBox is not valid | ||
* @example | ||
@@ -484,3 +481,3 @@ * validateBBox([-180, -40, 110, 50]) | ||
* @returns {void} | ||
* @throws Error if Id is not valid | ||
* @throws {Error} if Id is not valid | ||
* @example | ||
@@ -487,0 +484,0 @@ * validateId([-180, -40, 110, 50]) |
@@ -16,2 +16,4 @@ "use strict"; | ||
* | ||
* Keys are the name of the unit, values are the number of that unit in a single radian | ||
* | ||
* @memberof helpers | ||
@@ -23,3 +25,3 @@ * @type {Object} | ||
centimetres: exports.earthRadius * 100, | ||
degrees: exports.earthRadius / 111325, | ||
degrees: 360 / (2 * Math.PI), | ||
feet: exports.earthRadius * 3.28084, | ||
@@ -39,25 +41,3 @@ inches: exports.earthRadius * 39.37, | ||
/** | ||
* Units of measurement factors based on 1 meter. | ||
* | ||
* @memberof helpers | ||
* @type {Object} | ||
*/ | ||
exports.unitsFactors = { | ||
centimeters: 100, | ||
centimetres: 100, | ||
degrees: 1 / 111325, | ||
feet: 3.28084, | ||
inches: 39.37, | ||
kilometers: 1 / 1000, | ||
kilometres: 1 / 1000, | ||
meters: 1, | ||
metres: 1, | ||
miles: 1 / 1609.344, | ||
millimeters: 1000, | ||
millimetres: 1000, | ||
nauticalmiles: 1 / 1852, | ||
radians: 1 / exports.earthRadius, | ||
yards: 1.0936133, | ||
}; | ||
/** | ||
* Area of measurement factors based on 1 square meter. | ||
@@ -104,5 +84,4 @@ * | ||
*/ | ||
function feature(geom, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var feat = { type: "Feature" }; | ||
function feature(geom, properties, options = {}) { | ||
const feat = { type: "Feature" }; | ||
if (options.id === 0 || options.id) { | ||
@@ -134,4 +113,3 @@ feat.id = options.id; | ||
*/ | ||
function geometry(type, coordinates, _options) { | ||
if (_options === void 0) { _options = {}; } | ||
function geometry(type, coordinates, _options = {}) { | ||
switch (type) { | ||
@@ -170,4 +148,3 @@ case "Point": | ||
*/ | ||
function point(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
function point(coordinates, properties, options = {}) { | ||
if (!coordinates) { | ||
@@ -185,5 +162,5 @@ throw new Error("coordinates is required"); | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "Point", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -213,5 +190,4 @@ return feature(geom, properties, options); | ||
*/ | ||
function points(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
function points(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return point(coords, properties); | ||
@@ -236,10 +212,11 @@ }), options); | ||
*/ | ||
function polygon(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) { | ||
var ring = coordinates_1[_i]; | ||
function polygon(coordinates, properties, options = {}) { | ||
for (const ring of coordinates) { | ||
if (ring.length < 4) { | ||
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions."); | ||
} | ||
for (var j = 0; j < ring[ring.length - 1].length; j++) { | ||
if (ring[ring.length - 1].length !== ring[0].length) { | ||
throw new Error("First and last Position are not equivalent."); | ||
} | ||
for (let j = 0; j < ring[ring.length - 1].length; j++) { | ||
// Check if first point of Polygon contains two numbers | ||
@@ -251,5 +228,5 @@ if (ring[ring.length - 1][j] !== ring[0][j]) { | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "Polygon", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -277,5 +254,4 @@ return feature(geom, properties, options); | ||
*/ | ||
function polygons(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
function polygons(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return polygon(coords, properties); | ||
@@ -302,10 +278,9 @@ }), options); | ||
*/ | ||
function lineString(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
function lineString(coordinates, properties, options = {}) { | ||
if (coordinates.length < 2) { | ||
throw new Error("coordinates must be an array of two or more positions"); | ||
} | ||
var geom = { | ||
const geom = { | ||
type: "LineString", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -334,5 +309,4 @@ return feature(geom, properties, options); | ||
*/ | ||
function lineStrings(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
return featureCollection(coordinates.map(function (coords) { | ||
function lineStrings(coordinates, properties, options = {}) { | ||
return featureCollection(coordinates.map((coords) => { | ||
return lineString(coords, properties); | ||
@@ -364,5 +338,4 @@ }), options); | ||
*/ | ||
function featureCollection(features, options) { | ||
if (options === void 0) { options = {}; } | ||
var fc = { type: "FeatureCollection" }; | ||
function featureCollection(features, options = {}) { | ||
const fc = { type: "FeatureCollection" }; | ||
if (options.id) { | ||
@@ -395,7 +368,6 @@ fc.id = options.id; | ||
*/ | ||
function multiLineString(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
function multiLineString(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiLineString", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -422,7 +394,6 @@ return feature(geom, properties, options); | ||
*/ | ||
function multiPoint(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
function multiPoint(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiPoint", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -450,7 +421,6 @@ return feature(geom, properties, options); | ||
*/ | ||
function multiPolygon(coordinates, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
function multiPolygon(coordinates, properties, options = {}) { | ||
const geom = { | ||
type: "MultiPolygon", | ||
coordinates: coordinates, | ||
coordinates, | ||
}; | ||
@@ -478,7 +448,6 @@ return feature(geom, properties, options); | ||
*/ | ||
function geometryCollection(geometries, properties, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom = { | ||
function geometryCollection(geometries, properties, options = {}) { | ||
const geom = { | ||
type: "GeometryCollection", | ||
geometries: geometries, | ||
geometries, | ||
}; | ||
@@ -501,8 +470,7 @@ return feature(geom, properties, options); | ||
*/ | ||
function round(num, precision) { | ||
if (precision === void 0) { precision = 0; } | ||
function round(num, precision = 0) { | ||
if (precision && !(precision >= 0)) { | ||
throw new Error("precision must be a positive number"); | ||
} | ||
var multiplier = Math.pow(10, precision || 0); | ||
const multiplier = Math.pow(10, precision || 0); | ||
return Math.round(num * multiplier) / multiplier; | ||
@@ -521,5 +489,4 @@ } | ||
*/ | ||
function radiansToLength(radians, units) { | ||
if (units === void 0) { units = "kilometers"; } | ||
var factor = exports.factors[units]; | ||
function radiansToLength(radians, units = "kilometers") { | ||
const factor = exports.factors[units]; | ||
if (!factor) { | ||
@@ -541,5 +508,4 @@ throw new Error(units + " units is invalid"); | ||
*/ | ||
function lengthToRadians(distance, units) { | ||
if (units === void 0) { units = "kilometers"; } | ||
var factor = exports.factors[units]; | ||
function lengthToRadians(distance, units = "kilometers") { | ||
const factor = exports.factors[units]; | ||
if (!factor) { | ||
@@ -574,3 +540,3 @@ throw new Error(units + " units is invalid"); | ||
function bearingToAzimuth(bearing) { | ||
var angle = bearing % 360; | ||
let angle = bearing % 360; | ||
if (angle < 0) { | ||
@@ -590,3 +556,3 @@ angle += 360; | ||
function radiansToDegrees(radians) { | ||
var degrees = radians % (2 * Math.PI); | ||
const degrees = radians % (2 * Math.PI); | ||
return (degrees * 180) / Math.PI; | ||
@@ -603,3 +569,3 @@ } | ||
function degreesToRadians(degrees) { | ||
var radians = degrees % 360; | ||
const radians = degrees % 360; | ||
return (radians * Math.PI) / 180; | ||
@@ -617,5 +583,3 @@ } | ||
*/ | ||
function convertLength(length, originalUnit, finalUnit) { | ||
if (originalUnit === void 0) { originalUnit = "kilometers"; } | ||
if (finalUnit === void 0) { finalUnit = "kilometers"; } | ||
function convertLength(length, originalUnit = "kilometers", finalUnit = "kilometers") { | ||
if (!(length >= 0)) { | ||
@@ -635,13 +599,11 @@ throw new Error("length must be a positive number"); | ||
*/ | ||
function convertArea(area, originalUnit, finalUnit) { | ||
if (originalUnit === void 0) { originalUnit = "meters"; } | ||
if (finalUnit === void 0) { finalUnit = "kilometers"; } | ||
function convertArea(area, originalUnit = "meters", finalUnit = "kilometers") { | ||
if (!(area >= 0)) { | ||
throw new Error("area must be a positive number"); | ||
} | ||
var startFactor = exports.areaFactors[originalUnit]; | ||
const startFactor = exports.areaFactors[originalUnit]; | ||
if (!startFactor) { | ||
throw new Error("invalid original units"); | ||
} | ||
var finalFactor = exports.areaFactors[finalUnit]; | ||
const finalFactor = exports.areaFactors[finalUnit]; | ||
if (!finalFactor) { | ||
@@ -672,3 +634,3 @@ throw new Error("invalid final units"); | ||
* @param {*} input variable to validate | ||
* @returns {boolean} true/false | ||
* @returns {boolean} true/false, including false for Arrays and Functions | ||
* @example | ||
@@ -681,3 +643,3 @@ * turf.isObject({elevation: 10}) | ||
function isObject(input) { | ||
return !!input && input.constructor === Object; | ||
return input !== null && typeof input === "object" && !Array.isArray(input); | ||
} | ||
@@ -691,3 +653,3 @@ exports.isObject = isObject; | ||
* @returns {void} | ||
* @throws Error if BBox is not valid | ||
* @throws {Error} if BBox is not valid | ||
* @example | ||
@@ -717,3 +679,3 @@ * validateBBox([-180, -40, 110, 50]) | ||
} | ||
bbox.forEach(function (num) { | ||
bbox.forEach((num) => { | ||
if (!isNumber(num)) { | ||
@@ -731,3 +693,3 @@ throw new Error("bbox must only contain numbers"); | ||
* @returns {void} | ||
* @throws Error if Id is not valid | ||
* @throws {Error} if Id is not valid | ||
* @example | ||
@@ -734,0 +696,0 @@ * validateId([-180, -40, 110, 50]) |
/** | ||
* GeometryTypes | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-1.4 | ||
* The valid values for the "type" property of GeoJSON geometry objects. | ||
*/ | ||
export declare type GeometryTypes = "Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon" | "GeometryCollection"; | ||
export declare type CollectionTypes = "FeatureCollection" | "GeometryCollection"; | ||
/** | ||
* Types | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-1.4 | ||
* The value values for the "type" property of GeoJSON Objects. | ||
*/ | ||
export declare type Types = "Feature" | GeometryTypes | CollectionTypes; | ||
/** | ||
* Bounding box | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-5 | ||
* A GeoJSON object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections. | ||
* The value of the bbox member MUST be an array of length 2*n where n is the number of dimensions represented in the contained geometries, | ||
* with all axes of the most southwesterly point followed by all axes of the more northeasterly point. | ||
* The axes order of a bbox follows the axes order of geometries. | ||
*/ | ||
export declare type BBox2d = [number, number, number, number]; | ||
export declare type BBox3d = [number, number, number, number, number, number]; | ||
export declare type BBox = BBox2d | BBox3d; | ||
/** | ||
* Id | ||
@@ -34,161 +7,5 @@ * | ||
* the Feature object with the name "id", and the value of this member is either a JSON string or number. | ||
* | ||
* Should be contributed to @types/geojson | ||
*/ | ||
export declare type Id = string | number; | ||
/** | ||
* Position | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.1 | ||
* Array should contain between two and three elements. | ||
* The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values), | ||
* but the current specification only allows X, Y, and (optionally) Z to be defined. | ||
*/ | ||
export declare type Position = number[]; | ||
/** | ||
* Properties | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.2 | ||
* A Feature object has a member with the name "properties". | ||
* The value of the properties member is an object (any JSON object or a JSON null value). | ||
*/ | ||
export declare type Properties = { | ||
[name: string]: any; | ||
} | null; | ||
/** | ||
* Geometries | ||
*/ | ||
export declare type Geometries = Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon; | ||
/** | ||
* GeoJSON Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3 | ||
* The GeoJSON specification also allows [foreign members](https://tools.ietf.org/html/rfc7946#section-6.1) | ||
* Developers should use "&" type in TypeScript or extend the interface to add these foreign members. | ||
*/ | ||
export interface GeoJSONObject { | ||
/** | ||
* Specifies the type of GeoJSON object. | ||
*/ | ||
type: string; | ||
/** | ||
* Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections. | ||
* https://tools.ietf.org/html/rfc7946#section-5 | ||
*/ | ||
bbox?: BBox; | ||
} | ||
/** | ||
* Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3 | ||
*/ | ||
export interface GeometryObject extends GeoJSONObject { | ||
type: GeometryTypes; | ||
} | ||
/** | ||
* Geometry | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3 | ||
*/ | ||
export interface Geometry extends GeoJSONObject { | ||
coordinates: Position | Position[] | Position[][] | Position[][][]; | ||
} | ||
/** | ||
* Point Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
*/ | ||
export interface Point extends GeometryObject { | ||
type: "Point"; | ||
coordinates: Position; | ||
} | ||
/** | ||
* MultiPoint Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.3 | ||
*/ | ||
export interface MultiPoint extends GeometryObject { | ||
type: "MultiPoint"; | ||
coordinates: Position[]; | ||
} | ||
/** | ||
* LineString Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
*/ | ||
export interface LineString extends GeometryObject { | ||
type: "LineString"; | ||
coordinates: Position[]; | ||
} | ||
/** | ||
* MultiLineString Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.5 | ||
*/ | ||
export interface MultiLineString extends GeometryObject { | ||
type: "MultiLineString"; | ||
coordinates: Position[][]; | ||
} | ||
/** | ||
* Polygon Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
*/ | ||
export interface Polygon extends GeometryObject { | ||
type: "Polygon"; | ||
coordinates: Position[][]; | ||
} | ||
/** | ||
* MultiPolygon Geometry Object | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
*/ | ||
export interface MultiPolygon extends GeometryObject { | ||
type: "MultiPolygon"; | ||
coordinates: Position[][][]; | ||
} | ||
/** | ||
* GeometryCollection | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.1.8 | ||
* | ||
* A GeoJSON object with type "GeometryCollection" is a Geometry object. | ||
* A GeometryCollection has a member with the name "geometries". | ||
* The value of "geometries" is an array. Each element of this array is a GeoJSON Geometry object. | ||
* It is possible for this array to be empty. | ||
*/ | ||
export interface GeometryCollection extends GeometryObject { | ||
type: "GeometryCollection"; | ||
geometries: Array<Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon>; | ||
} | ||
/** | ||
* Feature | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.2 | ||
* A Feature object represents a spatially bounded thing. | ||
* Every Feature object is a GeoJSON object no matter where it occurs in a GeoJSON text. | ||
*/ | ||
export interface Feature<G = Geometry | GeometryCollection, P = Properties> extends GeoJSONObject { | ||
type: "Feature"; | ||
geometry: G; | ||
/** | ||
* A value that uniquely identifies this feature in a | ||
* https://tools.ietf.org/html/rfc7946#section-3.2. | ||
*/ | ||
id?: Id; | ||
/** | ||
* Properties associated with this feature. | ||
*/ | ||
properties: P; | ||
} | ||
/** | ||
* Feature Collection | ||
* | ||
* https://tools.ietf.org/html/rfc7946#section-3.3 | ||
* A GeoJSON object with the type "FeatureCollection" is a FeatureCollection object. | ||
* A FeatureCollection object has a member with the name "features". | ||
* The value of "features" is a JSON array. Each element of the array is a Feature object as defined above. | ||
* It is possible for this array to be empty. | ||
*/ | ||
export interface FeatureCollection<G = Geometry | GeometryCollection, P = Properties> extends GeoJSONObject { | ||
type: "FeatureCollection"; | ||
features: Array<Feature<G, P>>; | ||
} |
"use strict"; | ||
// Type definitions for geojson 7946.0 | ||
// Project: https://geojson.org/ | ||
// Definitions by: Jacob Bruun <https://github.com/cobster> | ||
// Arne Schubert <https://github.com/atd-schubert> | ||
// Jeff Jacobson <https://github.com/JeffJacobson> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.3 | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "@turf/helpers", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf helpers module", | ||
@@ -53,3 +53,3 @@ "author": "Turf Authors", | ||
"test:tape": "ts-node -r esm test.js", | ||
"test:types": "tsc --esModuleInterop --noEmit types.ts" | ||
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts" | ||
}, | ||
@@ -65,3 +65,6 @@ "devDependencies": { | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
372
README.md
@@ -5,32 +5,39 @@ # @turf/helpers | ||
## earthRadius | ||
## helpers | ||
### earthRadius | ||
Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth. | ||
## factors | ||
Type: [number][1] | ||
### factors | ||
Unit of measurement factors using a spherical (non-ellipsoid) earth radius. | ||
## unitsFactors | ||
Keys are the name of the unit, values are the number of that unit in a single radian | ||
Units of measurement factors based on 1 meter. | ||
Type: [Object][2] | ||
## areaFactors | ||
### areaFactors | ||
Area of measurement factors based on 1 square meter. | ||
Type: [Object][2] | ||
## feature | ||
Wraps a GeoJSON [Geometry][1] in a GeoJSON [Feature][2]. | ||
Wraps a GeoJSON [Geometry][3] in a GeoJSON [Feature][4]. | ||
**Parameters** | ||
### Parameters | ||
- `geometry` **[Geometry][3]** input geometry | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `geometry` **[Geometry][5]** input geometry | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -51,39 +58,37 @@ var geometry = { | ||
Creates a GeoJSON [Geometry][1] from a Geometry string type & coordinates. | ||
Creates a GeoJSON [Geometry][3] from a Geometry string type & coordinates. | ||
For GeometryCollection type use `helpers.geometryCollection` | ||
**Parameters** | ||
### Parameters | ||
- `type` **[string][7]** Geometry Type | ||
- `coordinates` **[Array][5]<[number][6]>** Coordinates | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Geometry | ||
* `type` **[string][7]** Geometry Type | ||
* `coordinates` **[Array][6]\<any>** Coordinates | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
### Examples | ||
```javascript | ||
var type = 'Point'; | ||
var type = "Point"; | ||
var coordinates = [110, 50]; | ||
var geometry = turf.geometry(type, coordinates); | ||
//=geometry | ||
// => geometry | ||
``` | ||
Returns **[Geometry][3]** a GeoJSON Geometry | ||
Returns **[Geometry][5]** a GeoJSON Geometry | ||
## point | ||
Creates a [Point][9] [Feature][2] from a Position. | ||
Creates a [Point][9] [Feature][4] from a Position. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[number][6]>** longitude, latitude position (each in decimal degrees) | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[number][1]>** longitude, latitude position (each in decimal degrees) | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -95,3 +100,3 @@ var point = turf.point([-75.343, 39.984]); | ||
Returns **[Feature][8]<[Point][10]>** a Point feature | ||
Returns **[Feature][8]<[Point][10]>** a Point feature | ||
@@ -102,12 +107,14 @@ ## points | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[number][6]>>** an array of Points | ||
- `properties` **[Object][4]** Translate these properties to each Feature (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the FeatureCollection | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the FeatureCollection | ||
* `coordinates` **[Array][6]<[Array][6]<[number][1]>>** an array of Points | ||
* `properties` **[Object][2]** Translate these properties to each Feature (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] | ||
associated with the FeatureCollection | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the FeatureCollection | ||
### Examples | ||
```javascript | ||
@@ -123,18 +130,19 @@ var points = turf.points([ | ||
Returns **[FeatureCollection][12]<[Point][10]>** Point Feature | ||
Returns **[FeatureCollection][12]<[Point][10]>** Point Feature | ||
## polygon | ||
Creates a [Polygon][13] [Feature][2] from an Array of LinearRings. | ||
Creates a [Polygon][13] [Feature][4] from an Array of LinearRings. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[Array][5]<[number][6]>>>** an array of LinearRings | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[Array][6]<[Array][6]<[number][1]>>>** an array of LinearRings | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -146,3 +154,3 @@ var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' }); | ||
Returns **[Feature][8]<[Polygon][14]>** Polygon Feature | ||
Returns **[Feature][8]<[Polygon][14]>** Polygon Feature | ||
@@ -153,12 +161,13 @@ ## polygons | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[Array][5]<[Array][5]<[number][6]>>>>** an array of Polygon coordinates | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the FeatureCollection | ||
* `coordinates` **[Array][6]<[Array][6]<[Array][6]<[Array][6]<[number][1]>>>>** an array of Polygon coordinates | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the FeatureCollection | ||
### Examples | ||
```javascript | ||
@@ -173,18 +182,19 @@ var polygons = turf.polygons([ | ||
Returns **[FeatureCollection][12]<[Polygon][14]>** Polygon FeatureCollection | ||
Returns **[FeatureCollection][12]<[Polygon][14]>** Polygon FeatureCollection | ||
## lineString | ||
Creates a [LineString][15] [Feature][2] from an Array of Positions. | ||
Creates a [LineString][15] [Feature][4] from an Array of Positions. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[number][6]>>** an array of Positions | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[Array][6]<[number][1]>>** an array of Positions | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -198,3 +208,3 @@ var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'}); | ||
Returns **[Feature][8]<[LineString][16]>** LineString Feature | ||
Returns **[Feature][8]<[LineString][16]>** LineString Feature | ||
@@ -205,12 +215,14 @@ ## lineStrings | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[number][6]>>** an array of LinearRings | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the FeatureCollection | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the FeatureCollection | ||
* `coordinates` **[Array][6]<[Array][6]<[Array][6]<[number][1]>>>** an array of LinearRings | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] | ||
associated with the FeatureCollection | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the FeatureCollection | ||
### Examples | ||
```javascript | ||
@@ -225,17 +237,18 @@ var linestrings = turf.lineStrings([ | ||
Returns **[FeatureCollection][12]<[LineString][16]>** LineString FeatureCollection | ||
Returns **[FeatureCollection][12]<[LineString][16]>** LineString FeatureCollection | ||
## featureCollection | ||
Takes one or more [Features][2] and creates a [FeatureCollection][11]. | ||
Takes one or more [Features][4] and creates a [FeatureCollection][11]. | ||
**Parameters** | ||
### Parameters | ||
- `features` **[Array][5]<[Feature][8]>** input features | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `features` **[Array][6]<[Feature][8]>** input features | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -259,15 +272,16 @@ var locationA = turf.point([-75.343, 39.984], {name: 'Location A'}); | ||
Creates a [Feature<MultiLineString>][17] based on a | ||
Creates a [Feature\<MultiLineString>][17] based on a | ||
coordinate array. Properties can be added optionally. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[Array][5]<[number][6]>>>** an array of LineStrings | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[Array][6]<[Array][6]<[number][1]>>>** an array of LineStrings | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -279,21 +293,22 @@ var multiLine = turf.multiLineString([[[0,0],[10,10]]]); | ||
- Throws **[Error][18]** if no coordinates are passed | ||
* Throws **[Error][18]** if no coordinates are passed | ||
Returns **[Feature][8]<[MultiLineString][19]>** a MultiLineString feature | ||
Returns **[Feature][8]<[MultiLineString][19]>** a MultiLineString feature | ||
## multiPoint | ||
Creates a [Feature<MultiPoint>][20] based on a | ||
Creates a [Feature\<MultiPoint>][20] based on a | ||
coordinate array. Properties can be added optionally. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[number][6]>>** an array of Positions | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[Array][6]<[number][1]>>** an array of Positions | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -305,21 +320,22 @@ var multiPt = turf.multiPoint([[0,0],[10,10]]); | ||
- Throws **[Error][18]** if no coordinates are passed | ||
* Throws **[Error][18]** if no coordinates are passed | ||
Returns **[Feature][8]<[MultiPoint][21]>** a MultiPoint feature | ||
Returns **[Feature][8]<[MultiPoint][21]>** a MultiPoint feature | ||
## multiPolygon | ||
Creates a [Feature<MultiPolygon>][22] based on a | ||
Creates a [Feature\<MultiPolygon>][22] based on a | ||
coordinate array. Properties can be added optionally. | ||
**Parameters** | ||
### Parameters | ||
- `coordinates` **[Array][5]<[Array][5]<[Array][5]<[Array][5]<[number][6]>>>>** an array of Polygons | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `coordinates` **[Array][6]<[Array][6]<[Array][6]<[Array][6]<[number][1]>>>>** an array of Polygons | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
@@ -331,36 +347,31 @@ var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]); | ||
- Throws **[Error][18]** if no coordinates are passed | ||
* Throws **[Error][18]** if no coordinates are passed | ||
Returns **[Feature][8]<[MultiPolygon][23]>** a multipolygon feature | ||
Returns **[Feature][8]<[MultiPolygon][23]>** a multipolygon feature | ||
## geometryCollection | ||
Creates a [Feature<GeometryCollection>][24] based on a | ||
Creates a [Feature\<GeometryCollection>][24] based on a | ||
coordinate array. Properties can be added optionally. | ||
**Parameters** | ||
### Parameters | ||
- `geometries` **[Array][5]<[Geometry][3]>** an array of GeoJSON Geometries | ||
- `properties` **[Object][4]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
- `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
- `options.bbox` **[Array][5]<[number][6]>?** Bounding Box Array [west, south, east, north] associated with the Feature | ||
- `options.id` **([string][7] \| [number][6])?** Identifier associated with the Feature | ||
* `geometries` **[Array][6]<[Geometry][5]>** an array of GeoJSON Geometries | ||
* `properties` **[Object][2]** an Object of key-value pairs to add as properties (optional, default `{}`) | ||
* `options` **[Object][2]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.bbox` **[Array][6]<[number][1]>?** Bounding Box Array \[west, south, east, north] associated with the Feature | ||
* `options.id` **([string][7] | [number][1])?** Identifier associated with the Feature | ||
### Examples | ||
```javascript | ||
var pt = { | ||
"type": "Point", | ||
"coordinates": [100, 0] | ||
}; | ||
var line = { | ||
"type": "LineString", | ||
"coordinates": [ [101, 0], [102, 1] ] | ||
}; | ||
var pt = turf.geometry("Point", [100, 0]); | ||
var line = turf.geometry("LineString", [[101, 0], [102, 1]]); | ||
var collection = turf.geometryCollection([pt, line]); | ||
//=collection | ||
// => collection | ||
``` | ||
Returns **[Feature][8]<[GeometryCollection][25]>** a GeoJSON GeometryCollection Feature | ||
Returns **[Feature][8]<[GeometryCollection][25]>** a GeoJSON GeometryCollection Feature | ||
@@ -371,8 +382,8 @@ ## round | ||
**Parameters** | ||
### Parameters | ||
- `num` **[number][6]** Number | ||
- `precision` **[number][6]** Precision (optional, default `0`) | ||
* `num` **[number][1]** Number | ||
* `precision` **[number][1]** Precision (optional, default `0`) | ||
**Examples** | ||
### Examples | ||
@@ -387,3 +398,3 @@ ```javascript | ||
Returns **[number][6]** rounded number | ||
Returns **[number][1]** rounded number | ||
@@ -395,8 +406,9 @@ ## radiansToLength | ||
**Parameters** | ||
### Parameters | ||
- `radians` **[number][6]** in radians across the sphere | ||
- `units` **[string][7]** can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default `'kilometers'`) | ||
* `radians` **[number][1]** in radians across the sphere | ||
* `units` **[string][7]** can be degrees, radians, miles, inches, yards, metres, | ||
meters, kilometres, kilometers. (optional, default `"kilometers"`) | ||
Returns **[number][6]** distance | ||
Returns **[number][1]** distance | ||
@@ -408,8 +420,9 @@ ## lengthToRadians | ||
**Parameters** | ||
### Parameters | ||
- `distance` **[number][6]** in real units | ||
- `units` **[string][7]** can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default `'kilometers'`) | ||
* `distance` **[number][1]** in real units | ||
* `units` **[string][7]** can be degrees, radians, miles, inches, yards, metres, | ||
meters, kilometres, kilometers. (optional, default `"kilometers"`) | ||
Returns **[number][6]** radians | ||
Returns **[number][1]** radians | ||
@@ -421,8 +434,9 @@ ## lengthToDegrees | ||
**Parameters** | ||
### Parameters | ||
- `distance` **[number][6]** in real units | ||
- `units` **[string][7]** can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default `'kilometers'`) | ||
* `distance` **[number][1]** in real units | ||
* `units` **[string][7]** can be degrees, radians, miles, inches, yards, metres, | ||
meters, kilometres, kilometers. (optional, default `"kilometers"`) | ||
Returns **[number][6]** degrees | ||
Returns **[number][1]** degrees | ||
@@ -434,7 +448,7 @@ ## bearingToAzimuth | ||
**Parameters** | ||
### Parameters | ||
- `bearing` **[number][6]** angle, between -180 and +180 degrees | ||
* `bearing` **[number][1]** angle, between -180 and +180 degrees | ||
Returns **[number][6]** angle between 0 and 360 degrees | ||
Returns **[number][1]** angle between 0 and 360 degrees | ||
@@ -445,7 +459,7 @@ ## radiansToDegrees | ||
**Parameters** | ||
### Parameters | ||
- `radians` **[number][6]** angle in radians | ||
* `radians` **[number][1]** angle in radians | ||
Returns **[number][6]** degrees between 0 and 360 degrees | ||
Returns **[number][1]** degrees between 0 and 360 degrees | ||
@@ -456,7 +470,7 @@ ## degreesToRadians | ||
**Parameters** | ||
### Parameters | ||
- `degrees` **[number][6]** angle between 0 and 360 degrees | ||
* `degrees` **[number][1]** angle between 0 and 360 degrees | ||
Returns **[number][6]** angle in radians | ||
Returns **[number][1]** angle in radians | ||
@@ -468,9 +482,9 @@ ## convertLength | ||
**Parameters** | ||
### Parameters | ||
- `length` **[number][6]** to be converted | ||
- `originalUnit` **[string][7]** of the length | ||
- `finalUnit` **[string][7]** returned unit (optional, default `'kilometers'`) | ||
* `length` **[number][1]** to be converted | ||
* `originalUnit` **Units** of the length (optional, default `"kilometers"`) | ||
* `finalUnit` **Units** returned unit (optional, default `"kilometers"`) | ||
Returns **[number][6]** the converted length | ||
Returns **[number][1]** the converted length | ||
@@ -482,9 +496,9 @@ ## convertArea | ||
**Parameters** | ||
### Parameters | ||
- `area` **[number][6]** to be converted | ||
- `originalUnit` **[string][7]** of the distance (optional, default `'meters'`) | ||
- `finalUnit` **[string][7]** returned unit (optional, default `'kilometers'`) | ||
* `area` **[number][1]** to be converted | ||
* `originalUnit` **Units** of the distance (optional, default `"meters"`) | ||
* `finalUnit` **Units** returned unit (optional, default `"kilometers"`) | ||
Returns **[number][6]** the converted distance | ||
Returns **[number][1]** the converted area | ||
@@ -495,7 +509,7 @@ ## isNumber | ||
**Parameters** | ||
### Parameters | ||
- `num` **any** Number to validate | ||
* `num` **any** Number to validate | ||
**Examples** | ||
### Examples | ||
@@ -515,7 +529,7 @@ ```javascript | ||
**Parameters** | ||
### Parameters | ||
- `input` **any** variable to validate | ||
* `input` **any** variable to validate | ||
**Examples** | ||
### Examples | ||
@@ -529,15 +543,15 @@ ```javascript | ||
Returns **[boolean][26]** true/false | ||
Returns **[boolean][26]** true/false, including false for Arrays and Functions | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.1 | ||
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.1 | ||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[4]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.1 | ||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | ||
@@ -544,0 +558,0 @@ [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
594
84440
1
1832
1
+ Addedtslib@^2.3.0
+ Addedtslib@2.8.1(transitive)