@accelint/geo 0.4.0 → 0.4.1
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.
- package/CHANGELOG.md +5 -0
- package/catalog-info.yaml +1 -1
- package/dist/cartesian.d.ts +3 -1
- package/dist/cartesian.js +34 -5
- package/dist/cartesian.js.map +1 -1
- package/dist/coordinates/coordinate.d.ts +37 -25
- package/dist/coordinates/coordinate.js +71 -77
- package/dist/coordinates/coordinate.js.map +1 -1
- package/dist/coordinates/latlon/decimal-degrees/formatter.d.ts +16 -2
- package/dist/coordinates/latlon/decimal-degrees/formatter.js +17 -3
- package/dist/coordinates/latlon/decimal-degrees/formatter.js.map +1 -1
- package/dist/coordinates/latlon/decimal-degrees/parser.d.ts +17 -4
- package/dist/coordinates/latlon/decimal-degrees/parser.js +60 -62
- package/dist/coordinates/latlon/decimal-degrees/parser.js.map +1 -1
- package/dist/coordinates/latlon/decimal-degrees/system.d.ts +16 -5
- package/dist/coordinates/latlon/decimal-degrees/system.js +26 -14
- package/dist/coordinates/latlon/decimal-degrees/system.js.map +1 -1
- package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.d.ts +16 -2
- package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.js +19 -8
- package/dist/coordinates/latlon/degrees-decimal-minutes/formatter.js.map +1 -1
- package/dist/coordinates/latlon/degrees-decimal-minutes/parser.d.ts +17 -4
- package/dist/coordinates/latlon/degrees-decimal-minutes/parser.js +79 -71
- package/dist/coordinates/latlon/degrees-decimal-minutes/parser.js.map +1 -1
- package/dist/coordinates/latlon/degrees-decimal-minutes/system.d.ts +16 -5
- package/dist/coordinates/latlon/degrees-decimal-minutes/system.js +30 -19
- package/dist/coordinates/latlon/degrees-decimal-minutes/system.js.map +1 -1
- package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.d.ts +16 -2
- package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.js +21 -10
- package/dist/coordinates/latlon/degrees-minutes-seconds/formatter.js.map +1 -1
- package/dist/coordinates/latlon/degrees-minutes-seconds/parser.d.ts +17 -4
- package/dist/coordinates/latlon/degrees-minutes-seconds/parser.js +81 -70
- package/dist/coordinates/latlon/degrees-minutes-seconds/parser.js.map +1 -1
- package/dist/coordinates/latlon/degrees-minutes-seconds/system.d.ts +16 -5
- package/dist/coordinates/latlon/degrees-minutes-seconds/system.js +32 -21
- package/dist/coordinates/latlon/degrees-minutes-seconds/system.js.map +1 -1
- package/dist/coordinates/latlon/internal/coordinate-system.d.ts +22 -9
- package/dist/coordinates/latlon/internal/coordinate-system.js +11 -2
- package/dist/coordinates/latlon/internal/create-cache.d.ts +17 -3
- package/dist/coordinates/latlon/internal/create-cache.js +27 -7
- package/dist/coordinates/latlon/internal/create-cache.js.map +1 -1
- package/dist/coordinates/latlon/internal/exhaustive-errors.d.ts +4 -2
- package/dist/coordinates/latlon/internal/exhaustive-errors.js +107 -62
- package/dist/coordinates/latlon/internal/exhaustive-errors.js.map +1 -1
- package/dist/coordinates/latlon/internal/format.d.ts +8 -6
- package/dist/coordinates/latlon/internal/format.js +24 -11
- package/dist/coordinates/latlon/internal/format.js.map +1 -1
- package/dist/coordinates/latlon/internal/in-range.d.ts +3 -1
- package/dist/coordinates/latlon/internal/in-range.js +22 -8
- package/dist/coordinates/latlon/internal/in-range.js.map +1 -1
- package/dist/coordinates/latlon/internal/index.d.ts +35 -33
- package/dist/coordinates/latlon/internal/index.js +64 -102
- package/dist/coordinates/latlon/internal/index.js.map +1 -1
- package/dist/coordinates/latlon/internal/lexer.d.ts +4 -2
- package/dist/coordinates/latlon/internal/lexer.js +54 -33
- package/dist/coordinates/latlon/internal/lexer.js.map +1 -1
- package/dist/coordinates/latlon/internal/ordinal.d.ts +3 -1
- package/dist/coordinates/latlon/internal/ordinal.js +17 -5
- package/dist/coordinates/latlon/internal/ordinal.js.map +1 -1
- package/dist/coordinates/latlon/internal/parse-format.d.ts +23 -10
- package/dist/coordinates/latlon/internal/parse-format.js +37 -54
- package/dist/coordinates/latlon/internal/parse-format.js.map +1 -1
- package/dist/coordinates/latlon/internal/parse.d.ts +18 -4
- package/dist/coordinates/latlon/internal/parse.js +55 -9
- package/dist/coordinates/latlon/internal/parse.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/check-ambiguous.d.ts +17 -3
- package/dist/coordinates/latlon/internal/pipes/check-ambiguous.js +31 -16
- package/dist/coordinates/latlon/internal/pipes/check-ambiguous.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/check-numbers.d.ts +16 -2
- package/dist/coordinates/latlon/internal/pipes/check-numbers.js +30 -28
- package/dist/coordinates/latlon/internal/pipes/check-numbers.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/fix-bearings.d.ts +18 -4
- package/dist/coordinates/latlon/internal/pipes/fix-bearings.js +66 -54
- package/dist/coordinates/latlon/internal/pipes/fix-bearings.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/fix-dividers.d.ts +18 -4
- package/dist/coordinates/latlon/internal/pipes/fix-dividers.js +42 -25
- package/dist/coordinates/latlon/internal/pipes/fix-dividers.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/genome.d.ts +16 -2
- package/dist/coordinates/latlon/internal/pipes/genome.js +46 -25
- package/dist/coordinates/latlon/internal/pipes/genome.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/index.d.ts +18 -4
- package/dist/coordinates/latlon/internal/pipes/index.js +58 -35
- package/dist/coordinates/latlon/internal/pipes/index.js.map +1 -1
- package/dist/coordinates/latlon/internal/pipes/simpler.d.ts +16 -2
- package/dist/coordinates/latlon/internal/pipes/simpler.js +25 -1
- package/dist/coordinates/latlon/internal/pipes/simpler.js.map +1 -1
- package/dist/coordinates/latlon/internal/violation.d.ts +3 -1
- package/dist/coordinates/latlon/internal/violation.js +15 -1
- package/dist/coordinates/latlon/internal/violation.js.map +1 -1
- package/dist/coordinates/mgrs/parser.d.ts +16 -4
- package/dist/coordinates/mgrs/parser.js +32 -35
- package/dist/coordinates/mgrs/parser.js.map +1 -1
- package/dist/coordinates/mgrs/system.d.ts +16 -5
- package/dist/coordinates/mgrs/system.js +28 -18
- package/dist/coordinates/mgrs/system.js.map +1 -1
- package/dist/coordinates/utm/parser.d.ts +16 -4
- package/dist/coordinates/utm/parser.js +32 -30
- package/dist/coordinates/utm/parser.js.map +1 -1
- package/dist/coordinates/utm/system.d.ts +16 -5
- package/dist/coordinates/utm/system.js +29 -23
- package/dist/coordinates/utm/system.js.map +1 -1
- package/dist/index.d.ts +24 -15
- package/dist/index.js +26 -13
- package/dist/patterning.d.ts +3 -1
- package/dist/patterning.js +75 -11
- package/dist/patterning.js.map +1 -1
- package/package.json +48 -14
- package/dist/coordinates/latlon/internal/coordinate-system.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/metafile-esm.json +0 -1
package/CHANGELOG.md
CHANGED
package/catalog-info.yaml
CHANGED
|
@@ -16,7 +16,7 @@ metadata:
|
|
|
16
16
|
annotations:
|
|
17
17
|
backstage.io/edit-url: https://github.com/gohypergiant/standard-toolkit/blob/main/packages/geo/catalog-info.yaml
|
|
18
18
|
backstage.io/techdocs-ref: dir:.
|
|
19
|
-
package/version: 0.4.
|
|
19
|
+
package/version: 0.4.1
|
|
20
20
|
github.com/project-slug: gohypergiant/standard-toolkit
|
|
21
21
|
links:
|
|
22
22
|
- url: https://github.com/gohypergiant/standard-toolkit/tree/main/packages/geo
|
package/dist/cartesian.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/cartesian.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Computes the Cartesian product of multiple arrays.
|
|
3
4
|
*
|
|
@@ -17,5 +18,6 @@
|
|
|
17
18
|
* // result: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
|
|
18
19
|
*/
|
|
19
20
|
declare function cartesian<T>(...all: T[][]): T[][];
|
|
20
|
-
|
|
21
|
+
//#endregion
|
|
21
22
|
export { cartesian };
|
|
23
|
+
//# sourceMappingURL=cartesian.d.ts.map
|
package/dist/cartesian.js
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
//#region src/cartesian.ts
|
|
15
|
+
/**
|
|
16
|
+
* Computes the Cartesian product of multiple arrays.
|
|
17
|
+
*
|
|
18
|
+
* @template T
|
|
19
|
+
* the type of elements in the input arrays.
|
|
20
|
+
* @param {...T[][]} all
|
|
21
|
+
* a variadic number of arrays to compute the Cartesian product of.
|
|
22
|
+
* @returns {T[][]}
|
|
23
|
+
* An array containing all possible combinations of elements from the input
|
|
24
|
+
* arrays, where each combination is represented as an array.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* pure function
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const result = cartesian([1, 2], ['a', 'b']);
|
|
31
|
+
* // result: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
|
|
32
|
+
*/
|
|
1
33
|
function cartesian(...all) {
|
|
2
|
-
|
|
3
|
-
(results, entries) => results.map((result) => entries.map((entry) => result.concat([entry]))).reduce((sub, res) => sub.concat(res), []),
|
|
4
|
-
[[]]
|
|
5
|
-
);
|
|
34
|
+
return all.reduce((results, entries) => results.map((result) => entries.map((entry) => result.concat([entry]))).reduce((sub, res) => sub.concat(res), []), [[]]);
|
|
6
35
|
}
|
|
7
36
|
|
|
37
|
+
//#endregion
|
|
8
38
|
export { cartesian };
|
|
9
|
-
//# sourceMappingURL=cartesian.js.map
|
|
10
39
|
//# sourceMappingURL=cartesian.js.map
|
package/dist/cartesian.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"cartesian.js","names":[],"sources":["../src/cartesian.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\n/**\n * Computes the Cartesian product of multiple arrays.\n *\n * @template T\n * the type of elements in the input arrays.\n * @param {...T[][]} all\n * a variadic number of arrays to compute the Cartesian product of.\n * @returns {T[][]}\n * An array containing all possible combinations of elements from the input\n * arrays, where each combination is represented as an array.\n *\n * @remarks\n * pure function\n *\n * @example\n * const result = cartesian([1, 2], ['a', 'b']);\n * // result: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]\n */\nexport function cartesian<T>(...all: T[][]): T[][] {\n return all.reduce<T[][]>(\n (results, entries) =>\n results\n .map((result) => entries.map((entry) => result.concat([entry])))\n .reduce((sub, res) => sub.concat(res), []),\n [[]],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,UAAa,GAAG,KAAmB;AACjD,QAAO,IAAI,QACR,SAAS,YACR,QACG,KAAK,WAAW,QAAQ,KAAK,UAAU,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAC/D,QAAQ,KAAK,QAAQ,IAAI,OAAO,IAAI,EAAE,EAAE,CAAC,EAC9C,CAAC,EAAE,CAAC,CACL"}
|
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
5
12
|
|
|
13
|
+
import { Format } from "./latlon/internal/index.js";
|
|
14
|
+
import { CoordinateSystem } from "./latlon/internal/coordinate-system.js";
|
|
15
|
+
|
|
16
|
+
//#region src/coordinates/coordinate.d.ts
|
|
6
17
|
type Coordinate = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/** {@interitDoc Formatter} */
|
|
19
|
+
dd: Formatter;
|
|
20
|
+
/** {@interitDoc Formatter} */
|
|
21
|
+
ddm: Formatter;
|
|
22
|
+
/** {@interitDoc Formatter} */
|
|
23
|
+
dms: Formatter;
|
|
24
|
+
/** {@interitDoc Formatter} */
|
|
25
|
+
mgrs: Formatter;
|
|
26
|
+
/** {@interitDoc Formatter} */
|
|
27
|
+
utm: Formatter;
|
|
28
|
+
errors: string[];
|
|
29
|
+
raw: CoordinateInternalValue;
|
|
30
|
+
valid: boolean;
|
|
20
31
|
};
|
|
21
32
|
type CoordinateInternalValue = {
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
LAT: number;
|
|
34
|
+
LON: number;
|
|
24
35
|
};
|
|
25
36
|
/**
|
|
26
37
|
* Output a string value of a coordinate using an available system. The
|
|
@@ -48,11 +59,11 @@ type CoordinateInternalValue = {
|
|
|
48
59
|
*/
|
|
49
60
|
type Formatter = (f?: Format) => string;
|
|
50
61
|
declare const coordinateSystems: Readonly<{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
readonly dd: CoordinateSystem;
|
|
63
|
+
readonly ddm: CoordinateSystem;
|
|
64
|
+
readonly dms: CoordinateSystem;
|
|
65
|
+
readonly mgrs: CoordinateSystem;
|
|
66
|
+
readonly utm: CoordinateSystem;
|
|
56
67
|
}>;
|
|
57
68
|
/**
|
|
58
69
|
* Create a coordinate object enabling: lexing, parsing, validation, and
|
|
@@ -70,5 +81,6 @@ declare const coordinateSystems: Readonly<{
|
|
|
70
81
|
* const create = createCoordinate(coordinateSystems.ddm, 'LONLAT')
|
|
71
82
|
*/
|
|
72
83
|
declare function createCoordinate(initSystem?: CoordinateSystem, initFormat?: Format): (input: string) => Readonly<Coordinate>;
|
|
73
|
-
|
|
84
|
+
//#endregion
|
|
74
85
|
export { coordinateSystems, createCoordinate };
|
|
86
|
+
//# sourceMappingURL=coordinate.d.ts.map
|
|
@@ -1,87 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
8
12
|
|
|
13
|
+
|
|
14
|
+
import { FORMATS_DEFAULT, SYMBOLS } from "./latlon/internal/index.js";
|
|
15
|
+
import { systemDecimalDegrees } from "./latlon/decimal-degrees/system.js";
|
|
16
|
+
import { systemDegreesDecimalMinutes } from "./latlon/degrees-decimal-minutes/system.js";
|
|
17
|
+
import { systemDegreesMinutesSeconds } from "./latlon/degrees-minutes-seconds/system.js";
|
|
18
|
+
import { createCache } from "./latlon/internal/create-cache.js";
|
|
19
|
+
import { systemMGRS } from "./mgrs/system.js";
|
|
20
|
+
import { systemUTM } from "./utm/system.js";
|
|
21
|
+
|
|
22
|
+
//#region src/coordinates/coordinate.ts
|
|
9
23
|
const coordinateSystems = Object.freeze({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
dd: systemDecimalDegrees,
|
|
25
|
+
ddm: systemDegreesDecimalMinutes,
|
|
26
|
+
dms: systemDegreesMinutesSeconds,
|
|
27
|
+
mgrs: systemMGRS,
|
|
28
|
+
utm: systemUTM
|
|
15
29
|
});
|
|
16
30
|
const freezeCoordinate = (errors, to, raw, valid) => Object.freeze({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
dd: (format) => to(systemDecimalDegrees, format),
|
|
32
|
+
ddm: (format) => to(systemDegreesDecimalMinutes, format),
|
|
33
|
+
dms: (format) => to(systemDegreesMinutesSeconds, format),
|
|
34
|
+
mgrs: (format) => to(systemMGRS, format),
|
|
35
|
+
utm: (format) => to(systemUTM, format),
|
|
36
|
+
errors,
|
|
37
|
+
raw,
|
|
38
|
+
valid
|
|
25
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Create a coordinate object enabling: lexing, parsing, validation, and
|
|
42
|
+
* formatting in alternative systems and formats. The system and format will be
|
|
43
|
+
* used for validation and eventually for output as defaults if no alternatives
|
|
44
|
+
* are provided.
|
|
45
|
+
*
|
|
46
|
+
* @param initSystem dd, ddm, dms, mgrs, or utm of coordinateSystems
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* pure function
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const create = createCoordinate(coordinateSystems.dd, 'LATLON')
|
|
53
|
+
* const create = createCoordinate(coordinateSystems.ddm, 'LONLAT')
|
|
54
|
+
*/
|
|
26
55
|
function createCoordinate(initSystem = coordinateSystems.dd, initFormat = FORMATS_DEFAULT) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
)
|
|
49
|
-
};
|
|
50
|
-
const raw = Object.fromEntries([
|
|
51
|
-
[
|
|
52
|
-
initFormat.slice(0, 3),
|
|
53
|
-
initSystem.toFloat(
|
|
54
|
-
tokens.slice(0, tokens.indexOf(SYMBOLS.DIVIDER))
|
|
55
|
-
)
|
|
56
|
-
],
|
|
57
|
-
[
|
|
58
|
-
initFormat.slice(3),
|
|
59
|
-
initSystem.toFloat(
|
|
60
|
-
tokens.slice(1 + tokens.indexOf(SYMBOLS.DIVIDER))
|
|
61
|
-
)
|
|
62
|
-
]
|
|
63
|
-
]);
|
|
64
|
-
function to(system = initSystem, format = initFormat) {
|
|
65
|
-
const key = system.name;
|
|
66
|
-
if (!cachedValues[key]?.[format]) {
|
|
67
|
-
cachedValues[key] = {
|
|
68
|
-
...cachedValues[key],
|
|
69
|
-
// use the Format to build the object, correctly pairing the halves of
|
|
70
|
-
// the coordinate value with their labels
|
|
71
|
-
[format]: system.toFormat(
|
|
72
|
-
format,
|
|
73
|
-
[format.slice(0, 3), format.slice(3)].map(
|
|
74
|
-
(key2) => raw[key2]
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return cachedValues[key][format];
|
|
80
|
-
}
|
|
81
|
-
return freezeCoordinate([], to, raw, true);
|
|
82
|
-
};
|
|
56
|
+
return (input) => {
|
|
57
|
+
let tokens;
|
|
58
|
+
let errors;
|
|
59
|
+
try {
|
|
60
|
+
[tokens, errors] = initSystem.parse(initFormat, input);
|
|
61
|
+
if (errors.length) throw errors;
|
|
62
|
+
} catch (errors$1) {
|
|
63
|
+
return freezeCoordinate(errors$1, () => "", {}, false);
|
|
64
|
+
}
|
|
65
|
+
const cachedValues = { [initSystem.name]: createCache(initFormat, initSystem.name === systemMGRS.name ? input : tokens.join(" ")) };
|
|
66
|
+
const raw = Object.fromEntries([[initFormat.slice(0, 3), initSystem.toFloat(tokens.slice(0, tokens.indexOf(SYMBOLS.DIVIDER)))], [initFormat.slice(3), initSystem.toFloat(tokens.slice(1 + tokens.indexOf(SYMBOLS.DIVIDER)))]]);
|
|
67
|
+
function to(system = initSystem, format = initFormat) {
|
|
68
|
+
const key = system.name;
|
|
69
|
+
if (!cachedValues[key]?.[format]) cachedValues[key] = {
|
|
70
|
+
...cachedValues[key],
|
|
71
|
+
[format]: system.toFormat(format, [format.slice(0, 3), format.slice(3)].map((key$1) => raw[key$1]))
|
|
72
|
+
};
|
|
73
|
+
return cachedValues[key][format];
|
|
74
|
+
}
|
|
75
|
+
return freezeCoordinate([], to, raw, true);
|
|
76
|
+
};
|
|
83
77
|
}
|
|
84
78
|
|
|
79
|
+
//#endregion
|
|
85
80
|
export { coordinateSystems, createCoordinate };
|
|
86
|
-
//# sourceMappingURL=coordinate.js.map
|
|
87
81
|
//# sourceMappingURL=coordinate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"coordinate.js","names":["tokens: Tokens","errors: Errors","errors","key"],"sources":["../../src/coordinates/coordinate.ts"],"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 {\n type CoordinateCache,\n createCache,\n} from './latlon/internal/create-cache';\nimport { systemMGRS } from './mgrs/system';\nimport { systemUTM } from './utm/system';\nimport type { CoordinateSystem } from './latlon/internal/coordinate-system';\nimport type { Tokens } from './latlon/internal/lexer';\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 utm: (format?: Format) => to(systemUTM, 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,IAAI;CACJ,KAAK;CACL,KAAK;CACL,MAAM;CACN,KAAK;CACN,CAAU;AAEX,MAAM,oBACJ,QACA,IACA,KACA,UAEA,OAAO,OAAO;CACZ,KAAK,WAAoB,GAAG,sBAAsB,OAAO;CACzD,MAAM,WAAoB,GAAG,6BAA6B,OAAO;CACjE,MAAM,WAAoB,GAAG,6BAA6B,OAAO;CACjE,OAAO,WAAoB,GAAG,YAAY,OAAO;CACjD,MAAM,WAAoB,GAAG,WAAW,OAAO;CAC/C;CACA;CACA;CACD,CAAe;;;;;;;;;;;;;;;;AAiBlB,SAAgB,iBACd,aAA+B,kBAAkB,IACjD,aAAqB,iBACrB;AACA,SAAQ,UAAkB;EACxB,IAAIA;EACJ,IAAIC;AAEJ,MAAI;AACF,IAAC,QAAQ,UAAU,WAAW,MAAM,YAAY,MAAM;AAEtD,OAAI,OAAO,OACT,OAAM;WAEDC,UAAQ;AACf,UAAO,iBACLA,gBACM,IACN,EAAE,EACF,MACD;;EAKH,MAAM,eAAe,GAClB,WAAW,OAAO,YACjB,YAEA,WAAW,SAAS,WAAW,OAAO,QAAQ,OAAO,KAAK,IAAI,CAC/D,EACF;EAKD,MAAM,MAAM,OAAO,YAAY,CAC7B,CACE,WAAW,MAAM,GAAG,EAAE,EACtB,WAAW,QACT,OAAO,MAAM,GAAG,OAAO,QAAQ,QAAQ,QAAQ,CAAC,CACjD,CACF,EACD,CACE,WAAW,MAAM,EAAE,EACnB,WAAW,QACT,OAAO,MAAM,IAAI,OAAO,QAAQ,QAAQ,QAAQ,CAAC,CAClD,CACF,CACF,CAAC;EAEF,SAAS,GACP,SAA2B,YAC3B,SAAiB,YACjB;GACA,MAAM,MAAM,OAAO;AAEnB,OAAI,CAAC,aAAa,OAAO,QAIvB,cAAa,OAAO;IAClB,GAAG,aAAa;KAGf,SAAS,OAAO,SACf,QACC,CAAC,OAAO,MAAM,GAAG,EAAE,EAAE,OAAO,MAAM,EAAE,CAAC,CAAY,KAC/C,UAAQ,IAAIC,OACd,CACF;IACF;AAGH,UAAO,aAAa,KAAK;;AAG3B,SAAO,iBAAiB,EAAE,EAA0B,IAAI,KAAK,KAAK"}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
2
12
|
|
|
3
|
-
|
|
13
|
+
import { FormatOptions } from "../internal/format.js";
|
|
4
14
|
|
|
15
|
+
//#region src/coordinates/latlon/decimal-degrees/formatter.d.ts
|
|
16
|
+
declare const formatDecimalDegrees: (coordinates: [number, number], config?: FormatOptions) => string;
|
|
17
|
+
//#endregion
|
|
5
18
|
export { formatDecimalDegrees };
|
|
19
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
2
12
|
|
|
13
|
+
|
|
14
|
+
import { createFormatter } from "../internal/format.js";
|
|
15
|
+
|
|
16
|
+
//#region src/coordinates/latlon/decimal-degrees/formatter.ts
|
|
3
17
|
const toDecimalDegrees = (num) => {
|
|
4
|
-
|
|
18
|
+
return `${num.toFixed(6)}°`;
|
|
5
19
|
};
|
|
6
20
|
const formatDecimalDegrees = createFormatter(toDecimalDegrees);
|
|
7
21
|
|
|
22
|
+
//#endregion
|
|
8
23
|
export { formatDecimalDegrees };
|
|
9
|
-
//# sourceMappingURL=formatter.js.map
|
|
10
24
|
//# sourceMappingURL=formatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/coordinates/latlon/decimal-degrees/formatter.ts"],"
|
|
1
|
+
{"version":3,"file":"formatter.js","names":[],"sources":["../../../../src/coordinates/latlon/decimal-degrees/formatter.ts"],"sourcesContent":["/*\n * Copyright 2025 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 { createFormatter } from '../internal/format';\n\nconst toDecimalDegrees = (num: number): string => {\n return `${num.toFixed(6)}°`;\n};\n\nexport const formatDecimalDegrees = createFormatter(toDecimalDegrees);\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAM,oBAAoB,QAAwB;AAChD,QAAO,GAAG,IAAI,QAAQ,EAAE,CAAC;;AAG3B,MAAa,uBAAuB,gBAAgB,iBAAiB"}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
4
12
|
|
|
13
|
+
import { Format } from "../internal/index.js";
|
|
14
|
+
import { ParseResults } from "../internal/parse.js";
|
|
15
|
+
|
|
16
|
+
//#region src/coordinates/latlon/decimal-degrees/parser.d.ts
|
|
5
17
|
/** Parse a Decimal Degrees coordinate. */
|
|
6
18
|
declare const parseDecimalDegrees: (format: Format, input: string) => ParseResults;
|
|
7
|
-
|
|
19
|
+
//#endregion
|
|
8
20
|
export { parseDecimalDegrees };
|
|
21
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1,76 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 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
|
+
*/
|
|
4
12
|
|
|
13
|
+
|
|
14
|
+
import { fromTemplate } from "../../../patterning.js";
|
|
15
|
+
import { BEARINGS, LIMITS, PARTIAL_PATTERNS, SYMBOLS, SYMBOL_PATTERNS } from "../internal/index.js";
|
|
16
|
+
import { createParser } from "../internal/parse-format.js";
|
|
17
|
+
|
|
18
|
+
//#region src/coordinates/latlon/decimal-degrees/parser.ts
|
|
5
19
|
const checks = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
sec: (val) => {
|
|
17
|
-
if (val.includes(SYMBOLS.SECONDS)) {
|
|
18
|
-
return `Seconds indicator (${SYMBOLS.SECONDS}) not valid in Decimal Degrees.`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
20
|
+
deg: (deg, limit) => {
|
|
21
|
+
if (Number.parseFloat(deg) > limit) return `Degrees value (${deg}) exceeds max value (${limit}).`;
|
|
22
|
+
},
|
|
23
|
+
min: (val) => {
|
|
24
|
+
if (val.includes(SYMBOLS.MINUTES)) return `Seconds indicator (${SYMBOLS.MINUTES}) not valid in Decimal Degrees.`;
|
|
25
|
+
},
|
|
26
|
+
sec: (val) => {
|
|
27
|
+
if (val.includes(SYMBOLS.SECONDS)) return `Seconds indicator (${SYMBOLS.SECONDS}) not valid in Decimal Degrees.`;
|
|
28
|
+
}
|
|
21
29
|
};
|
|
22
30
|
const formats = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`degLatDec NS ${SYMBOLS.DIVIDER} degLonDec EW`
|
|
26
|
-
),
|
|
27
|
-
LONLAT: Patterning.fromTemplate(
|
|
28
|
-
PARTIAL_PATTERNS,
|
|
29
|
-
`degLonDec EW ${SYMBOLS.DIVIDER} degLatDec NS`
|
|
30
|
-
)
|
|
31
|
+
LATLON: fromTemplate(PARTIAL_PATTERNS, `degLatDec NS ${SYMBOLS.DIVIDER} degLonDec EW`),
|
|
32
|
+
LONLAT: fromTemplate(PARTIAL_PATTERNS, `degLonDec EW ${SYMBOLS.DIVIDER} degLatDec NS`)
|
|
31
33
|
};
|
|
32
34
|
function identifyErrors(format) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return errors.length ? [[], errors] : [[deg, bear], []];
|
|
52
|
-
};
|
|
35
|
+
return (arg, i) => {
|
|
36
|
+
if (!arg) return [[], ["Invalid coordinate value."]];
|
|
37
|
+
let { bear, deg } = arg;
|
|
38
|
+
deg ??= "0";
|
|
39
|
+
let isNegative = SYMBOL_PATTERNS.NEGATIVE_SIGN.test(deg) ? 1 : 0;
|
|
40
|
+
const bearingOptions = BEARINGS[format][i];
|
|
41
|
+
if (!bear || isNegative) {
|
|
42
|
+
bear = bearingOptions[isNegative];
|
|
43
|
+
deg = Math.abs(Number.parseFloat(deg)).toString();
|
|
44
|
+
isNegative = 0;
|
|
45
|
+
}
|
|
46
|
+
const errors = [
|
|
47
|
+
...[checks.deg(deg, LIMITS[format][i] ?? 0)],
|
|
48
|
+
...[checks.min([bear, deg].join(""))],
|
|
49
|
+
...[checks.sec([bear, deg].join(""))]
|
|
50
|
+
].filter(Boolean);
|
|
51
|
+
return errors.length ? [[], errors] : [[deg, bear], []];
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
function identifyPieces(half) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return acc;
|
|
66
|
-
}, places);
|
|
55
|
+
if (half.length > 2 || half.length < 1) return;
|
|
56
|
+
return half.reduce((acc, token) => {
|
|
57
|
+
if (SYMBOL_PATTERNS.NSEW.test(token) && !acc.bear) acc.bear ||= token;
|
|
58
|
+
else acc.deg ||= token;
|
|
59
|
+
return acc;
|
|
60
|
+
}, {
|
|
61
|
+
bear: "",
|
|
62
|
+
deg: ""
|
|
63
|
+
});
|
|
67
64
|
}
|
|
65
|
+
/** Parse a Decimal Degrees coordinate. */
|
|
68
66
|
const parseDecimalDegrees = createParser({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
formats,
|
|
68
|
+
identifyErrors,
|
|
69
|
+
identifyPieces
|
|
72
70
|
});
|
|
73
71
|
|
|
72
|
+
//#endregion
|
|
74
73
|
export { parseDecimalDegrees };
|
|
75
|
-
//# sourceMappingURL=parser.js.map
|
|
76
74
|
//# sourceMappingURL=parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parser.js","names":["Patterning.fromTemplate","isNegative: 0 | 1"],"sources":["../../../../src/coordinates/latlon/decimal-degrees/parser.ts"],"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 * as Patterning from '@/patterning';\nimport {\n BEARINGS,\n type Format,\n LIMITS,\n PARTIAL_PATTERNS,\n SYMBOL_PATTERNS,\n SYMBOLS,\n} from '../internal';\nimport { createParser } from '../internal/parse-format';\nimport type { ParseResults } from '../internal/parse';\n\ntype DecimalDegrees = {\n bear: string;\n deg: string;\n};\n\nconst checks = {\n deg: (deg: string, limit: number) => {\n if (Number.parseFloat(deg) > limit) {\n return `Degrees value (${deg}) exceeds max value (${limit}).`;\n }\n },\n min: (val: string) => {\n if (val.includes(SYMBOLS.MINUTES)) {\n return `Seconds indicator (${SYMBOLS.MINUTES}) not valid in Decimal Degrees.`;\n }\n },\n sec: (val: string) => {\n if (val.includes(SYMBOLS.SECONDS)) {\n return `Seconds indicator (${SYMBOLS.SECONDS}) not valid in Decimal Degrees.`;\n }\n },\n};\n\nconst formats = {\n LATLON: Patterning.fromTemplate(\n PARTIAL_PATTERNS,\n `degLatDec NS ${SYMBOLS.DIVIDER} degLonDec EW`,\n ),\n LONLAT: Patterning.fromTemplate(\n PARTIAL_PATTERNS,\n `degLonDec EW ${SYMBOLS.DIVIDER} degLatDec NS`,\n ),\n};\n\nfunction identifyErrors(format: Format) {\n return (arg: DecimalDegrees | undefined, i: number) => {\n if (!arg) {\n return [[], ['Invalid coordinate value.']] as ParseResults;\n }\n\n let { bear, deg } = arg;\n\n deg ??= '0';\n\n let isNegative: 0 | 1 = SYMBOL_PATTERNS.NEGATIVE_SIGN.test(deg) ? 1 : 0;\n const bearingOptions = BEARINGS[format][i] as [string, string];\n\n if (!bear || isNegative) {\n bear = bearingOptions[isNegative];\n deg = Math.abs(Number.parseFloat(deg)).toString();\n isNegative = 0;\n }\n\n const errors = [\n ...[checks.deg(deg, LIMITS[format][i] ?? 0)],\n ...[checks.min([bear, deg].join(''))],\n ...[checks.sec([bear, deg].join(''))],\n ].filter(Boolean);\n\n return (errors.length ? [[], errors] : [[deg, bear], []]) as ParseResults;\n };\n}\n\nfunction identifyPieces(half: string[]) {\n if (half.length > 2 || half.length < 1) {\n return;\n }\n\n const places = { bear: '', deg: '' };\n\n return half.reduce((acc, token) => {\n if (SYMBOL_PATTERNS.NSEW.test(token) && !acc.bear) {\n acc.bear ||= token;\n } else {\n acc.deg ||= token;\n }\n\n return acc;\n }, places);\n}\n\n/** Parse a Decimal Degrees coordinate. */\nexport const parseDecimalDegrees = createParser<DecimalDegrees>({\n formats,\n identifyErrors,\n identifyPieces,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,MAAM,SAAS;CACb,MAAM,KAAa,UAAkB;AACnC,MAAI,OAAO,WAAW,IAAI,GAAG,MAC3B,QAAO,kBAAkB,IAAI,uBAAuB,MAAM;;CAG9D,MAAM,QAAgB;AACpB,MAAI,IAAI,SAAS,QAAQ,QAAQ,CAC/B,QAAO,sBAAsB,QAAQ,QAAQ;;CAGjD,MAAM,QAAgB;AACpB,MAAI,IAAI,SAAS,QAAQ,QAAQ,CAC/B,QAAO,sBAAsB,QAAQ,QAAQ;;CAGlD;AAED,MAAM,UAAU;CACd,QAAQA,aACN,kBACA,gBAAgB,QAAQ,QAAQ,eACjC;CACD,QAAQA,aACN,kBACA,gBAAgB,QAAQ,QAAQ,eACjC;CACF;AAED,SAAS,eAAe,QAAgB;AACtC,SAAQ,KAAiC,MAAc;AACrD,MAAI,CAAC,IACH,QAAO,CAAC,EAAE,EAAE,CAAC,4BAA4B,CAAC;EAG5C,IAAI,EAAE,MAAM,QAAQ;AAEpB,UAAQ;EAER,IAAIC,aAAoB,gBAAgB,cAAc,KAAK,IAAI,GAAG,IAAI;EACtE,MAAM,iBAAiB,SAAS,QAAQ;AAExC,MAAI,CAAC,QAAQ,YAAY;AACvB,UAAO,eAAe;AACtB,SAAM,KAAK,IAAI,OAAO,WAAW,IAAI,CAAC,CAAC,UAAU;AACjD,gBAAa;;EAGf,MAAM,SAAS;GACb,GAAG,CAAC,OAAO,IAAI,KAAK,OAAO,QAAQ,MAAM,EAAE,CAAC;GAC5C,GAAG,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;GACrC,GAAG,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;GACtC,CAAC,OAAO,QAAQ;AAEjB,SAAQ,OAAO,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;;;AAI5D,SAAS,eAAe,MAAgB;AACtC,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,EACnC;AAKF,QAAO,KAAK,QAAQ,KAAK,UAAU;AACjC,MAAI,gBAAgB,KAAK,KAAK,MAAM,IAAI,CAAC,IAAI,KAC3C,KAAI,SAAS;MAEb,KAAI,QAAQ;AAGd,SAAO;IATM;EAAE,MAAM;EAAI,KAAK;EAAI,CAU1B;;;AAIZ,MAAa,sBAAsB,aAA6B;CAC9D;CACA;CACA;CACD,CAAC"}
|