@accelint/geo 0.2.1 → 0.2.3
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.
|
@@ -29,6 +29,8 @@ type CoordinateInternalValue = {
|
|
|
29
29
|
* rounding errors. All alternative values are computed from a common
|
|
30
30
|
* internal value to reduce complexity.
|
|
31
31
|
*
|
|
32
|
+
* @link https://en.wikipedia.org/wiki/Coordinate_system
|
|
33
|
+
*
|
|
32
34
|
* @remarks
|
|
33
35
|
* pure function
|
|
34
36
|
*
|
|
@@ -64,7 +66,6 @@ declare const coordinateSystems: Readonly<{
|
|
|
64
66
|
* pure function
|
|
65
67
|
*
|
|
66
68
|
* @example
|
|
67
|
-
* // Hello from demo.
|
|
68
69
|
* const create = createCoordinate(coordinateSystems.dd, 'LATLON')
|
|
69
70
|
* const create = createCoordinate(coordinateSystems.ddm, 'LONLAT')
|
|
70
71
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/coordinates/coordinate.ts"],"names":["errors","key"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../src/coordinates/coordinate.ts"],"names":["errors","key"],"mappings":";;;;;;;;;AAgFa,IAAA,iBAAA,GAAoB,OAAO,MAAO,CAAA;AAAA,EAC7C,EAAI,EAAA,oBAAA;AAAA,EACJ,GAAK,EAAA,2BAAA;AAAA,EACL,GAAK,EAAA,2BAAA;AAAA,EACL,IAAM,EAAA,UAAA;AAAA,EACN,GAAK,EAAA;AACP,CAAU;AAEV,IAAM,mBAAmB,CACvB,MAAA,EACA,IACA,GACA,EAAA,KAAA,KAEA,OAAO,MAAO,CAAA;AAAA,EACZ,EAAI,EAAA,CAAC,MAAoB,KAAA,EAAA,CAAG,sBAAsB,MAAM,CAAA;AAAA,EACxD,GAAK,EAAA,CAAC,MAAoB,KAAA,EAAA,CAAG,6BAA6B,MAAM,CAAA;AAAA,EAChE,GAAK,EAAA,CAAC,MAAoB,KAAA,EAA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,CAAA,OAAA,CAAQ,OAAO,CAAC;AAAA;AAClD;AACF,KACD,CAAA;AAED,IAAA,SAAS,EACP,CAAA,MAAA,GAA2B,UAC3B,EAAA,MAAA,GAAiB,UACjB,EAAA;AACA,MAAA,MAAM,MAAM,MAAO,CAAA,IAAA;AAEnB,MAAA,IAAI,CAAC,YAAA,CAAa,GAAG,CAAA,GAAI,MAAM,CAAG,EAAA;AAIhC,QAAA,YAAA,CAAa,GAAG,CAAI,GAAA;AAAA,UAClB,GAAG,aAAa,GAAG,CAAA;AAAA;AAAA;AAAA,UAGnB,CAAC,MAAM,GAAG,MAAO,CAAA,QAAA;AAAA,YACf,MAAA;AAAA,YACC,CAAC,MAAO,CAAA,KAAA,CAAM,CAAG,EAAA,CAAC,GAAG,MAAO,CAAA,KAAA,CAAM,CAAC,CAAC,CAAa,CAAA,GAAA;AAAA,cAChD,CAACC,IAAQ,KAAA,GAAA,CAAIA,IAAG;AAAA;AAClB;AACF,SACF;AAAA;AAGF,MAAO,OAAA,YAAA,CAAa,GAAG,CAAA,CAAE,MAAM,CAAA;AAAA;AAGjC,IAAA,OAAO,gBAAiB,CAAA,EAA4B,EAAA,EAAA,EAAI,KAAK,IAAI,CAAA;AAAA,GACnE;AACF","file":"coordinate.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 { systemDecimalDegrees } from './latlon/decimal-degrees/system';\nimport { systemDegreesDecimalMinutes } from './latlon/degrees-decimal-minutes/system';\nimport { systemDegreesMinutesSeconds } from './latlon/degrees-minutes-seconds/system';\nimport {\n type Axes,\n type Errors,\n FORMATS_DEFAULT,\n type Format,\n SYMBOLS,\n} from './latlon/internal';\nimport type { CoordinateSystem } from './latlon/internal/coordinate-system';\nimport {\n type CoordinateCache,\n createCache,\n} from './latlon/internal/create-cache';\nimport type { Tokens } from './latlon/internal/lexer';\nimport { systemMGRS } from './mgrs/system';\nimport { systemUTM } from './utm/system';\n\ntype Coordinate = {\n /** {@interitDoc Formatter} */\n dd: Formatter;\n /** {@interitDoc Formatter} */\n ddm: Formatter;\n /** {@interitDoc Formatter} */\n dms: Formatter;\n /** {@interitDoc Formatter} */\n mgrs: Formatter;\n /** {@interitDoc Formatter} */\n utm: Formatter;\n errors: string[];\n raw: CoordinateInternalValue;\n valid: boolean;\n};\n\n// biome-ignore lint/style/useNamingConvention: consistency with Axes type\ntype CoordinateInternalValue = { LAT: number; LON: number };\n\n/**\n * Output a string value of a coordinate using an available system. The\n * original value is preserved without conversion to an internal\n * representation - Decimal Degrees - to prevent the possibility of\n * rounding errors. All alternative values are computed from a common\n * internal value to reduce complexity.\n *\n * @link https://en.wikipedia.org/wiki/Coordinate_system\n *\n * @remarks\n * pure function\n *\n * @example\n * const create = createCoordinate(coordinateSystems.dd, 'LATLON')\n * const coord = create('89.765432109 / 123.456789012')\n *\n * // honors the instantiation format 'LATLON'\n * coord.dd() === '89.765432109 N / 123.456789012 E'\n * coord.ddm() === '89 45.92592654 N / 123 27.40734072 E'\n * coord.dms() === '89 45 55.5555924 N / 123 27 24.4404432 E'\n *\n * // change format to 'LONLAT'\n * coord.dms('LONLAT') === '123 27 24.4404432 E / 89 45 55.5555924 N'\n */\ntype Formatter = (f?: Format) => string;\n\ntype ToFloatArg = Parameters<CoordinateSystem['toFloat']>[0];\n\ntype OutputCache = Record<keyof typeof coordinateSystems, CoordinateCache>;\n\nexport const coordinateSystems = Object.freeze({\n dd: systemDecimalDegrees,\n ddm: systemDegreesDecimalMinutes,\n dms: systemDegreesMinutesSeconds,\n mgrs: systemMGRS,\n utm: systemUTM,\n} as const);\n\nconst freezeCoordinate = (\n errors: Coordinate['errors'],\n to: (s?: CoordinateSystem, f?: Format) => string,\n raw: CoordinateInternalValue,\n valid: Coordinate['valid'],\n) =>\n Object.freeze({\n dd: (format?: Format) => to(systemDecimalDegrees, format),\n ddm: (format?: Format) => to(systemDegreesDecimalMinutes, format),\n dms: (format?: Format) => to(systemDegreesMinutesSeconds, format),\n mgrs: (format?: Format) => to(systemMGRS, format),\n errors,\n raw,\n valid,\n } as Coordinate);\n\n/**\n * Create a coordinate object enabling: lexing, parsing, validation, and\n * formatting in alternative systems and formats. The system and format will be\n * used for validation and eventually for output as defaults if no alternatives\n * are provided.\n *\n * @param initSystem dd, ddm, dms, mgrs, or utm of coordinateSystems\n *\n * @remarks\n * pure function\n *\n * @example\n * const create = createCoordinate(coordinateSystems.dd, 'LATLON')\n * const create = createCoordinate(coordinateSystems.ddm, 'LONLAT')\n */\nexport function createCoordinate(\n initSystem: CoordinateSystem = coordinateSystems.dd,\n initFormat: Format = FORMATS_DEFAULT,\n) {\n return (input: string) => {\n let tokens: Tokens;\n let errors: Errors;\n\n try {\n [tokens, errors] = initSystem.parse(initFormat, input);\n\n if (errors.length) {\n throw errors;\n }\n } catch (errors) {\n return freezeCoordinate(\n errors as Coordinate['errors'],\n () => '',\n {} as CoordinateInternalValue,\n false,\n );\n }\n\n // start with the original value for the original system in the original format\n // other values will be computed as needed and cached per request\n const cachedValues = {\n [initSystem.name]: createCache(\n initFormat,\n // because mgrs doesn't have two formats: LATLON v LONLAT\n initSystem.name === systemMGRS.name ? input : tokens.join(' '),\n ),\n } as OutputCache;\n\n // Create the \"internal\" representation - Decimal Degrees - for\n // consistency and ease of computation; all systems expect to\n // start from a common starting point to reduce complexity.\n const raw = Object.fromEntries([\n [\n initFormat.slice(0, 3),\n initSystem.toFloat(\n tokens.slice(0, tokens.indexOf(SYMBOLS.DIVIDER)) as ToFloatArg,\n ),\n ],\n [\n initFormat.slice(3),\n initSystem.toFloat(\n tokens.slice(1 + tokens.indexOf(SYMBOLS.DIVIDER)) as ToFloatArg,\n ),\n ],\n ]) as CoordinateInternalValue;\n\n function to(\n system: CoordinateSystem = initSystem,\n format: Format = initFormat,\n ) {\n const key = system.name as keyof typeof coordinateSystems;\n\n if (!cachedValues[key]?.[format]) {\n // cache \"miss\" - fill the missing value in the cache before returning it\n\n // update the cache to include the newly computed value\n cachedValues[key] = {\n ...cachedValues[key],\n // use the Format to build the object, correctly pairing the halves of\n // the coordinate value with their labels\n [format]: system.toFormat(\n format,\n ([format.slice(0, 3), format.slice(3)] as Axes[]).map(\n (key) => raw[key],\n ) as [number, number],\n ),\n };\n }\n\n return cachedValues[key][format];\n }\n\n return freezeCoordinate([] as Coordinate['errors'], to, raw, true);\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@accelint/geo",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"esbuild-plugin-file-path-extensions": "2.1.3",
|
|
27
|
-
"tsup": "8.
|
|
27
|
+
"tsup": "8.4.0",
|
|
28
28
|
"vitest": "2.1.3",
|
|
29
29
|
"@accelint/typescript-config": "0.1.2",
|
|
30
30
|
"@accelint/vitest-config": "0.1.3"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@ngageoint/mgrs-js": "1.0.0",
|
|
35
35
|
"typescript": "5.6.3",
|
|
36
36
|
"@accelint/math": "0.1.3",
|
|
37
|
-
"@accelint/predicates": "0.
|
|
37
|
+
"@accelint/predicates": "0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"$schema": "https://json.schemastore.org/package",
|
|
40
40
|
"author": "https://hypergiant.com",
|