geo-coordinates-parser 1.5.7 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
package/converter.js DELETED
@@ -1,419 +0,0 @@
1
- //function for converting coordinates from a string to decimal and verbatim
2
- //this is just a comment
3
-
4
- const toCoordinateFormat = require('./toCoordinateFormat.js')
5
-
6
- /**
7
- * Function for converting coordinates in a variety of formats to decimal coordinates
8
- * @param {string} coordsString The coordinates string to convert
9
- * @param {number} decimalPlaces The number of decimal places for converted coordinates; default is 5
10
- * @returns {object} { verbatimCoordinates, decimalCoordinates, decimalLatitude, decimalLongitude }
11
- */
12
- function converter(coordsString, decimalPlaces) {
13
-
14
- //TODO add exact match to entered string, so that it can be used to filter out superflous text around it
15
- if(!decimalPlaces) {
16
- decimalPlaces = 5
17
- }
18
-
19
- coordsString = coordsString.replace(/\s+/g, ' ').trim(); //just to tidy up whitespaces
20
-
21
- var ddLat = null;
22
- var ddLng = null;
23
- var latdir = "";
24
- var lngdir = "";
25
- var match = [];
26
- var matchSuccess = false;
27
-
28
- if (dd_re.test(coordsString)){
29
- match = dd_re.exec(coordsString);
30
- matchSuccess = checkMatch(match);
31
- if (matchSuccess){
32
- ddLat = match[2];
33
- ddLng = match[6];
34
-
35
- //need to fix if there are ','s instead of '.'
36
- if(ddLat.includes(',')) {
37
- ddLat = ddLat.replace(',','.');
38
- }
39
- if(ddLng.includes(',')) {
40
- ddLng = ddLng.replace(',', '.');
41
- }
42
-
43
- //validation, we don't want things like 23.00000
44
-
45
- //some more validation: no zero coords or degrees only
46
- if (Number(Math.round(ddLat)) == Number(ddLat)) {
47
- throw new Error('degree only coordinate provided')
48
- }
49
-
50
- if (Number(Math.round(ddLng)) == Number(ddLng)) {
51
- throw new Error('degree only coordinate provided')
52
- }
53
-
54
- //get directions
55
- if(match[1]) {
56
- latdir = match[1];
57
- lngdir = match[5];
58
- }
59
- else if (match[4]) {
60
- latdir = match[4];
61
- lngdir = match[8];
62
- }
63
-
64
- }
65
- else {
66
- throw new Error("invalid decimal coordinate format")
67
- }
68
-
69
- }
70
- else if (dms_periods.test(coordsString)) {
71
- match = dms_periods.exec(coordsString);
72
- matchSuccess = checkMatch(match);
73
- if (matchSuccess){
74
-
75
- ddLat = Math.abs(parseInt(match[2]));
76
-
77
- if (match[4]) {
78
- ddLat += match[4]/60;
79
- }
80
-
81
- if (match[6]){
82
- ddLat += match[6].replace(',', '.')/3600;
83
- }
84
-
85
- if (parseInt(match[2]) < 0) {
86
- ddLat = -1 * ddLat;
87
- }
88
-
89
- ddLng = Math.abs(parseInt(match[9]));
90
-
91
- if (match[11]) {
92
- ddLng += match[11]/60;
93
- }
94
-
95
- if (match[13]) {
96
- ddLng += match[13].replace(',', '.')/3600;
97
- }
98
-
99
- if (parseInt(match[9]) < 0) {
100
- ddLng = -1 * ddLng;
101
- }
102
-
103
- //the compass directions
104
- if(match[1]) {
105
- latdir = match[1];
106
- lngdir = match[8];
107
- }
108
- else if (match[7]) {
109
- latdir = match[7];
110
- lngdir = match[14];
111
- }
112
- }
113
- else {
114
- throw new Error("invalid DMS coordinates format")
115
- }
116
- }
117
- else if (dms_abbr.test(coordsString)) {
118
- match = dms_abbr.exec(coordsString);
119
- matchSuccess = checkMatch(match);
120
-
121
- if (matchSuccess) {
122
- ddLat = Math.abs(parseInt(match[2]));
123
- if (match[4]) {
124
- ddLat += match[4]/60;
125
- }
126
-
127
- if (match[6]) {
128
- ddLat += match[6]/3600;
129
- }
130
-
131
- if (parseInt(match[2]) < 0) {
132
- ddLat = -1 * ddLat;
133
- }
134
-
135
- ddLng = Math.abs(parseInt(match[10]));
136
-
137
- if (match[12]) {
138
- ddLng += match[12]/60;
139
- }
140
-
141
- if (match[14]) {
142
- ddLng += match[14]/3600;
143
- }
144
-
145
- if (parseInt(match[10]) < 0) {
146
- ddLng = -1 * ddLng;
147
- }
148
-
149
- if(match[1]) {
150
- latdir = match[1];
151
- lngdir = match[9];
152
- }
153
- else if (match[8]) {
154
- latdir = match[8];
155
- lngdir = match[16];
156
- }
157
-
158
- }
159
- else {
160
- throw new Error("invalid DMS coordinates format")
161
- }
162
- }
163
- else if (coords_other.test(coordsString)) {
164
- match = coords_other.exec(coordsString);
165
- matchSuccess = checkMatch(match);
166
-
167
- if (matchSuccess) {
168
- ddLat = Math.abs(parseInt(match[2]));
169
- if (match[4]){
170
- ddLat += match[4]/60;
171
- }
172
-
173
- if (match[6]) {
174
- ddLat += match[6]/3600;
175
- }
176
-
177
- if (parseInt(match[2]) < 0) {
178
- ddLat = -1 * ddLat;
179
- }
180
-
181
- ddLng = Math.abs(parseInt(match[10]));
182
- if (match[12]) {
183
- ddLng += match[12]/60;
184
- }
185
-
186
- if (match[14]) {
187
- ddLng += match[14]/3600;
188
- }
189
-
190
- if (parseInt(match[10]) < 0) {
191
- ddLng = -1 * ddLng;
192
- }
193
-
194
- if(match[1]) {
195
- latdir = match[1];
196
- lngdir = match[9];
197
- } else if (match[8]) {
198
- latdir = match[8];
199
- lngdir = match[16];
200
- }
201
-
202
- }
203
- else {
204
- throw new Error("invalid coordinates format")
205
- }
206
- }
207
-
208
- if (matchSuccess){
209
-
210
- //more validation....
211
-
212
- //check longitude value - it can be wrong!
213
- if (Math.abs(ddLng) >= 180) {
214
- throw new Error("invalid longitude value")
215
- }
216
-
217
- //just to be safe check latitude also...
218
- if (Math.abs(ddLat) >= 90) {
219
- throw new Error("invalid latitude value")
220
- }
221
-
222
- //if we have one direction we must have the other
223
- if((latdir || lngdir) && (!latdir || !lngdir)) {
224
- throw new Error("invalid coordinates format")
225
- }
226
-
227
- //the directions can't be the same
228
- if(latdir && latdir == lngdir) {
229
- throw new Error("invalid coordinates format")
230
- }
231
-
232
- //make sure the signs and cardinal directions match
233
- var patt = /S|SOUTH/i;
234
- if (patt.test(latdir)) {
235
- if (ddLat > 0) {
236
- ddLat = -1 * ddLat;
237
- }
238
- }
239
-
240
- patt = /W|WEST/i;
241
- if (patt.test(lngdir)){
242
- if (ddLng > 0) {
243
- ddLng = -1 * ddLng;
244
- }
245
- }
246
-
247
- //we need to get the verbatim coords from the string
248
- //we can't split down the middle because if there are decimals they may have different numbers on each side
249
- //so we need to find the separating character, or if none, use the match values to split down the middle
250
- var verbatimCoordinates = match[0].trim()
251
- var verbatimLat
252
- var verbatimLng
253
-
254
- var sepChars = /[,/;\u0020]/g //comma, forward slash and spacebar
255
- var seps = verbatimCoordinates.match(sepChars)
256
-
257
- if (seps == null) {
258
- //split down the middle
259
- var middle = Math.floor(coordsString.length/2)
260
- verbatimLat = verbatimCoordinates.substring(0, middle).trim()
261
- verbatimLng = verbatimCoordinates.substring(middle).trim()
262
- }
263
- else { //if length is odd then find the index of the middle value
264
-
265
- //get the middle index
266
- var middle
267
- //easy for odd numbers
268
- if (seps.length % 2 == 1) {
269
- middle = Math.floor(seps.length / 2)
270
- }
271
- else {
272
- middle = (seps.length / 2) - 1
273
- }
274
-
275
- //walk through seps until we get to the middle
276
- var splitIndex = 0;
277
-
278
- //it might be only one value
279
- if (middle == 0){
280
- splitIndex = verbatimCoordinates.indexOf(seps[0])
281
- verbatimLat = verbatimCoordinates.substring(0, splitIndex).trim()
282
- verbatimLng = verbatimCoordinates.substring(splitIndex + 1).trim()
283
- }
284
- else {
285
- var currSepIndex = 0
286
- var startSearchIndex = 0
287
- while (currSepIndex <= middle){
288
- splitIndex = verbatimCoordinates.indexOf(seps[currSepIndex], startSearchIndex)
289
- startSearchIndex = splitIndex + 1
290
- currSepIndex++
291
- }
292
-
293
- verbatimLat = verbatimCoordinates.substring(0, splitIndex).trim()
294
- verbatimLng = verbatimCoordinates.substring(splitIndex + 1).trim()
295
-
296
- }
297
-
298
- }
299
-
300
- if(isNaN(ddLat) && ddLat.includes(',')) {
301
- ddLat = ddLat.replace(',', '.')
302
- }
303
-
304
- //all done!!
305
- //just truncate the decimals appropriately
306
- ddLat = Number(Number(ddLat).toFixed(decimalPlaces))
307
-
308
- if(isNaN(ddLng) && ddLng.includes(',')) {
309
- ddLng = ddLng.replace(',', '.')
310
- }
311
-
312
- ddLng = Number(Number(ddLng).toFixed(decimalPlaces))
313
-
314
- return Object.freeze({
315
- verbatimCoordinates,
316
- verbatimLatitude: verbatimLat,
317
- verbatimLongitude: verbatimLng,
318
- decimalLatitude: ddLat,
319
- decimalLongitude: ddLng,
320
- decimalCoordinates: `${ddLat},${ddLng}`,
321
- closeEnough: coordsCloseEnough,
322
- toCoordinateFormat
323
- })
324
- }
325
- else {
326
- throw new Error("coordinates pattern match failed")
327
- }
328
-
329
- }
330
-
331
- function checkMatch(match) { //test if the matched groups arrays are 'balanced'. match is the resulting array
332
-
333
- if(!isNaN(match[0])){ //we've matched a number, not what we want....
334
- return false
335
- }
336
-
337
- //first remove the empty values from the array
338
- var filteredMatch = match.filter(x=>x);
339
-
340
- //we need to shift the array because it contains the whole coordinates string in the first item
341
- filteredMatch.shift();
342
-
343
- //check the array length is an even number else exit
344
- if (filteredMatch.length % 2 > 0) {
345
- return false;
346
- }
347
-
348
- //regex for testing corresponding values match
349
- var numerictest = /^[-+]?\d+([\.,]\d+)?$/; //for testing numeric values
350
- var stringtest = /[eastsouthnorthwest]+/i; //for testing string values (north, south, etc)
351
-
352
-
353
- var halflen = filteredMatch.length/2;
354
- for (var i = 0; i < halflen; i++) {
355
- const leftside = filteredMatch[i]
356
- const rightside = filteredMatch[i + halflen]
357
- if ((numerictest.test(leftside) && numerictest.test(rightside)) || (stringtest.test(leftside) && stringtest.test(rightside)) || leftside == rightside) {
358
- continue;
359
- }
360
- else {
361
- return false
362
- }
363
- }
364
-
365
- return true;
366
-
367
- }
368
-
369
- //functions for coordinate validation
370
-
371
- //as decimal arithmetic is not straightforward, we approximate
372
- function decimalsCloseEnough(dec1, dec2){
373
- var originaldiff = Math.abs(dec1 - dec2)
374
- diff = Number(originaldiff.toFixed(6))
375
- if (diff <= 0.00001){
376
- return true
377
- }
378
- else {
379
- return false
380
- }
381
- }
382
-
383
- function coordsCloseEnough(coordsToTest) {
384
- if (coordsToTest.includes(',')){
385
- var coords = coordsToTest.split(',')
386
- if(Number(coords[0]) == NaN || Number(coords[1]) == NaN) {
387
- throw new Error("coords are not valid decimals")
388
- }
389
- else {
390
- return decimalsCloseEnough(this.decimalLatitude, Number(coords[0])) && decimalsCloseEnough(this.decimalLongitude, coords[1]) //this here will be the converted coordinates object
391
- }
392
- }
393
- else {
394
- throw new Error("coords being tested must be separated by a comma")
395
- }
396
- }
397
-
398
- //Coordinates pattern matching regex
399
-
400
- //decimal degrees
401
- var dd_re = /(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))[\s]*([•º°]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))[\s]*([•º°]?)[\s]*(EAST|WEST|[EW])?/i;
402
-
403
- //degrees minutes seconds with '.' as separator - gives array with 15 values
404
- var dms_periods = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(\.)\s*([0-5]?[0-9])\s*(\.)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(\.)\s*([0-5]?[0-9])\s*(\.)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(EAST|WEST|[EW])?/i;
405
-
406
- //degrees minutes seconds with words 'degrees, minutes, seconds' as separators (needed because the s of seconds messes with the S of SOUTH) - gives array of 17 values
407
- var dms_abbr = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)\s*(EAST|WEST|[EW])?/i;
408
-
409
- //everything else - gives array of 17 values
410
- var coords_other = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|’’|´´|["″”\.])?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|´´|’’|["″”\.])?\s*(EAST|WEST|[EW])?/i;
411
-
412
- const to = Object.freeze({
413
- DMS: 'DMS',
414
- DM: 'DM'
415
- })
416
-
417
- converter.to = to
418
-
419
- module.exports = converter
package/failFormats.js DELETED
@@ -1,17 +0,0 @@
1
- //TODO These formats should throw...
2
-
3
- const failingFormats = [
4
- '50°4\'17.698"south, 24.34532', //different formats on each side
5
- '90°4\'17.698"south, 23°4\'17.698"east', //latitude out of bounds
6
- '89°4\'17.698"south, 183°4\'17.698"east', //longitude out of bounds
7
- '50°4\'17.698"east, 23°4\'17.698"south', //directions wrong way round
8
- 'E23.34355,S25.324234', // directions wrong way round
9
- '23°45\'12.2\'\'S 18.33\'56.7\'\'E', //symbols don't match
10
- 'S 27.45.34 23.23.23', //missing direction on right side
11
- 'S 27.45.34 S 23.23.23', //invalid direction on right side
12
- 'S 90°4\'17.698" S 23°4\'17.698"',
13
- '27.45.34 S S 23.23.23', //invalid direction on right side
14
- '27.45.34 23.23.23 E' //no dir on one side
15
- ]
16
-
17
- module.exports = failingFormats
package/formatsOnly.json DELETED
@@ -1,41 +0,0 @@
1
- [
2
- "40.123, -74.123",
3
- "40.123° N 74.123° W",
4
- "40.123° N 74.123° W",
5
- "40° 7´ 22.8\" N 74° 7´ 22.8\" W",
6
- "40° 7.38’ , -74° 7.38’",
7
- "N40°7’22.8’’, W74°7’22.8’’",
8
- "40°7’22.8\"N, 74°7’22.8\"W",
9
- "40°7'22.8\"N, 74°7'22.8\"W",
10
- "40 7 22.8, -74 7 22.8",
11
- "40.123 -74.123",
12
- "40.123°,-74.123°",
13
- "40.123N74.123W",
14
- "4007.38N7407.38W",
15
- "40°7’22.8\"N, 74°7’22.8\"W",
16
- "400722.8N740722.8W",
17
- "N 40 7.38 W 74 7.38",
18
- "40:7:22.8N 74:7:22.8W",
19
- "40:7:23N,74:7:23W",
20
- "40°7’23\"N 74°7’23\"W",
21
- "40°7’23\" -74°7’23\"",
22
- "40d 7’ 23\" N 74d 7’ 23\" W",
23
- "40.123N 74.123W",
24
- "40° 7.38, -74° 7.38",
25
- "40° 7.38, -74° 7.38",
26
- "50°4'17.698\"south, 14°24'2.826\"east",
27
- "50d4m17.698S 14d24m2.826E",
28
- "40:26:46N,79:56:55W",
29
- "40:26:46.302N 79:56:55.903W",
30
- "40°26′47″N 79°58′36″W",
31
- "40d 26′ 47″ N 79d 58′ 36″ W",
32
- "40.446195N 79.948862W",
33
- "40,446195° 79,948862°",
34
- "40° 26.7717, -79° 56.93172",
35
- "40.446195, -79.948862",
36
- "18.24S 22.45E",
37
- "27deg 15min 45.2sec S 18deg 32min 53.7sec E",
38
- "-23.3245° S / 28.2344° E",
39
- "40° 26.7717 -79° 56.93172",
40
- "27.15.45S 18.32.53E"
41
- ]
File without changes
@@ -1,11 +0,0 @@
1
- const fs = require('fs');
2
- const testFormats = require('./testformats')
3
-
4
- fs.writeFile("testFormats.json", JSON.stringify(testFormats, null, 2), 'utf8', function (err) {
5
- if (err) {
6
- console.log("An error occured while writing JSON Object to File.");
7
- return console.log(err);
8
- }
9
-
10
- console.log("JSON file has been saved.");
11
- });
package/merge.js DELETED
@@ -1,9 +0,0 @@
1
- //adds the formats to the convert object
2
- //we need to use this as the source for the npm package so that the formats are not included in the bundle
3
-
4
- var convert = require('./converter.js')
5
- var formats = require('./testformats').map(format => format.verbatimCoordinates)
6
-
7
- convert.formats = formats
8
-
9
- module.exports = convert
package/test.js DELETED
@@ -1,66 +0,0 @@
1
- const convert = require('./converter')
2
- const testFormats = require('./testformats')
3
- const failingFormats = require('./failFormats')
4
-
5
- let allPassed = true;
6
-
7
- //FORMATS THAT SHOULD BE CONVERTED
8
- for (const t of testFormats) {
9
- try {
10
- var converted = convert(t.verbatimCoordinates, 8)
11
-
12
- var testDecimalCoordsString = `${t.decimalLatitude},${t.decimalLongitude}`
13
-
14
- //check the calculation is correct
15
- if(!converted.closeEnough(testDecimalCoordsString)) {
16
- console.log("Error in decimal conversion")
17
- console.log(t.verbatimCoordinates)
18
- console.log(t.decimalLatitude)
19
- console.log(t.decimalLongitude)
20
- allPassed = false;
21
- }
22
-
23
-
24
- //check the verbatim coords are correct
25
- if(converted.verbatimLatitude != t.verbatimLatitude || converted.verbatimLongitude != t.verbatimLongitude) {
26
- console.log("Error in verbatim extraction")
27
- console.log('For', t.verbatimCoordinates)
28
- console.log('got', converted.verbatimLatitude, 'should be ', t.verbatimLatitude)
29
- console.log('got', converted.verbatimLongitude, 'should be', t.verbatimLongitude)
30
- allPassed = false;
31
- }
32
-
33
- }
34
- catch(err) {
35
- console.log("Failed to convert the following format")
36
- console.log(t.verbatimCoordinates)
37
- console.log(err.message)
38
- allPassed = false;
39
- }
40
- }
41
-
42
-
43
- //FORMATS THAT SHOULD NOT BE CONVERTED
44
- const converting = []
45
- for (const f of failingFormats) {
46
- try {
47
- let converted = convert(f)
48
- converting.push(f)
49
- allPassed = false
50
- }
51
- catch {
52
- //nothing here
53
- }
54
- }
55
-
56
- if(converting.length) {
57
- console.log("The following coordinates should NOT have converted successfully: " + converting.join(' | '))
58
- }
59
-
60
- if (allPassed) {
61
- console.log("all formats successfully converted")
62
- }
63
-
64
-
65
-
66
-
@@ -1,8 +0,0 @@
1
- const toCoordinateFormat = require('./toCoordinateFormat.js')
2
-
3
- let test = {
4
- decimalCoordinates: '-234.3456, 28.92435',
5
- toCoordinateFormat
6
- }
7
-
8
- console.log(test.toCoordinateFormat('DMS'))