@accelint/geo 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/README.md +3 -0
  2. package/dist/cartesian.d.ts +21 -0
  3. package/dist/cartesian.js +11 -0
  4. package/dist/cartesian.js.map +1 -0
  5. package/dist/coordinates/coordinate.d.ts +72 -0
  6. package/dist/coordinates/coordinate.js +87 -0
  7. package/dist/coordinates/coordinate.js.map +1 -0
  8. package/dist/coordinates/latlon/decimal-degrees/parser.d.ts +8 -0
  9. package/dist/coordinates/latlon/decimal-degrees/parser.js +77 -0
  10. package/dist/coordinates/latlon/decimal-degrees/parser.js.map +1 -0
  11. package/dist/coordinates/latlon/decimal-degrees/system.d.ts +8 -0
  12. package/dist/coordinates/latlon/decimal-degrees/system.js +21 -0
  13. package/dist/coordinates/latlon/decimal-degrees/system.js.map +1 -0
  14. package/dist/coordinates/latlon/degrees-decimal-minutes/parser.d.ts +8 -0
  15. package/dist/coordinates/latlon/degrees-decimal-minutes/parser.js +86 -0
  16. package/dist/coordinates/latlon/degrees-decimal-minutes/parser.js.map +1 -0
  17. package/dist/coordinates/latlon/degrees-decimal-minutes/system.d.ts +8 -0
  18. package/dist/coordinates/latlon/degrees-decimal-minutes/system.js +26 -0
  19. package/dist/coordinates/latlon/degrees-decimal-minutes/system.js.map +1 -0
  20. package/dist/coordinates/latlon/degrees-minutes-seconds/parser.d.ts +8 -0
  21. package/dist/coordinates/latlon/degrees-minutes-seconds/parser.js +85 -0
  22. package/dist/coordinates/latlon/degrees-minutes-seconds/parser.js.map +1 -0
  23. package/dist/coordinates/latlon/degrees-minutes-seconds/system.d.ts +8 -0
  24. package/dist/coordinates/latlon/degrees-minutes-seconds/system.js +28 -0
  25. package/dist/coordinates/latlon/degrees-minutes-seconds/system.js.map +1 -0
  26. package/dist/coordinates/latlon/internal/coordinate-system.d.ts +12 -0
  27. package/dist/coordinates/latlon/internal/coordinate-system.js +3 -0
  28. package/dist/coordinates/latlon/internal/coordinate-system.js.map +1 -0
  29. package/dist/coordinates/latlon/internal/create-cache.d.ts +12 -0
  30. package/dist/coordinates/latlon/internal/create-cache.js +15 -0
  31. package/dist/coordinates/latlon/internal/create-cache.js.map +1 -0
  32. package/dist/coordinates/latlon/internal/exhaustive-errors.d.ts +9 -0
  33. package/dist/coordinates/latlon/internal/exhaustive-errors.js +72 -0
  34. package/dist/coordinates/latlon/internal/exhaustive-errors.js.map +1 -0
  35. package/dist/coordinates/latlon/internal/in-range.d.ts +7 -0
  36. package/dist/coordinates/latlon/internal/in-range.js +14 -0
  37. package/dist/coordinates/latlon/internal/in-range.js.map +1 -0
  38. package/dist/coordinates/latlon/internal/index.d.ts +59 -0
  39. package/dist/coordinates/latlon/internal/index.js +117 -0
  40. package/dist/coordinates/latlon/internal/index.js.map +1 -0
  41. package/dist/coordinates/latlon/internal/lexer.d.ts +20 -0
  42. package/dist/coordinates/latlon/internal/lexer.js +46 -0
  43. package/dist/coordinates/latlon/internal/lexer.js.map +1 -0
  44. package/dist/coordinates/latlon/internal/parse-format.d.ts +15 -0
  45. package/dist/coordinates/latlon/internal/parse-format.js +63 -0
  46. package/dist/coordinates/latlon/internal/parse-format.js.map +1 -0
  47. package/dist/coordinates/latlon/internal/parse.d.ts +41 -0
  48. package/dist/coordinates/latlon/internal/parse.js +16 -0
  49. package/dist/coordinates/latlon/internal/parse.js.map +1 -0
  50. package/dist/coordinates/latlon/internal/pipes/check-ambiguous.d.ts +10 -0
  51. package/dist/coordinates/latlon/internal/pipes/check-ambiguous.js +23 -0
  52. package/dist/coordinates/latlon/internal/pipes/check-ambiguous.js.map +1 -0
  53. package/dist/coordinates/latlon/internal/pipes/check-numbers.d.ts +8 -0
  54. package/dist/coordinates/latlon/internal/pipes/check-numbers.js +35 -0
  55. package/dist/coordinates/latlon/internal/pipes/check-numbers.js.map +1 -0
  56. package/dist/coordinates/latlon/internal/pipes/fix-bearings.d.ts +12 -0
  57. package/dist/coordinates/latlon/internal/pipes/fix-bearings.js +68 -0
  58. package/dist/coordinates/latlon/internal/pipes/fix-bearings.js.map +1 -0
  59. package/dist/coordinates/latlon/internal/pipes/fix-dividers.d.ts +15 -0
  60. package/dist/coordinates/latlon/internal/pipes/fix-dividers.js +34 -0
  61. package/dist/coordinates/latlon/internal/pipes/fix-dividers.js.map +1 -0
  62. package/dist/coordinates/latlon/internal/pipes/genome.d.ts +9 -0
  63. package/dist/coordinates/latlon/internal/pipes/genome.js +37 -0
  64. package/dist/coordinates/latlon/internal/pipes/genome.js.map +1 -0
  65. package/dist/coordinates/latlon/internal/pipes/index.d.ts +24 -0
  66. package/dist/coordinates/latlon/internal/pipes/index.js +46 -0
  67. package/dist/coordinates/latlon/internal/pipes/index.js.map +1 -0
  68. package/dist/coordinates/latlon/internal/pipes/simpler.d.ts +15 -0
  69. package/dist/coordinates/latlon/internal/pipes/simpler.js +6 -0
  70. package/dist/coordinates/latlon/internal/pipes/simpler.js.map +1 -0
  71. package/dist/coordinates/latlon/internal/violation.d.ts +3 -0
  72. package/dist/coordinates/latlon/internal/violation.js +6 -0
  73. package/dist/coordinates/latlon/internal/violation.js.map +1 -0
  74. package/dist/coordinates/mgrs/parser.d.ts +7 -0
  75. package/dist/coordinates/mgrs/parser.js +45 -0
  76. package/dist/coordinates/mgrs/parser.js.map +1 -0
  77. package/dist/coordinates/mgrs/system.d.ts +8 -0
  78. package/dist/coordinates/mgrs/system.js +25 -0
  79. package/dist/coordinates/mgrs/system.js.map +1 -0
  80. package/dist/coordinates/utm/parser.d.ts +7 -0
  81. package/dist/coordinates/utm/parser.js +38 -0
  82. package/dist/coordinates/utm/parser.js.map +1 -0
  83. package/dist/coordinates/utm/system.d.ts +8 -0
  84. package/dist/coordinates/utm/system.js +25 -0
  85. package/dist/coordinates/utm/system.js.map +1 -0
  86. package/dist/index.d.ts +10 -5
  87. package/dist/index.js +7 -5
  88. package/dist/index.js.map +1 -1
  89. package/dist/patterning.d.ts +63 -0
  90. package/dist/patterning.js +16 -0
  91. package/dist/patterning.js.map +1 -0
  92. package/package.json +17 -11
  93. package/dist/coordinates/configurations.d.ts +0 -6
  94. package/dist/coordinates/configurations.js +0 -15
  95. package/dist/coordinates/configurations.js.map +0 -1
  96. package/dist/coordinates/index.d.ts +0 -11
  97. package/dist/coordinates/index.js +0 -23
  98. package/dist/coordinates/index.js.map +0 -1
  99. package/dist/coordinates/match.d.ts +0 -34
  100. package/dist/coordinates/match.js +0 -35
  101. package/dist/coordinates/match.js.map +0 -1
  102. package/dist/coordinates/normalize.d.ts +0 -1
  103. package/dist/coordinates/normalize.js +0 -28
  104. package/dist/coordinates/normalize.js.map +0 -1
  105. package/dist/coordinates/regex.d.ts +0 -126
  106. package/dist/coordinates/regex.js +0 -142
  107. package/dist/coordinates/regex.js.map +0 -1
  108. package/dist/coordinates/utils.d.ts +0 -5
  109. package/dist/coordinates/utils.js +0 -27
  110. package/dist/coordinates/utils.js.map +0 -1
@@ -0,0 +1,41 @@
1
+ import { Errors, Format } from './index.js';
2
+ import { Tokens } from './lexer.js';
3
+
4
+ type ParseResults = [Tokens, Errors];
5
+ /**
6
+ * Parse a raw input string into a validated and normalized coordinate
7
+ * primitive ready for further refinement/validation by a more specific parser.
8
+ *
9
+ * @param input
10
+ * raw input, from a user or external system, of unknown validity
11
+ *
12
+ * @param format
13
+ * the expected format - LATLON or LONLAT - the coordinate should conform to
14
+ *
15
+ * @returns
16
+ * tuple with two values: tokens, and errors
17
+ *
18
+ * @remarks
19
+ * pure function
20
+ *
21
+ * @example
22
+ * const input = '1 2 3 / 4 5 6'
23
+ * parse(input); // [['1', '2', '3', '/', '4', '5', '6'], []]
24
+ *
25
+ * @description
26
+ * __Assumptions/Specification__
27
+ * 1. Decimals are indicated by a "." and not ","
28
+ * 2. A degrees indicator is "°"
29
+ * 3. A minutes indicator is "'"
30
+ * 4. A seconds indicator is '"'
31
+ * 5. Each indicator is expected to follow the number it is annotating
32
+ * 6. Numeric parts - degrees, minutes, and seconds - are positional and can
33
+ * not be arranged in alternative orders and be considered valid
34
+ * 7. Output will have explicit bearings characters (NSEW) and not rely on
35
+ * positive and negative values; when bearings are available. Negative
36
+ * values will only be replaced with absolute values if bearings are available.
37
+ *
38
+ */
39
+ declare function parse(input: string, format?: Format): ParseResults;
40
+
41
+ export { type ParseResults, parse };
@@ -0,0 +1,16 @@
1
+ import { lexer } from './lexer.js';
2
+ import { pipesRunner } from './pipes/index.js';
3
+ import { violation } from './violation.js';
4
+
5
+ // src/coordinates/latlon/internal/parse.ts
6
+ function parse(input, format) {
7
+ if (!input?.length) {
8
+ return [[], [violation("No input.")]];
9
+ }
10
+ const [tokens, errors] = pipesRunner(lexer(input), format);
11
+ return [tokens, errors?.length ? errors.map(violation) : []];
12
+ }
13
+
14
+ export { parse };
15
+ //# sourceMappingURL=parse.js.map
16
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/coordinates/latlon/internal/parse.ts"],"names":[],"mappings":";;;;;AAsDO,SAAS,KAAA,CAAM,OAAe,MAA+B,EAAA;AAClE,EAAI,IAAA,CAAC,OAAO,MAAQ,EAAA;AAClB,IAAA,OAAO,CAAC,EAAC,EAAG,CAAC,SAAU,CAAA,WAAW,CAAC,CAAC,CAAA;AAAA;AAGtC,EAAM,MAAA,CAAC,QAAQ,MAAM,CAAA,GAAI,YAAY,KAAM,CAAA,KAAK,GAAG,MAAM,CAAA;AAEzD,EAAO,OAAA,CAAC,QAAQ,MAAQ,EAAA,MAAA,GAAS,OAAO,GAAI,CAAA,SAAS,CAAI,GAAA,EAAE,CAAA;AAC7D","file":"parse.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { Errors, Format } from '.';\nimport { type Tokens, lexer } from './lexer';\nimport { pipesRunner } from './pipes';\nimport { violation } from './violation';\n\nexport type ParseResults = [Tokens, Errors];\n\n/**\n * Parse a raw input string into a validated and normalized coordinate\n * primitive ready for further refinement/validation by a more specific parser.\n *\n * @param input\n * raw input, from a user or external system, of unknown validity\n *\n * @param format\n * the expected format - LATLON or LONLAT - the coordinate should conform to\n *\n * @returns\n * tuple with two values: tokens, and errors\n *\n * @remarks\n * pure function\n *\n * @example\n * const input = '1 2 3 / 4 5 6'\n * parse(input); // [['1', '2', '3', '/', '4', '5', '6'], []]\n *\n * @description\n * __Assumptions/Specification__\n * 1. Decimals are indicated by a \".\" and not \",\"\n * 2. A degrees indicator is \"°\"\n * 3. A minutes indicator is \"'\"\n * 4. A seconds indicator is '\"'\n * 5. Each indicator is expected to follow the number it is annotating\n * 6. Numeric parts - degrees, minutes, and seconds - are positional and can\n * not be arranged in alternative orders and be considered valid\n * 7. Output will have explicit bearings characters (NSEW) and not rely on\n * positive and negative values; when bearings are available. Negative\n * values will only be replaced with absolute values if bearings are available.\n *\n */\nexport function parse(input: string, format?: Format): ParseResults {\n if (!input?.length) {\n return [[], [violation('No input.')]];\n }\n\n const [tokens, errors] = pipesRunner(lexer(input), format);\n\n return [tokens, errors?.length ? errors.map(violation) : []];\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { Format } from '../index.js';
2
+ import { Tokens } from '../lexer.js';
3
+
4
+ /**
5
+ * Look for groupings of numbers that are ambiguous; no indicators, or no
6
+ * dividers and not possibility of deducing where a divider should be inserted.
7
+ */
8
+ declare function checkAmbiguousGrouping(tokens: Tokens, _format?: Format): [string[], string | boolean];
9
+
10
+ export { checkAmbiguousGrouping };
@@ -0,0 +1,23 @@
1
+ import { SYMBOLS, SYMBOL_PATTERNS } from '../index.js';
2
+ import { pipesResult } from '../pipes/index.js';
3
+ import { simpler } from './simpler.js';
4
+
5
+ // src/coordinates/latlon/internal/pipes/check-ambiguous.ts
6
+ function checkAmbiguousGrouping(tokens, _format) {
7
+ if (tokens.includes(SYMBOLS.DIVIDER)) {
8
+ return pipesResult(tokens, false);
9
+ }
10
+ const simple = simpler(tokens);
11
+ const ambiguous = /^(?:(?:BN{3,5})|(?:N{3,5}B))$/.test(simple);
12
+ const bookends = /^BN{3,5}B$/.test(simple);
13
+ const helpful = tokens.slice(1, -1).reduce((acc, t) => {
14
+ const helps = t.includes(SYMBOLS.DEGREES) || t.includes(SYMBOLS.SECONDS) || SYMBOL_PATTERNS.NSEW.test(t);
15
+ return `${acc}${helps ? "H" : "_"}`;
16
+ }, "").includes("H");
17
+ const hopeless = /^N{3,5}$/.test(simple) && !helpful;
18
+ return pipesResult(tokens, ambiguous || bookends || hopeless);
19
+ }
20
+
21
+ export { checkAmbiguousGrouping };
22
+ //# sourceMappingURL=check-ambiguous.js.map
23
+ //# sourceMappingURL=check-ambiguous.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/check-ambiguous.ts"],"names":[],"mappings":";;;;;AAuBO,SAAS,sBAAA,CAAuB,QAAgB,OAAkB,EAAA;AACvE,EAAA,IAAI,MAAO,CAAA,QAAA,CAAS,OAAQ,CAAA,OAAO,CAAG,EAAA;AACpC,IAAO,OAAA,WAAA,CAAY,QAAQ,KAAK,CAAA;AAAA;AAGlC,EAAM,MAAA,MAAA,GAAS,QAAQ,MAAM,CAAA;AAG7B,EAAM,MAAA,SAAA,GAAY,+BAAgC,CAAA,IAAA,CAAK,MAAM,CAAA;AAE7D,EAAM,MAAA,QAAA,GAAW,YAAa,CAAA,IAAA,CAAK,MAAM,CAAA;AAMzC,EAAM,MAAA,OAAA,GAAU,OAGb,KAAM,CAAA,CAAA,EAAG,EAAE,CACX,CAAA,MAAA,CAAO,CAAC,GAAA,EAAK,CAAM,KAAA;AAClB,IAAA,MAAM,KACJ,GAAA,CAAA,CAAE,QAAS,CAAA,OAAA,CAAQ,OAAO,CAC1B,IAAA,CAAA,CAAE,QAAS,CAAA,OAAA,CAAQ,OAAO,CAAA,IAC1B,eAAgB,CAAA,IAAA,CAAK,KAAK,CAAC,CAAA;AAE7B,IAAA,OAAO,CAAG,EAAA,GAAG,CAAG,EAAA,KAAA,GAAQ,MAAM,GAAG,CAAA,CAAA;AAAA,GAChC,EAAA,EAAE,CACJ,CAAA,QAAA,CAAS,GAAG,CAAA;AAEf,EAAA,MAAM,QAAW,GAAA,UAAA,CAAW,IAAK,CAAA,MAAM,KAAK,CAAC,OAAA;AAE7C,EAAA,OAAO,WAAY,CAAA,MAAA,EAAQ,SAAa,IAAA,QAAA,IAAY,QAAQ,CAAA;AAC9D","file":"check-ambiguous.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { type Format, SYMBOLS, SYMBOL_PATTERNS } from '..';\nimport type { Tokens } from '../lexer';\nimport { pipesResult } from '../pipes';\n\nimport { simpler } from './simpler';\n\n/**\n * Look for groupings of numbers that are ambiguous; no indicators, or no\n * dividers and not possibility of deducing where a divider should be inserted.\n */\nexport function checkAmbiguousGrouping(tokens: Tokens, _format?: Format) {\n if (tokens.includes(SYMBOLS.DIVIDER)) {\n return pipesResult(tokens, false);\n }\n\n const simple = simpler(tokens);\n\n // 3-5 numbers after or before a single bearing indicator BNNN, NNNB\n const ambiguous = /^(?:(?:BN{3,5})|(?:N{3,5}B))$/.test(simple);\n // 3-5 numbers between 2 bearings indicators BNNNB\n const bookends = /^BN{3,5}B$/.test(simple);\n // \"helpful\" indicators:\n // 1. degrees number in the right-of-divider position e.g. # #°\n // 2. seconds number in the left-of-divider position e.g. # #\" #\n // 3. trailing bearings in the left-of-divider position e.g. # N #\n // 4. leading bearings in the right-of-divider position e.g. N # E #\n const helpful = tokens\n // helpful tokens are only helpful in the middle of the token list\n // not the beginning or end of the list\n .slice(1, -1)\n .reduce((acc, t) => {\n const helps =\n t.includes(SYMBOLS.DEGREES) ||\n t.includes(SYMBOLS.SECONDS) ||\n SYMBOL_PATTERNS.NSEW.test(t);\n\n return `${acc}${helps ? 'H' : '_'}`;\n }, '')\n .includes('H');\n // 3-5 numbers with no bearings indicators, and no helpful indicators\n const hopeless = /^N{3,5}$/.test(simple) && !helpful;\n\n return pipesResult(tokens, ambiguous || bookends || hopeless);\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { Tokens } from '../lexer.js';
2
+
3
+ /**
4
+ * Check for problems in the numeric values.
5
+ */
6
+ declare function checkNumberValues(tokens: Tokens): [string[], string | boolean];
7
+
8
+ export { checkNumberValues };
@@ -0,0 +1,35 @@
1
+ import { pipesResult } from '../pipes/index.js';
2
+ import { simpler } from './simpler.js';
3
+
4
+ // src/coordinates/latlon/internal/pipes/check-numbers.ts
5
+ function checkNumberValues(tokens) {
6
+ const simple = simpler(tokens);
7
+ if ((simple.match(/N/g) ?? []).length < 2) {
8
+ return pipesResult(tokens, "Too few numbers.");
9
+ }
10
+ const error = (
11
+ // 4 consecutive numbers in specific formation is not going to be valid
12
+ /(?:N{4,}BN+)|(?:N+BN{4,})/.test(simple) || // more than 6 numbers total
13
+ (simple.match(/N/g) ?? []).length > 6
14
+ );
15
+ if (error) {
16
+ return pipesResult(tokens, "Too many numbers.");
17
+ }
18
+ const pattern = tokens.reduce((acc, t) => {
19
+ if (/\d/.test(t)) {
20
+ acc.push(Number.parseFloat(t) < 0 ? "-" : "+");
21
+ } else {
22
+ acc.push("_");
23
+ }
24
+ return acc;
25
+ }, []).join("");
26
+ const matches = pattern.match(/[^_]-./);
27
+ if (!!matches && pattern !== "_--_") {
28
+ return pipesResult(tokens, "Negative value for non-degrees value found.");
29
+ }
30
+ return pipesResult(tokens, false);
31
+ }
32
+
33
+ export { checkNumberValues };
34
+ //# sourceMappingURL=check-numbers.js.map
35
+ //# sourceMappingURL=check-numbers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/check-numbers.ts"],"names":[],"mappings":";;;;AAqBO,SAAS,kBAAkB,MAAgB,EAAA;AAChD,EAAM,MAAA,MAAA,GAAS,QAAQ,MAAM,CAAA;AAE7B,EAAA,IAAA,CAAK,OAAO,KAAM,CAAA,IAAI,KAAK,EAAC,EAAG,SAAS,CAAG,EAAA;AACzC,IAAO,OAAA,WAAA,CAAY,QAAQ,kBAAkB,CAAA;AAAA;AAG/C,EAAM,MAAA,KAAA;AAAA;AAAA,IAEJ,2BAAA,CAA4B,KAAK,MAAM,CAAA;AAAA,IAAA,CAEtC,OAAO,KAAM,CAAA,IAAI,CAAK,IAAA,IAAI,MAAS,GAAA;AAAA,GAAA;AAEtC,EAAA,IAAI,KAAO,EAAA;AACT,IAAO,OAAA,WAAA,CAAY,QAAQ,mBAAmB,CAAA;AAAA;AAGhD,EAAA,MAAM,OAAU,GAAA,MAAA,CACb,MAAO,CAAA,CAAC,KAAK,CAAM,KAAA;AAClB,IAAI,IAAA,IAAA,CAAK,IAAK,CAAA,CAAC,CAAG,EAAA;AAChB,MAAA,GAAA,CAAI,KAAK,MAAO,CAAA,UAAA,CAAW,CAAC,CAAI,GAAA,CAAA,GAAI,MAAM,GAAG,CAAA;AAAA,KACxC,MAAA;AACL,MAAA,GAAA,CAAI,KAAK,GAAG,CAAA;AAAA;AAGd,IAAO,OAAA,GAAA;AAAA,GACN,EAAA,EAAc,CAAA,CAChB,KAAK,EAAE,CAAA;AAEV,EAAM,MAAA,OAAA,GAAU,OAAQ,CAAA,KAAA,CAAM,QAAQ,CAAA;AAItC,EAAA,IAAI,CAAC,CAAC,OAAW,IAAA,OAAA,KAAY,MAAQ,EAAA;AACnC,IAAO,OAAA,WAAA,CAAY,QAAQ,6CAA6C,CAAA;AAAA;AAG1E,EAAO,OAAA,WAAA,CAAY,QAAQ,KAAK,CAAA;AAClC","file":"check-numbers.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { Tokens } from '../lexer';\nimport { pipesResult } from '../pipes';\n\nimport { simpler } from './simpler';\n\n/**\n * Check for problems in the numeric values.\n */\nexport function checkNumberValues(tokens: Tokens) {\n const simple = simpler(tokens);\n\n if ((simple.match(/N/g) ?? []).length < 2) {\n return pipesResult(tokens, 'Too few numbers.');\n }\n\n const error =\n // 4 consecutive numbers in specific formation is not going to be valid\n /(?:N{4,}BN+)|(?:N+BN{4,})/.test(simple) ||\n // more than 6 numbers total\n (simple.match(/N/g) ?? []).length > 6;\n\n if (error) {\n return pipesResult(tokens, 'Too many numbers.');\n }\n\n const pattern = tokens\n .reduce((acc, t) => {\n if (/\\d/.test(t)) {\n acc.push(Number.parseFloat(t) < 0 ? '-' : '+');\n } else {\n acc.push('_');\n }\n\n return acc;\n }, [] as string[])\n .join('');\n\n const matches = pattern.match(/[^_]-./);\n\n // special case '_--_' when the input is something like 'S -1 -1 W'\n // which is invalid for other reasons and will be caught elsewhere\n if (!!matches && pattern !== '_--_') {\n return pipesResult(tokens, 'Negative value for non-degrees value found.');\n }\n\n return pipesResult(tokens, false);\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { Format } from '../index.js';
2
+ import { Tokens } from '../lexer.js';
3
+ import { PipeResult } from './index.js';
4
+
5
+ /**
6
+ * Normalize bearings - negative and positive numeric values to NSEW - and
7
+ * positioning of bearings - after the numeric values - and fill in any missing
8
+ * bearings if only one is provided.
9
+ */
10
+ declare function fixBearings(tokens: Tokens, format?: Format): PipeResult;
11
+
12
+ export { fixBearings };
@@ -0,0 +1,68 @@
1
+ import { BEARINGS, SYMBOLS, SYMBOL_PATTERNS } from '../index.js';
2
+
3
+ // src/coordinates/latlon/internal/pipes/fix-bearings.ts
4
+ var orthogonal = {
5
+ N: BEARINGS.LON,
6
+ S: BEARINGS.LON,
7
+ E: BEARINGS.LAT,
8
+ W: BEARINGS.LAT
9
+ };
10
+ var bearingConflictsWithNumber = (tokens) => tokens[0] && tokens[1] && SYMBOL_PATTERNS.NEGATIVE_SIGN.test(tokens[1]) && SYMBOL_PATTERNS.NSEW.test(tokens[0]) && !SYMBOL_PATTERNS.NEGATIVE_BEARINGS.test(tokens[0]);
11
+ var bePositive = (n) => n.replace(SYMBOL_PATTERNS.NEGATIVE_SIGN, "");
12
+ var conflict = ([a, b]) => `Bearing (${a}) conflicts with negative number (${b}).`;
13
+ function fixBearings(tokens, format) {
14
+ const [left, right] = [
15
+ tokens.slice(0, tokens.indexOf(SYMBOLS.DIVIDER)),
16
+ tokens.slice(1 + tokens.indexOf(SYMBOLS.DIVIDER))
17
+ ].map(moveBearingsToHead);
18
+ if (bearingConflictsWithNumber(left)) {
19
+ return [[], conflict(left)];
20
+ }
21
+ if (bearingConflictsWithNumber(right)) {
22
+ return [[], conflict(right)];
23
+ }
24
+ const [leftHasBearing, rightHasBearing] = [left, right].map(
25
+ (list) => !!(list?.[0] && SYMBOL_PATTERNS.NSEW.test(list[0]))
26
+ );
27
+ let leftBearing = "";
28
+ let rightBearing = "";
29
+ if (leftHasBearing && rightHasBearing) {
30
+ leftBearing = left.shift() ?? "";
31
+ rightBearing = right.shift() ?? "";
32
+ } else if (leftHasBearing) {
33
+ leftBearing = left.shift() ?? "";
34
+ rightBearing = orthogonal[leftBearing][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(right[0] ?? "")];
35
+ } else if (rightHasBearing) {
36
+ rightBearing = right.shift() ?? "";
37
+ leftBearing = orthogonal[rightBearing][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(right[0] ?? "")];
38
+ } else if (format) {
39
+ leftBearing = `${BEARINGS[format][0][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(`${left[0]}`)]}`;
40
+ rightBearing = `${BEARINGS[format][1][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(`${right[0]}`)]}`;
41
+ } else {
42
+ return [[...left, SYMBOLS.DIVIDER, ...right], false];
43
+ }
44
+ return [
45
+ [
46
+ ...left.map(bePositive),
47
+ leftBearing,
48
+ SYMBOLS.DIVIDER,
49
+ ...right.map(bePositive),
50
+ rightBearing
51
+ ],
52
+ false
53
+ ];
54
+ }
55
+ function moveBearingsToHead(coord) {
56
+ return coord.reduce((acc, t) => {
57
+ if (/\d/.test(t)) {
58
+ acc.push(t);
59
+ } else {
60
+ acc.unshift(t);
61
+ }
62
+ return acc;
63
+ }, []);
64
+ }
65
+
66
+ export { fixBearings };
67
+ //# sourceMappingURL=fix-bearings.js.map
68
+ //# sourceMappingURL=fix-bearings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/fix-bearings.ts"],"names":[],"mappings":";;;AAiBA,IAAM,UAAa,GAAA;AAAA,EACjB,GAAG,QAAS,CAAA,GAAA;AAAA,EACZ,GAAG,QAAS,CAAA,GAAA;AAAA,EACZ,GAAG,QAAS,CAAA,GAAA;AAAA,EACZ,GAAG,QAAS,CAAA;AACd,CAAA;AAEA,IAAM,0BAA6B,GAAA,CAAC,MAClC,KAAA,MAAA,CAAO,CAAC,CAAA,IACR,MAAO,CAAA,CAAC,C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,EAAO,OAAA;AAAA,IACL;AAAA,MACE,GAAG,IAAK,CAAA,GAAA,CAAI,UAAU,CAAA;AAAA,MACtB,WAAA;AAAA,MACA,OAAQ,CAAA,OAAA;AAAA,MACR,GAAG,KAAM,CAAA,GAAA,CAAI,UAAU,CAAA;AAAA,MACvB;AAAA,KACF;AAAA,IACA;AAAA,GACF;AACF;AAQA,SAAS,mBAAmB,KAAe,EAAA;AACzC,EAAA,OAAO,KAAM,CAAA,MAAA,CAAO,CAAC,GAAA,EAAK,CAAM,KAAA;AAC9B,IAAI,IAAA,IAAA,CAAK,IAAK,CAAA,CAAC,CAAG,EAAA;AAChB,MAAA,GAAA,CAAI,KAAK,CAAC,CAAA;AAAA,KACL,MAAA;AACL,MAAA,GAAA,CAAI,QAAQ,CAAC,CAAA;AAAA;AAGf,IAAO,OAAA,GAAA;AAAA,GACT,EAAG,EAAY,CAAA;AACjB","file":"fix-bearings.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { BEARINGS, type Format, SYMBOLS, SYMBOL_PATTERNS } from '..';\nimport type { Tokens } from '../lexer';\nimport type { PipeResult } from '../pipes';\n\nconst orthogonal = {\n N: BEARINGS.LON,\n S: BEARINGS.LON,\n E: BEARINGS.LAT,\n W: BEARINGS.LAT,\n};\n\nconst bearingConflictsWithNumber = (tokens: Tokens) =>\n tokens[0] &&\n tokens[1] &&\n SYMBOL_PATTERNS.NEGATIVE_SIGN.test(tokens[1]) &&\n SYMBOL_PATTERNS.NSEW.test(tokens[0]) &&\n !SYMBOL_PATTERNS.NEGATIVE_BEARINGS.test(tokens[0]);\n\nconst bePositive = (n: string) => n.replace(SYMBOL_PATTERNS.NEGATIVE_SIGN, '');\n\nconst conflict = ([a, b]: Tokens) =>\n `Bearing (${a}) conflicts with negative number (${b}).`;\n\n/**\n * Normalize bearings - negative and positive numeric values to NSEW - and\n * positioning of bearings - after the numeric values - and fill in any missing\n * bearings if only one is provided.\n */\nexport function fixBearings(tokens: Tokens, format?: Format): PipeResult {\n const [left, right] = [\n tokens.slice(0, tokens.indexOf(SYMBOLS.DIVIDER)),\n tokens.slice(1 + tokens.indexOf(SYMBOLS.DIVIDER)),\n ].map(moveBearingsToHead) as [Tokens, Tokens];\n\n if (bearingConflictsWithNumber(left)) {\n return [[], conflict(left)];\n }\n\n if (bearingConflictsWithNumber(right)) {\n return [[], conflict(right)];\n }\n\n const [leftHasBearing, rightHasBearing] = [left, right].map(\n (list) => !!(list?.[0] && SYMBOL_PATTERNS.NSEW.test(list[0])),\n );\n\n let leftBearing = '';\n let rightBearing = '';\n\n if (leftHasBearing && rightHasBearing) {\n leftBearing = left.shift() ?? '';\n rightBearing = right.shift() ?? '';\n } else if (leftHasBearing) {\n leftBearing = left.shift() ?? '';\n rightBearing =\n orthogonal[leftBearing as keyof typeof orthogonal][\n +SYMBOL_PATTERNS.NEGATIVE_SIGN.test(right[0] ?? '') as 0 | 1\n ];\n } else if (rightHasBearing) {\n rightBearing = right.shift() ?? '';\n leftBearing =\n orthogonal[rightBearing as keyof typeof orthogonal][\n +SYMBOL_PATTERNS.NEGATIVE_SIGN.test(right[0] ?? '') as 0 | 1\n ];\n } else if (format) {\n leftBearing = `${BEARINGS[format][0][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(`${left[0]}`)]}`;\n rightBearing = `${BEARINGS[format][1][+SYMBOL_PATTERNS.NEGATIVE_SIGN.test(`${right[0]}`)]}`;\n } else {\n // neither exist\n return [[...left, SYMBOLS.DIVIDER, ...right], false];\n }\n\n return [\n [\n ...left.map(bePositive),\n leftBearing,\n SYMBOLS.DIVIDER,\n ...right.map(bePositive),\n rightBearing,\n ],\n false,\n ];\n}\n\n/**\n * Move the bearings indicators to the first element in the list - in this\n * module only - so that it is easier to work with; moving a bearing to the\n * \"head\" allows for `push()` of subsequent number processing will keep the\n * order of the numeric values intact.\n */\nfunction moveBearingsToHead(coord: Tokens) {\n return coord.reduce((acc, t) => {\n if (/\\d/.test(t)) {\n acc.push(t);\n } else {\n acc.unshift(t);\n }\n\n return acc;\n }, [] as Tokens);\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { Format } from '../index.js';
2
+ import { Tokens } from '../lexer.js';
3
+ import { PipeResult } from './index.js';
4
+
5
+ /**
6
+ * For tokens lists without a divider, `fixDivider` attempts to determine the
7
+ * __safe__ location to add a divider based on the existing formatting of the
8
+ * coordinate: numbers, number positions, and number indicators.
9
+ *
10
+ * @remarks
11
+ * pure function
12
+ */
13
+ declare function fixDivider(original: Tokens, _format?: Format): PipeResult;
14
+
15
+ export { fixDivider };
@@ -0,0 +1,34 @@
1
+ import { SYMBOLS } from '../index.js';
2
+ import { getGenomeIndex } from './genome.js';
3
+ import { simpler } from './simpler.js';
4
+
5
+ // src/coordinates/latlon/internal/pipes/fix-dividers.ts
6
+ var SIMPLER_PATTERNS = {
7
+ NN: 1,
8
+ NNB: 1,
9
+ BNNB: 2,
10
+ BNN: 2
11
+ };
12
+ var insertDivider = (tokens, index) => [
13
+ [...tokens.slice(0, index), SYMBOLS.DIVIDER, ...tokens.slice(index)],
14
+ false
15
+ ];
16
+ function fixDivider(original, _format) {
17
+ if (original.includes(SYMBOLS.DIVIDER)) {
18
+ return [original, false];
19
+ }
20
+ const tokens = original.slice(0);
21
+ const genomeIndex = getGenomeIndex(tokens);
22
+ if (genomeIndex) {
23
+ return insertDivider(tokens, genomeIndex);
24
+ }
25
+ const simple = simpler(tokens);
26
+ if (SIMPLER_PATTERNS[simple]) {
27
+ return insertDivider(tokens, SIMPLER_PATTERNS[simple]);
28
+ }
29
+ return [[], true];
30
+ }
31
+
32
+ export { fixDivider };
33
+ //# sourceMappingURL=fix-dividers.js.map
34
+ //# sourceMappingURL=fix-dividers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/fix-dividers.ts"],"names":[],"mappings":";;;;;AAqBA,IAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,CAAA;AAAA,EACJ,GAAK,EAAA,CAAA;AAAA,EACL,IAAM,EAAA,CAAA;AAAA,EACN,GAAK,EAAA;AACP,CAAA;AAEA,IAAM,aAAA,GAAgB,CAAC,MAAA,EAAgB,KAA8B,KAAA;AAAA,EACnE,CAAC,GAAG,MAAO,CAAA,KAAA,CAAM,CAAG,EAAA,KAAK,CAAG,EAAA,OAAA,CAAQ,OAAS,EAAA,GAAG,MAAO,CAAA,KAAA,CAAM,KAAK,CAAC,CAAA;AAAA,EACnE;AACF,CAAA;AAUO,SAAS,UAAA,CAAW,UAAkB,OAA8B,EAAA;AAEzE,EAAA,IAAI,QAAS,CAAA,QAAA,CAAS,OAAQ,CAAA,OAAO,CAAG,EAAA;AACtC,IAAO,OAAA,CAAC,UAAU,KAAK,CAAA;AAAA;AAIzB,EAAM,MAAA,MAAA,GAAS,QAAS,CAAA,KAAA,CAAM,CAAC,CAAA;AAE/B,EAAM,MAAA,WAAA,GAAc,eAAe,MAAM,CAAA;AAEzC,EAAA,IAAI,WAAa,EAAA;AACf,IAAO,OAAA,aAAA,CAAc,QAAQ,WAAW,CAAA;AAAA;AAG1C,EAAM,MAAA,MAAA,GAAS,QAAQ,MAAM,CAAA;AAE7B,EAAI,IAAA,gBAAA,CAAiB,MAAM,CAAG,EAAA;AAC5B,IAAA,OAAO,aAAc,CAAA,MAAA,EAAQ,gBAAiB,CAAA,MAAM,CAAC,CAAA;AAAA;AAKvD,EAAO,OAAA,CAAC,EAAC,EAAG,IAAI,CAAA;AAClB","file":"fix-dividers.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { type Format, SYMBOLS } from '..';\nimport type { Tokens } from '../lexer';\nimport type { PipeResult } from '../pipes';\nimport { getGenomeIndex } from './genome';\nimport { simpler } from './simpler';\n\n// N = number\n// B = bearing\nconst SIMPLER_PATTERNS = {\n NN: 1,\n NNB: 1,\n BNNB: 2,\n BNN: 2,\n};\n\nconst insertDivider = (tokens: Tokens, index: number): PipeResult => [\n [...tokens.slice(0, index), SYMBOLS.DIVIDER, ...tokens.slice(index)],\n false,\n];\n\n/**\n * For tokens lists without a divider, `fixDivider` attempts to determine the\n * __safe__ location to add a divider based on the existing formatting of the\n * coordinate: numbers, number positions, and number indicators.\n *\n * @remarks\n * pure function\n */\nexport function fixDivider(original: Tokens, _format?: Format): PipeResult {\n // if there is already a divider then there is nothing to do\n if (original.includes(SYMBOLS.DIVIDER)) {\n return [original, false];\n }\n\n // disconnect from argument memory space so we aren't working on shared memory\n const tokens = original.slice(0);\n\n const genomeIndex = getGenomeIndex(tokens);\n\n if (genomeIndex) {\n return insertDivider(tokens, genomeIndex);\n }\n\n const simple = simpler(tokens) as keyof typeof SIMPLER_PATTERNS;\n\n if (SIMPLER_PATTERNS[simple]) {\n return insertDivider(tokens, SIMPLER_PATTERNS[simple]);\n }\n\n // no position is found to be a safe location to insert a divider; any placement\n // would be a guess and therefor only has a 50% chance of being wrong or right\n return [[], true];\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { Tokens } from '../lexer.js';
2
+
3
+ /**
4
+ * Use the "genome" sequence of the token list to find the index for inserting
5
+ * a missing divider token.
6
+ */
7
+ declare function getGenomeIndex(tokens: Tokens): number;
8
+
9
+ export { getGenomeIndex };
@@ -0,0 +1,37 @@
1
+ import { SYMBOLS, SYMBOL_PATTERNS } from '../index.js';
2
+
3
+ // src/coordinates/latlon/internal/pipes/genome.ts
4
+ var GENOME_PATTERN = /^(B?)([DN]?[MN]?[SN]?)(B?)(?:B?)([DN]?[MN]?[SN]?)(?:B?)$/;
5
+ function dividerIndexer(_full, ...args) {
6
+ const [bearing1 = "", number1, bearing2 = "", number2] = args;
7
+ if (!(number1?.length && number2?.length)) {
8
+ return "0";
9
+ }
10
+ return `${number1.length + (bearing1.length || bearing2.length)}`;
11
+ }
12
+ function genomeSequencer(acc, t) {
13
+ if (t.includes(SYMBOLS.DEGREES)) {
14
+ return `${acc}D`;
15
+ }
16
+ if (t.includes(SYMBOLS.MINUTES)) {
17
+ return `${acc}M`;
18
+ }
19
+ if (t.includes(SYMBOLS.SECONDS)) {
20
+ return `${acc}S`;
21
+ }
22
+ if (SYMBOL_PATTERNS.NSEW.test(t)) {
23
+ return `${acc}B`;
24
+ }
25
+ if (/\d/.test(t)) {
26
+ return `${acc}N`;
27
+ }
28
+ return `${acc}X`;
29
+ }
30
+ function getGenomeIndex(tokens) {
31
+ const seq = tokens.reduce(genomeSequencer, "");
32
+ return GENOME_PATTERN.test(seq) ? Number.parseInt(seq.replace(GENOME_PATTERN, dividerIndexer)) : 0;
33
+ }
34
+
35
+ export { getGenomeIndex };
36
+ //# sourceMappingURL=genome.js.map
37
+ //# sourceMappingURL=genome.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/genome.ts"],"names":[],"mappings":";;;AAgBA,IAAM,cACJ,GAAA,0DAAA;AAOF,SAAS,cAAA,CAAe,UAAkB,IAAgB,EAAA;AACxD,EAAA,MAAM,CAAC,QAAW,GAAA,EAAA,EAAI,SAAS,QAAW,GAAA,EAAA,EAAI,OAAO,CAAI,GAAA,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","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { SYMBOLS, SYMBOL_PATTERNS } from '..';\nimport type { Tokens } from '../lexer';\n\nconst GENOME_PATTERN =\n /^(B?)([DN]?[MN]?[SN]?)(B?)(?:B?)([DN]?[MN]?[SN]?)(?:B?)$/;\n\n/**\n * Get the position (index) of where to insert a divider into the token list;\n * basically, the count of numeric components (left-of-divider position) plus\n * 1 if there is a bearing identifier (left-of-divider).\n */\nfunction dividerIndexer(_full: string, ...args: string[]) {\n const [bearing1 = '', number1, bearing2 = '', number2] = args;\n\n // if no numeric values exist there no way to infer a location to insert a divider\n if (!(number1?.length && number2?.length)) {\n return '0';\n }\n\n return `${number1.length + (bearing1.length || bearing2.length)}`;\n}\n\n/**\n * The genome sequence is a simplification of the tokens list:\n *\n * - B = bearings (NSEW)\n * - D = degrees (number with degree character following)\n * - M = minutes (number with minutes character following)\n * - S = seconds (number with seconds character following)\n * - N = number (no identifying character following)\n * - X = for unmatched token types\n */\nfunction genomeSequencer(acc: string, t: string) {\n if (t.includes(SYMBOLS.DEGREES)) {\n return `${acc}D`;\n }\n\n if (t.includes(SYMBOLS.MINUTES)) {\n return `${acc}M`;\n }\n\n if (t.includes(SYMBOLS.SECONDS)) {\n return `${acc}S`;\n }\n\n if (SYMBOL_PATTERNS.NSEW.test(t)) {\n return `${acc}B`;\n }\n\n if (/\\d/.test(t)) {\n return `${acc}N`;\n }\n\n return `${acc}X`;\n}\n\n/**\n * Use the \"genome\" sequence of the token list to find the index for inserting\n * a missing divider token.\n */\nexport function getGenomeIndex(tokens: Tokens) {\n const seq = tokens.reduce(genomeSequencer, '');\n\n return GENOME_PATTERN.test(seq)\n ? Number.parseInt(seq.replace(GENOME_PATTERN, dividerIndexer))\n : 0;\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import { Format } from '../index.js';
2
+ import { Tokens } from '../lexer.js';
3
+
4
+ type Pipe = (t: Tokens, f?: Format) => [Tokens, boolean | string];
5
+ type PipeResult = ReturnType<Pipe>;
6
+ /**
7
+ * Consistently create a PipesResult array to return. Use this instead of
8
+ * casting to PipesResult everywhere.
9
+ *
10
+ * @param e true = has error, false = no error
11
+ *
12
+ * @remarks
13
+ * pure function
14
+ */
15
+ declare const pipesResult: (t: Tokens, e: boolean | string) => PipeResult;
16
+ /**
17
+ * Run the tokens through a preset pipeline of violations checks exiting the
18
+ * process as early as possible when violations are found because violations
19
+ * will make further violations checks less accurate and could return inaccurate
20
+ * violations that could be misleading or hide the most important violation
21
+ */
22
+ declare function pipesRunner(tokens: Tokens, format?: Format): [Tokens, string[]];
23
+
24
+ export { type PipeResult, pipesResult, pipesRunner };
@@ -0,0 +1,46 @@
1
+ import { SYMBOL_PATTERNS } from '../index.js';
2
+ import { checkAmbiguousGrouping } from './check-ambiguous.js';
3
+ import { checkNumberValues } from './check-numbers.js';
4
+ import { fixBearings } from './fix-bearings.js';
5
+ import { fixDivider } from './fix-dividers.js';
6
+
7
+ // src/coordinates/latlon/internal/pipes/index.ts
8
+ var makeGlobal = (k) => new RegExp(SYMBOL_PATTERNS[k], "g");
9
+ var pipesResult = (t, e) => [
10
+ // if there are errors do NOT return the tokens
11
+ e ? [] : t,
12
+ e
13
+ ];
14
+ var tooMany = (p) => (t) => pipesResult(t, (t.join("").match(p) ?? []).length > 2);
15
+ var pipes = [
16
+ // Unrecoverable violations
17
+ ["Too many bearings.", tooMany(makeGlobal("NSEW"))],
18
+ ["Too many numeric signs.", tooMany(/[-+]/g)],
19
+ ["Too many degrees indicators.", tooMany(makeGlobal("DEGREES"))],
20
+ ["Too many minutes indicators.", tooMany(makeGlobal("MINUTES"))],
21
+ ["Too many seconds indicators.", tooMany(makeGlobal("SECONDS"))],
22
+ ["Number values checks.", checkNumberValues],
23
+ ["Ambiguous grouping of numbers with no divider.", checkAmbiguousGrouping],
24
+ // fix values and formatting to be consistent
25
+ ["Unable to identify latitude from longitude.", fixDivider],
26
+ ["Unable to identify bearings.", fixBearings]
27
+ ];
28
+ function pipesRunner(tokens, format) {
29
+ let copy = tokens.slice(0);
30
+ let error = false;
31
+ const errors = [];
32
+ for (const [message, op] of pipes) {
33
+ [copy, error] = op(copy, format);
34
+ if (error) {
35
+ errors.push(error === true ? message : error);
36
+ if (!copy.length) {
37
+ return [copy, [error === true ? message : error]];
38
+ }
39
+ }
40
+ }
41
+ return [copy, errors];
42
+ }
43
+
44
+ export { pipesResult, pipesRunner };
45
+ //# sourceMappingURL=index.js.map
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/index.ts"],"names":[],"mappings":";;;;;;;AA0BA,IAAM,UAAA,GAAa,CAAC,CAClB,KAAA,IAAI,OAAO,eAAgB,CAAA,CAAC,GAAG,GAAG,CAAA;AAWvB,IAAA,WAAA,GAAc,CAAC,CAAA,EAAW,CAAoC,KAAA;AAAA;AAAA,EAEzE,CAAA,GAAI,EAAK,GAAA,CAAA;AAAA,EACT;AACF;AAGA,IAAM,UAAU,CAAC,CAAA,KAAc,CAAC,CAAA,KAC9B,YAAY,CAAI,EAAA,CAAA,CAAA,CAAE,IAAK,CAAA,EAAE,EAAE,KAAM,CAAA,CAAC,KAAK,EAAC,EAAG,SAAS,CAAC,CAAA;AAEvD,IAAM,KAA0B,GAAA;AAAA;AAAA,EAE9B,CAAC,oBAAsB,EAAA,OAAA,CAAQ,UAAW,CAAA,MAAM,CAAC,CAAC,CAAA;AAAA,EAClD,CAAC,yBAAA,EAA2B,OAAQ,CAAA,OAAO,CAAC,CAAA;AAAA,EAC5C,CAAC,8BAAgC,EAAA,OAAA,CAAQ,UAAW,CAAA,SAAS,CAAC,CAAC,CAAA;AAAA,EAC/D,CAAC,8BAAgC,EAAA,OAAA,CAAQ,UAAW,CAAA,SAAS,CAAC,CAAC,CAAA;AAAA,EAC/D,CAAC,8BAAgC,EAAA,OAAA,CAAQ,UAAW,CAAA,SAAS,CAAC,CAAC,CAAA;AAAA,EAC/D,CAAC,yBAAyB,iBAAiB,CAAA;AAAA,EAC3C,CAAC,kDAAkD,sBAAsB,CAAA;AAAA;AAAA,EAGzE,CAAC,+CAA+C,UAAU,CAAA;AAAA,EAC1D,CAAC,gCAAgC,WAAW;AAC9C,CAAA;AAQO,SAAS,WAAA,CACd,QACA,MACoB,EAAA;AACpB,EAAI,IAAA,IAAA,GAAO,MAAO,CAAA,KAAA,CAAM,CAAC,CAAA;AACzB,EAAA,IAAI,KAAuB,GAAA,KAAA;AAC3B,EAAA,MAAM,SAAS,EAAC;AAEhB,EAAA,KAAA,MAAW,CAAC,OAAA,EAAS,EAAE,CAAA,IAAK,KAAO,EAAA;AACjC,IAAA,CAAC,IAAM,EAAA,KAAK,CAAI,GAAA,EAAA,CAAG,MAAM,MAAM,CAAA;AAE/B,IAAA,IAAI,KAAO,EAAA;AAGT,MAAA,MAAA,CAAO,IAAK,CAAA,KAAA,KAAU,IAAO,GAAA,OAAA,GAAU,KAAK,CAAA;AAE5C,MAAI,IAAA,CAAC,KAAK,MAAQ,EAAA;AAChB,QAAA,OAAO,CAAC,IAAM,EAAA,CAAC,UAAU,IAAO,GAAA,OAAA,GAAU,KAAK,CAAC,CAAA;AAAA;AAClD;AACF;AAGF,EAAO,OAAA,CAAC,MAAM,MAAM,CAAA;AACtB","file":"index.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { type Format, SYMBOL_PATTERNS } from '..';\nimport type { Tokens } from '../lexer';\n\nimport { checkAmbiguousGrouping } from './check-ambiguous';\nimport { checkNumberValues } from './check-numbers';\nimport { fixBearings } from './fix-bearings';\nimport { fixDivider } from './fix-dividers';\n\ntype Pipe = (t: Tokens, f?: Format) => [Tokens, boolean | string];\n\nexport type PipeResult = ReturnType<Pipe>;\n\n/** Make a RegExp global. */\nconst makeGlobal = (k: keyof typeof SYMBOL_PATTERNS) =>\n new RegExp(SYMBOL_PATTERNS[k], 'g');\n\n/**\n * Consistently create a PipesResult array to return. Use this instead of\n * casting to PipesResult everywhere.\n *\n * @param e true = has error, false = no error\n *\n * @remarks\n * pure function\n */\nexport const pipesResult = (t: Tokens, e: boolean | string): PipeResult => [\n // if there are errors do NOT return the tokens\n e ? [] : t,\n e,\n];\n\n/** Check if there are more than 2 of something. */\nconst tooMany = (p: RegExp) => (t: Tokens) =>\n pipesResult(t, (t.join('').match(p) ?? []).length > 2);\n\nconst pipes: [string, Pipe][] = [\n // Unrecoverable violations\n ['Too many bearings.', tooMany(makeGlobal('NSEW'))],\n ['Too many numeric signs.', tooMany(/[-+]/g)],\n ['Too many degrees indicators.', tooMany(makeGlobal('DEGREES'))],\n ['Too many minutes indicators.', tooMany(makeGlobal('MINUTES'))],\n ['Too many seconds indicators.', tooMany(makeGlobal('SECONDS'))],\n ['Number values checks.', checkNumberValues],\n ['Ambiguous grouping of numbers with no divider.', checkAmbiguousGrouping],\n\n // fix values and formatting to be consistent\n ['Unable to identify latitude from longitude.', fixDivider],\n ['Unable to identify bearings.', fixBearings],\n];\n\n/**\n * Run the tokens through a preset pipeline of violations checks exiting the\n * process as early as possible when violations are found because violations\n * will make further violations checks less accurate and could return inaccurate\n * violations that could be misleading or hide the most important violation\n */\nexport function pipesRunner(\n tokens: Tokens,\n format?: Format,\n): [Tokens, string[]] {\n let copy = tokens.slice(0);\n let error: PipeResult[1] = false;\n const errors = [] as string[];\n\n for (const [message, op] of pipes) {\n [copy, error] = op(copy, format);\n\n if (error) {\n // accumulate the \"errors\" because if tokens are returned\n // the errors are only warnings and are recoverable\n errors.push(error === true ? message : error);\n\n if (!copy.length) {\n return [copy, [error === true ? message : error]];\n }\n }\n }\n\n return [copy, errors];\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { Tokens } from '../lexer.js';
2
+
3
+ /**
4
+ * Create a simplified pattern string - numbers = 'N', bearings = 'B' - to
5
+ * allow for simpler pattern matching.
6
+ *
7
+ * @remarks
8
+ * pure function
9
+ *
10
+ * @example
11
+ * simplify(tokens); // 'NNNBNNNB' or similar
12
+ */
13
+ declare const simpler: (tokens: Tokens) => string;
14
+
15
+ export { simpler };
@@ -0,0 +1,6 @@
1
+ // src/coordinates/latlon/internal/pipes/simpler.ts
2
+ var simpler = (tokens) => tokens.map((t) => /\d/.test(t) ? "N" : "B").join("");
3
+
4
+ export { simpler };
5
+ //# sourceMappingURL=simpler.js.map
6
+ //# sourceMappingURL=simpler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/coordinates/latlon/internal/pipes/simpler.ts"],"names":[],"mappings":";AAyBO,IAAM,OAAU,GAAA,CAAC,MACtB,KAAA,MAAA,CAAO,IAAI,CAAC,CAAA,KAAO,IAAK,CAAA,IAAA,CAAK,CAAC,CAAI,GAAA,GAAA,GAAM,GAAI,CAAA,CAAE,KAAK,EAAE","file":"simpler.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport type { Tokens } from '../lexer';\n\n/**\n * Create a simplified pattern string - numbers = 'N', bearings = 'B' - to\n * allow for simpler pattern matching.\n *\n * @remarks\n * pure function\n *\n * @example\n * simplify(tokens); // 'NNNBNNNB' or similar\n */\nexport const simpler = (tokens: Tokens) =>\n tokens.map((t) => (/\\d/.test(t) ? 'N' : 'B')).join('');\n"]}
@@ -0,0 +1,3 @@
1
+ declare const violation: (s: string) => string;
2
+
3
+ export { violation };
@@ -0,0 +1,6 @@
1
+ // src/coordinates/latlon/internal/violation.ts
2
+ var violation = (s) => `[ERROR] ${s}`;
3
+
4
+ export { violation };
5
+ //# sourceMappingURL=violation.js.map
6
+ //# sourceMappingURL=violation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/coordinates/latlon/internal/violation.ts"],"names":[],"mappings":";AAaO,IAAM,SAAY,GAAA,CAAC,CAAc,KAAA,CAAA,QAAA,EAAW,CAAC,CAAA","file":"violation.js","sourcesContent":["// __private-exports\n/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport const violation = (s: string) => `[ERROR] ${s}`;\n"]}
@@ -0,0 +1,7 @@
1
+ import { ParseResults } from '../latlon/internal/parse.js';
2
+ import '../latlon/internal/index.js';
3
+ import '../latlon/internal/lexer.js';
4
+
5
+ declare function parseMGRS(_format: any, input: string): ParseResults;
6
+
7
+ export { parseMGRS };
@@ -0,0 +1,45 @@
1
+ import { MGRS } from '@ngageoint/mgrs-js';
2
+ import { parse } from '../latlon/internal/parse.js';
3
+ import { violation } from '../latlon/internal/violation.js';
4
+
5
+ // src/coordinates/mgrs/parser.ts
6
+ var PATTERN_PARTS = /^((?:..?)?)(\w?)\s*((?:\w{2})?)\s*(?:(\d+(?:\.\d*)?)?)\s*(?:(\d+(?:\.\d*)?)?)$/i;
7
+ var error = (message) => [
8
+ [],
9
+ [`${violation(message)}; expected format DDZ AA DDD DDD.`]
10
+ ];
11
+ function detailedErrors(input) {
12
+ if (!input) {
13
+ return error("No input provided");
14
+ }
15
+ const [utm, bnd, hkm, east, north] = (input.trim().replace(/\s+/g, " ").match(PATTERN_PARTS) ?? []).slice(1);
16
+ if (!utm || +utm > 60 || +utm < 1) {
17
+ return error(
18
+ `Invalid UTM zone number (${utm}) found in grid zone designation`
19
+ );
20
+ }
21
+ if (!/[C-HJ-NP-X]/i.test(bnd)) {
22
+ return error(
23
+ `Invalid Latitude band letter (${bnd}) found in grid zone designation`
24
+ );
25
+ }
26
+ if (!/^[A-HJ-NP-Z]*$/i.test(hkm)) {
27
+ return error(`Invalid 100K m square identification (${hkm}) found`);
28
+ }
29
+ if (!(east && north && +east > 0 && +north > 0)) {
30
+ return error(`Invalid numerical location (${[east, north].join()}) found`);
31
+ }
32
+ return error("Uncaught error condition.");
33
+ }
34
+ function parseMGRS(_format, input) {
35
+ try {
36
+ const point = MGRS.parse(input).toPoint();
37
+ return parse(`${point.getLatitude()} / ${point.getLongitude()}`, "LATLON");
38
+ } catch (_e) {
39
+ return detailedErrors(input);
40
+ }
41
+ }
42
+
43
+ export { parseMGRS };
44
+ //# sourceMappingURL=parser.js.map
45
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/coordinates/mgrs/parser.ts"],"names":[],"mappings":";;;;;AAmBA,IAAM,aACJ,GAAA,iFAAA;AAEF,IAAM,KAAA,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IAAA,MAAM,KAAQ,GAAA,IAAA,CAAK,KAAM,CAAA,KAAK,EAAE,OAAQ,EAAA;AAExC,IAAO,OAAA,KAAA,CAAM,CAAG,EAAA,KAAA,CAAM,WAAY,EAAC,MAAM,KAAM,CAAA,YAAA,EAAc,CAAA,CAAA,EAAI,QAAQ,CAAA;AAAA,WAClE,EAAI,EAAA;AACX,IAAA,OAAO,eAAe,KAAK,CAAA;AAAA;AAE/B","file":"parser.js","sourcesContent":["/*\n * Copyright 2024 Hypergiant Galactic Systems Inc. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { MGRS } from '@ngageoint/mgrs-js';\n\nimport { type ParseResults, parse } from '../latlon/internal/parse';\nimport { violation } from '../latlon/internal/violation';\n\ntype Match = [string, string, string, string, string];\n\nconst PATTERN_PARTS =\n /^((?:..?)?)(\\w?)\\s*((?:\\w{2})?)\\s*(?:(\\d+(?:\\.\\d*)?)?)\\s*(?:(\\d+(?:\\.\\d*)?)?)$/i;\n\nconst error = (message: string) =>\n [\n [],\n [`${violation(message)}; expected format DDZ AA DDD DDD.`],\n ] as ParseResults;\n\nfunction detailedErrors(input: string) {\n if (!input) {\n return error('No input provided');\n }\n\n const [utm, bnd, hkm, east, north] = (\n input.trim().replace(/\\s+/g, ' ').match(PATTERN_PARTS) ?? []\n ).slice(1) as Match;\n\n if (!utm || +utm > 60 || +utm < 1) {\n return error(\n `Invalid UTM zone number (${utm}) found in grid zone designation`,\n );\n }\n\n if (!/[C-HJ-NP-X]/i.test(bnd)) {\n return error(\n `Invalid Latitude band letter (${bnd}) found in grid zone designation`,\n );\n }\n\n if (!/^[A-HJ-NP-Z]*$/i.test(hkm)) {\n return error(`Invalid 100K m square identification (${hkm}) found`);\n }\n\n if (!(east && north && +east > 0 && +north > 0)) {\n return error(`Invalid numerical location (${[east, north].join()}) found`);\n }\n\n return error('Uncaught error condition.');\n}\n\n// biome-ignore lint/style/useNamingConvention: <explanation>\n// biome-ignore lint/suspicious/noExplicitAny: <explanation>\nexport function parseMGRS(_format: any, input: string) {\n try {\n const point = MGRS.parse(input).toPoint();\n\n return parse(`${point.getLatitude()} / ${point.getLongitude()}`, 'LATLON');\n } catch (_e) {\n return detailedErrors(input);\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { CoordinateSystem } from '../latlon/internal/coordinate-system.js';
2
+ import '../latlon/internal/index.js';
3
+ import '../latlon/internal/parse.js';
4
+ import '../latlon/internal/lexer.js';
5
+
6
+ declare const systemMGRS: CoordinateSystem;
7
+
8
+ export { systemMGRS };
@@ -0,0 +1,25 @@
1
+ import { Point } from '@ngageoint/grid-js';
2
+ import { MGRS } from '@ngageoint/mgrs-js';
3
+ import { SYMBOL_PATTERNS } from '../latlon/internal/index.js';
4
+ import { parseMGRS } from './parser.js';
5
+
6
+ // src/coordinates/mgrs/system.ts
7
+ var systemMGRS = {
8
+ name: "Military Grid Reference System",
9
+ parse: parseMGRS,
10
+ toFloat(arg) {
11
+ const [num, bear] = arg;
12
+ return Number.parseFloat(num) * (SYMBOL_PATTERNS.NEGATIVE_BEARINGS.test(bear) ? -1 : 1);
13
+ },
14
+ toFormat(format, [left, right]) {
15
+ const { LAT, LON } = Object.fromEntries([
16
+ [format.slice(0, 3), left],
17
+ [format.slice(3), right]
18
+ ]);
19
+ return MGRS.from(Point.point(LON, LAT)).toString();
20
+ }
21
+ };
22
+
23
+ export { systemMGRS };
24
+ //# sourceMappingURL=system.js.map
25
+ //# sourceMappingURL=system.js.map