@turf/truncate
Advanced tools
Comparing version 5.1.5 to 6.0.0
36
index.js
@@ -1,4 +0,4 @@ | ||
import { coordEach } from '@turf/meta'; | ||
import { isObject } from '@turf/helpers'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var meta_1 = require("@turf/meta"); | ||
/** | ||
@@ -28,25 +28,23 @@ * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry. | ||
function truncate(geojson, options) { | ||
if (options === void 0) { 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 | ||
precision = (precision === undefined || precision === null || isNaN(precision)) ? 6 : precision; | ||
coordinates = (coordinates === undefined || coordinates === null || isNaN(coordinates)) ? 3 : coordinates; | ||
// validation | ||
if (!geojson) throw new Error('<geojson> is required'); | ||
if (typeof precision !== 'number') throw new Error('<precision> must be a number'); | ||
if (typeof coordinates !== 'number') throw new Error('<coordinates> must be a number'); | ||
if (!geojson) | ||
throw new Error('<geojson> is required'); | ||
if (typeof precision !== 'number') | ||
throw new Error('<precision> must be a number'); | ||
if (typeof coordinates !== 'number') | ||
throw new Error('<coordinates> must be a number'); | ||
// prevent input mutation | ||
if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson)); | ||
if (mutate === false || mutate === undefined) | ||
geojson = JSON.parse(JSON.stringify(geojson)); | ||
var factor = Math.pow(10, precision); | ||
// Truncate Coordinates | ||
coordEach(geojson, function (coords) { | ||
meta_1.coordEach(geojson, function (coords) { | ||
truncateCoords(coords, factor, coordinates); | ||
@@ -56,3 +54,2 @@ }); | ||
} | ||
/** | ||
@@ -69,4 +66,4 @@ * Truncate Coordinates - Mutates coordinates in place | ||
// Remove extra coordinates (usually elevation coordinates and more) | ||
if (coords.length > coordinates) coords.splice(coordinates, coords.length); | ||
if (coords.length > coordinates) | ||
coords.splice(coordinates, coords.length); | ||
// Truncate coordinate decimals | ||
@@ -78,3 +75,2 @@ for (var i = 0; i < coords.length; i++) { | ||
} | ||
export default truncate; | ||
exports.default = truncate; |
@@ -0,19 +1,15 @@ | ||
{ | ||
"name": "@turf/truncate", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf truncate module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -41,6 +37,5 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*", | ||
@@ -50,9 +45,5 @@ "write-json-file": "*" | ||
"dependencies": { | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/meta": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/helpers": "6.x", | ||
"@turf/meta": "6.x" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
5
10031
5
141
1
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/meta@6.5.0(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/meta@5.2.0(transitive)
Updated@turf/helpers@6.x
Updated@turf/meta@6.x