@turf/length 7.0.0-alpha.2 → 7.0.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/README.md +4 -9
- package/dist/cjs/index.cjs +23 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{es/index.js → cjs/index.d.cts} +8 -9
- package/dist/{js → esm}/index.d.ts +6 -3
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +33 -28
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -29
package/README.md
CHANGED
|
@@ -42,26 +42,21 @@ Returns **[number][8]** length of GeoJSON
|
|
|
42
42
|
|
|
43
43
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
44
44
|
|
|
45
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
46
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
47
|
-
./scripts/generate-readmes in the turf project. -->
|
|
45
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
48
46
|
|
|
49
47
|
---
|
|
50
48
|
|
|
51
|
-
This module is part of the [Turfjs project](
|
|
52
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
53
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
54
|
-
PRs and issues.
|
|
49
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
55
50
|
|
|
56
51
|
### Installation
|
|
57
52
|
|
|
58
|
-
Install this module individually:
|
|
53
|
+
Install this single module individually:
|
|
59
54
|
|
|
60
55
|
```sh
|
|
61
56
|
$ npm install @turf/length
|
|
62
57
|
```
|
|
63
58
|
|
|
64
|
-
Or install the
|
|
59
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
65
60
|
|
|
66
61
|
```sh
|
|
67
62
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _distance = require('@turf/distance');
|
|
6
|
+
var _meta = require('@turf/meta');
|
|
7
|
+
function length(geojson, options = {}) {
|
|
8
|
+
return _meta.segmentReduce.call(void 0,
|
|
9
|
+
geojson,
|
|
10
|
+
(previousValue, segment) => {
|
|
11
|
+
const coords = segment.geometry.coordinates;
|
|
12
|
+
return previousValue + _distance.distance.call(void 0, coords[0], coords[1], options);
|
|
13
|
+
},
|
|
14
|
+
0
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
__name(length, "length");
|
|
18
|
+
var turf_length_default = length;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
exports.default = turf_length_default; exports.length = length;
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,gBAAgB;AAEzB,SAAS,qBAAqB;AAkB9B,SAAS,OACP,SACA,UAEI,CAAC,GACG;AAER,SAAO;AAAA,IACL;AAAA,IACA,CAAC,eAAe,YAAY;AAC1B,YAAM,SAAS,QAAS,SAAS;AACjC,aAAO,gBAAiB,SAAS,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,IACA;AAAA,EACF;AACF;AAfS;AAkBT,IAAO,sBAAQ","sourcesContent":["import { Feature, FeatureCollection, GeometryCollection } from \"geojson\";\nimport { distance } from \"@turf/distance\";\nimport { Units } from \"@turf/helpers\";\nimport { segmentReduce } from \"@turf/meta\";\n\n/**\n * Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.\n *\n * @name length\n * @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers\n * @returns {number} length of GeoJSON\n * @example\n * var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);\n * var length = turf.length(line, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line];\n * line.properties.distance = length;\n */\nfunction length(\n geojson: Feature<any> | FeatureCollection<any> | GeometryCollection,\n options: {\n units?: Units;\n } = {}\n): number {\n // Calculate distance from 2-vertex line segments\n return segmentReduce(\n geojson,\n (previousValue, segment) => {\n const coords = segment!.geometry.coordinates;\n return previousValue! + distance(coords[0], coords[1], options);\n },\n 0\n );\n}\n\nexport { length };\nexport default length;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Feature, FeatureCollection, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
5
6
|
*
|
|
@@ -16,10 +17,8 @@ import { segmentReduce } from "@turf/meta";
|
|
|
16
17
|
* var addToMap = [line];
|
|
17
18
|
* line.properties.distance = length;
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, 0);
|
|
25
|
-
}
|
|
20
|
+
declare function length(geojson: Feature<any> | FeatureCollection<any> | GeometryCollection, options?: {
|
|
21
|
+
units?: Units;
|
|
22
|
+
}): number;
|
|
23
|
+
|
|
24
|
+
export { length as default, length };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, GeometryCollection } from
|
|
2
|
-
import { Units } from
|
|
1
|
+
import { Feature, FeatureCollection, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
5
6
|
*
|
|
@@ -16,6 +17,8 @@ import { Units } from "@turf/helpers";
|
|
|
16
17
|
* var addToMap = [line];
|
|
17
18
|
* line.properties.distance = length;
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
declare function length(geojson: Feature<any> | FeatureCollection<any> | GeometryCollection, options?: {
|
|
20
21
|
units?: Units;
|
|
21
22
|
}): number;
|
|
23
|
+
|
|
24
|
+
export { length as default, length };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { distance } from "@turf/distance";
|
|
6
|
+
import { segmentReduce } from "@turf/meta";
|
|
7
|
+
function length(geojson, options = {}) {
|
|
8
|
+
return segmentReduce(
|
|
9
|
+
geojson,
|
|
10
|
+
(previousValue, segment) => {
|
|
11
|
+
const coords = segment.geometry.coordinates;
|
|
12
|
+
return previousValue + distance(coords[0], coords[1], options);
|
|
13
|
+
},
|
|
14
|
+
0
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
__name(length, "length");
|
|
18
|
+
var turf_length_default = length;
|
|
19
|
+
export {
|
|
20
|
+
turf_length_default as default,
|
|
21
|
+
length
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, FeatureCollection, GeometryCollection } from \"geojson\";\nimport { distance } from \"@turf/distance\";\nimport { Units } from \"@turf/helpers\";\nimport { segmentReduce } from \"@turf/meta\";\n\n/**\n * Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.\n *\n * @name length\n * @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers\n * @returns {number} length of GeoJSON\n * @example\n * var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);\n * var length = turf.length(line, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line];\n * line.properties.distance = length;\n */\nfunction length(\n geojson: Feature<any> | FeatureCollection<any> | GeometryCollection,\n options: {\n units?: Units;\n } = {}\n): number {\n // Calculate distance from 2-vertex line segments\n return segmentReduce(\n geojson,\n (previousValue, segment) => {\n const coords = segment!.geometry.coordinates;\n return previousValue! + distance(coords[0], coords[1], options);\n },\n 0\n );\n}\n\nexport { length };\nexport default length;\n"],"mappings":";;;;AACA,SAAS,gBAAgB;AAEzB,SAAS,qBAAqB;AAkB9B,SAAS,OACP,SACA,UAEI,CAAC,GACG;AAER,SAAO;AAAA,IACL;AAAA,IACA,CAAC,eAAe,YAAY;AAC1B,YAAM,SAAS,QAAS,SAAS;AACjC,aAAO,gBAAiB,SAAS,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,IAChE;AAAA,IACA;AAAA,EACF;AACF;AAfS;AAkBT,IAAO,sBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/length",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf length module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -28,46 +28,51 @@
|
|
|
28
28
|
"units",
|
|
29
29
|
"gis"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "dist/cjs/index.cjs",
|
|
33
|
+
"module": "dist/esm/index.js",
|
|
34
|
+
"types": "dist/esm/index.d.ts",
|
|
33
35
|
"exports": {
|
|
34
36
|
"./package.json": "./package.json",
|
|
35
37
|
".": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.ts",
|
|
40
|
+
"default": "./dist/esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.cts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
},
|
|
41
|
-
"types": "dist/js/index.d.ts",
|
|
42
48
|
"sideEffects": false,
|
|
43
49
|
"files": [
|
|
44
50
|
"dist"
|
|
45
51
|
],
|
|
46
52
|
"scripts": {
|
|
47
|
-
"bench": "tsx bench.
|
|
48
|
-
"build": "
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"test": "npm-run-all test:*",
|
|
53
|
-
"test:tape": "tsx test.js"
|
|
53
|
+
"bench": "tsx bench.ts",
|
|
54
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
55
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
56
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
57
|
+
"test:tape": "tsx test.ts"
|
|
54
58
|
},
|
|
55
59
|
"devDependencies": {
|
|
56
|
-
"@types/
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
60
|
+
"@types/benchmark": "^2.1.5",
|
|
61
|
+
"@types/tape": "^4.2.32",
|
|
62
|
+
"benchmark": "^2.1.4",
|
|
63
|
+
"load-json-file": "^7.0.1",
|
|
64
|
+
"npm-run-all": "^4.1.5",
|
|
65
|
+
"tape": "^5.7.2",
|
|
66
|
+
"tsup": "^8.0.1",
|
|
67
|
+
"tsx": "^4.6.2",
|
|
68
|
+
"typescript": "^5.2.2",
|
|
69
|
+
"write-json-file": "^5.0.0"
|
|
65
70
|
},
|
|
66
71
|
"dependencies": {
|
|
67
|
-
"@turf/distance": "^7.0.0
|
|
68
|
-
"@turf/helpers": "^7.0.0
|
|
69
|
-
"@turf/meta": "^7.0.0
|
|
70
|
-
"tslib": "^2.
|
|
72
|
+
"@turf/distance": "^7.0.0",
|
|
73
|
+
"@turf/helpers": "^7.0.0",
|
|
74
|
+
"@turf/meta": "^7.0.0",
|
|
75
|
+
"tslib": "^2.6.2"
|
|
71
76
|
},
|
|
72
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
73
78
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
5
|
-
const meta_1 = require("@turf/meta");
|
|
6
|
-
/**
|
|
7
|
-
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
8
|
-
*
|
|
9
|
-
* @name length
|
|
10
|
-
* @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure
|
|
11
|
-
* @param {Object} [options={}] Optional parameters
|
|
12
|
-
* @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers
|
|
13
|
-
* @returns {number} length of GeoJSON
|
|
14
|
-
* @example
|
|
15
|
-
* var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
|
|
16
|
-
* var length = turf.length(line, {units: 'miles'});
|
|
17
|
-
*
|
|
18
|
-
* //addToMap
|
|
19
|
-
* var addToMap = [line];
|
|
20
|
-
* line.properties.distance = length;
|
|
21
|
-
*/
|
|
22
|
-
function length(geojson, options = {}) {
|
|
23
|
-
// Calculate distance from 2-vertex line segments
|
|
24
|
-
return meta_1.segmentReduce(geojson, (previousValue, segment) => {
|
|
25
|
-
const coords = segment.geometry.coordinates;
|
|
26
|
-
return previousValue + distance_1.default(coords[0], coords[1], options);
|
|
27
|
-
}, 0);
|
|
28
|
-
}
|
|
29
|
-
exports.default = length;
|