@turf/truncate
Advanced tools
Comparing version 4.7.3 to 5.0.0
@@ -1,15 +0,13 @@ | ||
/// <reference types="geojson" /> | ||
import { AllGeoJSON } from '@turf/helpers'; | ||
type Geoms = GeoJSON.Feature<any> | GeoJSON.FeatureCollection<any> | GeoJSON.GeometryObject | GeoJSON.GeometryCollection; | ||
/** | ||
* http://turfjs.org/docs/#truncate | ||
*/ | ||
declare function truncate<Geom extends Geoms>( | ||
geojson: Geom, | ||
precision?: number, | ||
coordinates?: number, | ||
mutate?: boolean): Geom; | ||
declare namespace truncate { } | ||
export = truncate; | ||
export default function truncate<T extends AllGeoJSON>( | ||
geojson: T, | ||
options?: { | ||
precision?: number, | ||
coordinates?: number, | ||
mutate?: boolean | ||
} | ||
): T; |
27
index.js
@@ -1,2 +0,3 @@ | ||
var coordEach = require('@turf/meta').coordEach; | ||
import { coordEach } from '@turf/meta'; | ||
import { isObject } from '@turf/helpers'; | ||
@@ -8,5 +9,6 @@ /** | ||
* @param {FeatureCollection|Feature<any>} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection. | ||
* @param {number} [precision=6] coordinate decimal precision | ||
* @param {number} [coordinates=3] maximum number of coordinates (primarly used to remove z coordinates) | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {number} [options.precision=6] coordinate decimal precision | ||
* @param {number} [options.coordinates=3] maximum number of coordinates (primarly used to remove z coordinates) | ||
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {FeatureCollection|Feature<any>} layer with truncated geometry | ||
@@ -25,3 +27,10 @@ * @example | ||
*/ | ||
module.exports = function (geojson, precision, coordinates, mutate) { | ||
function truncate(geojson, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var precision = options.precision; | ||
var coordinates = options.coordinates; | ||
var mutate = options.mutate; | ||
// default params | ||
@@ -43,6 +52,6 @@ precision = (precision === undefined || precision === null || isNaN(precision)) ? 6 : precision; | ||
coordEach(geojson, function (coords) { | ||
truncate(coords, factor, coordinates); | ||
truncateCoords(coords, factor, coordinates); | ||
}); | ||
return geojson; | ||
}; | ||
} | ||
@@ -58,3 +67,3 @@ /** | ||
*/ | ||
function truncate(coords, factor, coordinates) { | ||
function truncateCoords(coords, factor, coordinates) { | ||
// Remove extra coordinates (usually elevation coordinates and more) | ||
@@ -69,1 +78,3 @@ if (coords.length > coordinates) coords.splice(coordinates, coords.length); | ||
} | ||
export default truncate; |
{ | ||
"name": "@turf/truncate", | ||
"version": "4.7.3", | ||
"version": "5.0.0", | ||
"description": "turf truncate 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" | ||
}, | ||
@@ -35,11 +39,17 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/helpers": "^4.7.3", | ||
"benchmark": "2.1.4", | ||
"load-json-file": "2.0.0", | ||
"tape": "4.8.0", | ||
"write-json-file": "2.2.0" | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*", | ||
"@std/esm": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/meta": "^4.7.3" | ||
"@turf/helpers": "5.x", | ||
"@turf/meta": "5.x" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/truncate | ||
# truncate | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## truncate | ||
Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry. | ||
@@ -10,5 +12,6 @@ | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection. | ||
- `precision` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** coordinate decimal precision (optional, default `6`) | ||
- `coordinates` **\[[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** maximum number of coordinates (primarly used to remove z coordinates) (optional, default `3`) | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.precision` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** coordinate decimal precision (optional, default `6`) | ||
- `options.coordinates` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** maximum number of coordinates (primarly used to remove z coordinates) (optional, default `3`) | ||
- `options.mutate` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -15,0 +18,0 @@ **Examples** |
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
10453
6
146
58
2
6
+ Added@turf/helpers@5.x
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removed@turf/meta@4.7.4(transitive)
Updated@turf/meta@5.x