@turf/helpers
Advanced tools
Comparing version 5.1.0 to 5.1.4
128
main.js
@@ -94,3 +94,3 @@ 'use strict'; | ||
options = options || {}; | ||
if (!isObject(options)) { throw new Error('options is invalid'); } | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var bbox = options.bbox; | ||
@@ -100,11 +100,11 @@ var id = options.id; | ||
// Validation | ||
if (geometry === undefined) { throw new Error('geometry is required'); } | ||
if (properties && properties.constructor !== Object) { throw new Error('properties must be an Object'); } | ||
if (bbox) { validateBBox(bbox); } | ||
if (id) { validateId(id); } | ||
if (geometry === undefined) throw new Error('geometry is required'); | ||
if (properties && properties.constructor !== Object) throw new Error('properties must be an Object'); | ||
if (bbox) validateBBox(bbox); | ||
if (id) validateId(id); | ||
// Main | ||
var feat = {type: 'Feature'}; | ||
if (id) { feat.id = id; } | ||
if (bbox) { feat.bbox = bbox; } | ||
if (id) feat.id = id; | ||
if (bbox) feat.bbox = bbox; | ||
feat.properties = properties || {}; | ||
@@ -136,10 +136,10 @@ feat.geometry = geometry; | ||
options = options || {}; | ||
if (!isObject(options)) { throw new Error('options is invalid'); } | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var bbox = options.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'); } | ||
if (bbox) { validateBBox(bbox); } | ||
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'); | ||
if (bbox) validateBBox(bbox); | ||
@@ -157,3 +157,3 @@ // Main | ||
} | ||
if (bbox) { geom.bbox = bbox; } | ||
if (bbox) geom.bbox = bbox; | ||
return geom; | ||
@@ -178,6 +178,6 @@ } | ||
function point(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); } | ||
if (coordinates.length < 2) { throw new Error('coordinates must be at least 2 numbers long'); } | ||
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) { throw new Error('coordinates must contain numbers'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array'); | ||
if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long'); | ||
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers'); | ||
@@ -210,4 +210,4 @@ return feature({ | ||
function points(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array'); | ||
@@ -235,3 +235,3 @@ return featureCollection(coordinates.map(function (coords) { | ||
function polygon(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
@@ -245,3 +245,3 @@ for (var i = 0; i < coordinates.length; i++) { | ||
// Check if first point of Polygon contains two numbers | ||
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) { throw new Error('coordinates must contain numbers'); } | ||
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('coordinates must contain numbers'); | ||
if (ring[ring.length - 1][j] !== ring[0][j]) { | ||
@@ -278,4 +278,4 @@ throw new Error('First and last Position are not equivalent.'); | ||
function polygons(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array'); | ||
@@ -305,6 +305,6 @@ return featureCollection(coordinates.map(function (coords) { | ||
function lineString(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (coordinates.length < 2) { throw new Error('coordinates must be an array of two or more positions'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
if (coordinates.length < 2) throw new Error('coordinates must be an array of two or more positions'); | ||
// Check if first point of LineString contains two numbers | ||
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) { throw new Error('coordinates must contain numbers'); } | ||
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('coordinates must contain numbers'); | ||
@@ -336,4 +336,4 @@ return feature({ | ||
function lineStrings(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array'); | ||
@@ -370,3 +370,3 @@ return featureCollection(coordinates.map(function (coords) { | ||
options = options || {}; | ||
if (!isObject(options)) { throw new Error('options is invalid'); } | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var bbox = options.bbox; | ||
@@ -376,11 +376,11 @@ var id = options.id; | ||
// Validation | ||
if (!features) { throw new Error('No features passed'); } | ||
if (!Array.isArray(features)) { throw new Error('features must be an Array'); } | ||
if (bbox) { validateBBox(bbox); } | ||
if (id) { validateId(id); } | ||
if (!features) throw new Error('No features passed'); | ||
if (!Array.isArray(features)) throw new Error('features must be an Array'); | ||
if (bbox) validateBBox(bbox); | ||
if (id) validateId(id); | ||
// Main | ||
var fc = {type: 'FeatureCollection'}; | ||
if (id) { fc.id = id; } | ||
if (bbox) { fc.bbox = bbox; } | ||
if (id) fc.id = id; | ||
if (bbox) fc.bbox = bbox; | ||
fc.features = features; | ||
@@ -408,3 +408,3 @@ return fc; | ||
function multiLineString(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
@@ -435,3 +435,3 @@ return feature({ | ||
function multiPoint(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
@@ -463,3 +463,3 @@ return feature({ | ||
function multiPolygon(coordinates, properties, options) { | ||
if (!coordinates) { throw new Error('coordinates is required'); } | ||
if (!coordinates) throw new Error('coordinates is required'); | ||
@@ -497,4 +497,4 @@ return feature({ | ||
function geometryCollection(geometries, properties, options) { | ||
if (!geometries) { throw new Error('geometries is required'); } | ||
if (!Array.isArray(geometries)) { throw new Error('geometries must be an Array'); } | ||
if (!geometries) throw new Error('geometries is required'); | ||
if (!Array.isArray(geometries)) throw new Error('geometries must be an Array'); | ||
@@ -521,4 +521,4 @@ return feature({ | ||
function round(num, precision) { | ||
if (num === undefined || num === null || isNaN(num)) { throw new Error('num is required'); } | ||
if (precision && !(precision >= 0)) { throw new Error('precision must be a positive number'); } | ||
if (num === undefined || num === null || isNaN(num)) throw new Error('num is required'); | ||
if (precision && !(precision >= 0)) throw new Error('precision must be a positive number'); | ||
var multiplier = Math.pow(10, precision || 0); | ||
@@ -538,7 +538,7 @@ return Math.round(num * multiplier) / multiplier; | ||
function radiansToLength(radians, units) { | ||
if (radians === undefined || radians === null) { throw new Error('radians is required'); } | ||
if (radians === undefined || radians === null) throw new Error('radians is required'); | ||
if (units && typeof units !== 'string') { throw new Error('units must be a string'); } | ||
if (units && typeof units !== 'string') throw new Error('units must be a string'); | ||
var factor = factors[units || 'kilometers']; | ||
if (!factor) { throw new Error(units + ' units is invalid'); } | ||
if (!factor) throw new Error(units + ' units is invalid'); | ||
return radians * factor; | ||
@@ -557,7 +557,7 @@ } | ||
function lengthToRadians(distance, units) { | ||
if (distance === undefined || distance === null) { throw new Error('distance is required'); } | ||
if (distance === undefined || distance === null) throw new Error('distance is required'); | ||
if (units && typeof units !== 'string') { throw new Error('units must be a string'); } | ||
if (units && typeof units !== 'string') throw new Error('units must be a string'); | ||
var factor = factors[units || 'kilometers']; | ||
if (!factor) { throw new Error(units + ' units is invalid'); } | ||
if (!factor) throw new Error(units + ' units is invalid'); | ||
return distance / factor; | ||
@@ -588,6 +588,6 @@ } | ||
function bearingToAzimuth(bearing) { | ||
if (bearing === null || bearing === undefined) { throw new Error('bearing is required'); } | ||
if (bearing === null || bearing === undefined) throw new Error('bearing is required'); | ||
var angle = bearing % 360; | ||
if (angle < 0) { angle += 360; } | ||
if (angle < 0) angle += 360; | ||
return angle; | ||
@@ -604,3 +604,3 @@ } | ||
function radiansToDegrees(radians) { | ||
if (radians === null || radians === undefined) { throw new Error('radians is required'); } | ||
if (radians === null || radians === undefined) throw new Error('radians is required'); | ||
@@ -619,3 +619,3 @@ var degrees = radians % (2 * Math.PI); | ||
function degreesToRadians(degrees) { | ||
if (degrees === null || degrees === undefined) { throw new Error('degrees is required'); } | ||
if (degrees === null || degrees === undefined) throw new Error('degrees is required'); | ||
@@ -636,4 +636,4 @@ var radians = degrees % 360; | ||
function convertLength(length, originalUnit, finalUnit) { | ||
if (length === null || length === undefined) { throw new Error('length is required'); } | ||
if (!(length >= 0)) { throw new Error('length must be a positive number'); } | ||
if (length === null || length === undefined) throw new Error('length is required'); | ||
if (!(length >= 0)) throw new Error('length must be a positive number'); | ||
@@ -652,10 +652,10 @@ return radiansToLength(lengthToRadians(length, originalUnit), finalUnit || 'kilometers'); | ||
function convertArea(area, originalUnit, finalUnit) { | ||
if (area === null || area === undefined) { throw new Error('area is required'); } | ||
if (!(area >= 0)) { throw new Error('area must be a positive number'); } | ||
if (area === null || area === undefined) throw new Error('area is required'); | ||
if (!(area >= 0)) throw new Error('area must be a positive number'); | ||
var startFactor = areaFactors[originalUnit || 'meters']; | ||
if (!startFactor) { throw new Error('invalid original units'); } | ||
if (!startFactor) throw new Error('invalid original units'); | ||
var finalFactor = areaFactors[finalUnit || 'kilometers']; | ||
if (!finalFactor) { throw new Error('invalid final units'); } | ||
if (!finalFactor) throw new Error('invalid final units'); | ||
@@ -717,7 +717,7 @@ return (area / startFactor) * finalFactor; | ||
function validateBBox(bbox) { | ||
if (!bbox) { throw new Error('bbox is required'); } | ||
if (!Array.isArray(bbox)) { throw new Error('bbox must be an Array'); } | ||
if (bbox.length !== 4 && bbox.length !== 6) { throw new Error('bbox must be an Array of 4 or 6 numbers'); } | ||
if (!bbox) throw new Error('bbox is required'); | ||
if (!Array.isArray(bbox)) throw new Error('bbox must be an Array'); | ||
if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers'); | ||
bbox.forEach(function (num) { | ||
if (!isNumber(num)) { throw new Error('bbox must only contain numbers'); } | ||
if (!isNumber(num)) throw new Error('bbox must only contain numbers'); | ||
}); | ||
@@ -748,4 +748,4 @@ } | ||
function validateId(id) { | ||
if (!id) { throw new Error('id is required'); } | ||
if (['string', 'number'].indexOf(typeof id) === -1) { throw new Error('id must be a number or a string'); } | ||
if (!id) throw new Error('id is required'); | ||
if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string'); | ||
} | ||
@@ -752,0 +752,0 @@ |
{ | ||
"name": "@turf/helpers", | ||
"version": "5.1.0", | ||
"version": "5.1.4", | ||
"description": "turf helpers module", | ||
"main": "main.js", | ||
"module": "main.mjs", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
@@ -13,3 +13,3 @@ "files": [ | ||
"lib", | ||
"main.mjs" | ||
"main.es.js" | ||
], | ||
@@ -19,2 +19,3 @@ "scripts": { | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
@@ -49,3 +50,2 @@ "docs": "node ../../scripts/generate-readmes" | ||
"rollup": "*", | ||
"rollup-plugin-buble": "*", | ||
"tape": "*" | ||
@@ -52,0 +52,0 @@ }, |
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
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
4
99714
7
1817