geo-coordinates-parser 1.5.7 → 1.6.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.
Files changed (60) hide show
  1. package/README.md +8 -6
  2. package/dist/cjs/converter.d.ts +15 -0
  3. package/dist/cjs/converter.js +363 -0
  4. package/dist/cjs/merge.d.ts +2 -0
  5. package/dist/cjs/merge.js +12 -0
  6. package/dist/cjs/package.json +3 -0
  7. package/dist/cjs/regex.d.ts +4 -0
  8. package/dist/cjs/regex.js +16 -0
  9. package/dist/cjs/tests/failFormats.d.ts +2 -0
  10. package/dist/cjs/tests/failFormats.js +26 -0
  11. package/dist/cjs/tests/makeTestFormatsJSON.d.ts +1 -0
  12. package/dist/cjs/tests/makeTestFormatsJSON.js +14 -0
  13. package/dist/cjs/tests/test.d.ts +1 -0
  14. package/dist/cjs/tests/test.js +56 -0
  15. package/dist/cjs/tests/testFormatConverter.d.ts +1 -0
  16. package/dist/cjs/tests/testFormatConverter.js +11 -0
  17. package/dist/cjs/tests/testIndividual.d.ts +1 -0
  18. package/dist/cjs/tests/testIndividual.js +26 -0
  19. package/dist/cjs/tests/testformats.d.ts +2 -0
  20. package/dist/cjs/tests/testformats.js +359 -0
  21. package/dist/cjs/toCoordinateFormat.d.ts +6 -0
  22. package/dist/cjs/toCoordinateFormat.js +42 -0
  23. package/dist/mjs/converter.d.ts +15 -0
  24. package/dist/mjs/converter.js +358 -0
  25. package/dist/mjs/merge.d.ts +2 -0
  26. package/dist/mjs/merge.js +6 -0
  27. package/dist/mjs/package.json +3 -0
  28. package/dist/mjs/regex.d.ts +4 -0
  29. package/dist/mjs/regex.js +10 -0
  30. package/dist/mjs/tests/failFormats.d.ts +2 -0
  31. package/dist/mjs/tests/failFormats.js +24 -0
  32. package/dist/mjs/tests/makeTestFormatsJSON.d.ts +1 -0
  33. package/dist/mjs/tests/makeTestFormatsJSON.js +9 -0
  34. package/dist/mjs/tests/test.d.ts +1 -0
  35. package/dist/mjs/tests/test.js +51 -0
  36. package/dist/mjs/tests/testFormatConverter.d.ts +1 -0
  37. package/dist/mjs/tests/testFormatConverter.js +6 -0
  38. package/dist/mjs/tests/testIndividual.d.ts +1 -0
  39. package/dist/mjs/tests/testIndividual.js +21 -0
  40. package/dist/mjs/tests/testformats.d.ts +2 -0
  41. package/dist/mjs/tests/testformats.js +357 -0
  42. package/dist/mjs/toCoordinateFormat.d.ts +6 -0
  43. package/dist/mjs/toCoordinateFormat.js +40 -0
  44. package/package.json +50 -42
  45. package/bundle/demo.html +0 -39
  46. package/bundle/geocoordsparser.js +0 -1
  47. package/bundle/workflow.txt +0 -8
  48. package/conf.py +0 -3
  49. package/converter.js +0 -419
  50. package/failFormats.js +0 -17
  51. package/formatsOnly.json +0 -41
  52. package/geocoordsparser.js +0 -0
  53. package/makeTestFormatsJSON.js +0 -11
  54. package/merge.js +0 -9
  55. package/test.js +0 -66
  56. package/testFormatConverter.js +0 -8
  57. package/testFormats.json +0 -352
  58. package/testIndividual.js +0 -21
  59. package/testformats.js +0 -351
  60. package/toCoordinateFormat.js +0 -52
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ //return an array of coordinate strings for testing
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //coordinations-parser formats
5
+ //https://www.npmjs.com/package/coordinate-parser
6
+ const coordsParserFormats = [
7
+ {
8
+ verbatimCoordinates: '40.123, -74.123',
9
+ verbatimLatitude: '40.123',
10
+ verbatimLongitude: '-74.123'
11
+ },
12
+ {
13
+ verbatimCoordinates: '40.123° N 74.123° W',
14
+ verbatimLatitude: '40.123° N',
15
+ verbatimLongitude: '74.123° W'
16
+ },
17
+ {
18
+ verbatimCoordinates: '40.123° N 74.123° W',
19
+ verbatimLatitude: '40.123° N',
20
+ verbatimLongitude: '74.123° W'
21
+ },
22
+ {
23
+ verbatimCoordinates: '40° 7´ 22.8" N 74° 7´ 22.8" W',
24
+ verbatimLatitude: '40° 7´ 22.8" N',
25
+ verbatimLongitude: '74° 7´ 22.8" W'
26
+ },
27
+ {
28
+ verbatimCoordinates: '40° 7.38’ , -74° 7.38’',
29
+ verbatimLatitude: '40° 7.38’',
30
+ verbatimLongitude: '-74° 7.38’'
31
+ },
32
+ {
33
+ verbatimCoordinates: 'N40°7’22.8’’, W74°7’22.8’’',
34
+ verbatimLatitude: 'N40°7’22.8’’',
35
+ verbatimLongitude: 'W74°7’22.8’’'
36
+ },
37
+ {
38
+ verbatimCoordinates: '40°7’22.8"N, 74°7’22.8"W',
39
+ verbatimLatitude: '40°7’22.8"N',
40
+ verbatimLongitude: '74°7’22.8"W'
41
+ },
42
+ {
43
+ verbatimCoordinates: '40°7\'22.8"N, 74°7\'22.8"W',
44
+ verbatimLatitude: '40°7\'22.8"N',
45
+ verbatimLongitude: '74°7\'22.8"W'
46
+ },
47
+ {
48
+ verbatimCoordinates: '40 7 22.8, -74 7 22.8',
49
+ verbatimLatitude: '40 7 22.8',
50
+ verbatimLongitude: '-74 7 22.8'
51
+ },
52
+ {
53
+ verbatimCoordinates: '40.123 -74.123',
54
+ verbatimLatitude: '40.123',
55
+ verbatimLongitude: '-74.123'
56
+ },
57
+ {
58
+ verbatimCoordinates: '40.123°,-74.123°',
59
+ verbatimLatitude: '40.123°',
60
+ verbatimLongitude: '-74.123°'
61
+ },
62
+ {
63
+ verbatimCoordinates: '40.123N74.123W',
64
+ verbatimLatitude: '40.123N',
65
+ verbatimLongitude: '74.123W'
66
+ },
67
+ {
68
+ verbatimCoordinates: '4007.38N7407.38W',
69
+ verbatimLatitude: '4007.38N',
70
+ verbatimLongitude: '7407.38W'
71
+ },
72
+ {
73
+ verbatimCoordinates: '40°7’22.8"N, 74°7’22.8"W',
74
+ verbatimLatitude: '40°7’22.8"N',
75
+ verbatimLongitude: '74°7’22.8"W'
76
+ },
77
+ {
78
+ verbatimCoordinates: '400722.8N740722.8W',
79
+ verbatimLatitude: '400722.8N',
80
+ verbatimLongitude: '740722.8W'
81
+ },
82
+ {
83
+ verbatimCoordinates: 'N 40 7.38 W 74 7.38',
84
+ verbatimLatitude: 'N 40 7.38',
85
+ verbatimLongitude: 'W 74 7.38'
86
+ },
87
+ {
88
+ verbatimCoordinates: '40:7:22.8N 74:7:22.8W',
89
+ verbatimLatitude: '40:7:22.8N',
90
+ verbatimLongitude: '74:7:22.8W'
91
+ },
92
+ {
93
+ verbatimCoordinates: '40:7:23N,74:7:23W',
94
+ verbatimLatitude: '40:7:23N',
95
+ verbatimLongitude: '74:7:23W',
96
+ decimalLatitude: 40.1230555555,
97
+ decimalLongitude: -74.1230555555
98
+ },
99
+ {
100
+ verbatimCoordinates: '40°7’23"N 74°7’23"W',
101
+ verbatimLatitude: '40°7’23"N',
102
+ verbatimLongitude: '74°7’23"W',
103
+ decimalLatitude: 40.1230555555,
104
+ decimalLongitude: -74.12305555555555
105
+ },
106
+ {
107
+ verbatimCoordinates: '40°7’23"S 74°7’23"E',
108
+ verbatimLatitude: '40°7’23"S',
109
+ verbatimLongitude: '74°7’23"E',
110
+ decimalLatitude: -40.1230555555,
111
+ decimalLongitude: 74.12305555555555
112
+ },
113
+ {
114
+ verbatimCoordinates: '40°7’23" -74°7’23"',
115
+ verbatimLatitude: '40°7’23"',
116
+ verbatimLongitude: '-74°7’23"',
117
+ decimalLatitude: 40.1230555555,
118
+ decimalLongitude: -74.123055555
119
+ },
120
+ {
121
+ verbatimCoordinates: '40d 7’ 23" N 74d 7’ 23" W',
122
+ verbatimLatitude: '40d 7’ 23" N',
123
+ verbatimLongitude: '74d 7’ 23" W',
124
+ decimalLatitude: 40.1230555555,
125
+ decimalLongitude: -74.123055555
126
+ },
127
+ {
128
+ verbatimCoordinates: '40.123N 74.123W',
129
+ verbatimLatitude: '40.123N',
130
+ verbatimLongitude: '74.123W'
131
+ },
132
+ {
133
+ verbatimCoordinates: '40° 7.38, -74° 7.38',
134
+ verbatimLatitude: '40° 7.38',
135
+ verbatimLongitude: '-74° 7.38'
136
+ },
137
+ {
138
+ verbatimCoordinates: '40° 7.38, -74° 7.38',
139
+ verbatimLatitude: '40° 7.38',
140
+ verbatimLongitude: '-74° 7.38'
141
+ },
142
+ {
143
+ verbatimCoordinates: '40 7 22.8; -74 7 22.8',
144
+ verbatimLatitude: '40 7 22.8',
145
+ verbatimLongitude: '-74 7 22.8'
146
+ }
147
+ ];
148
+ const coordsParserDecimals = {
149
+ decimalLatitude: 40.123,
150
+ decimalLongitude: -74.123
151
+ };
152
+ //formats from https://gist.github.com/moole/3707127/337bd31d813a10abcf55084381803e5bbb0b20dc
153
+ const coordsRegexFormats = [
154
+ {
155
+ verbatimCoordinates: '50°4\'17.698"south, 14°24\'2.826"east',
156
+ verbatimLatitude: '50°4\'17.698"south',
157
+ verbatimLongitude: '14°24\'2.826"east',
158
+ decimalLatitude: -50.0715827777777778,
159
+ decimalLongitude: 14.400785
160
+ },
161
+ {
162
+ verbatimCoordinates: '50d4m17.698S 14d24m2.826E',
163
+ verbatimLatitude: '50d4m17.698S',
164
+ verbatimLongitude: '14d24m2.826E',
165
+ decimalLatitude: -50.0715827777777778,
166
+ decimalLongitude: 14.400785
167
+ },
168
+ {
169
+ verbatimCoordinates: '40:26:46N,79:56:55W',
170
+ verbatimLatitude: '40:26:46N',
171
+ verbatimLongitude: '79:56:55W',
172
+ decimalLatitude: 40.4461111111111111,
173
+ decimalLongitude: -79.9486111111111111
174
+ },
175
+ {
176
+ verbatimCoordinates: '40:26:46.302N 79:56:55.903W',
177
+ verbatimLatitude: '40:26:46.302N',
178
+ verbatimLongitude: '79:56:55.903W',
179
+ decimalLatitude: 40.446195,
180
+ decimalLongitude: -79.9488619444444444
181
+ },
182
+ {
183
+ verbatimCoordinates: '40°26′47″N 79°58′36″W',
184
+ verbatimLatitude: '40°26′47″N',
185
+ verbatimLongitude: '79°58′36″W',
186
+ decimalLatitude: 40.4463888888888889,
187
+ decimalLongitude: -79.9766666666666667
188
+ },
189
+ {
190
+ verbatimCoordinates: '40d 26′ 47″ N 79d 58′ 36″ W',
191
+ verbatimLatitude: '40d 26′ 47″ N',
192
+ verbatimLongitude: '79d 58′ 36″ W',
193
+ decimalLatitude: 40.4463888888888889,
194
+ decimalLongitude: -79.9766666666666667
195
+ },
196
+ {
197
+ verbatimCoordinates: '40.446195N 79.948862W',
198
+ verbatimLatitude: '40.446195N',
199
+ verbatimLongitude: '79.948862W',
200
+ decimalLatitude: 40.446195,
201
+ decimalLongitude: -79.948862
202
+ },
203
+ {
204
+ verbatimCoordinates: '40,446195° 79,948862°',
205
+ verbatimLatitude: '40,446195°',
206
+ verbatimLongitude: '79,948862°',
207
+ decimalLatitude: 40.446195,
208
+ decimalLongitude: 79.948862
209
+ },
210
+ {
211
+ verbatimCoordinates: '40° 26.7717, -79° 56.93172',
212
+ verbatimLatitude: '40° 26.7717',
213
+ verbatimLongitude: '-79° 56.93172',
214
+ decimalLatitude: 40.446195,
215
+ decimalLongitude: -79.948862
216
+ },
217
+ {
218
+ verbatimCoordinates: '40.446195, -79.948862',
219
+ verbatimLatitude: '40.446195',
220
+ verbatimLongitude: '-79.948862',
221
+ decimalLatitude: 40.446195,
222
+ decimalLongitude: -79.948862
223
+ },
224
+ {
225
+ verbatimCoordinates: '40.123256; -74.123256',
226
+ verbatimLatitude: '40.123256',
227
+ verbatimLongitude: '-74.123256',
228
+ decimalLatitude: 40.123256,
229
+ decimalLongitude: -74.123256
230
+ },
231
+ {
232
+ verbatimCoordinates: '18°24S 22°45E',
233
+ verbatimLatitude: '18°24S',
234
+ verbatimLongitude: '22°45E',
235
+ decimalLatitude: -18.4,
236
+ decimalLongitude: 22.75
237
+ }
238
+ ];
239
+ const otherFormats = [
240
+ // additional formats we've encountered
241
+ {
242
+ verbatimCoordinates: '10.432342S 10.6345345E',
243
+ verbatimLatitude: '10.432342S',
244
+ verbatimLongitude: '10.6345345E',
245
+ decimalLatitude: -10.432342,
246
+ decimalLongitude: 10.6345345
247
+ },
248
+ {
249
+ verbatimCoordinates: '10.00S 10.00E',
250
+ verbatimLatitude: '10.00S',
251
+ verbatimLongitude: '10.00E',
252
+ decimalLatitude: -10.00000,
253
+ decimalLongitude: 10.00000
254
+ },
255
+ {
256
+ verbatimCoordinates: '00.00S 01.00E',
257
+ verbatimLatitude: '00.00S',
258
+ verbatimLongitude: '01.00E',
259
+ decimalLatitude: 0.00000,
260
+ decimalLongitude: 1.00000
261
+ },
262
+ {
263
+ verbatimCoordinates: '18.24S 22.45E',
264
+ verbatimLatitude: '18.24S',
265
+ verbatimLongitude: '22.45E',
266
+ decimalLatitude: -18.4,
267
+ decimalLongitude: 22.75
268
+ },
269
+ {
270
+ verbatimCoordinates: '27deg 15min 45.2sec S 18deg 32min 53.7sec E',
271
+ verbatimLatitude: '27deg 15min 45.2sec S',
272
+ verbatimLongitude: '18deg 32min 53.7sec E',
273
+ decimalLatitude: -27.2625555555555556,
274
+ decimalLongitude: 18.54825
275
+ },
276
+ {
277
+ verbatimCoordinates: '-23.3245° S / 28.2344° E',
278
+ verbatimLatitude: '-23.3245° S',
279
+ verbatimLongitude: '28.2344° E',
280
+ decimalLatitude: -23.3245,
281
+ decimalLongitude: 28.2344
282
+ },
283
+ {
284
+ verbatimCoordinates: '40° 26.7717 -79° 56.93172',
285
+ verbatimLatitude: '40° 26.7717',
286
+ verbatimLongitude: '-79° 56.93172',
287
+ decimalLatitude: 40.446195,
288
+ decimalLongitude: -79.948862
289
+ },
290
+ {
291
+ verbatimCoordinates: '27.15.45S 18.32.53E',
292
+ verbatimLatitude: '27.15.45S',
293
+ verbatimLongitude: '18.32.53E',
294
+ decimalLatitude: -27.2625,
295
+ decimalLongitude: 18.548055
296
+ },
297
+ {
298
+ verbatimCoordinates: '-27.15.45 18.32.53',
299
+ verbatimLatitude: '-27.15.45',
300
+ verbatimLongitude: '18.32.53',
301
+ decimalLatitude: -27.2625,
302
+ decimalLongitude: 18.548055
303
+ },
304
+ {
305
+ verbatimCoordinates: '27.15.45.2S 18.32.53.4E',
306
+ verbatimLatitude: '27.15.45.2S',
307
+ verbatimLongitude: '18.32.53.4E',
308
+ decimalLatitude: -27.262556,
309
+ decimalLongitude: 18.548167
310
+ },
311
+ {
312
+ verbatimCoordinates: '27.15.45,2S 18.32.53,4E',
313
+ verbatimLatitude: '27.15.45,2S',
314
+ verbatimLongitude: '18.32.53,4E',
315
+ decimalLatitude: -27.262556,
316
+ decimalLongitude: 18.548167
317
+ },
318
+ {
319
+ verbatimCoordinates: 'S23.43563 ° E22.45634 °',
320
+ verbatimLatitude: 'S23.43563 °',
321
+ verbatimLongitude: 'E22.45634 °',
322
+ decimalLatitude: -23.43563,
323
+ decimalLongitude: 22.45634
324
+ },
325
+ {
326
+ verbatimCoordinates: '27,71372° S 23,07771° E',
327
+ verbatimLatitude: '27,71372° S',
328
+ verbatimLongitude: '23,07771° E',
329
+ decimalLatitude: -27.71372,
330
+ decimalLongitude: 23.07771
331
+ },
332
+ {
333
+ verbatimCoordinates: '27.45.34 S 23.23.23 E',
334
+ verbatimLatitude: '27.45.34 S',
335
+ verbatimLongitude: '23.23.23 E',
336
+ decimalLatitude: -27.759444,
337
+ decimalLongitude: 23.38972222
338
+ },
339
+ {
340
+ verbatimCoordinates: 'S 27.45.34 E 23.23.23',
341
+ verbatimLatitude: 'S 27.45.34',
342
+ verbatimLongitude: 'E 23.23.23',
343
+ decimalLatitude: -27.759444,
344
+ decimalLongitude: 23.38972222
345
+ }
346
+ ];
347
+ function getAllTestFormats() {
348
+ const arr1 = [];
349
+ coordsParserFormats.forEach(item => {
350
+ if (item.decimalLatitude) {
351
+ arr1.push(item);
352
+ }
353
+ else {
354
+ arr1.push(Object.assign(Object.assign({}, item), coordsParserDecimals));
355
+ }
356
+ });
357
+ return [...arr1, ...coordsRegexFormats, ...otherFormats];
358
+ }
359
+ exports.default = getAllTestFormats();
@@ -0,0 +1,6 @@
1
+ export default toCoordinateFormat;
2
+ /**
3
+ * Converts decimalCoordinates to other formats commonly used
4
+ * @param {*} format Either DMS or DM
5
+ */
6
+ declare function toCoordinateFormat(format: any): string;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ //borrowed from https://www.codegrepper.com/code-examples/javascript/javascript+converting+latitude+longitude+to+gps+coordinates
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * Converts decimalCoordinates to other formats commonly used
6
+ * @param {*} format Either DMS or DM
7
+ */
8
+ function toCoordinateFormat(format) {
9
+ if (!['DMS', 'DM'].includes(format))
10
+ throw new Error('invalid format specified');
11
+ if (this.decimalCoordinates && this.decimalCoordinates.trim()) {
12
+ const parts = this.decimalCoordinates.split(',').map(x => x.trim());
13
+ const convertedLat = convert(parts[0], format, true);
14
+ const convertedLong = convert(parts[1], format, false);
15
+ return `${convertedLat}, ${convertedLong}`;
16
+ }
17
+ else {
18
+ throw new Error('no decimal coordinates to convert');
19
+ }
20
+ }
21
+ //assumes everything is valid...
22
+ function convert(coordString, format, isLatitude) {
23
+ const coord = Number(coordString);
24
+ let direction;
25
+ if (isLatitude) {
26
+ direction = coord >= 0 ? "N" : "S";
27
+ }
28
+ else {
29
+ direction = coord >= 0 ? "E" : "W";
30
+ }
31
+ const absolute = Math.abs(coord);
32
+ const degrees = Math.floor(absolute);
33
+ const minutesNotTruncated = (absolute - degrees) * 60;
34
+ if (format == 'DM') {
35
+ return `${degrees}° ${minutesNotTruncated.toFixed(3).replace(/\.0+$/, '')}' ${direction}`;
36
+ }
37
+ //else
38
+ const minutes = Math.floor(minutesNotTruncated);
39
+ const seconds = ((minutesNotTruncated - minutes) * 60).toFixed(1).replace(/\.0$/, '');
40
+ return `${degrees}° ${minutes}' ${seconds}" ${direction}`;
41
+ }
42
+ exports.default = toCoordinateFormat;
@@ -0,0 +1,15 @@
1
+ export default converter;
2
+ /**
3
+ * Function for converting coordinates in a variety of formats to decimal coordinates
4
+ * @param {string} coordsString The coordinates string to convert
5
+ * @param {number} decimalPlaces The number of decimal places for converted coordinates; default is 5
6
+ * @returns {object} { verbatimCoordinates, decimalCoordinates, decimalLatitude, decimalLongitude }
7
+ */
8
+ declare function converter(coordsString: string, decimalPlaces: number): object;
9
+ declare namespace converter {
10
+ export { to };
11
+ }
12
+ declare const to: Readonly<{
13
+ DMS: "DMS";
14
+ DM: "DM";
15
+ }>;