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

@turf/clean-coords

Package Overview
Dependencies
Maintainers
4
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/clean-coords - npm Package Compare versions

Comparing version 4.7.3 to 5.0.4

main.js

14

index.d.ts

@@ -1,11 +0,11 @@

/// <reference types="geojson" />
import { Feature, GeometryObject } from '@turf/helpers'
type GeometryObject = GeoJSON.GeometryObject;
type Feature = GeoJSON.Feature<any>;
/**
* http://turfjs.org/docs/#cleancoords
*/
declare function cleanCoords<T extends GeometryObject|Feature>(feature: T, mutate?: boolean): T;
declare namespace cleanCoords {}
export = cleanCoords;
export default function <T extends GeometryObject | Feature<any>>(
feature: T,
options?: {
mutate?: boolean
}
): T;

@@ -1,5 +0,3 @@

var helpers = require('@turf/helpers');
var invariant = require('@turf/invariant');
var getCoords = invariant.getCoords;
var getGeomType = invariant.getGeomType;
import { feature } from '@turf/helpers';
import { getCoords, getType } from '@turf/invariant';

@@ -11,3 +9,4 @@ /**

* @param {Geometry|Feature} geojson Feature or Geometry
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated
* @returns {Geometry|Feature} the cleaned input Feature/Geometry

@@ -24,5 +23,7 @@ * @example

*/
module.exports = function (geojson, mutate) {
function cleanCoords(geojson, options) {
// Backwards compatible with v4.0
var mutate = (typeof options === 'object') ? options.mutate : options;
if (!geojson) throw new Error('geojson is required');
var type = getGeomType(geojson);
var type = getType(geojson);

@@ -34,3 +35,3 @@ // Store new "clean" points in this Array

case 'LineString':
newCoords = cleanCoords(geojson);
newCoords = cleanLine(geojson);
break;

@@ -40,3 +41,3 @@ case 'MultiLineString':

getCoords(geojson).forEach(function (line) {
newCoords.push(cleanCoords(line));
newCoords.push(cleanLine(line));
});

@@ -48,3 +49,3 @@ break;

polygons.forEach(function (ring) {
polyPoints.push(cleanCoords(ring));
polyPoints.push(cleanLine(ring));
});

@@ -76,3 +77,3 @@ newCoords.push(polyPoints);

}
return geometry(geojson, type, newCoords);
return {type: type, coordinates: newCoords};
} else {

@@ -83,41 +84,7 @@ if (mutate === true) {

}
return feature(geojson, type, newCoords);
return feature({type: type, coordinates: newCoords}, geojson.properties, geojson.bbox, geojson.id);
}
};
/**
* Create Geometry from existing Geometry
*
* @private
* @param {Geometry} geojson Existing Geometry
* @param {string} type Geometry Type
* @param {Array<number>} coordinates Coordinates
* @returns {Geometry} Geometry
*/
function geometry(geojson, type, coordinates) {
var geom = {
type: type,
coordinates: coordinates
};
if (geojson.bbox) geom.bbox = geojson.bbox;
return geom;
}
/**
* Create Feature from existing Feature
*
* @private
* @param {Feature} geojson Existing Feature
* @param {string} type Feature Type
* @param {Array<number>} coordinates Coordinates
* @returns {Feature} Feature
*/
function feature(geojson, type, coordinates) {
var feat = helpers.feature(geometry(geojson.geometry, type, coordinates), geojson.properties);
if (geojson.id) feat.id = geojson.id;
if (geojson.bbox) feat.bbox = geojson.bbox;
return feat;
}
/**
* Clean Coords

@@ -129,3 +96,3 @@ *

*/
function cleanCoords(line) {
function cleanLine(line) {
var points = getCoords(line);

@@ -190,1 +157,3 @@ // handle "clean" segment

}
export default cleanCoords;
{
"name": "@turf/clean-coords",
"version": "4.7.3",
"version": "5.0.4",
"description": "turf clean-coords module",
"main": "index.js",
"main": "main",
"module": "index",
"jsnext:main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"main.js"
],
"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"
},

@@ -34,12 +38,18 @@ "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.2.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/helpers": "^5.0.4",
"@turf/invariant": "^5.0.4"
},
"@std/esm": {
"esm": "js",
"cjs": true
}
}
# @turf/clean-coords
# cleanCoords
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## cleanCoords
Removes redundant coordinates from any GeoJSON Geometry.

@@ -10,3 +12,4 @@

- `geojson` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** Feature or Geometry
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (optional, default `false`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (optional, default `false`)

@@ -13,0 +16,0 @@ **Examples**

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