@placemarkio/polyline 1.2.0 → 2.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Placemark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,7 +1,9 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decode = decode;
4
+ exports.encode = encode;
5
+ exports.geoJSONToPolyline = geoJSONToPolyline;
6
+ exports.polylineToGeoJSON = polylineToGeoJSON;
5
7
  // https://github.com/mapbox/polyline/blob/master/src/polyline.js
6
8
  // Based off of [the offical Google document](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
7
9
  //
@@ -39,7 +41,7 @@ function resultChange(result) {
39
41
  * outside of the normal range.
40
42
  */
41
43
  function decode(str, precision = 5) {
42
- const factor = Math.pow(10, precision);
44
+ const factor = 10 ** precision;
43
45
  let index = 0;
44
46
  let lat = 0;
45
47
  let lng = 0;
@@ -86,7 +88,7 @@ function encode(coordinates, precision = 5) {
86
88
  if (!coordinates.length) {
87
89
  return "";
88
90
  }
89
- const factor = Math.pow(10, precision);
91
+ const factor = 10 ** precision;
90
92
  let output = encodeNumber(coordinates[0][1], 0, factor) +
91
93
  encodeNumber(coordinates[0][0], 0, factor);
92
94
  for (let i = 1; i < coordinates.length; i++) {
@@ -117,9 +119,4 @@ function polylineToGeoJSON(str, precision = 5) {
117
119
  coordinates: coords,
118
120
  };
119
121
  }
120
-
121
- exports.decode = decode;
122
- exports.encode = encode;
123
- exports.geoJSONToPolyline = geoJSONToPolyline;
124
- exports.polylineToGeoJSON = polylineToGeoJSON;
125
- //# sourceMappingURL=polyline.cjs.map
122
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ import type { LineString, Position } from "geojson";
2
+ /**
3
+ * Decodes any string into a [longitude, latitude] coordinates array.
4
+ *
5
+ * Any string is a valid polyline, but if you provide this
6
+ * with an arbitrary string, it'll produce coordinates well
7
+ * outside of the normal range.
8
+ */
9
+ export declare function decode(str: string, precision?: number): Position[];
10
+ /**
11
+ * Encodes the given [latitude, longitude] coordinates array.
12
+ *
13
+ * @param coordinates Coordinates, in longitude, latitude order
14
+ * @returns encoded polyline
15
+ */
16
+ export declare function encode(coordinates: number[][], precision?: number): string;
17
+ /**
18
+ * Encodes a GeoJSON LineString feature/geometry.
19
+ *
20
+ * @param geojson A LineString
21
+ */
22
+ export declare function geoJSONToPolyline(geojson: LineString, precision?: number): string;
23
+ /**
24
+ * Decodes to a GeoJSON LineString geometry.
25
+ *
26
+ * @param str An encoded polyline as a string.
27
+ */
28
+ export declare function polylineToGeoJSON(str: string, precision?: number): LineString;
29
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -26,3 +26,4 @@ export declare function geoJSONToPolyline(geojson: LineString, precision?: numbe
26
26
  * @param str An encoded polyline as a string.
27
27
  */
28
28
  export declare function polylineToGeoJSON(str: string, precision?: number): LineString;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -34,8 +34,8 @@ function resultChange(result) {
34
34
  * with an arbitrary string, it'll produce coordinates well
35
35
  * outside of the normal range.
36
36
  */
37
- function decode(str, precision = 5) {
38
- const factor = Math.pow(10, precision);
37
+ export function decode(str, precision = 5) {
38
+ const factor = 10 ** precision;
39
39
  let index = 0;
40
40
  let lat = 0;
41
41
  let lng = 0;
@@ -78,11 +78,11 @@ function decode(str, precision = 5) {
78
78
  * @param coordinates Coordinates, in longitude, latitude order
79
79
  * @returns encoded polyline
80
80
  */
81
- function encode(coordinates, precision = 5) {
81
+ export function encode(coordinates, precision = 5) {
82
82
  if (!coordinates.length) {
83
83
  return "";
84
84
  }
85
- const factor = Math.pow(10, precision);
85
+ const factor = 10 ** precision;
86
86
  let output = encodeNumber(coordinates[0][1], 0, factor) +
87
87
  encodeNumber(coordinates[0][0], 0, factor);
88
88
  for (let i = 1; i < coordinates.length; i++) {
@@ -98,7 +98,7 @@ function encode(coordinates, precision = 5) {
98
98
  *
99
99
  * @param geojson A LineString
100
100
  */
101
- function geoJSONToPolyline(geojson, precision = 5) {
101
+ export function geoJSONToPolyline(geojson, precision = 5) {
102
102
  return encode(geojson.coordinates, precision);
103
103
  }
104
104
  /**
@@ -106,13 +106,11 @@ function geoJSONToPolyline(geojson, precision = 5) {
106
106
  *
107
107
  * @param str An encoded polyline as a string.
108
108
  */
109
- function polylineToGeoJSON(str, precision = 5) {
109
+ export function polylineToGeoJSON(str, precision = 5) {
110
110
  const coords = decode(str, precision);
111
111
  return {
112
112
  type: "LineString",
113
113
  coordinates: coords,
114
114
  };
115
115
  }
116
-
117
- export { decode, encode, geoJSONToPolyline, polylineToGeoJSON };
118
- //# sourceMappingURL=polyline.es.mjs.map
116
+ //# sourceMappingURL=index.js.map