@turf/line-slice-along 7.3.1 → 7.3.3
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 +12 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +24 -9
- package/dist/esm/index.d.ts +24 -9
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +1 -1
- package/package.json +12 -10
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
2
|
var _bearing = require('@turf/bearing');
|
|
3
3
|
var _distance = require('@turf/distance');
|
|
4
4
|
var _destination = require('@turf/destination');
|
|
5
5
|
var _helpers = require('@turf/helpers');
|
|
6
|
-
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
7
|
-
options = options || {};
|
|
6
|
+
function lineSliceAlong(line, startDist, stopDist, options = {}) {
|
|
8
7
|
if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
|
|
8
|
+
const { units = "kilometers" } = options;
|
|
9
9
|
var coords;
|
|
10
10
|
var slice = [];
|
|
11
11
|
if (line.type === "Feature") coords = line.geometry.coordinates;
|
|
12
12
|
else if (line.type === "LineString") coords = line.coordinates;
|
|
13
13
|
else throw new Error("input must be a LineString Feature or Geometry");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (
|
|
14
|
+
const origCoordsLength = coords.length;
|
|
15
|
+
let travelled = 0;
|
|
16
|
+
let overshot, direction, interpolated;
|
|
17
|
+
for (let i = 0; i < coords.length; i++) {
|
|
18
18
|
if (startDist >= travelled && i === coords.length - 1) break;
|
|
19
19
|
else if (travelled > startDist && slice.length === 0) {
|
|
20
|
-
|
|
21
|
-
if (!
|
|
20
|
+
let overshot2 = startDist - travelled;
|
|
21
|
+
if (!overshot2) {
|
|
22
22
|
slice.push(coords[i]);
|
|
23
23
|
return _helpers.lineString.call(void 0, slice);
|
|
24
24
|
}
|
|
25
25
|
direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
|
|
26
|
-
interpolated = _destination.destination.call(void 0, coords[i],
|
|
26
|
+
interpolated = _destination.destination.call(void 0, coords[i], overshot2, direction, { units });
|
|
27
27
|
slice.push(interpolated.geometry.coordinates);
|
|
28
28
|
}
|
|
29
29
|
if (travelled >= stopDist) {
|
|
@@ -33,7 +33,7 @@ function lineSliceAlong(line, startDist, stopDist, options) {
|
|
|
33
33
|
return _helpers.lineString.call(void 0, slice);
|
|
34
34
|
}
|
|
35
35
|
direction = _bearing.bearing.call(void 0, coords[i], coords[i - 1]) - 180;
|
|
36
|
-
interpolated = _destination.destination.call(void 0, coords[i], overshot, direction,
|
|
36
|
+
interpolated = _destination.destination.call(void 0, coords[i], overshot, direction, { units });
|
|
37
37
|
slice.push(interpolated.geometry.coordinates);
|
|
38
38
|
return _helpers.lineString.call(void 0, slice);
|
|
39
39
|
}
|
|
@@ -43,7 +43,7 @@ function lineSliceAlong(line, startDist, stopDist, options) {
|
|
|
43
43
|
if (i === coords.length - 1) {
|
|
44
44
|
return _helpers.lineString.call(void 0, slice);
|
|
45
45
|
}
|
|
46
|
-
travelled += _distance.distance.call(void 0, coords[i], coords[i + 1],
|
|
46
|
+
travelled += _distance.distance.call(void 0, coords[i], coords[i + 1], { units });
|
|
47
47
|
}
|
|
48
48
|
if (travelled < startDist && coords.length === origCoordsLength)
|
|
49
49
|
throw new Error("Start position is beyond line");
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice-along/dist/cjs/index.cjs","../../index.
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice-along/dist/cjs/index.cjs","../../index.ts"],"names":["overshot"],"mappings":"AAAA;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a,gCAAA,MAAS,CAAO,CAAC,CAAA,EAAG,MAAA,CAAO,EAAA,EAAI,CAAC,CAAA,EAAG,EAAE,MAAM,CAAC,CAAA;AAAA,EAC3D;AAEA,EAAA,GAAA,CAAI,UAAA,EAAY,UAAA,GAAa,MAAA,CAAO,OAAA,IAAW,gBAAA;AAC7C,IAAA,MAAM,IAAI,KAAA,CAAM,+BAA+B,CAAA;AAEjD,EAAA,IAAI,KAAA,EAAO,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,CAAC,CAAA;AACnC,EAAA,OAAO,iCAAA,CAAY,IAAA,EAAM,IAAI,CAAC,CAAA;AAChC;AAGA,IAAO,cAAA,EAAQ,cAAA;ADxCf;AACE;AACA;AACF,yEAAC","file":"/home/runner/work/turf/turf/packages/turf-line-slice-along/dist/cjs/index.cjs","sourcesContent":[null,"import { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineString, isObject, Units } from \"@turf/helpers\";\nimport { Feature, LineString, Point, Position } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},\n * and a specified distance along the line to a stop point\n * and returns a subsection of the line in-between those points.\n *\n * This can be useful for extracting only the part of a route between two distances.\n *\n * @function\n * @param {Feature<LineString>|LineString} line input line\n * @param {number} startDist distance along the line to starting point\n * @param {number} stopDist distance along the line to ending point\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);\n * var start = 12.5;\n * var stop = 25;\n * var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, start, stop, sliced]\n */\nfunction lineSliceAlong(\n line: Feature<LineString> | LineString,\n startDist: number,\n stopDist: number,\n options: { units?: Units } = {}\n): Feature<LineString> {\n // Optional parameters\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { units = \"kilometers\" } = options;\n\n var coords: Position[];\n var slice: Position[] = [];\n\n // Validation\n if (line.type === \"Feature\") coords = line.geometry.coordinates;\n else if (line.type === \"LineString\") coords = line.coordinates;\n else throw new Error(\"input must be a LineString Feature or Geometry\");\n const origCoordsLength = coords.length;\n let travelled = 0;\n let overshot: number, direction: number, interpolated: Feature<Point>;\n for (let i = 0; i < coords.length; i++) {\n if (startDist >= travelled && i === coords.length - 1) break;\n else if (travelled > startDist && slice.length === 0) {\n let overshot = startDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, { units });\n slice.push(interpolated.geometry.coordinates);\n }\n\n if (travelled >= stopDist) {\n overshot = stopDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, { units });\n slice.push(interpolated.geometry.coordinates);\n return lineString(slice);\n }\n\n if (travelled >= startDist) {\n slice.push(coords[i]);\n }\n\n if (i === coords.length - 1) {\n return lineString(slice);\n }\n\n travelled += distance(coords[i], coords[i + 1], { units });\n }\n\n if (travelled < startDist && coords.length === origCoordsLength)\n throw new Error(\"Start position is beyond line\");\n\n var last = coords[coords.length - 1];\n return lineString([last, last]);\n}\n\nexport { lineSliceAlong };\nexport default lineSliceAlong;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import { Feature, LineString } from 'geojson';
|
|
2
1
|
import { Units } from '@turf/helpers';
|
|
2
|
+
import { Feature, LineString } from 'geojson';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},
|
|
6
|
+
* and a specified distance along the line to a stop point
|
|
7
|
+
* and returns a subsection of the line in-between those points.
|
|
8
|
+
*
|
|
9
|
+
* This can be useful for extracting only the part of a route between two distances.
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @param {Feature<LineString>|LineString} line input line
|
|
13
|
+
* @param {number} startDist distance along the line to starting point
|
|
14
|
+
* @param {number} stopDist distance along the line to ending point
|
|
15
|
+
* @param {Object} [options={}] Optional parameters
|
|
16
|
+
* @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
|
|
17
|
+
* @returns {Feature<LineString>} sliced line
|
|
18
|
+
* @example
|
|
19
|
+
* var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);
|
|
20
|
+
* var start = 12.5;
|
|
21
|
+
* var stop = 25;
|
|
22
|
+
* var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});
|
|
23
|
+
*
|
|
24
|
+
* //addToMap
|
|
25
|
+
* var addToMap = [line, start, stop, sliced]
|
|
6
26
|
*/
|
|
7
|
-
declare function lineSliceAlong(
|
|
8
|
-
line: Feature<LineString> | LineString,
|
|
9
|
-
startDist: number,
|
|
10
|
-
stopDist: number,
|
|
11
|
-
options?: {
|
|
27
|
+
declare function lineSliceAlong(line: Feature<LineString> | LineString, startDist: number, stopDist: number, options?: {
|
|
12
28
|
units?: Units;
|
|
13
|
-
|
|
14
|
-
): Feature<LineString>;
|
|
29
|
+
}): Feature<LineString>;
|
|
15
30
|
|
|
16
31
|
export { lineSliceAlong as default, lineSliceAlong };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
|
-
import { Feature, LineString } from 'geojson';
|
|
2
1
|
import { Units } from '@turf/helpers';
|
|
2
|
+
import { Feature, LineString } from 'geojson';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},
|
|
6
|
+
* and a specified distance along the line to a stop point
|
|
7
|
+
* and returns a subsection of the line in-between those points.
|
|
8
|
+
*
|
|
9
|
+
* This can be useful for extracting only the part of a route between two distances.
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @param {Feature<LineString>|LineString} line input line
|
|
13
|
+
* @param {number} startDist distance along the line to starting point
|
|
14
|
+
* @param {number} stopDist distance along the line to ending point
|
|
15
|
+
* @param {Object} [options={}] Optional parameters
|
|
16
|
+
* @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
|
|
17
|
+
* @returns {Feature<LineString>} sliced line
|
|
18
|
+
* @example
|
|
19
|
+
* var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);
|
|
20
|
+
* var start = 12.5;
|
|
21
|
+
* var stop = 25;
|
|
22
|
+
* var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});
|
|
23
|
+
*
|
|
24
|
+
* //addToMap
|
|
25
|
+
* var addToMap = [line, start, stop, sliced]
|
|
6
26
|
*/
|
|
7
|
-
declare function lineSliceAlong(
|
|
8
|
-
line: Feature<LineString> | LineString,
|
|
9
|
-
startDist: number,
|
|
10
|
-
stopDist: number,
|
|
11
|
-
options?: {
|
|
27
|
+
declare function lineSliceAlong(line: Feature<LineString> | LineString, startDist: number, stopDist: number, options?: {
|
|
12
28
|
units?: Units;
|
|
13
|
-
|
|
14
|
-
): Feature<LineString>;
|
|
29
|
+
}): Feature<LineString>;
|
|
15
30
|
|
|
16
31
|
export { lineSliceAlong as default, lineSliceAlong };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
// index.
|
|
1
|
+
// index.ts
|
|
2
2
|
import { bearing } from "@turf/bearing";
|
|
3
3
|
import { distance } from "@turf/distance";
|
|
4
4
|
import { destination } from "@turf/destination";
|
|
5
5
|
import { lineString, isObject } from "@turf/helpers";
|
|
6
|
-
function lineSliceAlong(line, startDist, stopDist, options) {
|
|
7
|
-
options = options || {};
|
|
6
|
+
function lineSliceAlong(line, startDist, stopDist, options = {}) {
|
|
8
7
|
if (!isObject(options)) throw new Error("options is invalid");
|
|
8
|
+
const { units = "kilometers" } = options;
|
|
9
9
|
var coords;
|
|
10
10
|
var slice = [];
|
|
11
11
|
if (line.type === "Feature") coords = line.geometry.coordinates;
|
|
12
12
|
else if (line.type === "LineString") coords = line.coordinates;
|
|
13
13
|
else throw new Error("input must be a LineString Feature or Geometry");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (
|
|
14
|
+
const origCoordsLength = coords.length;
|
|
15
|
+
let travelled = 0;
|
|
16
|
+
let overshot, direction, interpolated;
|
|
17
|
+
for (let i = 0; i < coords.length; i++) {
|
|
18
18
|
if (startDist >= travelled && i === coords.length - 1) break;
|
|
19
19
|
else if (travelled > startDist && slice.length === 0) {
|
|
20
|
-
|
|
21
|
-
if (!
|
|
20
|
+
let overshot2 = startDist - travelled;
|
|
21
|
+
if (!overshot2) {
|
|
22
22
|
slice.push(coords[i]);
|
|
23
23
|
return lineString(slice);
|
|
24
24
|
}
|
|
25
25
|
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
26
|
-
interpolated = destination(coords[i],
|
|
26
|
+
interpolated = destination(coords[i], overshot2, direction, { units });
|
|
27
27
|
slice.push(interpolated.geometry.coordinates);
|
|
28
28
|
}
|
|
29
29
|
if (travelled >= stopDist) {
|
|
@@ -33,7 +33,7 @@ function lineSliceAlong(line, startDist, stopDist, options) {
|
|
|
33
33
|
return lineString(slice);
|
|
34
34
|
}
|
|
35
35
|
direction = bearing(coords[i], coords[i - 1]) - 180;
|
|
36
|
-
interpolated = destination(coords[i], overshot, direction,
|
|
36
|
+
interpolated = destination(coords[i], overshot, direction, { units });
|
|
37
37
|
slice.push(interpolated.geometry.coordinates);
|
|
38
38
|
return lineString(slice);
|
|
39
39
|
}
|
|
@@ -43,7 +43,7 @@ function lineSliceAlong(line, startDist, stopDist, options) {
|
|
|
43
43
|
if (i === coords.length - 1) {
|
|
44
44
|
return lineString(slice);
|
|
45
45
|
}
|
|
46
|
-
travelled += distance(coords[i], coords[i + 1],
|
|
46
|
+
travelled += distance(coords[i], coords[i + 1], { units });
|
|
47
47
|
}
|
|
48
48
|
if (travelled < startDist && coords.length === origCoordsLength)
|
|
49
49
|
throw new Error("Start position is beyond line");
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { bearing } from \"@turf/bearing\";\nimport { distance } from \"@turf/distance\";\nimport { destination } from \"@turf/destination\";\nimport { lineString, isObject, Units } from \"@turf/helpers\";\nimport { Feature, LineString, Point, Position } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a specified distance along the line to a start {@link Point},\n * and a specified distance along the line to a stop point\n * and returns a subsection of the line in-between those points.\n *\n * This can be useful for extracting only the part of a route between two distances.\n *\n * @function\n * @param {Feature<LineString>|LineString} line input line\n * @param {number} startDist distance along the line to starting point\n * @param {number} stopDist distance along the line to ending point\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);\n * var start = 12.5;\n * var stop = 25;\n * var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [line, start, stop, sliced]\n */\nfunction lineSliceAlong(\n line: Feature<LineString> | LineString,\n startDist: number,\n stopDist: number,\n options: { units?: Units } = {}\n): Feature<LineString> {\n // Optional parameters\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { units = \"kilometers\" } = options;\n\n var coords: Position[];\n var slice: Position[] = [];\n\n // Validation\n if (line.type === \"Feature\") coords = line.geometry.coordinates;\n else if (line.type === \"LineString\") coords = line.coordinates;\n else throw new Error(\"input must be a LineString Feature or Geometry\");\n const origCoordsLength = coords.length;\n let travelled = 0;\n let overshot: number, direction: number, interpolated: Feature<Point>;\n for (let i = 0; i < coords.length; i++) {\n if (startDist >= travelled && i === coords.length - 1) break;\n else if (travelled > startDist && slice.length === 0) {\n let overshot = startDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, { units });\n slice.push(interpolated.geometry.coordinates);\n }\n\n if (travelled >= stopDist) {\n overshot = stopDist - travelled;\n if (!overshot) {\n slice.push(coords[i]);\n return lineString(slice);\n }\n direction = bearing(coords[i], coords[i - 1]) - 180;\n interpolated = destination(coords[i], overshot, direction, { units });\n slice.push(interpolated.geometry.coordinates);\n return lineString(slice);\n }\n\n if (travelled >= startDist) {\n slice.push(coords[i]);\n }\n\n if (i === coords.length - 1) {\n return lineString(slice);\n }\n\n travelled += distance(coords[i], coords[i + 1], { units });\n }\n\n if (travelled < startDist && coords.length === origCoordsLength)\n throw new Error(\"Start position is beyond line\");\n\n var last = coords[coords.length - 1];\n return lineString([last, last]);\n}\n\nexport { lineSliceAlong };\nexport default lineSliceAlong;\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,YAAY,gBAAuB;AA0B5C,SAAS,eACP,MACA,WACA,UACA,UAA6B,CAAC,GACT;AAErB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,EAAE,QAAQ,aAAa,IAAI;AAEjC,MAAI;AACJ,MAAI,QAAoB,CAAC;AAGzB,MAAI,KAAK,SAAS,UAAW,UAAS,KAAK,SAAS;AAAA,WAC3C,KAAK,SAAS,aAAc,UAAS,KAAK;AAAA,MAC9C,OAAM,IAAI,MAAM,gDAAgD;AACrE,QAAM,mBAAmB,OAAO;AAChC,MAAI,YAAY;AAChB,MAAI,UAAkB,WAAmB;AACzC,WAAS,IAAI,GAAG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6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-slice-along",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.3",
|
|
4
4
|
"description": "Useful for extracting only the part of a route between two distances.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,22 +50,24 @@
|
|
|
50
50
|
"test:tape": "tsx test.ts"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@turf/along": "7.3.
|
|
54
|
-
"@turf/length": "7.3.
|
|
53
|
+
"@turf/along": "7.3.3",
|
|
54
|
+
"@turf/length": "7.3.3",
|
|
55
55
|
"@types/benchmark": "^2.1.5",
|
|
56
56
|
"@types/tape": "^5.8.1",
|
|
57
57
|
"benchmark": "^2.1.4",
|
|
58
58
|
"load-json-file": "^7.0.1",
|
|
59
59
|
"tape": "^5.9.0",
|
|
60
60
|
"tsup": "^8.4.0",
|
|
61
|
-
"tsx": "^4.19.4"
|
|
61
|
+
"tsx": "^4.19.4",
|
|
62
|
+
"typescript": "^5.8.3"
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
|
-
"@turf/bearing": "7.3.
|
|
65
|
-
"@turf/destination": "7.3.
|
|
66
|
-
"@turf/distance": "7.3.
|
|
67
|
-
"@turf/helpers": "7.3.
|
|
68
|
-
"@types/geojson": "^7946.0.10"
|
|
65
|
+
"@turf/bearing": "7.3.3",
|
|
66
|
+
"@turf/destination": "7.3.3",
|
|
67
|
+
"@turf/distance": "7.3.3",
|
|
68
|
+
"@turf/helpers": "7.3.3",
|
|
69
|
+
"@types/geojson": "^7946.0.10",
|
|
70
|
+
"tslib": "^2.8.1"
|
|
69
71
|
},
|
|
70
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "fa0e2da8ce02d9a82720eae922f89c9386596e04"
|
|
71
73
|
}
|