geo-coordinates-parser 1.5.8 → 1.6.0

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