geo-coordinates-parser 1.5.8 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/README.md +5 -4
  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 -443
  50. package/failFormats.js +0 -24
  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/regex.js +0 -20
  56. package/test.js +0 -66
  57. package/testFormatConverter.js +0 -8
  58. package/testFormats.json +0 -352
  59. package/testIndividual.js +0 -22
  60. package/testformats.js +0 -372
  61. package/toCoordinateFormat.js +0 -52
@@ -0,0 +1,357 @@
1
+ //return an array of coordinate strings for testing
2
+ //coordinations-parser formats
3
+ //https://www.npmjs.com/package/coordinate-parser
4
+ const coordsParserFormats = [
5
+ {
6
+ verbatimCoordinates: '40.123, -74.123',
7
+ verbatimLatitude: '40.123',
8
+ verbatimLongitude: '-74.123'
9
+ },
10
+ {
11
+ verbatimCoordinates: '40.123° N 74.123° W',
12
+ verbatimLatitude: '40.123° N',
13
+ verbatimLongitude: '74.123° W'
14
+ },
15
+ {
16
+ verbatimCoordinates: '40.123° N 74.123° W',
17
+ verbatimLatitude: '40.123° N',
18
+ verbatimLongitude: '74.123° W'
19
+ },
20
+ {
21
+ verbatimCoordinates: '40° 7´ 22.8" N 74° 7´ 22.8" W',
22
+ verbatimLatitude: '40° 7´ 22.8" N',
23
+ verbatimLongitude: '74° 7´ 22.8" W'
24
+ },
25
+ {
26
+ verbatimCoordinates: '40° 7.38’ , -74° 7.38’',
27
+ verbatimLatitude: '40° 7.38’',
28
+ verbatimLongitude: '-74° 7.38’'
29
+ },
30
+ {
31
+ verbatimCoordinates: 'N40°7’22.8’’, W74°7’22.8’’',
32
+ verbatimLatitude: 'N40°7’22.8’’',
33
+ verbatimLongitude: 'W74°7’22.8’’'
34
+ },
35
+ {
36
+ verbatimCoordinates: '40°7’22.8"N, 74°7’22.8"W',
37
+ verbatimLatitude: '40°7’22.8"N',
38
+ verbatimLongitude: '74°7’22.8"W'
39
+ },
40
+ {
41
+ verbatimCoordinates: '40°7\'22.8"N, 74°7\'22.8"W',
42
+ verbatimLatitude: '40°7\'22.8"N',
43
+ verbatimLongitude: '74°7\'22.8"W'
44
+ },
45
+ {
46
+ verbatimCoordinates: '40 7 22.8, -74 7 22.8',
47
+ verbatimLatitude: '40 7 22.8',
48
+ verbatimLongitude: '-74 7 22.8'
49
+ },
50
+ {
51
+ verbatimCoordinates: '40.123 -74.123',
52
+ verbatimLatitude: '40.123',
53
+ verbatimLongitude: '-74.123'
54
+ },
55
+ {
56
+ verbatimCoordinates: '40.123°,-74.123°',
57
+ verbatimLatitude: '40.123°',
58
+ verbatimLongitude: '-74.123°'
59
+ },
60
+ {
61
+ verbatimCoordinates: '40.123N74.123W',
62
+ verbatimLatitude: '40.123N',
63
+ verbatimLongitude: '74.123W'
64
+ },
65
+ {
66
+ verbatimCoordinates: '4007.38N7407.38W',
67
+ verbatimLatitude: '4007.38N',
68
+ verbatimLongitude: '7407.38W'
69
+ },
70
+ {
71
+ verbatimCoordinates: '40°7’22.8"N, 74°7’22.8"W',
72
+ verbatimLatitude: '40°7’22.8"N',
73
+ verbatimLongitude: '74°7’22.8"W'
74
+ },
75
+ {
76
+ verbatimCoordinates: '400722.8N740722.8W',
77
+ verbatimLatitude: '400722.8N',
78
+ verbatimLongitude: '740722.8W'
79
+ },
80
+ {
81
+ verbatimCoordinates: 'N 40 7.38 W 74 7.38',
82
+ verbatimLatitude: 'N 40 7.38',
83
+ verbatimLongitude: 'W 74 7.38'
84
+ },
85
+ {
86
+ verbatimCoordinates: '40:7:22.8N 74:7:22.8W',
87
+ verbatimLatitude: '40:7:22.8N',
88
+ verbatimLongitude: '74:7:22.8W'
89
+ },
90
+ {
91
+ verbatimCoordinates: '40:7:23N,74:7:23W',
92
+ verbatimLatitude: '40:7:23N',
93
+ verbatimLongitude: '74:7:23W',
94
+ decimalLatitude: 40.1230555555,
95
+ decimalLongitude: -74.1230555555
96
+ },
97
+ {
98
+ verbatimCoordinates: '40°7’23"N 74°7’23"W',
99
+ verbatimLatitude: '40°7’23"N',
100
+ verbatimLongitude: '74°7’23"W',
101
+ decimalLatitude: 40.1230555555,
102
+ decimalLongitude: -74.12305555555555
103
+ },
104
+ {
105
+ verbatimCoordinates: '40°7’23"S 74°7’23"E',
106
+ verbatimLatitude: '40°7’23"S',
107
+ verbatimLongitude: '74°7’23"E',
108
+ decimalLatitude: -40.1230555555,
109
+ decimalLongitude: 74.12305555555555
110
+ },
111
+ {
112
+ verbatimCoordinates: '40°7’23" -74°7’23"',
113
+ verbatimLatitude: '40°7’23"',
114
+ verbatimLongitude: '-74°7’23"',
115
+ decimalLatitude: 40.1230555555,
116
+ decimalLongitude: -74.123055555
117
+ },
118
+ {
119
+ verbatimCoordinates: '40d 7’ 23" N 74d 7’ 23" W',
120
+ verbatimLatitude: '40d 7’ 23" N',
121
+ verbatimLongitude: '74d 7’ 23" W',
122
+ decimalLatitude: 40.1230555555,
123
+ decimalLongitude: -74.123055555
124
+ },
125
+ {
126
+ verbatimCoordinates: '40.123N 74.123W',
127
+ verbatimLatitude: '40.123N',
128
+ verbatimLongitude: '74.123W'
129
+ },
130
+ {
131
+ verbatimCoordinates: '40° 7.38, -74° 7.38',
132
+ verbatimLatitude: '40° 7.38',
133
+ verbatimLongitude: '-74° 7.38'
134
+ },
135
+ {
136
+ verbatimCoordinates: '40° 7.38, -74° 7.38',
137
+ verbatimLatitude: '40° 7.38',
138
+ verbatimLongitude: '-74° 7.38'
139
+ },
140
+ {
141
+ verbatimCoordinates: '40 7 22.8; -74 7 22.8',
142
+ verbatimLatitude: '40 7 22.8',
143
+ verbatimLongitude: '-74 7 22.8'
144
+ }
145
+ ];
146
+ const coordsParserDecimals = {
147
+ decimalLatitude: 40.123,
148
+ decimalLongitude: -74.123
149
+ };
150
+ //formats from https://gist.github.com/moole/3707127/337bd31d813a10abcf55084381803e5bbb0b20dc
151
+ const coordsRegexFormats = [
152
+ {
153
+ verbatimCoordinates: '50°4\'17.698"south, 14°24\'2.826"east',
154
+ verbatimLatitude: '50°4\'17.698"south',
155
+ verbatimLongitude: '14°24\'2.826"east',
156
+ decimalLatitude: -50.0715827777777778,
157
+ decimalLongitude: 14.400785
158
+ },
159
+ {
160
+ verbatimCoordinates: '50d4m17.698S 14d24m2.826E',
161
+ verbatimLatitude: '50d4m17.698S',
162
+ verbatimLongitude: '14d24m2.826E',
163
+ decimalLatitude: -50.0715827777777778,
164
+ decimalLongitude: 14.400785
165
+ },
166
+ {
167
+ verbatimCoordinates: '40:26:46N,79:56:55W',
168
+ verbatimLatitude: '40:26:46N',
169
+ verbatimLongitude: '79:56:55W',
170
+ decimalLatitude: 40.4461111111111111,
171
+ decimalLongitude: -79.9486111111111111
172
+ },
173
+ {
174
+ verbatimCoordinates: '40:26:46.302N 79:56:55.903W',
175
+ verbatimLatitude: '40:26:46.302N',
176
+ verbatimLongitude: '79:56:55.903W',
177
+ decimalLatitude: 40.446195,
178
+ decimalLongitude: -79.9488619444444444
179
+ },
180
+ {
181
+ verbatimCoordinates: '40°26′47″N 79°58′36″W',
182
+ verbatimLatitude: '40°26′47″N',
183
+ verbatimLongitude: '79°58′36″W',
184
+ decimalLatitude: 40.4463888888888889,
185
+ decimalLongitude: -79.9766666666666667
186
+ },
187
+ {
188
+ verbatimCoordinates: '40d 26′ 47″ N 79d 58′ 36″ W',
189
+ verbatimLatitude: '40d 26′ 47″ N',
190
+ verbatimLongitude: '79d 58′ 36″ W',
191
+ decimalLatitude: 40.4463888888888889,
192
+ decimalLongitude: -79.9766666666666667
193
+ },
194
+ {
195
+ verbatimCoordinates: '40.446195N 79.948862W',
196
+ verbatimLatitude: '40.446195N',
197
+ verbatimLongitude: '79.948862W',
198
+ decimalLatitude: 40.446195,
199
+ decimalLongitude: -79.948862
200
+ },
201
+ {
202
+ verbatimCoordinates: '40,446195° 79,948862°',
203
+ verbatimLatitude: '40,446195°',
204
+ verbatimLongitude: '79,948862°',
205
+ decimalLatitude: 40.446195,
206
+ decimalLongitude: 79.948862
207
+ },
208
+ {
209
+ verbatimCoordinates: '40° 26.7717, -79° 56.93172',
210
+ verbatimLatitude: '40° 26.7717',
211
+ verbatimLongitude: '-79° 56.93172',
212
+ decimalLatitude: 40.446195,
213
+ decimalLongitude: -79.948862
214
+ },
215
+ {
216
+ verbatimCoordinates: '40.446195, -79.948862',
217
+ verbatimLatitude: '40.446195',
218
+ verbatimLongitude: '-79.948862',
219
+ decimalLatitude: 40.446195,
220
+ decimalLongitude: -79.948862
221
+ },
222
+ {
223
+ verbatimCoordinates: '40.123256; -74.123256',
224
+ verbatimLatitude: '40.123256',
225
+ verbatimLongitude: '-74.123256',
226
+ decimalLatitude: 40.123256,
227
+ decimalLongitude: -74.123256
228
+ },
229
+ {
230
+ verbatimCoordinates: '18°24S 22°45E',
231
+ verbatimLatitude: '18°24S',
232
+ verbatimLongitude: '22°45E',
233
+ decimalLatitude: -18.4,
234
+ decimalLongitude: 22.75
235
+ }
236
+ ];
237
+ const otherFormats = [
238
+ // additional formats we've encountered
239
+ {
240
+ verbatimCoordinates: '10.432342S 10.6345345E',
241
+ verbatimLatitude: '10.432342S',
242
+ verbatimLongitude: '10.6345345E',
243
+ decimalLatitude: -10.432342,
244
+ decimalLongitude: 10.6345345
245
+ },
246
+ {
247
+ verbatimCoordinates: '10.00S 10.00E',
248
+ verbatimLatitude: '10.00S',
249
+ verbatimLongitude: '10.00E',
250
+ decimalLatitude: -10.00000,
251
+ decimalLongitude: 10.00000
252
+ },
253
+ {
254
+ verbatimCoordinates: '00.00S 01.00E',
255
+ verbatimLatitude: '00.00S',
256
+ verbatimLongitude: '01.00E',
257
+ decimalLatitude: 0.00000,
258
+ decimalLongitude: 1.00000
259
+ },
260
+ {
261
+ verbatimCoordinates: '18.24S 22.45E',
262
+ verbatimLatitude: '18.24S',
263
+ verbatimLongitude: '22.45E',
264
+ decimalLatitude: -18.4,
265
+ decimalLongitude: 22.75
266
+ },
267
+ {
268
+ verbatimCoordinates: '27deg 15min 45.2sec S 18deg 32min 53.7sec E',
269
+ verbatimLatitude: '27deg 15min 45.2sec S',
270
+ verbatimLongitude: '18deg 32min 53.7sec E',
271
+ decimalLatitude: -27.2625555555555556,
272
+ decimalLongitude: 18.54825
273
+ },
274
+ {
275
+ verbatimCoordinates: '-23.3245° S / 28.2344° E',
276
+ verbatimLatitude: '-23.3245° S',
277
+ verbatimLongitude: '28.2344° E',
278
+ decimalLatitude: -23.3245,
279
+ decimalLongitude: 28.2344
280
+ },
281
+ {
282
+ verbatimCoordinates: '40° 26.7717 -79° 56.93172',
283
+ verbatimLatitude: '40° 26.7717',
284
+ verbatimLongitude: '-79° 56.93172',
285
+ decimalLatitude: 40.446195,
286
+ decimalLongitude: -79.948862
287
+ },
288
+ {
289
+ verbatimCoordinates: '27.15.45S 18.32.53E',
290
+ verbatimLatitude: '27.15.45S',
291
+ verbatimLongitude: '18.32.53E',
292
+ decimalLatitude: -27.2625,
293
+ decimalLongitude: 18.548055
294
+ },
295
+ {
296
+ verbatimCoordinates: '-27.15.45 18.32.53',
297
+ verbatimLatitude: '-27.15.45',
298
+ verbatimLongitude: '18.32.53',
299
+ decimalLatitude: -27.2625,
300
+ decimalLongitude: 18.548055
301
+ },
302
+ {
303
+ verbatimCoordinates: '27.15.45.2S 18.32.53.4E',
304
+ verbatimLatitude: '27.15.45.2S',
305
+ verbatimLongitude: '18.32.53.4E',
306
+ decimalLatitude: -27.262556,
307
+ decimalLongitude: 18.548167
308
+ },
309
+ {
310
+ verbatimCoordinates: '27.15.45,2S 18.32.53,4E',
311
+ verbatimLatitude: '27.15.45,2S',
312
+ verbatimLongitude: '18.32.53,4E',
313
+ decimalLatitude: -27.262556,
314
+ decimalLongitude: 18.548167
315
+ },
316
+ {
317
+ verbatimCoordinates: 'S23.43563 ° E22.45634 °',
318
+ verbatimLatitude: 'S23.43563 °',
319
+ verbatimLongitude: 'E22.45634 °',
320
+ decimalLatitude: -23.43563,
321
+ decimalLongitude: 22.45634
322
+ },
323
+ {
324
+ verbatimCoordinates: '27,71372° S 23,07771° E',
325
+ verbatimLatitude: '27,71372° S',
326
+ verbatimLongitude: '23,07771° E',
327
+ decimalLatitude: -27.71372,
328
+ decimalLongitude: 23.07771
329
+ },
330
+ {
331
+ verbatimCoordinates: '27.45.34 S 23.23.23 E',
332
+ verbatimLatitude: '27.45.34 S',
333
+ verbatimLongitude: '23.23.23 E',
334
+ decimalLatitude: -27.759444,
335
+ decimalLongitude: 23.38972222
336
+ },
337
+ {
338
+ verbatimCoordinates: 'S 27.45.34 E 23.23.23',
339
+ verbatimLatitude: 'S 27.45.34',
340
+ verbatimLongitude: 'E 23.23.23',
341
+ decimalLatitude: -27.759444,
342
+ decimalLongitude: 23.38972222
343
+ }
344
+ ];
345
+ function getAllTestFormats() {
346
+ const arr1 = [];
347
+ coordsParserFormats.forEach(item => {
348
+ if (item.decimalLatitude) {
349
+ arr1.push(item);
350
+ }
351
+ else {
352
+ arr1.push({ ...item, ...coordsParserDecimals });
353
+ }
354
+ });
355
+ return [...arr1, ...coordsRegexFormats, ...otherFormats];
356
+ }
357
+ export 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,40 @@
1
+ //borrowed from https://www.codegrepper.com/code-examples/javascript/javascript+converting+latitude+longitude+to+gps+coordinates
2
+ /**
3
+ * Converts decimalCoordinates to other formats commonly used
4
+ * @param {*} format Either DMS or DM
5
+ */
6
+ function toCoordinateFormat(format) {
7
+ if (!['DMS', 'DM'].includes(format))
8
+ throw new Error('invalid format specified');
9
+ if (this.decimalCoordinates && this.decimalCoordinates.trim()) {
10
+ const parts = this.decimalCoordinates.split(',').map(x => x.trim());
11
+ const convertedLat = convert(parts[0], format, true);
12
+ const convertedLong = convert(parts[1], format, false);
13
+ return `${convertedLat}, ${convertedLong}`;
14
+ }
15
+ else {
16
+ throw new Error('no decimal coordinates to convert');
17
+ }
18
+ }
19
+ //assumes everything is valid...
20
+ function convert(coordString, format, isLatitude) {
21
+ const coord = Number(coordString);
22
+ let direction;
23
+ if (isLatitude) {
24
+ direction = coord >= 0 ? "N" : "S";
25
+ }
26
+ else {
27
+ direction = coord >= 0 ? "E" : "W";
28
+ }
29
+ const absolute = Math.abs(coord);
30
+ const degrees = Math.floor(absolute);
31
+ const minutesNotTruncated = (absolute - degrees) * 60;
32
+ if (format == 'DM') {
33
+ return `${degrees}° ${minutesNotTruncated.toFixed(3).replace(/\.0+$/, '')}' ${direction}`;
34
+ }
35
+ //else
36
+ const minutes = Math.floor(minutesNotTruncated);
37
+ const seconds = ((minutesNotTruncated - minutes) * 60).toFixed(1).replace(/\.0$/, '');
38
+ return `${degrees}° ${minutes}' ${seconds}" ${direction}`;
39
+ }
40
+ export default toCoordinateFormat;
package/package.json CHANGED
@@ -1,42 +1,50 @@
1
- {
2
- "name": "geo-coordinates-parser",
3
- "version": "1.5.8",
4
- "description": "A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.",
5
- "main": "merge.js",
6
- "scripts": {
7
- "test": "node test.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/ianengelbrecht/geo-coordinates-parser.git"
12
- },
13
- "keywords": [
14
- "geographic",
15
- "coordinates",
16
- "conversion",
17
- "converter",
18
- "parse",
19
- "decimal degrees",
20
- "degrees minutes seconds",
21
- "degrees minutes",
22
- "Darwin Core",
23
- "DMS",
24
- "DM",
25
- "DD",
26
- "DDD° MM' SS.S\"",
27
- "DDD° MM.MMM'",
28
- "DDD.DDDDD°",
29
- "DD MM SS",
30
- "DD MM.MMM",
31
- "DD.DDDDD"
32
- ],
33
- "author": "Ian Engelbrecht",
34
- "license": "MIT",
35
- "bugs": {
36
- "url": "https://github.com/ianengelbrecht/geo-coordinates-parser/issues"
37
- },
38
- "homepage": "https://github.com/ianengelbrecht/geo-coordinates-parser#readme",
39
- "devDependencies": {
40
- "tinyify": "^2.5.1"
41
- }
42
- }
1
+ {
2
+ "name": "geo-coordinates-parser",
3
+ "version": "1.6.1",
4
+ "description": "A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.",
5
+ "type": "module",
6
+ "main": "merge.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/mjs/merge.js",
10
+ "require": "./dist/cjs/merge.js"
11
+ }
12
+ },
13
+ "scripts": {
14
+ "build": "rd /s /q dist && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && fixup.bat",
15
+ "test": "node test.js"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ianengelbrecht/geo-coordinates-parser.git"
20
+ },
21
+ "keywords": [
22
+ "geographic",
23
+ "coordinates",
24
+ "conversion",
25
+ "converter",
26
+ "parse",
27
+ "decimal degrees",
28
+ "degrees minutes seconds",
29
+ "degrees minutes",
30
+ "Darwin Core",
31
+ "DMS",
32
+ "DM",
33
+ "DD",
34
+ "DDD° MM' SS.S\"",
35
+ "DDD° MM.MMM'",
36
+ "DDD.DDDDD°",
37
+ "DD MM SS",
38
+ "DD MM.MMM",
39
+ "DD.DDDDD"
40
+ ],
41
+ "author": "Ian Engelbrecht",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/ianengelbrecht/geo-coordinates-parser/issues"
45
+ },
46
+ "homepage": "https://github.com/ianengelbrecht/geo-coordinates-parser#readme",
47
+ "devDependencies": {
48
+ "tinyify": "^2.5.1"
49
+ }
50
+ }
package/bundle/demo.html DELETED
@@ -1,39 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Title of the document</title>
6
- <script type="text/javascript" src="geocoordsparser.js"></script>
7
- </head>
8
-
9
- <body>
10
-
11
- <h1>Add Coordinates here and click convert</h1>
12
- <input type="text" id="inputcoords" size="50"><br><br/>
13
- <button onclick="convertCoords()">Convert</button><br/><br/>
14
- decimalLatitude: <span id="ddlat"></span><br/>
15
- decimalLongitude: <span id="ddlng"></span><br/>
16
- verbatimLatitude: <span id="vlat"></span><br/>
17
- verbatimLongitude: <span id="vlng"></span><br/>
18
-
19
- <script>
20
- function convertCoords() {
21
- var coordsString = document.getElementById("inputcoords").value.trim()
22
- if(coordsString){
23
-
24
- var converted = convert(coordsString)
25
- document.getElementById("ddlat").textContent = converted.decimalLatitude
26
- document.getElementById("ddlng").textContent = converted.decimalLongitude
27
- document.getElementById("vlat").textContent = converted.verbatimLatitude
28
- document.getElementById("vlng").textContent = converted.verbatimLongitude
29
- }
30
- else {
31
- alert("please enter valid coordinates")
32
- }
33
- }
34
-
35
- </script>
36
-
37
- </body>
38
-
39
- </html>
@@ -1 +0,0 @@
1
- !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).convert=t()}}(function(){function t(t,e,i){const a=Number(t);let r;r=i?a>=0?"N":"S":a>=0?"E":"W";const d=Math.abs(a),o=Math.floor(d),n=60*(d-o);if("DM"==e)return`${o}\xb0 ${n.toFixed(3).replace(/\.0+$/,"")}' ${r}`;const m=Math.floor(n);return`${o}\xb0 ${m}' ${(60*(n-m)).toFixed(1).replace(/\.0$/,"")}" ${r}`}var e=function(e){if(!["DMS","DM"].includes(e))throw new Error("invalid format specified");if(this.decimalCoordinates&&this.decimalCoordinates.trim()){const i=this.decimalCoordinates.split(",").map(t=>t.trim());return`${t(i[0],e,!0)}, ${t(i[1],e,!1)}`}throw new Error("no decimal coordinates to convert")},i={};function a(t,i){i||(i=5),t=t.replace(/\s\s+/g," ").trim();var a=null,d=null,s="",v="",L=[],l=!1;if(n.test(t)){if(!(l=r(L=n.exec(t))))throw new Error("invalid decimal coordinate format");if(a=L[2],d=L[6],a.includes(",")&&(a=a.replace(",",".")),d.includes(",")&&(d=d.replace(",",".")),Number(Math.round(a))==Number(a))throw new Error("degree only coordinate provided");if(Number(Math.round(d))==Number(d))throw new Error("degree only coordinate provided");L[1]?(s=L[1],v=L[5]):L[4]&&(s=L[4],v=L[8])}else if(m.test(t)){if(!(l=r(L=m.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60),L[6]&&(a+=L[6]/3600),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[9])),L[11]&&(d+=L[11]/60),L[13]&&(d+=L[13]/3600),parseInt(L[9])<0&&(d*=-1),L[1]?(s=L[1],v=L[8]):L[7]&&(s=L[7],v=L[14])}else if(u.test(t)){if(!(l=r(L=u.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}else if(b.test(t)){if(!(l=r(L=b.exec(t))))throw new Error("invalid coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}if(Math.abs(d)>=180)throw new Error("invalid longitude value");if(Math.abs(a)>=90)throw new Error("invalid latitude value");if(l){var c=/S|SOUTH/i;c.test(s)&&a>0&&(a*=-1),(c=/W|WEST/i).test(v)&&d>0&&(d*=-1);var g,N,E=L[0].trim(),f=E.match(/[,/;\u0020]/g);if(null==f){var S=Math.floor(t.length/2);g=E.substring(0,S).trim(),N=E.substring(S).trim()}else{var W=0;if(0==(S=f.length%2==1?Math.floor(f.length/2):f.length/2-1))W=E.indexOf(f[0]),g=E.substring(0,W).trim(),N=E.substring(W+1).trim();else{for(var C=0,h=0;C<=S;)h=(W=E.indexOf(f[C],h))+1,C++;g=E.substring(0,W).trim(),N=E.substring(W+1).trim()}}return isNaN(a)&&a.includes(",")&&(a=a.replace(",",".")),a=Number(Number(a).toFixed(i)),isNaN(d)&&d.includes(",")&&(d=d.replace(",",".")),d=Number(Number(d).toFixed(i)),Object.freeze({verbatimCoordinates:E,verbatimLatitude:g,verbatimLongitude:N,decimalLatitude:a,decimalLongitude:d,decimalCoordinates:`${a},${d}`,closeEnough:o,toCoordinateFormat:e})}throw new Error("coordinates pattern match failed")}function r(t){if(!isNaN(t[0]))return!1;var e=t.filter(t=>t);if(e.shift(),e.length%2>0)return!1;for(var i=/^[-+]?\d+([\.,]{1}\d+)?$/,a=/[eastsouthnorthwest]+/i,r=e.length/2,d=0;d<r;d++){const t=e[d],o=e[d+r];if(!(i.test(t)&&i.test(o)||a.test(t)&&a.test(o)||t==o))return!1}return!0}function d(t,e){var i=Math.abs(t-e);return diff=Number(i.toFixed(6)),diff<=1e-5}function o(t){if(t.includes(",")){var e=t.split(",");if(NaN==Number(e[0])||NaN==Number(e[1]))throw new Error("coords are not valid decimals");return d(this.decimalLatitude,Number(e[0]))&&d(this.decimalLongitude,e[1])}throw new Error("coords being tested must be separated by a comma")}var n=/(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(EAST|WEST|[EW])?/i,m=/(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*(\.)[\ \t]*([0-5]?[0-9])[\ \t]*(\.)?[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(NORTH|SOUTH|[NS])?(?:[\ \t]*[,/;][\ \t]*|[\ \t]*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*(\.)[\ \t]*([0-5]?[0-9])[\ \t]*(\.)?[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(EAST|WEST|[EW])?/i,u=/(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*(D(?:EG)?(?:REES)?)[\ \t]*([0-5]?[0-9])[\ \t]*(M(?:IN)?(?:UTES)?)[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(S(?:EC)?(?:ONDS)?)?[\ \t]*(NORTH|SOUTH|[NS])?(?:[\ \t]*[,/;][\ \t]*|[\ \t]*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*(D(?:EG)?(?:REES)?)[\ \t]*([0-5]?[0-9])[\ \t]*(M(?:IN)?(?:UTES)?)[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(S(?:EC)?(?:ONDS)?)[\ \t]*(EAST|WEST|[EW])?/i,b=/(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\u2019\u2019|\xb4\xb4|["\u2033\u201d\.])?[\ \t]*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\xb4\xb4|\u2019\u2019|["\u2033\u201d\.])?[\ \t]*(EAST|WEST|[EW])?/i;const s=Object.freeze({DMS:"DMS",DM:"DM"});a.to=s,i=a;var v,L={decimalLatitude:40.123,decimalLongitude:-74.123},l=(v=[],[{verbatimCoordinates:"40.123, -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:'40\xb0 7\xb4 22.8" N 74\xb0 7\xb4 22.8" W',verbatimLatitude:'40\xb0 7\xb4 22.8" N',verbatimLongitude:'74\xb0 7\xb4 22.8" W'},{verbatimCoordinates:"40\xb0 7.38\u2019 , -74\xb0 7.38\u2019",verbatimLatitude:"40\xb0 7.38\u2019",verbatimLongitude:"-74\xb0 7.38\u2019"},{verbatimCoordinates:"N40\xb07\u201922.8\u2019\u2019, W74\xb07\u201922.8\u2019\u2019",verbatimLatitude:"N40\xb07\u201922.8\u2019\u2019",verbatimLongitude:"W74\xb07\u201922.8\u2019\u2019"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"40\xb07'22.8\"N, 74\xb07'22.8\"W",verbatimLatitude:"40\xb07'22.8\"N",verbatimLongitude:"74\xb07'22.8\"W"},{verbatimCoordinates:"40 7 22.8, -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"},{verbatimCoordinates:"40.123 -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0,-74.123\xb0",verbatimLatitude:"40.123\xb0",verbatimLongitude:"-74.123\xb0"},{verbatimCoordinates:"40.123N74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"4007.38N7407.38W",verbatimLatitude:"4007.38N",verbatimLongitude:"7407.38W"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"400722.8N740722.8W",verbatimLatitude:"400722.8N",verbatimLongitude:"740722.8W"},{verbatimCoordinates:"N 40 7.38 W 74 7.38",verbatimLatitude:"N 40 7.38",verbatimLongitude:"W 74 7.38"},{verbatimCoordinates:"40:7:22.8N 74:7:22.8W",verbatimLatitude:"40:7:22.8N",verbatimLongitude:"74:7:22.8W"},{verbatimCoordinates:"40:7:23N,74:7:23W",verbatimLatitude:"40:7:23N",verbatimLongitude:"74:7:23W",decimalLatitude:40.1230555555,decimalLongitude:-74.1230555555},{verbatimCoordinates:'40\xb07\u201923"N 74\xb07\u201923"W',verbatimLatitude:'40\xb07\u201923"N',verbatimLongitude:'74\xb07\u201923"W',decimalLatitude:40.1230555555,decimalLongitude:-74.12305555555555},{verbatimCoordinates:'40\xb07\u201923" -74\xb07\u201923"',verbatimLatitude:'40\xb07\u201923"',verbatimLongitude:'-74\xb07\u201923"',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:'40d 7\u2019 23" N 74d 7\u2019 23" W',verbatimLatitude:'40d 7\u2019 23" N',verbatimLongitude:'74d 7\u2019 23" W',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:"40.123N 74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40 7 22.8; -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"}].forEach(t=>{t.decimalLatitude?v.push(t):v.push({...t,...L})}),[...v,{verbatimCoordinates:"50\xb04'17.698\"south, 14\xb024'2.826\"east",verbatimLatitude:"50\xb04'17.698\"south",verbatimLongitude:"14\xb024'2.826\"east",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"50d4m17.698S 14d24m2.826E",verbatimLatitude:"50d4m17.698S",verbatimLongitude:"14d24m2.826E",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"40:26:46N,79:56:55W",verbatimLatitude:"40:26:46N",verbatimLongitude:"79:56:55W",decimalLatitude:40.44611111111111,decimalLongitude:-79.9486111111111},{verbatimCoordinates:"40:26:46.302N 79:56:55.903W",verbatimLatitude:"40:26:46.302N",verbatimLongitude:"79:56:55.903W",decimalLatitude:40.446195,decimalLongitude:-79.94886194444445},{verbatimCoordinates:"40\xb026\u203247\u2033N 79\xb058\u203236\u2033W",verbatimLatitude:"40\xb026\u203247\u2033N",verbatimLongitude:"79\xb058\u203236\u2033W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40d 26\u2032 47\u2033 N 79d 58\u2032 36\u2033 W",verbatimLatitude:"40d 26\u2032 47\u2033 N",verbatimLongitude:"79d 58\u2032 36\u2033 W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40.446195N 79.948862W",verbatimLatitude:"40.446195N",verbatimLongitude:"79.948862W",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40,446195\xb0 79,948862\xb0",verbatimLatitude:"40,446195\xb0",verbatimLongitude:"79,948862\xb0",decimalLatitude:40.446195,decimalLongitude:79.948862},{verbatimCoordinates:"40\xb0 26.7717, -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.446195, -79.948862",verbatimLatitude:"40.446195",verbatimLongitude:"-79.948862",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.123256; -74.123256",verbatimLatitude:"40.123256",verbatimLongitude:"-74.123256",decimalLatitude:40.123256,decimalLongitude:-74.123256},{verbatimCoordinates:"18\xb024S 22\xb045E",verbatimLatitude:"18\xb024S",verbatimLongitude:"22\xb045E",decimalLatitude:-18.4,decimalLongitude:22.75},{verbatimCoordinates:"18.24S 22.45E",verbatimLatitude:"18.24S",verbatimLongitude:"22.45E",decimalLatitude:-18.4,decimalLongitude:22.75},{verbatimCoordinates:"27deg 15min 45.2sec S 18deg 32min 53.7sec E",verbatimLatitude:"27deg 15min 45.2sec S",verbatimLongitude:"18deg 32min 53.7sec E",decimalLatitude:-27.262555555555554,decimalLongitude:18.54825},{verbatimCoordinates:"-23.3245\xb0 S / 28.2344\xb0 E",verbatimLatitude:"-23.3245\xb0 S",verbatimLongitude:"28.2344\xb0 E",decimalLatitude:-23.3245,decimalLongitude:28.2344},{verbatimCoordinates:"40\xb0 26.7717 -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"27.15.45S 18.32.53E",verbatimLatitude:"27.15.45S",verbatimLongitude:"18.32.53E",decimalLatitude:-27.2625,decimalLongitude:18.548055},{verbatimCoordinates:"S23.43563 \xb0 E22.45634 \xb0",verbatimLatitude:"S23.43563 \xb0",verbatimLongitude:"E22.45634 \xb0",decimalLatitude:-23.43563,decimalLongitude:22.45634},{verbatimCoordinates:"27,71372\xb0 S 23,07771\xb0 E",verbatimLatitude:"27,71372\xb0 S",verbatimLongitude:"23,07771\xb0 E",decimalLatitude:-27.71372,decimalLongitude:23.07771}]).map(t=>t.verbatimCoordinates);return i.formats=l,i});
@@ -1,8 +0,0 @@
1
- This is to bundle the function to make it available for browsers
2
-
3
- browserify -p tinyify ./merge.js --standalone convert > ./bundle/geocoordsparser.js
4
-
5
- Then update version in package.json, then npm publish, then git...
6
-
7
- geocoordsparser.js can then be included in <script> tags
8
- This puts a function called convert into the global environment
package/conf.py DELETED
@@ -1,3 +0,0 @@
1
- def converter(coordsString, decimalPlaces):
2
- if decimalPlaces == None:
3
- decimalPlaces = 5