@accelint/geo 0.6.1 → 0.7.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 (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +98 -1
  3. package/catalog-info.yaml +1 -1
  4. package/dist/coordinates/latlon/decimal-degrees/formatter.d.ts +35 -2
  5. package/dist/coordinates/latlon/decimal-degrees/formatter.js +33 -4
  6. package/dist/coordinates/latlon/decimal-degrees/formatter.js.map +1 -1
  7. package/dist/coordinates/latlon/decimal-degrees/system.js +5 -3
  8. package/dist/coordinates/latlon/decimal-degrees/system.js.map +1 -1
  9. package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.d.ts +42 -2
  10. package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.js +60 -8
  11. package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.js.map +1 -1
  12. package/dist/coordinates/latlon/degrees-decimal-minutes/system.js +7 -6
  13. package/dist/coordinates/latlon/degrees-decimal-minutes/system.js.map +1 -1
  14. package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.d.ts +45 -2
  15. package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.js +66 -12
  16. package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.js.map +1 -1
  17. package/dist/coordinates/latlon/degrees-minutes-seconds/system.js +7 -6
  18. package/dist/coordinates/latlon/degrees-minutes-seconds/system.js.map +1 -1
  19. package/dist/coordinates/latlon/internal/format.d.ts +50 -5
  20. package/dist/coordinates/latlon/internal/format.js +39 -9
  21. package/dist/coordinates/latlon/internal/format.js.map +1 -1
  22. package/dist/coordinates/latlon/internal/index.d.ts +3 -2
  23. package/dist/coordinates/latlon/internal/index.js +3 -2
  24. package/dist/coordinates/latlon/internal/index.js.map +1 -1
  25. package/dist/coordinates/latlon/internal/lexer.js +2 -1
  26. package/dist/coordinates/latlon/internal/lexer.js.map +1 -1
  27. package/dist/coordinates/latlon/internal/ordinal.d.ts +39 -9
  28. package/dist/coordinates/latlon/internal/ordinal.js +31 -12
  29. package/dist/coordinates/latlon/internal/ordinal.js.map +1 -1
  30. package/dist/coordinates/latlon/internal/plain-decimal.d.ts +35 -0
  31. package/dist/coordinates/latlon/internal/plain-decimal.js +59 -0
  32. package/dist/coordinates/latlon/internal/plain-decimal.js.map +1 -0
  33. package/dist/coordinates/latlon/internal/validate.d.ts +28 -1
  34. package/dist/coordinates/latlon/internal/validate.js +30 -1
  35. package/dist/coordinates/latlon/internal/validate.js.map +1 -1
  36. package/dist/coordinates/mgrs/parts.d.ts +86 -0
  37. package/dist/coordinates/mgrs/parts.js +94 -0
  38. package/dist/coordinates/mgrs/parts.js.map +1 -0
  39. package/dist/coordinates/mgrs/system.js +4 -2
  40. package/dist/coordinates/mgrs/system.js.map +1 -1
  41. package/dist/coordinates/utm/parts.d.ts +134 -0
  42. package/dist/coordinates/utm/parts.js +142 -0
  43. package/dist/coordinates/utm/parts.js.map +1 -0
  44. package/dist/coordinates/utm/system.js +4 -3
  45. package/dist/coordinates/utm/system.js.map +1 -1
  46. package/dist/index.d.ts +10 -7
  47. package/dist/index.js +10 -7
  48. package/package.json +6 -3
@@ -0,0 +1,142 @@
1
+ /*
2
+ * Copyright 2026 Hypergiant Galactic Systems Inc. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at https://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+
14
+ import { isValidNumericCoordinate } from "../latlon/internal/validate.js";
15
+ import { LatLon } from "geodesy/utm";
16
+
17
+ //#region src/coordinates/utm/parts.ts
18
+ /**
19
+ * Lowest latitude (degrees) the UTM/MGRS grid is defined for, inclusive.
20
+ *
21
+ * Matches the patched geodesy valid range; latitudes below this yield an
22
+ * out-of-range result rather than a projected grid reference.
23
+ */
24
+ const GRID_LATITUDE_MIN = -80;
25
+ /**
26
+ * Highest latitude (degrees) the UTM/MGRS grid is defined for, inclusive.
27
+ *
28
+ * Matches the patched geodesy valid range; latitudes above this yield an
29
+ * out-of-range result rather than a projected grid reference.
30
+ */
31
+ const GRID_LATITUDE_MAX = 84;
32
+ /**
33
+ * Reports whether a latitude falls within the inclusive UTM/MGRS grid band.
34
+ *
35
+ * @param lat - The latitude in degrees.
36
+ * @returns `true` when `-80 ≤ lat ≤ 84`.
37
+ *
38
+ * @remarks pure function
39
+ */
40
+ const isWithinGridBand = (lat) => lat >= GRID_LATITUDE_MIN && lat <= GRID_LATITUDE_MAX;
41
+ /**
42
+ * Reports whether a longitude sits on the eastern antimeridian singularity.
43
+ *
44
+ * At exactly `+180°` the UTM zone formula yields the nonexistent zone `61`,
45
+ * for which geodesy throws. `-180°` and values beyond `±180°` project
46
+ * normally, so only `+180°` is excluded here — the same point is reachable as
47
+ * `-180°`, or via a caller's own longitude normalization.
48
+ *
49
+ * @param lon - The longitude in degrees.
50
+ * @returns `true` when `lon` is exactly `180`.
51
+ *
52
+ * @remarks pure function
53
+ */
54
+ const isOnEasternAntimeridian = (lon) => lon === 180;
55
+ /**
56
+ * Reports whether a signed `[lat, lon]` coordinate can be projected to a UTM
57
+ * zone (and therefore to MGRS).
58
+ *
59
+ * A coordinate is projectable when it is finite and in range, its latitude is
60
+ * within the inclusive `80°S`–`84°N` grid band, and it does not sit on the
61
+ * `+180°` antimeridian singularity. This is the single validity gate shared by
62
+ * {@link toUtmParts} and {@link toMgrsParts}.
63
+ *
64
+ * @param coordinate - Signed `[latitude, longitude]` tuple.
65
+ * @returns `true` when the coordinate projects to a grid reference.
66
+ *
67
+ * @remarks pure function
68
+ */
69
+ const isGridProjectable = ([lat, lon]) => isValidNumericCoordinate(lat, lon) && isWithinGridBand(lat) && !isOnEasternAntimeridian(lon);
70
+ /**
71
+ * Converts a signed `[lat, lon]` coordinate into UTM grid parts.
72
+ *
73
+ * Reads the geodesy `Utm` fields directly and rounds `easting`/`northing` to
74
+ * integer metres (matching the existing UTM string renderer). The UTM/MGRS
75
+ * grid is defined for `-80 ≤ lat ≤ 84` inclusive; latitudes outside that band,
76
+ * a longitude of exactly `+180°` (the antimeridian zone singularity), or
77
+ * non-finite input, produce `{ ok: false, reason: 'out-of-range' }`.
78
+ *
79
+ * @param coordinate - Signed `[latitude, longitude]` tuple.
80
+ * @returns A discriminated result with `{ zone, hemisphere, easting, northing }` on success.
81
+ *
82
+ * @remarks pure function
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * toUtmParts([38.8977, -77.0365]);
87
+ * // { ok: true, value: { zone: 18, hemisphere: 'N', easting: 323394, northing: 4307396 } }
88
+ * ```
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * toUtmParts([85, 0]);
93
+ * // { ok: false, reason: 'out-of-range' }
94
+ * ```
95
+ */
96
+ const toUtmParts = ([lat, lon]) => {
97
+ if (!isGridProjectable([lat, lon])) return {
98
+ ok: false,
99
+ reason: "out-of-range"
100
+ };
101
+ try {
102
+ const utm = new LatLon(lat, lon).toUtm();
103
+ return {
104
+ ok: true,
105
+ value: {
106
+ zone: utm.zone,
107
+ hemisphere: utm.hemisphere,
108
+ easting: Math.round(utm.easting),
109
+ northing: Math.round(utm.northing)
110
+ }
111
+ };
112
+ } catch {
113
+ return {
114
+ ok: false,
115
+ reason: "out-of-range"
116
+ };
117
+ }
118
+ };
119
+ /**
120
+ * Renders UTM grid parts as their canonical coordinate string.
121
+ *
122
+ * Left-pads the zone to two digits and joins zone+hemisphere, easting, and
123
+ * northing with single spaces, matching geodesy's `Utm.toString()` output.
124
+ * `easting`/`northing` are already the rounded integer metres `toUtmParts`
125
+ * yields, so no further rounding is applied here.
126
+ *
127
+ * @param parts - The UTM grid parts to render.
128
+ * @returns The canonical UTM string, e.g. `"18N 323394 4307396"`.
129
+ *
130
+ * @remarks pure function
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * formatUtmParts({ zone: 18, hemisphere: 'N', easting: 323394, northing: 4307396 });
135
+ * // '18N 323394 4307396'
136
+ * ```
137
+ */
138
+ const formatUtmParts = ({ zone, hemisphere, easting, northing }) => `${zone.toString().padStart(2, "0")}${hemisphere} ${easting} ${northing}`;
139
+
140
+ //#endregion
141
+ export { GRID_LATITUDE_MAX, GRID_LATITUDE_MIN, formatUtmParts, isGridProjectable, isOnEasternAntimeridian, isWithinGridBand, toUtmParts };
142
+ //# sourceMappingURL=parts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parts.js","names":[],"sources":["../../../src/coordinates/utm/parts.ts"],"sourcesContent":["/*\n * Copyright 2026 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 { LatLon } from 'geodesy/utm';\nimport { isValidNumericCoordinate } from '../latlon/internal';\n\n/**\n * Lowest latitude (degrees) the UTM/MGRS grid is defined for, inclusive.\n *\n * Matches the patched geodesy valid range; latitudes below this yield an\n * out-of-range result rather than a projected grid reference.\n */\nexport const GRID_LATITUDE_MIN = -80;\n\n/**\n * Highest latitude (degrees) the UTM/MGRS grid is defined for, inclusive.\n *\n * Matches the patched geodesy valid range; latitudes above this yield an\n * out-of-range result rather than a projected grid reference.\n */\nexport const GRID_LATITUDE_MAX = 84;\n\n/**\n * Discriminated result for a grid-parts conversion.\n *\n * `ok: true` carries the structured grid parts; `ok: false` carries a typed\n * `reason` so consumers branch on a field instead of matching error text.\n *\n * @template Value - The grid parts shape carried on success.\n */\nexport type GridPartsResult<Value> =\n | { ok: true; value: Value }\n | { ok: false; reason: 'out-of-range' };\n\n/**\n * Structured UTM grid parts for a signed `[lat, lon]` coordinate.\n *\n * `easting` and `northing` are the rounded integer metres geodesy yields.\n */\nexport type UtmParts = {\n zone: number;\n hemisphere: 'N' | 'S';\n easting: number;\n northing: number;\n};\n\n/**\n * Reports whether a latitude falls within the inclusive UTM/MGRS grid band.\n *\n * @param lat - The latitude in degrees.\n * @returns `true` when `-80 ≤ lat ≤ 84`.\n *\n * @remarks pure function\n */\nexport const isWithinGridBand = (lat: number): boolean =>\n lat >= GRID_LATITUDE_MIN && lat <= GRID_LATITUDE_MAX;\n\n/**\n * Reports whether a longitude sits on the eastern antimeridian singularity.\n *\n * At exactly `+180°` the UTM zone formula yields the nonexistent zone `61`,\n * for which geodesy throws. `-180°` and values beyond `±180°` project\n * normally, so only `+180°` is excluded here — the same point is reachable as\n * `-180°`, or via a caller's own longitude normalization.\n *\n * @param lon - The longitude in degrees.\n * @returns `true` when `lon` is exactly `180`.\n *\n * @remarks pure function\n */\nexport const isOnEasternAntimeridian = (lon: number): boolean => lon === 180;\n\n/**\n * Reports whether a signed `[lat, lon]` coordinate can be projected to a UTM\n * zone (and therefore to MGRS).\n *\n * A coordinate is projectable when it is finite and in range, its latitude is\n * within the inclusive `80°S`–`84°N` grid band, and it does not sit on the\n * `+180°` antimeridian singularity. This is the single validity gate shared by\n * {@link toUtmParts} and {@link toMgrsParts}.\n *\n * @param coordinate - Signed `[latitude, longitude]` tuple.\n * @returns `true` when the coordinate projects to a grid reference.\n *\n * @remarks pure function\n */\nexport const isGridProjectable = ([lat, lon]: [number, number]): boolean =>\n isValidNumericCoordinate(lat, lon) &&\n isWithinGridBand(lat) &&\n !isOnEasternAntimeridian(lon);\n\n/**\n * Converts a signed `[lat, lon]` coordinate into UTM grid parts.\n *\n * Reads the geodesy `Utm` fields directly and rounds `easting`/`northing` to\n * integer metres (matching the existing UTM string renderer). The UTM/MGRS\n * grid is defined for `-80 ≤ lat ≤ 84` inclusive; latitudes outside that band,\n * a longitude of exactly `+180°` (the antimeridian zone singularity), or\n * non-finite input, produce `{ ok: false, reason: 'out-of-range' }`.\n *\n * @param coordinate - Signed `[latitude, longitude]` tuple.\n * @returns A discriminated result with `{ zone, hemisphere, easting, northing }` on success.\n *\n * @remarks pure function\n *\n * @example\n * ```typescript\n * toUtmParts([38.8977, -77.0365]);\n * // { ok: true, value: { zone: 18, hemisphere: 'N', easting: 323394, northing: 4307396 } }\n * ```\n *\n * @example\n * ```typescript\n * toUtmParts([85, 0]);\n * // { ok: false, reason: 'out-of-range' }\n * ```\n */\nexport const toUtmParts = ([lat, lon]: [\n number,\n number,\n]): GridPartsResult<UtmParts> => {\n if (!isGridProjectable([lat, lon])) {\n return { ok: false, reason: 'out-of-range' };\n }\n\n try {\n const utm = new LatLon(lat, lon).toUtm();\n\n return {\n ok: true,\n value: {\n zone: utm.zone,\n hemisphere: utm.hemisphere as 'N' | 'S',\n easting: Math.round(utm.easting),\n northing: Math.round(utm.northing),\n },\n };\n } catch {\n // geodesy applies its own bounds after projecting; keep the result total\n // rather than leaking a RangeError (e.g. an unpatched geodesy at 84°N).\n return { ok: false, reason: 'out-of-range' };\n }\n};\n\n/**\n * Renders UTM grid parts as their canonical coordinate string.\n *\n * Left-pads the zone to two digits and joins zone+hemisphere, easting, and\n * northing with single spaces, matching geodesy's `Utm.toString()` output.\n * `easting`/`northing` are already the rounded integer metres `toUtmParts`\n * yields, so no further rounding is applied here.\n *\n * @param parts - The UTM grid parts to render.\n * @returns The canonical UTM string, e.g. `\"18N 323394 4307396\"`.\n *\n * @remarks pure function\n *\n * @example\n * ```typescript\n * formatUtmParts({ zone: 18, hemisphere: 'N', easting: 323394, northing: 4307396 });\n * // '18N 323394 4307396'\n * ```\n */\nexport const formatUtmParts = ({\n zone,\n hemisphere,\n easting,\n northing,\n}: UtmParts): string =>\n `${zone.toString().padStart(2, '0')}${hemisphere} ${easting} ${northing}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,oBAAoB;;;;;;;;;AAkCjC,MAAa,oBAAoB,QAC/B,OAAO,qBAAqB,OAAO;;;;;;;;;;;;;;AAerC,MAAa,2BAA2B,QAAyB,QAAQ;;;;;;;;;;;;;;;AAgBzE,MAAa,qBAAqB,CAAC,KAAK,SACtC,yBAAyB,KAAK,IAAI,IAClC,iBAAiB,IAAI,IACrB,CAAC,wBAAwB,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B/B,MAAa,cAAc,CAAC,KAAK,SAGA;AAC/B,KAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC,CAChC,QAAO;EAAE,IAAI;EAAO,QAAQ;EAAgB;AAG9C,KAAI;EACF,MAAM,MAAM,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO;AAExC,SAAO;GACL,IAAI;GACJ,OAAO;IACL,MAAM,IAAI;IACV,YAAY,IAAI;IAChB,SAAS,KAAK,MAAM,IAAI,QAAQ;IAChC,UAAU,KAAK,MAAM,IAAI,SAAS;IACnC;GACF;SACK;AAGN,SAAO;GAAE,IAAI;GAAO,QAAQ;GAAgB;;;;;;;;;;;;;;;;;;;;;;AAuBhD,MAAa,kBAAkB,EAC7B,MACA,YACA,SACA,eAEA,GAAG,KAAK,UAAU,CAAC,SAAS,GAAG,IAAI,GAAG,WAAW,GAAG,QAAQ,GAAG"}
@@ -12,8 +12,8 @@
12
12
 
13
13
 
14
14
  import { SYMBOL_PATTERNS } from "../latlon/internal/index.js";
15
+ import { formatUtmParts, toUtmParts } from "./parts.js";
15
16
  import { parseUTM } from "./parser.js";
16
- import { LatLon } from "geodesy/utm";
17
17
 
18
18
  //#region src/coordinates/utm/system.ts
19
19
  /**
@@ -45,8 +45,9 @@ const systemUTM = {
45
45
  },
46
46
  toFormat(format, [left, right]) {
47
47
  const { LAT, LON } = Object.fromEntries([[format.slice(0, 3), left], [format.slice(3), right]]);
48
- const utm = new LatLon(LAT, LON).toUtm();
49
- return `${utm.zone.toString().padStart(2, "0")}${utm.hemisphere} ${Math.round(utm.easting).toString()} ${Math.round(utm.northing).toString()}`;
48
+ const result = toUtmParts([LAT, LON]);
49
+ if (!result.ok) throw new RangeError(`Coordinate [${LAT}, ${LON}] cannot be represented in UTM (outside 80°S–84°N, on the +180° antimeridian, or not finite).`);
50
+ return formatUtmParts(result.value);
50
51
  }
51
52
  };
52
53
 
@@ -1 +1 @@
1
- {"version":3,"file":"system.js","names":["systemUTM: CoordinateSystem"],"sources":["../../../src/coordinates/utm/system.ts"],"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 { LatLon } from 'geodesy/utm';\nimport { type Compass, type Format, SYMBOL_PATTERNS } from '../latlon/internal';\nimport { parseUTM } from './parser';\nimport type { CoordinateSystem } from '../latlon/internal/coordinate-system';\n\n/**\n * Universal Transverse Mercator (UTM) coordinate system implementation.\n *\n * Provides parsing, conversion, and formatting for UTM coordinates. UTM divides\n * the Earth into 60 zones, each 6 degrees of longitude wide, using a transverse\n * Mercator projection. Coordinates are expressed as zone number, hemisphere (N/S),\n * easting, and northing values.\n *\n * @example\n * ```typescript\n * systemUTM.parse(null, '18N 585628 4511644');\n * // [['40.7128', '/', '-74.0060'], []]\n * ```\n *\n * @example\n * ```typescript\n * systemUTM.toFormat('LATLON', [40.7128, -74.0060]);\n * // '18N 585628 4511644'\n * ```\n */\nexport const systemUTM: CoordinateSystem = {\n name: 'Universal Transverse Mercator',\n\n parse: parseUTM,\n\n toFloat(arg) {\n const [num, bear] = arg as [string, Compass];\n\n return (\n Number.parseFloat(num) *\n (SYMBOL_PATTERNS.NEGATIVE_BEARINGS.test(bear) ? -1 : 1)\n );\n },\n\n toFormat(format: Format, [left, right]: [number, number]) {\n const { LAT, LON } = Object.fromEntries([\n [format.slice(0, 3), left],\n [format.slice(3), right],\n ]) as Record<'LAT' | 'LON', number>;\n\n const latlon = new LatLon(LAT, LON);\n const utm = latlon.toUtm();\n\n // Format UTM coordinates manually to ensure correct format\n // Expected format: \"18N 585628 4511644\" (zone hemisphere easting northing)\n const zone = utm.zone.toString().padStart(2, '0');\n const hemisphere = utm.hemisphere;\n const easting = Math.round(utm.easting).toString();\n const northing = Math.round(utm.northing).toString();\n\n return `${zone}${hemisphere} ${easting} ${northing}`;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAaA,YAA8B;CACzC,MAAM;CAEN,OAAO;CAEP,QAAQ,KAAK;EACX,MAAM,CAAC,KAAK,QAAQ;AAEpB,SACE,OAAO,WAAW,IAAI,IACrB,gBAAgB,kBAAkB,KAAK,KAAK,GAAG,KAAK;;CAIzD,SAAS,QAAgB,CAAC,MAAM,QAA0B;EACxD,MAAM,EAAE,KAAK,QAAQ,OAAO,YAAY,CACtC,CAAC,OAAO,MAAM,GAAG,EAAE,EAAE,KAAK,EAC1B,CAAC,OAAO,MAAM,EAAE,EAAE,MAAM,CACzB,CAAC;EAGF,MAAM,MADS,IAAI,OAAO,KAAK,IAAI,CAChB,OAAO;AAS1B,SAAO,GALM,IAAI,KAAK,UAAU,CAAC,SAAS,GAAG,IAAI,GAC9B,IAAI,WAIK,GAHZ,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,CAGX,GAFtB,KAAK,MAAM,IAAI,SAAS,CAAC,UAAU;;CAIvD"}
1
+ {"version":3,"file":"system.js","names":["systemUTM: CoordinateSystem"],"sources":["../../../src/coordinates/utm/system.ts"],"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 Compass, type Format, SYMBOL_PATTERNS } from '../latlon/internal';\nimport { parseUTM } from './parser';\nimport { formatUtmParts, toUtmParts } from './parts';\nimport type { CoordinateSystem } from '../latlon/internal/coordinate-system';\n\n/**\n * Universal Transverse Mercator (UTM) coordinate system implementation.\n *\n * Provides parsing, conversion, and formatting for UTM coordinates. UTM divides\n * the Earth into 60 zones, each 6 degrees of longitude wide, using a transverse\n * Mercator projection. Coordinates are expressed as zone number, hemisphere (N/S),\n * easting, and northing values.\n *\n * @example\n * ```typescript\n * systemUTM.parse(null, '18N 585628 4511644');\n * // [['40.7128', '/', '-74.0060'], []]\n * ```\n *\n * @example\n * ```typescript\n * systemUTM.toFormat('LATLON', [40.7128, -74.0060]);\n * // '18N 585628 4511644'\n * ```\n */\nexport const systemUTM: CoordinateSystem = {\n name: 'Universal Transverse Mercator',\n\n parse: parseUTM,\n\n toFloat(arg) {\n const [num, bear] = arg as [string, Compass];\n\n return (\n Number.parseFloat(num) *\n (SYMBOL_PATTERNS.NEGATIVE_BEARINGS.test(bear) ? -1 : 1)\n );\n },\n\n toFormat(format: Format, [left, right]: [number, number]) {\n const { LAT, LON } = Object.fromEntries([\n [format.slice(0, 3), left],\n [format.slice(3), right],\n ]) as Record<'LAT' | 'LON', number>;\n\n const result = toUtmParts([LAT, LON]);\n\n if (!result.ok) {\n // The legacy `toFormat` contract throws for coordinates the grid cannot\n // represent; the parts API returns `{ ok: false }` for the same inputs.\n throw new RangeError(\n `Coordinate [${LAT}, ${LON}] cannot be represented in UTM (outside 80°S–84°N, on the +180° antimeridian, or not finite).`,\n );\n }\n\n return formatUtmParts(result.value);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAaA,YAA8B;CACzC,MAAM;CAEN,OAAO;CAEP,QAAQ,KAAK;EACX,MAAM,CAAC,KAAK,QAAQ;AAEpB,SACE,OAAO,WAAW,IAAI,IACrB,gBAAgB,kBAAkB,KAAK,KAAK,GAAG,KAAK;;CAIzD,SAAS,QAAgB,CAAC,MAAM,QAA0B;EACxD,MAAM,EAAE,KAAK,QAAQ,OAAO,YAAY,CACtC,CAAC,OAAO,MAAM,GAAG,EAAE,EAAE,KAAK,EAC1B,CAAC,OAAO,MAAM,EAAE,EAAE,MAAM,CACzB,CAAC;EAEF,MAAM,SAAS,WAAW,CAAC,KAAK,IAAI,CAAC;AAErC,MAAI,CAAC,OAAO,GAGV,OAAM,IAAI,WACR,eAAe,IAAI,IAAI,IAAI,+FAC5B;AAGH,SAAO,eAAe,OAAO,MAAM;;CAEtC"}
package/dist/index.d.ts CHANGED
@@ -11,16 +11,19 @@
11
11
  */
12
12
 
13
13
  import { CoordinateInput, CoordinateInternalValue, CoordinateObject, CoordinateTuple, LatLonTuple, LonLatTuple, isCoordinateObject, isCoordinateTuple, normalizeObjectToLatLon, tupleToLatLon } from "./coordinates/latlon/internal/normalize.js";
14
- import { isFiniteNumber, validateNumericCoordinate, validateSignedRange } from "./coordinates/latlon/internal/validate.js";
14
+ import { toPlainDecimalString } from "./coordinates/latlon/internal/plain-decimal.js";
15
+ import { isFiniteNumber, isValidNumericCoordinate, validateNumericCoordinate, validateSignedRange } from "./coordinates/latlon/internal/validate.js";
15
16
  import { coordinateSystems, createCoordinate } from "./coordinates/coordinate.js";
16
- import { FormatOptions, createFormatter } from "./coordinates/latlon/internal/format.js";
17
- import { formatDecimalDegrees } from "./coordinates/latlon/decimal-degrees/formatter.js";
17
+ import { FormatOptions, createFormatter, formatCoordinateSystem } from "./coordinates/latlon/internal/format.js";
18
+ import { Axis, Hemisphere, getHemisphere, getOrdinal } from "./coordinates/latlon/internal/ordinal.js";
19
+ import { DECIMAL_DEGREES_PRECISION, DecimalDegreesParts, formatDecimalDegrees, toDecimalDegreesParts } from "./coordinates/latlon/decimal-degrees/formatter.js";
18
20
  import { parseDecimalDegrees } from "./coordinates/latlon/decimal-degrees/parser.js";
19
- import { formatDegreesDecimalMinutes } from "./coordinates/latlon/degrees-decimal-minutes/formatter.js";
21
+ import { DDM_PRECISION, DdmParts, formatDegreesDecimalMinutes, toDdmParts } from "./coordinates/latlon/degrees-decimal-minutes/formatter.js";
20
22
  import { parseDegreesDecimalMinutes } from "./coordinates/latlon/degrees-decimal-minutes/parser.js";
21
- import { formatDegreesMinutesSeconds } from "./coordinates/latlon/degrees-minutes-seconds/formatter.js";
23
+ import { DMS_PRECISION, DmsParts, formatDegreesMinutesSeconds, toDmsParts } from "./coordinates/latlon/degrees-minutes-seconds/formatter.js";
22
24
  import { parseDegreesMinutesSeconds } from "./coordinates/latlon/degrees-minutes-seconds/parser.js";
23
- import { getOrdinal } from "./coordinates/latlon/internal/ordinal.js";
24
25
  import { parseMGRS } from "./coordinates/mgrs/parser.js";
26
+ import { GRID_LATITUDE_MAX, GRID_LATITUDE_MIN, GridPartsResult, UtmParts, formatUtmParts, isGridProjectable, isOnEasternAntimeridian, isWithinGridBand, toUtmParts } from "./coordinates/utm/parts.js";
27
+ import { MgrsParts, formatMgrsParts, toMgrsParts } from "./coordinates/mgrs/parts.js";
25
28
  import { parseUTM } from "./coordinates/utm/parser.js";
26
- export { type CoordinateInput, type CoordinateInternalValue, type CoordinateObject, type CoordinateTuple, type FormatOptions, type LatLonTuple, type LonLatTuple, coordinateSystems, createCoordinate, createFormatter, formatDecimalDegrees, formatDegreesDecimalMinutes, formatDegreesMinutesSeconds, getOrdinal, isCoordinateObject, isCoordinateTuple, isFiniteNumber, normalizeObjectToLatLon, parseDecimalDegrees, parseDegreesDecimalMinutes, parseDegreesMinutesSeconds, parseMGRS, parseUTM, tupleToLatLon, validateNumericCoordinate, validateSignedRange };
29
+ export { type Axis, type CoordinateInput, type CoordinateInternalValue, type CoordinateObject, type CoordinateTuple, DDM_PRECISION, DECIMAL_DEGREES_PRECISION, DMS_PRECISION, type DdmParts, type DecimalDegreesParts, type DmsParts, type FormatOptions, GRID_LATITUDE_MAX, GRID_LATITUDE_MIN, type GridPartsResult, type Hemisphere, type LatLonTuple, type LonLatTuple, type MgrsParts, type UtmParts, coordinateSystems, createCoordinate, createFormatter, formatCoordinateSystem, formatDecimalDegrees, formatDegreesDecimalMinutes, formatDegreesMinutesSeconds, formatMgrsParts, formatUtmParts, getHemisphere, getOrdinal, isCoordinateObject, isCoordinateTuple, isFiniteNumber, isGridProjectable, isOnEasternAntimeridian, isValidNumericCoordinate, isWithinGridBand, normalizeObjectToLatLon, parseDecimalDegrees, parseDegreesDecimalMinutes, parseDegreesMinutesSeconds, parseMGRS, parseUTM, toDdmParts, toDecimalDegreesParts, toDmsParts, toMgrsParts, toPlainDecimalString, toUtmParts, tupleToLatLon, validateNumericCoordinate, validateSignedRange };
package/dist/index.js CHANGED
@@ -12,17 +12,20 @@
12
12
 
13
13
 
14
14
  import { isCoordinateObject, isCoordinateTuple, normalizeObjectToLatLon, tupleToLatLon } from "./coordinates/latlon/internal/normalize.js";
15
- import { isFiniteNumber, validateNumericCoordinate, validateSignedRange } from "./coordinates/latlon/internal/validate.js";
15
+ import { toPlainDecimalString } from "./coordinates/latlon/internal/plain-decimal.js";
16
+ import { isFiniteNumber, isValidNumericCoordinate, validateNumericCoordinate, validateSignedRange } from "./coordinates/latlon/internal/validate.js";
17
+ import { getHemisphere, getOrdinal } from "./coordinates/latlon/internal/ordinal.js";
18
+ import { createFormatter, formatCoordinateSystem } from "./coordinates/latlon/internal/format.js";
16
19
  import { parseDecimalDegrees } from "./coordinates/latlon/decimal-degrees/parser.js";
17
20
  import { parseDegreesDecimalMinutes } from "./coordinates/latlon/degrees-decimal-minutes/parser.js";
18
21
  import { parseDegreesMinutesSeconds } from "./coordinates/latlon/degrees-minutes-seconds/parser.js";
19
22
  import { parseMGRS } from "./coordinates/mgrs/parser.js";
23
+ import { GRID_LATITUDE_MAX, GRID_LATITUDE_MIN, formatUtmParts, isGridProjectable, isOnEasternAntimeridian, isWithinGridBand, toUtmParts } from "./coordinates/utm/parts.js";
24
+ import { formatMgrsParts, toMgrsParts } from "./coordinates/mgrs/parts.js";
20
25
  import { parseUTM } from "./coordinates/utm/parser.js";
21
26
  import { coordinateSystems, createCoordinate } from "./coordinates/coordinate.js";
22
- import { getOrdinal } from "./coordinates/latlon/internal/ordinal.js";
23
- import { createFormatter } from "./coordinates/latlon/internal/format.js";
24
- import { formatDecimalDegrees } from "./coordinates/latlon/decimal-degrees/formatter.js";
25
- import { formatDegreesDecimalMinutes } from "./coordinates/latlon/degrees-decimal-minutes/formatter.js";
26
- import { formatDegreesMinutesSeconds } from "./coordinates/latlon/degrees-minutes-seconds/formatter.js";
27
+ import { DECIMAL_DEGREES_PRECISION, formatDecimalDegrees, toDecimalDegreesParts } from "./coordinates/latlon/decimal-degrees/formatter.js";
28
+ import { DDM_PRECISION, formatDegreesDecimalMinutes, toDdmParts } from "./coordinates/latlon/degrees-decimal-minutes/formatter.js";
29
+ import { DMS_PRECISION, formatDegreesMinutesSeconds, toDmsParts } from "./coordinates/latlon/degrees-minutes-seconds/formatter.js";
27
30
 
28
- export { coordinateSystems, createCoordinate, createFormatter, formatDecimalDegrees, formatDegreesDecimalMinutes, formatDegreesMinutesSeconds, getOrdinal, isCoordinateObject, isCoordinateTuple, isFiniteNumber, normalizeObjectToLatLon, parseDecimalDegrees, parseDegreesDecimalMinutes, parseDegreesMinutesSeconds, parseMGRS, parseUTM, tupleToLatLon, validateNumericCoordinate, validateSignedRange };
31
+ export { DDM_PRECISION, DECIMAL_DEGREES_PRECISION, DMS_PRECISION, GRID_LATITUDE_MAX, GRID_LATITUDE_MIN, coordinateSystems, createCoordinate, createFormatter, formatCoordinateSystem, formatDecimalDegrees, formatDegreesDecimalMinutes, formatDegreesMinutesSeconds, formatMgrsParts, formatUtmParts, getHemisphere, getOrdinal, isCoordinateObject, isCoordinateTuple, isFiniteNumber, isGridProjectable, isOnEasternAntimeridian, isValidNumericCoordinate, isWithinGridBand, normalizeObjectToLatLon, parseDecimalDegrees, parseDegreesDecimalMinutes, parseDegreesMinutesSeconds, parseMGRS, parseUTM, toDdmParts, toDecimalDegreesParts, toDmsParts, toMgrsParts, toPlainDecimalString, toUtmParts, tupleToLatLon, validateNumericCoordinate, validateSignedRange };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@accelint/geo",
3
3
  "description": "A collection of JavaScript functions for working with coordinates and geospatial data.",
4
- "version": "0.6.1",
4
+ "version": "0.7.0",
5
5
  "author": "https://hypergiant.com",
6
6
  "$schema": "https://json.schemastore.org/package",
7
7
  "dependencies": {
@@ -12,8 +12,8 @@
12
12
  "tsdown": "^0.18.0",
13
13
  "typescript": "^5.9.3",
14
14
  "vitest": "^4.0.15",
15
- "@accelint/vitest-config": "0.1.6",
16
- "@accelint/typescript-config": "0.1.4"
15
+ "@accelint/typescript-config": "0.1.4",
16
+ "@accelint/vitest-config": "0.1.6"
17
17
  },
18
18
  "engines": {
19
19
  "node": ">=22",
@@ -50,11 +50,14 @@
50
50
  "./coordinates/latlon/internal/pipes/fix-dividers": "./dist/coordinates/latlon/internal/pipes/fix-dividers.js",
51
51
  "./coordinates/latlon/internal/pipes/genome": "./dist/coordinates/latlon/internal/pipes/genome.js",
52
52
  "./coordinates/latlon/internal/pipes/simpler": "./dist/coordinates/latlon/internal/pipes/simpler.js",
53
+ "./coordinates/latlon/internal/plain-decimal": "./dist/coordinates/latlon/internal/plain-decimal.js",
53
54
  "./coordinates/latlon/internal/validate": "./dist/coordinates/latlon/internal/validate.js",
54
55
  "./coordinates/latlon/internal/violation": "./dist/coordinates/latlon/internal/violation.js",
55
56
  "./coordinates/mgrs/parser": "./dist/coordinates/mgrs/parser.js",
57
+ "./coordinates/mgrs/parts": "./dist/coordinates/mgrs/parts.js",
56
58
  "./coordinates/mgrs/system": "./dist/coordinates/mgrs/system.js",
57
59
  "./coordinates/utm/parser": "./dist/coordinates/utm/parser.js",
60
+ "./coordinates/utm/parts": "./dist/coordinates/utm/parts.js",
58
61
  "./coordinates/utm/system": "./dist/coordinates/utm/system.js",
59
62
  "./patterning": "./dist/patterning.js",
60
63
  "./package.json": "./package.json"