@turf/truncate 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +3 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +3 -6
- package/dist/esm/index.js.map +1 -1
- package/package.json +10 -10
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,15 +3,13 @@ var _meta = require('@turf/meta');
|
|
|
3
3
|
var _helpers = require('@turf/helpers');
|
|
4
4
|
function truncate(geojson, options) {
|
|
5
5
|
options = options != null ? options : {};
|
|
6
|
-
if (!_helpers.isObject.call(void 0, options))
|
|
7
|
-
throw new Error("options is invalid");
|
|
6
|
+
if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
|
|
8
7
|
var precision = options.precision;
|
|
9
8
|
var coordinates = options.coordinates;
|
|
10
9
|
var mutate = options.mutate;
|
|
11
10
|
precision = precision === void 0 || precision === null || isNaN(precision) ? 6 : precision;
|
|
12
11
|
coordinates = coordinates === void 0 || coordinates === null || isNaN(coordinates) ? 3 : coordinates;
|
|
13
|
-
if (!geojson)
|
|
14
|
-
throw new Error("<geojson> is required");
|
|
12
|
+
if (!geojson) throw new Error("<geojson> is required");
|
|
15
13
|
if (typeof precision !== "number")
|
|
16
14
|
throw new Error("<precision> must be a number");
|
|
17
15
|
if (typeof coordinates !== "number")
|
|
@@ -25,8 +23,7 @@ function truncate(geojson, options) {
|
|
|
25
23
|
return geojson;
|
|
26
24
|
}
|
|
27
25
|
function truncateCoords(coords, factor, coordinates) {
|
|
28
|
-
if (coords.length > coordinates)
|
|
29
|
-
coords.splice(coordinates, coords.length);
|
|
26
|
+
if (coords.length > coordinates) coords.splice(coordinates, coords.length);
|
|
30
27
|
for (var i = 0; i < coords.length; i++) {
|
|
31
28
|
coords[i] = Math.round(coords[i] * factor) / factor;
|
|
32
29
|
}
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-truncate/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACAA,kCAA0B;AAC1B,wCAAqC;AAyBrC,SAAS,QAAA,CACP,OAAA,EACA,OAAA,EAKG;AAEH,EAAA,QAAA,EAAU,QAAA,GAAA,KAAA,EAAA,QAAA,EAAW,CAAC,CAAA;AACtB,EAAA,GAAA,CAAI,CAAC,+BAAA,OAAgB,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAC5D,EAAA,IAAI,UAAA,EAAY,OAAA,CAAQ,SAAA;AACxB,EAAA,IAAI,YAAA,EAAc,OAAA,CAAQ,WAAA;AAC1B,EAAA,IAAI,OAAA,EAAS,OAAA,CAAQ,MAAA;AAGrB,EAAA,UAAA,EACE,UAAA,IAAc,KAAA,EAAA,GAAa,UAAA,IAAc,KAAA,GAAQ,KAAA,CAAM,SAAS,EAAA,EAC5D,EAAA,EACA,SAAA;AACN,EAAA,YAAA,EACE,YAAA,IAAgB,KAAA,EAAA,GAAa,YAAA,IAAgB,KAAA,GAAQ,KAAA,CAAM,WAAW,EAAA,EAClE,EAAA,EACA,WAAA;AAGN,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,uBAAuB,CAAA;AACrD,EAAA,GAAA,CAAI,OAAO,UAAA,IAAc,QAAA;AACvB,IAAA,MAAM,IAAI,KAAA,CAAM,8BAA8B,CAAA;AAChD,EAAA,GAAA,CAAI,OAAO,YAAA,IAAgB,QAAA;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,gCAAgC,CAAA;AAGlD,EAAA,GAAA,CAAI,OAAA,IAAW,MAAA,GAAS,OAAA,IAAW,KAAA,CAAA;AACjC,IAAA,QAAA,EAAU,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,OAAO,CAAC,CAAA;AAE9C,EAAA,IAAI,OAAA,EAAS,IAAA,CAAK,GAAA,CAAI,EAAA,EAAI,SAAS,CAAA;AAGnC,EAAA,6BAAA,OAAU,EAAS,QAAA,CAAU,MAAA,EAAQ;AACnC,IAAA,cAAA,CAAe,MAAA,EAAQ,MAAA,EAAQ,WAAY,CAAA;AAAA,EAC7C,CAAC,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAWA,SAAS,cAAA,CAAe,MAAA,EAAkB,MAAA,EAAgB,WAAA,EAAqB;AAE7E,EAAA,GAAA,CAAI,MAAA,CAAO,OAAA,EAAS,WAAA,EAAa,MAAA,CAAO,MAAA,CAAO,WAAA,EAAa,MAAA,CAAO,MAAM,CAAA;AAGzE,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,MAAA,CAAO,MAAA,EAAQ,CAAA,EAAA,EAAK;AACtC,IAAA,MAAA,CAAO,CAAC,EAAA,EAAI,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,CAAC,EAAA,EAAI,MAAM,EAAA,EAAI,MAAA;AAAA,EAC/C;AACA,EAAA,OAAO,MAAA;AACT;AAGA,IAAO,sBAAA,EAAQ,QAAA;AD5Df;AACE;AACA;AACF,qEAAC","file":"/home/runner/work/turf/turf/packages/turf-truncate/dist/cjs/index.cjs","sourcesContent":[null,"import { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isObject } from \"@turf/helpers\";\n\n/**\n * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.\n *\n * @function\n * @param {GeoJSON} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.precision=6] coordinate decimal precision\n * @param {number} [options.coordinates=3] maximum number of coordinates (primarly used to remove z coordinates)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} layer with truncated geometry\n * @example\n * var point = turf.point([\n * 70.46923055566859,\n * 58.11088890802906,\n * 1508\n * ]);\n * var options = {precision: 3, coordinates: 2};\n * var truncated = turf.truncate(point, options);\n * //=truncated.geometry.coordinates => [70.469, 58.111]\n *\n * //addToMap\n * var addToMap = [truncated];\n */\nfunction truncate<T extends AllGeoJSON>(\n geojson: T,\n options?: {\n precision?: number;\n coordinates?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options ?? {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var precision = options.precision;\n var coordinates = options.coordinates;\n var mutate = options.mutate;\n\n // default params\n precision =\n precision === undefined || precision === null || isNaN(precision)\n ? 6\n : precision;\n coordinates =\n coordinates === undefined || coordinates === null || isNaN(coordinates)\n ? 3\n : coordinates;\n\n // validation\n if (!geojson) throw new Error(\"<geojson> is required\");\n if (typeof precision !== \"number\")\n throw new Error(\"<precision> must be a number\");\n if (typeof coordinates !== \"number\")\n throw new Error(\"<coordinates> must be a number\");\n\n // prevent input mutation\n if (mutate === false || mutate === undefined)\n geojson = JSON.parse(JSON.stringify(geojson));\n\n var factor = Math.pow(10, precision);\n\n // Truncate Coordinates\n coordEach(geojson, function (coords) {\n truncateCoords(coords, factor, coordinates!);\n });\n return geojson;\n}\n\n/**\n * Truncate Coordinates - Mutates coordinates in place\n *\n * @private\n * @param {Array<any>} coords Geometry Coordinates\n * @param {number} factor rounding factor for coordinate decimal precision\n * @param {number} coordinates maximum number of coordinates (primarly used to remove z coordinates)\n * @returns {Array<any>} mutated coordinates\n */\nfunction truncateCoords(coords: number[], factor: number, coordinates: number) {\n // Remove extra coordinates (usually elevation coordinates and more)\n if (coords.length > coordinates) coords.splice(coordinates, coords.length);\n\n // Truncate coordinate decimals\n for (var i = 0; i < coords.length; i++) {\n coords[i] = Math.round(coords[i] * factor) / factor;\n }\n return coords;\n}\n\nexport { truncate };\nexport default truncate;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { AllGeoJSON } from '@turf/helpers';
|
|
|
3
3
|
/**
|
|
4
4
|
* Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @function
|
|
7
7
|
* @param {GeoJSON} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.
|
|
8
8
|
* @param {Object} [options={}] Optional parameters
|
|
9
9
|
* @param {number} [options.precision=6] coordinate decimal precision
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AllGeoJSON } from '@turf/helpers';
|
|
|
3
3
|
/**
|
|
4
4
|
* Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
6
|
+
* @function
|
|
7
7
|
* @param {GeoJSON} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.
|
|
8
8
|
* @param {Object} [options={}] Optional parameters
|
|
9
9
|
* @param {number} [options.precision=6] coordinate decimal precision
|
package/dist/esm/index.js
CHANGED
|
@@ -3,15 +3,13 @@ import { coordEach } from "@turf/meta";
|
|
|
3
3
|
import { isObject } from "@turf/helpers";
|
|
4
4
|
function truncate(geojson, options) {
|
|
5
5
|
options = options != null ? options : {};
|
|
6
|
-
if (!isObject(options))
|
|
7
|
-
throw new Error("options is invalid");
|
|
6
|
+
if (!isObject(options)) throw new Error("options is invalid");
|
|
8
7
|
var precision = options.precision;
|
|
9
8
|
var coordinates = options.coordinates;
|
|
10
9
|
var mutate = options.mutate;
|
|
11
10
|
precision = precision === void 0 || precision === null || isNaN(precision) ? 6 : precision;
|
|
12
11
|
coordinates = coordinates === void 0 || coordinates === null || isNaN(coordinates) ? 3 : coordinates;
|
|
13
|
-
if (!geojson)
|
|
14
|
-
throw new Error("<geojson> is required");
|
|
12
|
+
if (!geojson) throw new Error("<geojson> is required");
|
|
15
13
|
if (typeof precision !== "number")
|
|
16
14
|
throw new Error("<precision> must be a number");
|
|
17
15
|
if (typeof coordinates !== "number")
|
|
@@ -25,8 +23,7 @@ function truncate(geojson, options) {
|
|
|
25
23
|
return geojson;
|
|
26
24
|
}
|
|
27
25
|
function truncateCoords(coords, factor, coordinates) {
|
|
28
|
-
if (coords.length > coordinates)
|
|
29
|
-
coords.splice(coordinates, coords.length);
|
|
26
|
+
if (coords.length > coordinates) coords.splice(coordinates, coords.length);
|
|
30
27
|
for (var i = 0; i < coords.length; i++) {
|
|
31
28
|
coords[i] = Math.round(coords[i] * factor) / factor;
|
|
32
29
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isObject } from \"@turf/helpers\";\n\n/**\n * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.\n *\n * @
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { coordEach } from \"@turf/meta\";\nimport { AllGeoJSON, isObject } from \"@turf/helpers\";\n\n/**\n * Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.\n *\n * @function\n * @param {GeoJSON} geojson any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.precision=6] coordinate decimal precision\n * @param {number} [options.coordinates=3] maximum number of coordinates (primarly used to remove z coordinates)\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} layer with truncated geometry\n * @example\n * var point = turf.point([\n * 70.46923055566859,\n * 58.11088890802906,\n * 1508\n * ]);\n * var options = {precision: 3, coordinates: 2};\n * var truncated = turf.truncate(point, options);\n * //=truncated.geometry.coordinates => [70.469, 58.111]\n *\n * //addToMap\n * var addToMap = [truncated];\n */\nfunction truncate<T extends AllGeoJSON>(\n geojson: T,\n options?: {\n precision?: number;\n coordinates?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options ?? {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var precision = options.precision;\n var coordinates = options.coordinates;\n var mutate = options.mutate;\n\n // default params\n precision =\n precision === undefined || precision === null || isNaN(precision)\n ? 6\n : precision;\n coordinates =\n coordinates === undefined || coordinates === null || isNaN(coordinates)\n ? 3\n : coordinates;\n\n // validation\n if (!geojson) throw new Error(\"<geojson> is required\");\n if (typeof precision !== \"number\")\n throw new Error(\"<precision> must be a number\");\n if (typeof coordinates !== \"number\")\n throw new Error(\"<coordinates> must be a number\");\n\n // prevent input mutation\n if (mutate === false || mutate === undefined)\n geojson = JSON.parse(JSON.stringify(geojson));\n\n var factor = Math.pow(10, precision);\n\n // Truncate Coordinates\n coordEach(geojson, function (coords) {\n truncateCoords(coords, factor, coordinates!);\n });\n return geojson;\n}\n\n/**\n * Truncate Coordinates - Mutates coordinates in place\n *\n * @private\n * @param {Array<any>} coords Geometry Coordinates\n * @param {number} factor rounding factor for coordinate decimal precision\n * @param {number} coordinates maximum number of coordinates (primarly used to remove z coordinates)\n * @returns {Array<any>} mutated coordinates\n */\nfunction truncateCoords(coords: number[], factor: number, coordinates: number) {\n // Remove extra coordinates (usually elevation coordinates and more)\n if (coords.length > coordinates) coords.splice(coordinates, coords.length);\n\n // Truncate coordinate decimals\n for (var i = 0; i < coords.length; i++) {\n coords[i] = Math.round(coords[i] * factor) / factor;\n }\n return coords;\n}\n\nexport { truncate };\nexport default truncate;\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAqB,gBAAgB;AAyBrC,SAAS,SACP,SACA,SAKG;AAEH,YAAU,4BAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,YAAY,QAAQ;AACxB,MAAI,cAAc,QAAQ;AAC1B,MAAI,SAAS,QAAQ;AAGrB,cACE,cAAc,UAAa,cAAc,QAAQ,MAAM,SAAS,IAC5D,IACA;AACN,gBACE,gBAAgB,UAAa,gBAAgB,QAAQ,MAAM,WAAW,IAClE,IACA;AAGN,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,uBAAuB;AACrD,MAAI,OAAO,cAAc;AACvB,UAAM,IAAI,MAAM,8BAA8B;AAChD,MAAI,OAAO,gBAAgB;AACzB,UAAM,IAAI,MAAM,gCAAgC;AAGlD,MAAI,WAAW,SAAS,WAAW;AACjC,cAAU,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC;AAE9C,MAAI,SAAS,KAAK,IAAI,IAAI,SAAS;AAGnC,YAAU,SAAS,SAAU,QAAQ;AACnC,mBAAe,QAAQ,QAAQ,WAAY;AAAA,EAC7C,CAAC;AACD,SAAO;AACT;AAWA,SAAS,eAAe,QAAkB,QAAgB,aAAqB;AAE7E,MAAI,OAAO,SAAS,YAAa,QAAO,OAAO,aAAa,OAAO,MAAM;AAGzE,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,WAAO,CAAC,IAAI,KAAK,MAAM,OAAO,CAAC,IAAI,MAAM,IAAI;AAAA,EAC/C;AACA,SAAO;AACT;AAGA,IAAO,wBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/truncate",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "turf truncate module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -56,21 +56,21 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/benchmark": "^2.1.5",
|
|
59
|
-
"@types/tape": "^4.
|
|
59
|
+
"@types/tape": "^4.13.4",
|
|
60
60
|
"benchmark": "^2.1.4",
|
|
61
61
|
"load-json-file": "^7.0.1",
|
|
62
62
|
"npm-run-all": "^4.1.5",
|
|
63
|
-
"tape": "^5.
|
|
64
|
-
"tsup": "^8.
|
|
65
|
-
"tsx": "^4.
|
|
66
|
-
"typescript": "^5.
|
|
63
|
+
"tape": "^5.9.0",
|
|
64
|
+
"tsup": "^8.3.5",
|
|
65
|
+
"tsx": "^4.19.2",
|
|
66
|
+
"typescript": "^5.5.4",
|
|
67
67
|
"write-json-file": "^5.0.0"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@turf/helpers": "^7.
|
|
71
|
-
"@turf/meta": "^7.
|
|
70
|
+
"@turf/helpers": "^7.2.0",
|
|
71
|
+
"@turf/meta": "^7.2.0",
|
|
72
72
|
"@types/geojson": "^7946.0.10",
|
|
73
|
-
"tslib": "^2.
|
|
73
|
+
"tslib": "^2.8.1"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
|
|
76
76
|
}
|