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/README.md CHANGED
@@ -9,13 +9,14 @@ A Javascript function for reading a variety of coordinate formats and converting
9
9
  npm install geo-coordinates-parser
10
10
  ```
11
11
 
12
+ # NOTE THAT USAGE CHANGED IN THE LAST VERSION TO BETTER SUPPOER ES6 AND COMMONJS
12
13
  ### Usage
13
14
  ```js
14
- const convert = require('geo-coordinates-parser');
15
+ const { convert } = require('geo-coordinates-parser'); //CommonJS
15
16
  ```
16
17
  OR
17
18
  ```js
18
- import convert from 'geo-coordinates-parser' //ES6, if you're using a bundler
19
+ import { convert } from 'geo-coordinates-parser' //ES6
19
20
  ```
20
21
  THEN
21
22
  ```js
@@ -71,13 +72,14 @@ Formats used for testing can be be accessed with:
71
72
  convert.formats
72
73
  ```
73
74
 
74
- **<span style="color:red">Please add coordinate formats that throw an error in the Github Issues.</span>**
75
+ **Please add coordinate formats that throw an error in the Github Issues.**
75
76
 
76
- **<span style="color:red">Note that formats like 24.56S 26.48E are treated as degrees and minutes! And 24.0, 26.0 is treated as an error. If you don't want this behaviour you need to catch these cases with your own code before you use convert.</span>**
77
+ **CAUTION!!!**
78
+ **Coordinates like '24.56S 26.48E' are treated as degrees and minutes and '24, 26' or '24.0, 26.0' will throw an error. If you don't want this behaviour you need to catch these cases with your own code before you use convert.* *
77
79
 
78
80
  ### Want to use it in the browser?
79
81
  Add ```<script src="https://cdn.jsdelivr.net/npm/geo-coordinates-parser/bundle/geocoordsparser.js"></script>```
80
- to your html head and you'll have the ```convert``` function available globally. You won't have .formats, .closeEnough or .toCoordinateFormat though, only the coordinates conversion function.
82
+ to your html head and you'll have the ```convert``` function available globally.
81
83
 
82
84
  ### Convert back to standard formats
83
85
  Sometimes we might want to convert back to more traditional formats for representing coordinates, such as DMS or DM. This can be useful for standardizing coordinates. The convert function has an enum to help.
@@ -90,4 +92,4 @@ converted.toCoordinateFormat(convert.to.DMS) /// '40° 26.771" N, 79° 56.932" W
90
92
  MIT Licence
91
93
 
92
94
  ### Acknowledgements
93
- Support for development was provided by the [Animal Demography Unit](http://adu.uct.ac.za) of the University of Cape Town, and the [Natural Science Collections Facility](http://nscf.co.za).
95
+ Support for development was provided by the [Animal Demography Unit](http://adu.uct.ac.za) of the University of Cape Town, and the [Natural Science Collections Facility](http://nscf.co.za). CommonJS and ESM support was added following [https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html](https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html).
@@ -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
+ }>;
@@ -0,0 +1,363 @@
1
+ "use strict";
2
+ //function for converting coordinates from a string to decimal and verbatim
3
+ //this is just a comment
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const regex_js_1 = require("./regex.js");
9
+ const toCoordinateFormat_js_1 = __importDefault(require("./toCoordinateFormat.js"));
10
+ /**
11
+ * Function for converting coordinates in a variety of formats to decimal coordinates
12
+ * @param {string} coordsString The coordinates string to convert
13
+ * @param {number} decimalPlaces The number of decimal places for converted coordinates; default is 5
14
+ * @returns {object} { verbatimCoordinates, decimalCoordinates, decimalLatitude, decimalLongitude }
15
+ */
16
+ function converter(coordsString, decimalPlaces) {
17
+ //TODO add exact match to entered string, so that it can be used to filter out superflous text around it
18
+ if (!decimalPlaces) {
19
+ decimalPlaces = 5;
20
+ }
21
+ coordsString = coordsString.replace(/\s+/g, ' ').trim(); //just to tidy up whitespaces
22
+ let ddLat = null;
23
+ let ddLng = null;
24
+ let latdir = "";
25
+ let lngdir = "";
26
+ let match = [];
27
+ let matchSuccess = false;
28
+ if (regex_js_1.dd_re.test(coordsString)) {
29
+ match = regex_js_1.dd_re.exec(coordsString);
30
+ matchSuccess = checkMatch(match);
31
+ if (matchSuccess) {
32
+ ddLat = match[2];
33
+ ddLng = match[6];
34
+ //need to fix if there are ','s instead of '.'
35
+ if (ddLat.includes(',')) {
36
+ ddLat = ddLat.replace(',', '.');
37
+ }
38
+ if (ddLng.includes(',')) {
39
+ ddLng = ddLng.replace(',', '.');
40
+ }
41
+ //validation, we don't want things like 23.00000
42
+ //some more validation: no zero coords or degrees only
43
+ if (Number(Math.round(ddLat)) == Number(ddLat)) {
44
+ throw new Error('integer only coordinate provided');
45
+ }
46
+ if (Number(Math.round(ddLng)) == Number(ddLng)) {
47
+ throw new Error('integer only coordinate provided');
48
+ }
49
+ //get directions
50
+ if (match[1]) {
51
+ latdir = match[1];
52
+ lngdir = match[5];
53
+ }
54
+ else if (match[4]) {
55
+ latdir = match[4];
56
+ lngdir = match[8];
57
+ }
58
+ }
59
+ else {
60
+ throw new Error("invalid decimal coordinate format");
61
+ }
62
+ }
63
+ else if (regex_js_1.dms_periods.test(coordsString)) {
64
+ match = regex_js_1.dms_periods.exec(coordsString);
65
+ matchSuccess = checkMatch(match);
66
+ if (matchSuccess) {
67
+ ddLat = Math.abs(parseInt(match[2]));
68
+ if (match[4]) {
69
+ ddLat += match[4] / 60;
70
+ }
71
+ if (match[6]) {
72
+ ddLat += match[6].replace(',', '.') / 3600;
73
+ }
74
+ if (parseInt(match[2]) < 0) {
75
+ ddLat = -1 * ddLat;
76
+ }
77
+ ddLng = Math.abs(parseInt(match[9]));
78
+ if (match[11]) {
79
+ ddLng += match[11] / 60;
80
+ }
81
+ if (match[13]) {
82
+ ddLng += match[13].replace(',', '.') / 3600;
83
+ }
84
+ if (parseInt(match[9]) < 0) {
85
+ ddLng = -1 * ddLng;
86
+ }
87
+ //the compass directions
88
+ if (match[1]) {
89
+ latdir = match[1];
90
+ lngdir = match[8];
91
+ }
92
+ else if (match[7]) {
93
+ latdir = match[7];
94
+ lngdir = match[14];
95
+ }
96
+ }
97
+ else {
98
+ throw new Error("invalid DMS coordinates format");
99
+ }
100
+ }
101
+ else if (regex_js_1.dms_abbr.test(coordsString)) {
102
+ match = regex_js_1.dms_abbr.exec(coordsString);
103
+ matchSuccess = checkMatch(match);
104
+ if (matchSuccess) {
105
+ ddLat = Math.abs(parseInt(match[2]));
106
+ if (match[4]) {
107
+ ddLat += match[4] / 60;
108
+ }
109
+ if (match[6]) {
110
+ ddLat += match[6] / 3600;
111
+ }
112
+ if (parseInt(match[2]) < 0) {
113
+ ddLat = -1 * ddLat;
114
+ }
115
+ ddLng = Math.abs(parseInt(match[10]));
116
+ if (match[12]) {
117
+ ddLng += match[12] / 60;
118
+ }
119
+ if (match[14]) {
120
+ ddLng += match[14] / 3600;
121
+ }
122
+ if (parseInt(match[10]) < 0) {
123
+ ddLng = -1 * ddLng;
124
+ }
125
+ if (match[1]) {
126
+ latdir = match[1];
127
+ lngdir = match[9];
128
+ }
129
+ else if (match[8]) {
130
+ latdir = match[8];
131
+ lngdir = match[16];
132
+ }
133
+ }
134
+ else {
135
+ throw new Error("invalid DMS coordinates format");
136
+ }
137
+ }
138
+ else if (regex_js_1.coords_other.test(coordsString)) {
139
+ match = regex_js_1.coords_other.exec(coordsString);
140
+ matchSuccess = checkMatch(match);
141
+ if (matchSuccess) {
142
+ ddLat = Math.abs(parseInt(match[2]));
143
+ if (match[4]) {
144
+ ddLat += match[4] / 60;
145
+ }
146
+ if (match[6]) {
147
+ ddLat += match[6] / 3600;
148
+ }
149
+ if (parseInt(match[2]) < 0) {
150
+ ddLat = -1 * ddLat;
151
+ }
152
+ ddLng = Math.abs(parseInt(match[10]));
153
+ if (match[12]) {
154
+ ddLng += match[12] / 60;
155
+ }
156
+ if (match[14]) {
157
+ ddLng += match[14] / 3600;
158
+ }
159
+ if (parseInt(match[10]) < 0) {
160
+ ddLng = -1 * ddLng;
161
+ }
162
+ if (match[1]) {
163
+ latdir = match[1];
164
+ lngdir = match[9];
165
+ }
166
+ else if (match[8]) {
167
+ latdir = match[8];
168
+ lngdir = match[16];
169
+ }
170
+ }
171
+ else {
172
+ throw new Error("invalid coordinates format");
173
+ }
174
+ }
175
+ if (matchSuccess) {
176
+ //more validation....
177
+ //check longitude value - it can be wrong!
178
+ if (Math.abs(ddLng) >= 180) {
179
+ throw new Error("invalid longitude value");
180
+ }
181
+ //just to be safe check latitude also...
182
+ if (Math.abs(ddLat) >= 90) {
183
+ throw new Error("invalid latitude value");
184
+ }
185
+ //if we have one direction we must have the other
186
+ if ((latdir || lngdir) && (!latdir || !lngdir)) {
187
+ throw new Error("invalid coordinates format");
188
+ }
189
+ //the directions can't be the same
190
+ if (latdir && latdir == lngdir) {
191
+ throw new Error("invalid coordinates format");
192
+ }
193
+ //make sure the signs and cardinal directions match
194
+ let patt = /S|SOUTH/i;
195
+ if (patt.test(latdir)) {
196
+ if (ddLat > 0) {
197
+ ddLat = -1 * ddLat;
198
+ }
199
+ }
200
+ patt = /W|WEST/i;
201
+ if (patt.test(lngdir)) {
202
+ if (ddLng > 0) {
203
+ ddLng = -1 * ddLng;
204
+ }
205
+ }
206
+ //we need to get the verbatim coords from the string
207
+ //we can't split down the middle because if there are decimals they may have different numbers on each side
208
+ //so we need to find the separating character, or if none, use the match values to split down the middle
209
+ const verbatimCoordinates = match[0].trim();
210
+ let verbatimLat;
211
+ let verbatimLng;
212
+ const sepChars = /[,/;\u0020]/g; //comma, forward slash and spacebar
213
+ const seps = verbatimCoordinates.match(sepChars);
214
+ if (seps == null) {
215
+ //split down the middle
216
+ const middle = Math.floor(coordsString.length / 2);
217
+ verbatimLat = verbatimCoordinates.substring(0, middle).trim();
218
+ verbatimLng = verbatimCoordinates.substring(middle).trim();
219
+ }
220
+ else { //if length is odd then find the index of the middle value
221
+ //get the middle index
222
+ let middle;
223
+ //easy for odd numbers
224
+ if (seps.length % 2 == 1) {
225
+ middle = Math.floor(seps.length / 2);
226
+ }
227
+ else {
228
+ middle = (seps.length / 2) - 1;
229
+ }
230
+ //walk through seps until we get to the middle
231
+ let splitIndex = 0;
232
+ //it might be only one value
233
+ if (middle == 0) {
234
+ splitIndex = verbatimCoordinates.indexOf(seps[0]);
235
+ verbatimLat = verbatimCoordinates.substring(0, splitIndex).trim();
236
+ verbatimLng = verbatimCoordinates.substring(splitIndex + 1).trim();
237
+ }
238
+ else {
239
+ let currSepIndex = 0;
240
+ let startSearchIndex = 0;
241
+ while (currSepIndex <= middle) {
242
+ splitIndex = verbatimCoordinates.indexOf(seps[currSepIndex], startSearchIndex);
243
+ startSearchIndex = splitIndex + 1;
244
+ currSepIndex++;
245
+ }
246
+ verbatimLat = verbatimCoordinates.substring(0, splitIndex).trim();
247
+ verbatimLng = verbatimCoordinates.substring(splitIndex + 1).trim();
248
+ }
249
+ }
250
+ //validation again...
251
+ //we only allow zeros after the period if its DM
252
+ const splitLat = verbatimLat.split('.');
253
+ if (splitLat.length == 2) {
254
+ if (splitLat[1] == 0 && splitLat[1].length != 2) {
255
+ throw new Error('invalid coordinates format');
256
+ }
257
+ }
258
+ const splitLon = verbatimLng.split('.');
259
+ if (splitLon.length == 2) {
260
+ if (splitLon[1] == 0 && splitLon[1].length != 2) {
261
+ throw new Error('invalid coordinates format');
262
+ }
263
+ }
264
+ //no integer coords allowed
265
+ //validation -- no integer coords
266
+ if (/^\d+$/.test(verbatimLat) || /^\d+$/.test(verbatimLng)) {
267
+ throw new Error('degree only coordinate/s provided');
268
+ }
269
+ //some tidying up...
270
+ if (isNaN(ddLat) && ddLat.includes(',')) {
271
+ ddLat = ddLat.replace(',', '.');
272
+ }
273
+ //all done!!
274
+ //just truncate the decimals appropriately
275
+ ddLat = Number(Number(ddLat).toFixed(decimalPlaces));
276
+ if (isNaN(ddLng) && ddLng.includes(',')) {
277
+ ddLng = ddLng.replace(',', '.');
278
+ }
279
+ ddLng = Number(Number(ddLng).toFixed(decimalPlaces));
280
+ return Object.freeze({
281
+ verbatimCoordinates,
282
+ verbatimLatitude: verbatimLat,
283
+ verbatimLongitude: verbatimLng,
284
+ decimalLatitude: ddLat,
285
+ decimalLongitude: ddLng,
286
+ decimalCoordinates: `${ddLat},${ddLng}`,
287
+ closeEnough: coordsCloseEnough,
288
+ toCoordinateFormat: toCoordinateFormat_js_1.default
289
+ });
290
+ }
291
+ else {
292
+ throw new Error("coordinates pattern match failed");
293
+ }
294
+ }
295
+ function checkMatch(match) {
296
+ if (!isNaN(match[0])) { //we've matched a number, not what we want....
297
+ return false;
298
+ }
299
+ //first remove the empty values from the array
300
+ const filteredMatch = [...match];
301
+ //we need to shift the array because it contains the whole coordinates string in the first item
302
+ filteredMatch.shift();
303
+ //check the array length is an even number else exit
304
+ if (filteredMatch.length % 2 > 0) {
305
+ return false;
306
+ }
307
+ //regex for testing corresponding values match
308
+ const numerictest = /^[-+]?\d+([\.,]\d+)?$/; //for testing numeric values
309
+ const stringtest = /[eastsouthnorthwest]+/i; //for testing string values (north, south, etc)
310
+ const halflen = filteredMatch.length / 2;
311
+ for (let i = 0; i < halflen; i++) {
312
+ const leftside = filteredMatch[i];
313
+ const rightside = filteredMatch[i + halflen];
314
+ const bothAreNumbers = numerictest.test(leftside) && numerictest.test(rightside);
315
+ const bothAreStrings = stringtest.test(leftside) && stringtest.test(rightside);
316
+ const valuesAreEqual = leftside == rightside;
317
+ if (leftside == undefined && rightside == undefined) { //we have to handle undefined because regex converts it to string 'undefined'!!
318
+ continue;
319
+ }
320
+ else if (leftside == undefined || rightside == undefined) { //no we need to handle the case where one is and the other not...
321
+ return false;
322
+ }
323
+ else if (bothAreNumbers || bothAreStrings || valuesAreEqual) {
324
+ continue;
325
+ }
326
+ else {
327
+ return false;
328
+ }
329
+ }
330
+ return true;
331
+ }
332
+ //functions for coordinate validation
333
+ //as decimal arithmetic is not straightforward, we approximate
334
+ function decimalsCloseEnough(dec1, dec2) {
335
+ const originaldiff = Math.abs(dec1 - dec2);
336
+ const diff = Number(originaldiff.toFixed(6));
337
+ if (diff <= 0.00001) {
338
+ return true;
339
+ }
340
+ else {
341
+ return false;
342
+ }
343
+ }
344
+ function coordsCloseEnough(coordsToTest) {
345
+ if (coordsToTest.includes(',')) {
346
+ const coords = coordsToTest.split(',');
347
+ if (Number(coords[0]) == NaN || Number(coords[1]) == NaN) {
348
+ throw new Error("coords are not valid decimals");
349
+ }
350
+ else {
351
+ return decimalsCloseEnough(this.decimalLatitude, Number(coords[0])) && decimalsCloseEnough(this.decimalLongitude, coords[1]); //this here will be the converted coordinates object
352
+ }
353
+ }
354
+ else {
355
+ throw new Error("coords being tested must be separated by a comma");
356
+ }
357
+ }
358
+ const to = Object.freeze({
359
+ DMS: 'DMS',
360
+ DM: 'DM'
361
+ });
362
+ converter.to = to;
363
+ exports.default = converter;
@@ -0,0 +1,2 @@
1
+ export const convert: typeof converter;
2
+ import converter from './converter.js';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ //adds the formats to the convert object
3
+ //we need to use this as the source for the npm package so that the formats are not included in the bundle
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.convert = void 0;
9
+ const converter_js_1 = __importDefault(require("./converter.js"));
10
+ const testformats_js_1 = __importDefault(require("./tests/testformats.js"));
11
+ converter_js_1.default.formats = testformats_js_1.default.map(format => format.verbatimCoordinates);
12
+ exports.convert = converter_js_1.default;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,4 @@
1
+ export const dd_re: RegExp;
2
+ export const dms_periods: RegExp;
3
+ export const dms_abbr: RegExp;
4
+ export const coords_other: RegExp;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ //Coordinates pattern matching regex
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.coords_other = exports.dms_abbr = exports.dms_periods = exports.dd_re = void 0;
5
+ //decimal degrees
6
+ const 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;
7
+ exports.dd_re = dd_re;
8
+ //degrees minutes seconds with '.' as separator - gives array with 15 values
9
+ const 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;
10
+ exports.dms_periods = dms_periods;
11
+ //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
12
+ const 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;
13
+ exports.dms_abbr = dms_abbr;
14
+ //everything else - gives array of 17 values
15
+ const 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;
16
+ exports.coords_other = coords_other;
@@ -0,0 +1,2 @@
1
+ export default failingFormats;
2
+ declare const failingFormats: string[];
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ //TODO These formats should throw...
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const failingFormats = [
5
+ '10,10',
6
+ '46,8',
7
+ '12.12323, 123',
8
+ '24.0, 26.0',
9
+ '33.25°S 18.25°E',
10
+ '27.0 23.0',
11
+ '10.00000S 10.000000E',
12
+ '00.00 01.00',
13
+ '50°4\'17.698"south, 24.34532',
14
+ '90°4\'17.698"south, 23°4\'17.698"east',
15
+ '89°4\'17.698"south, 183°4\'17.698"east',
16
+ '50°4\'17.698"east, 23°4\'17.698"south',
17
+ 'E23.34355,S25.324234',
18
+ '23°45\'12.2\'\'S 18.33\'56.7\'\'E',
19
+ 'S 27.45.34 23.23.23',
20
+ 'S 27.45.34 S 23.23.23',
21
+ 'S 90°4\'17.698" S 23°4\'17.698"',
22
+ '27.45.34 S S 23.23.23',
23
+ '27.45.34 23.23.23 E',
24
+ '8°83S 35°67E '
25
+ ];
26
+ exports.default = failingFormats;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const testformats_js_1 = __importDefault(require("./testformats.js"));
8
+ fs_1.default.writeFile("testFormats.json", JSON.stringify(testformats_js_1.default, null, 2), 'utf8', function (err) {
9
+ if (err) {
10
+ console.log("An error occured while writing JSON Object to File.");
11
+ return console.log(err);
12
+ }
13
+ console.log("JSON file has been saved.");
14
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const converter_js_1 = __importDefault(require("../converter.js"));
7
+ const testformats_js_1 = __importDefault(require("../testformats.js"));
8
+ const failFormats_js_1 = __importDefault(require("./failFormats.js"));
9
+ let allPassed = true;
10
+ //FORMATS THAT SHOULD BE CONVERTED
11
+ for (const t of testformats_js_1.default) {
12
+ try {
13
+ const converted = (0, converter_js_1.default)(t.verbatimCoordinates, 8);
14
+ const testDecimalCoordsString = `${t.decimalLatitude},${t.decimalLongitude}`;
15
+ //check the calculation is correct
16
+ if (!converted.closeEnough(testDecimalCoordsString)) {
17
+ console.log("Error in decimal conversion");
18
+ console.log(t.verbatimCoordinates);
19
+ console.log(t.decimalLatitude);
20
+ console.log(t.decimalLongitude);
21
+ allPassed = false;
22
+ }
23
+ //check the verbatim coords are correct
24
+ if (converted.verbatimLatitude != t.verbatimLatitude || converted.verbatimLongitude != t.verbatimLongitude) {
25
+ console.log("Error in verbatim extraction");
26
+ console.log('For', t.verbatimCoordinates);
27
+ console.log('got', converted.verbatimLatitude, 'should be ', t.verbatimLatitude);
28
+ console.log('got', converted.verbatimLongitude, 'should be', t.verbatimLongitude);
29
+ allPassed = false;
30
+ }
31
+ }
32
+ catch (err) {
33
+ console.log("Failed to convert the following format");
34
+ console.log(t.verbatimCoordinates);
35
+ console.log(err.message);
36
+ allPassed = false;
37
+ }
38
+ }
39
+ //FORMATS THAT SHOULD NOT BE CONVERTED
40
+ const converting = [];
41
+ for (let f of failFormats_js_1.default) {
42
+ try {
43
+ const converted = (0, converter_js_1.default)(f);
44
+ converting.push(f);
45
+ allPassed = false;
46
+ }
47
+ catch (_a) {
48
+ //nothing here
49
+ }
50
+ }
51
+ if (converting.length) {
52
+ console.log("The following coordinates should NOT have converted successfully: " + converting.join(' | '));
53
+ }
54
+ if (allPassed) {
55
+ console.log("all formats successfully converted");
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const index_js_1 = __importDefault(require("../src/toCoordinateFormat.js/index.js"));
7
+ let test = {
8
+ decimalCoordinates: '-234.3456, 28.92435',
9
+ toCoordinateFormat: index_js_1.default
10
+ };
11
+ console.log(test.toCoordinateFormat('DMS'));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const converter_js_1 = __importDefault(require("../converter.js"));
7
+ //const test = '26°44S 29°46E'
8
+ //const test = '00.00, 01.00'
9
+ const test = `8°83S 35°67E`;
10
+ try {
11
+ let converted = (0, converter_js_1.default)(test);
12
+ console.log(converted);
13
+ console.log(converted.toCoordinateFormat(converter_js_1.default.to.DM));
14
+ //and just to make sure it's frozen
15
+ let previous = converted.decimalLatitude;
16
+ converted.decimalLatitude = 24;
17
+ if (converted.decimalLatitude === previous) {
18
+ console.log('the result is frozen');
19
+ }
20
+ else {
21
+ console.error('!!!The result is not frozen!!!!');
22
+ }
23
+ }
24
+ catch (err) {
25
+ console.log(err.message);
26
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: any[];
2
+ export default _default;