@accelint/geo 0.4.0 → 0.4.2
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 +13 -0
- package/catalog-info.yaml +2 -4
- 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 +77 -42
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"exhaustive-errors.js","names":["values: Values","values"],"sources":["../../../../src/coordinates/latlon/internal/exhaustive-errors.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 { cartesian } from '@/cartesian';\n\ntype Values = {\n invalid: Record<string, string[]>;\n valid: Record<string, string>;\n};\n\nconst values: Values = {\n invalid: {\n BLAT: ['X', 'random garbage'],\n BLON: ['X', 'random garbage'],\n DLAT: ['91', 'nope'],\n DDLAT: ['90.1', 'nope'],\n DLON: ['181', 'nope'],\n DDLON: ['180.1', 'nope'],\n M: ['-1', '61', 'nope'],\n MM: ['-0.1', '60.1', 'nope'],\n SS: ['-0.1', '60.1', 'nope'],\n },\n valid: {\n '/': '/',\n BLAT: 'N',\n BLON: 'E',\n DLAT: '89',\n DDLAT: '89.999999999',\n DLON: '179',\n DDLON: '179.999999999',\n M: '59',\n MM: '59.999999999',\n SS: '59.999999999',\n },\n};\n\nconst systems = [\n {\n designation: 'DD',\n LAT: ['DDLAT', 'BLAT DDLAT', 'DDLAT BLAT'],\n LON: ['DDLON', 'BLON DDLON', 'DDLON BLON'],\n },\n {\n designation: 'DDM',\n LAT: ['DLAT MM', 'BLAT DLAT MM', 'DLAT MM BLAT'],\n LON: ['DLON MM', 'BLON DLON MM', 'DLON MM BLON'],\n },\n {\n designation: 'DMS',\n LAT: ['DLAT M SS', 'BLAT DLAT M SS', 'DLAT M SS BLAT'],\n LON: ['DLON M SS', 'BLON DLON M SS', 'DLON M SS BLON'],\n },\n];\n\n/**\n * A collection of input strings each with exactly one error in a unique\n * position for each format (LATLON and LONLAT) in each system (DD, DDM, DMS).\n */\nexport const EXHAUSTIVE_ERRORS = Object.fromEntries(\n systems.map(({ designation, ...system }) => {\n // for both format options\n const options = ['LAT LON', 'LON LAT'].map((format) => [\n // create object key: 'LATLON' or 'LONLAT'\n format.replace(' ', ''),\n\n // cross-join each variation of LAT with each variation of LON in the system\n cartesian(\n ...format.split(' ').map((key) => system[key as keyof typeof system]),\n )\n // input not including this isn't an error so no need for variation\n .map((pair) => pair.join(' / '))\n // fill the generated template with actual values\n .flatMap((t) => fillTemplate(t, values)),\n ]);\n\n return [designation, Object.fromEntries(options)];\n }),\n);\n\nfunction fillTemplate(template: string, values: Values) {\n return template\n .split(' ')\n .flatMap((key, i, original) => {\n if (!values.invalid[key]) {\n return '';\n }\n\n return (values.invalid[key] as string[]).map((opt) =>\n [...original.slice(0, i), opt, ...original.slice(i + 1)]\n .map((token) => (token in values.valid ? values.valid[token] : token))\n .join(' '),\n );\n })\n .filter(Boolean);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAMA,SAAiB;CACrB,SAAS;EACP,MAAM,CAAC,KAAK,iBAAiB;EAC7B,MAAM,CAAC,KAAK,iBAAiB;EAC7B,MAAM,CAAC,MAAM,OAAO;EACpB,OAAO,CAAC,QAAQ,OAAO;EACvB,MAAM,CAAC,OAAO,OAAO;EACrB,OAAO,CAAC,SAAS,OAAO;EACxB,GAAG;GAAC;GAAM;GAAM;GAAO;EACvB,IAAI;GAAC;GAAQ;GAAQ;GAAO;EAC5B,IAAI;GAAC;GAAQ;GAAQ;GAAO;EAC7B;CACD,OAAO;EACL,KAAK;EACL,MAAM;EACN,MAAM;EACN,MAAM;EACN,OAAO;EACP,MAAM;EACN,OAAO;EACP,GAAG;EACH,IAAI;EACJ,IAAI;EACL;CACF;AAED,MAAM,UAAU;CACd;EACE,aAAa;EACb,KAAK;GAAC;GAAS;GAAc;GAAa;EAC1C,KAAK;GAAC;GAAS;GAAc;GAAa;EAC3C;CACD;EACE,aAAa;EACb,KAAK;GAAC;GAAW;GAAgB;GAAe;EAChD,KAAK;GAAC;GAAW;GAAgB;GAAe;EACjD;CACD;EACE,aAAa;EACb,KAAK;GAAC;GAAa;GAAkB;GAAiB;EACtD,KAAK;GAAC;GAAa;GAAkB;GAAiB;EACvD;CACF;;;;;AAMD,MAAa,oBAAoB,OAAO,YACtC,QAAQ,KAAK,EAAE,aAAa,GAAG,aAAa;CAE1C,MAAM,UAAU,CAAC,WAAW,UAAU,CAAC,KAAK,WAAW,CAErD,OAAO,QAAQ,KAAK,GAAG,EAGvB,UACE,GAAG,OAAO,MAAM,IAAI,CAAC,KAAK,QAAQ,OAAO,KAA4B,CACtE,CAEE,KAAK,SAAS,KAAK,KAAK,MAAM,CAAC,CAE/B,SAAS,MAAM,aAAa,GAAG,OAAO,CAAC,CAC3C,CAAC;AAEF,QAAO,CAAC,aAAa,OAAO,YAAY,QAAQ,CAAC;EACjD,CACH;AAED,SAAS,aAAa,UAAkB,UAAgB;AACtD,QAAO,SACJ,MAAM,IAAI,CACV,SAAS,KAAK,GAAG,aAAa;AAC7B,MAAI,CAACC,SAAO,QAAQ,KAClB,QAAO;AAGT,SAAQA,SAAO,QAAQ,KAAkB,KAAK,QAC5C;GAAC,GAAG,SAAS,MAAM,GAAG,EAAE;GAAE;GAAK,GAAG,SAAS,MAAM,IAAI,EAAE;GAAC,CACrD,KAAK,UAAW,SAASA,SAAO,QAAQA,SAAO,MAAM,SAAS,MAAO,CACrE,KAAK,IAAI,CACb;GACD,CACD,OAAO,QAAQ"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
//#region src/coordinates/latlon/internal/format.d.ts
|
|
1
2
|
interface FormatOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
prefix: string;
|
|
4
|
+
suffix: string;
|
|
5
|
+
separator: string;
|
|
6
|
+
withOrdinal?: boolean;
|
|
6
7
|
}
|
|
7
8
|
declare const createFormatter: (fn: (coord: number) => string) => (coordinates: [number, number], config?: FormatOptions) => string;
|
|
8
|
-
|
|
9
|
-
export {
|
|
9
|
+
//#endregion
|
|
10
|
+
export { FormatOptions, createFormatter };
|
|
11
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1,17 +1,30 @@
|
|
|
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 { getOrdinal } from "./ordinal.js";
|
|
15
|
+
|
|
16
|
+
//#region src/coordinates/latlon/internal/format.ts
|
|
3
17
|
const createFormatter = (fn) => (coordinates, config) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return `${prefix}${lat}${latOrdinal}${separator}${lon}${lonOrdinal}${suffix}`;
|
|
18
|
+
const [latitude, longitude] = coordinates;
|
|
19
|
+
const latOrdinal = `${config?.withOrdinal ? ` ${getOrdinal(latitude, true)}` : ""}`;
|
|
20
|
+
const lonOrdinal = `${config?.withOrdinal ? ` ${getOrdinal(longitude, false)}` : ""}`;
|
|
21
|
+
const lat = fn(latitude);
|
|
22
|
+
const lon = fn(longitude);
|
|
23
|
+
const prefix = config?.prefix ?? "";
|
|
24
|
+
const suffix = config?.suffix ?? "";
|
|
25
|
+
return `${prefix}${lat}${latOrdinal}${config?.separator ?? ", "}${lon}${lonOrdinal}${suffix}`;
|
|
13
26
|
};
|
|
14
27
|
|
|
28
|
+
//#endregion
|
|
15
29
|
export { createFormatter };
|
|
16
|
-
//# sourceMappingURL=format.js.map
|
|
17
30
|
//# sourceMappingURL=format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../../../src/coordinates/latlon/internal/format.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\n// __private-exports\n\nimport { getOrdinal } from './ordinal';\n\nexport interface FormatOptions {\n prefix: string;\n suffix: string;\n separator: string;\n withOrdinal?: boolean;\n}\n\nexport const createFormatter =\n (fn: (coord: number) => string) =>\n (coordinates: [number, number], config?: FormatOptions): string => {\n const [latitude, longitude] = coordinates;\n const latOrdinal = `${config?.withOrdinal ? ` ${getOrdinal(latitude, true)}` : ''}`;\n const lonOrdinal = `${config?.withOrdinal ? ` ${getOrdinal(longitude, false)}` : ''}`;\n const lat = fn(latitude);\n const lon = fn(longitude);\n const prefix = config?.prefix ?? '';\n const suffix = config?.suffix ?? '';\n const separator = config?.separator ?? ', ';\n\n return `${prefix}${lat}${latOrdinal}${separator}${lon}${lonOrdinal}${suffix}`;\n };\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAa,mBACV,QACA,aAA+B,WAAmC;CACjE,MAAM,CAAC,UAAU,aAAa;CAC9B,MAAM,aAAa,GAAG,QAAQ,cAAc,IAAI,WAAW,UAAU,KAAK,KAAK;CAC/E,MAAM,aAAa,GAAG,QAAQ,cAAc,IAAI,WAAW,WAAW,MAAM,KAAK;CACjF,MAAM,MAAM,GAAG,SAAS;CACxB,MAAM,MAAM,GAAG,UAAU;CACzB,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,SAAS,QAAQ,UAAU;AAGjC,QAAO,GAAG,SAAS,MAAM,aAFP,QAAQ,aAAa,OAEW,MAAM,aAAa"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
//#region src/coordinates/latlon/internal/in-range.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Return an error string if the value is outside the range where the limits
|
|
3
4
|
* are 0-limit.
|
|
4
5
|
*/
|
|
5
6
|
declare const inRange: (label: string, value: string, limit: number) => string | undefined;
|
|
6
|
-
|
|
7
|
+
//#endregion
|
|
7
8
|
export { inRange };
|
|
9
|
+
//# sourceMappingURL=in-range.d.ts.map
|
|
@@ -1,13 +1,27 @@
|
|
|
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/coordinates/latlon/internal/in-range.ts
|
|
15
|
+
/**
|
|
16
|
+
* Return an error string if the value is outside the range where the limits
|
|
17
|
+
* are 0-limit.
|
|
18
|
+
*/
|
|
1
19
|
const inRange = (label, value, limit) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
if (num < 0) {
|
|
7
|
-
return `${label} value (${value}) must be positive.`;
|
|
8
|
-
}
|
|
20
|
+
const num = Number.parseFloat(value);
|
|
21
|
+
if (limit < num) return `${label} value (${value}) exceeds max value (${limit}).`;
|
|
22
|
+
if (num < 0) return `${label} value (${value}) must be positive.`;
|
|
9
23
|
};
|
|
10
24
|
|
|
25
|
+
//#endregion
|
|
11
26
|
export { inRange };
|
|
12
|
-
//# sourceMappingURL=in-range.js.map
|
|
13
27
|
//# sourceMappingURL=in-range.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"in-range.js","names":[],"sources":["../../../../src/coordinates/latlon/internal/in-range.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 * Return an error string if the value is outside the range where the limits\n * are 0-limit.\n */\nexport const inRange = (label: string, value: string, limit: number) => {\n const num = Number.parseFloat(value);\n\n if (limit < num) {\n return `${label} value (${value}) exceeds max value (${limit}).`;\n }\n\n if (num < 0) {\n return `${label} value (${value}) must be positive.`;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,WAAW,OAAe,OAAe,UAAkB;CACtE,MAAM,MAAM,OAAO,WAAW,MAAM;AAEpC,KAAI,QAAQ,IACV,QAAO,GAAG,MAAM,UAAU,MAAM,uBAAuB,MAAM;AAG/D,KAAI,MAAM,EACR,QAAO,GAAG,MAAM,UAAU,MAAM"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/coordinates/latlon/internal/index.d.ts
|
|
1
2
|
type Axes = 'LAT' | 'LON';
|
|
2
3
|
type Compass = 'N' | 'S' | 'E' | 'W';
|
|
3
4
|
type Errors = string[];
|
|
@@ -13,47 +14,48 @@ type Format = (typeof FORMATS)[number];
|
|
|
13
14
|
* an `isNegative` boolean to reference the negative bearing of each axis
|
|
14
15
|
*/
|
|
15
16
|
declare const BEARINGS: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
readonly LAT: readonly ["N", "S"];
|
|
18
|
+
readonly LON: readonly ["E", "W"];
|
|
19
|
+
readonly LATLON: readonly [readonly ["N", "S"], readonly ["E", "W"]];
|
|
20
|
+
readonly LONLAT: readonly [readonly ["E", "W"], readonly ["N", "S"]];
|
|
20
21
|
};
|
|
21
22
|
declare const FORMATS: readonly ["LATLON", "LONLAT"];
|
|
22
23
|
declare const FORMATS_DEFAULT: "LATLON";
|
|
23
24
|
declare const LIMITS: {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
readonly LATLON: readonly [90, 180];
|
|
26
|
+
readonly LONLAT: readonly [180, 90];
|
|
26
27
|
};
|
|
27
28
|
declare const SYMBOLS: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
DEGREES: string;
|
|
30
|
+
MINUTES: string;
|
|
31
|
+
SECONDS: string;
|
|
32
|
+
DIVIDER: string;
|
|
32
33
|
};
|
|
33
34
|
declare const SYMBOL_PATTERNS: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
readonly LAT: RegExp;
|
|
36
|
+
readonly LON: RegExp;
|
|
37
|
+
readonly NSEW: RegExp;
|
|
38
|
+
readonly NEGATIVE_BEARINGS: RegExp;
|
|
39
|
+
readonly NEGATIVE_SIGN: RegExp;
|
|
40
|
+
readonly DEGREES: RegExp;
|
|
41
|
+
readonly MINUTES: RegExp;
|
|
42
|
+
readonly SECONDS: RegExp;
|
|
43
|
+
readonly DIVIDER: RegExp;
|
|
44
|
+
readonly DMS: RegExp;
|
|
44
45
|
};
|
|
45
46
|
declare const PARTIAL_PATTERNS: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
readonly ' ': RegExp;
|
|
48
|
+
readonly '/': RegExp;
|
|
49
|
+
readonly NS: RegExp;
|
|
50
|
+
readonly EW: RegExp;
|
|
51
|
+
readonly degLatDec: RegExp;
|
|
52
|
+
readonly degLonDec: RegExp;
|
|
53
|
+
readonly degLat: RegExp;
|
|
54
|
+
readonly degLon: RegExp;
|
|
55
|
+
readonly min: RegExp;
|
|
56
|
+
readonly minDec: RegExp;
|
|
57
|
+
readonly secDec: RegExp;
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
-
export {
|
|
59
|
+
//#endregion
|
|
60
|
+
export { Axes, BEARINGS, Compass, Errors, FORMATS, FORMATS_DEFAULT, Format, LIMITS, PARTIAL_PATTERNS, SYMBOLS, SYMBOL_PATTERNS };
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,116 +1,78 @@
|
|
|
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 { capture, merge, optional } from "../../../patterning.js";
|
|
15
|
+
|
|
16
|
+
//#region src/coordinates/latlon/internal/index.ts
|
|
17
|
+
/**
|
|
18
|
+
* Bearings are the consistent/explicit identifiers of directionality of a
|
|
19
|
+
* coordinate component; this library has opted for these over implicit
|
|
20
|
+
* indication by number sign not because there is an inherent superiority
|
|
21
|
+
* but because something had to be chosen.
|
|
22
|
+
*
|
|
23
|
+
* NOTE: these arrays are position-important; negative values are [1] and
|
|
24
|
+
* positive values are [0] so that they can be consistently indexed using
|
|
25
|
+
* an `isNegative` boolean to reference the negative bearing of each axis
|
|
26
|
+
*/
|
|
3
27
|
const BEARINGS = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
["E", "W"]
|
|
9
|
-
],
|
|
10
|
-
LONLAT: [
|
|
11
|
-
["E", "W"],
|
|
12
|
-
["N", "S"]
|
|
13
|
-
]
|
|
28
|
+
LAT: ["N", "S"],
|
|
29
|
+
LON: ["E", "W"],
|
|
30
|
+
LATLON: [["N", "S"], ["E", "W"]],
|
|
31
|
+
LONLAT: [["E", "W"], ["N", "S"]]
|
|
14
32
|
};
|
|
15
33
|
const FORMATS = ["LATLON", "LONLAT"];
|
|
16
34
|
const FORMATS_DEFAULT = FORMATS[0];
|
|
17
|
-
const LIMITS = {
|
|
35
|
+
const LIMITS = {
|
|
36
|
+
LATLON: [90, 180],
|
|
37
|
+
LONLAT: [180, 90]
|
|
38
|
+
};
|
|
18
39
|
const SYMBOLS = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
DEGREES: "°",
|
|
41
|
+
MINUTES: "'",
|
|
42
|
+
SECONDS: "\"",
|
|
43
|
+
DIVIDER: "/"
|
|
23
44
|
};
|
|
24
45
|
const SYMBOL_PATTERNS = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// follow: new RegExp(`\\s?\\k<${'NAMED_SEPARATOR'}>\\s?`),
|
|
40
|
-
// },
|
|
46
|
+
LAT: /* @__PURE__ */ new RegExp(`[${BEARINGS.LAT.join("")}]`),
|
|
47
|
+
LON: /* @__PURE__ */ new RegExp(`[${BEARINGS.LON.join("")}]`),
|
|
48
|
+
NSEW: /* @__PURE__ */ new RegExp(`[${[...BEARINGS.LAT, ...BEARINGS.LON].join("")}]`),
|
|
49
|
+
NEGATIVE_BEARINGS: /[SW]/i,
|
|
50
|
+
NEGATIVE_SIGN: /-/,
|
|
51
|
+
DEGREES: new RegExp(SYMBOLS.DEGREES),
|
|
52
|
+
MINUTES: new RegExp(SYMBOLS.MINUTES),
|
|
53
|
+
SECONDS: new RegExp(SYMBOLS.SECONDS),
|
|
54
|
+
DIVIDER: new RegExp(SYMBOLS.DIVIDER),
|
|
55
|
+
DMS: /* @__PURE__ */ new RegExp(`[${[
|
|
56
|
+
SYMBOLS.DEGREES,
|
|
57
|
+
SYMBOLS.MINUTES,
|
|
58
|
+
SYMBOLS.SECONDS
|
|
59
|
+
].join("")}]`)
|
|
41
60
|
};
|
|
42
|
-
const decimalSecAndMin = (symbol) =>
|
|
43
|
-
// Negative lookbehind
|
|
44
|
-
// to ensure that the match is not preceded by a digit,
|
|
45
|
-
// avoiding partial matches within larger numbers.
|
|
46
|
-
/(?<!\d)/,
|
|
47
|
-
// 0-59 including 9 decimal places and leading zeros or no number before
|
|
48
|
-
// acceptable values: 0, 0.123456789, .987654321, 001, 59.999999999
|
|
49
|
-
/([-+]?0*(?:[0-5]?\d|\.\d{1,9})(?:\.\d{1,9})?)/,
|
|
50
|
-
Patterning.optional(symbol),
|
|
51
|
-
// Negative lookahead
|
|
52
|
-
// to ensure that the match is not followed by a digit,
|
|
53
|
-
// avoiding partial matches within larger numbers.
|
|
54
|
-
/(?!\d)/
|
|
55
|
-
);
|
|
61
|
+
const decimalSecAndMin = (symbol) => optional(/(?<!\d)/, /([-+]?0*(?:[0-5]?\d|\.\d{1,9})(?:\.\d{1,9})?)/, optional(symbol), /(?!\d)/);
|
|
56
62
|
const PARTIAL_PATTERNS = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
),
|
|
69
|
-
Patterning.optional(SYMBOL_PATTERNS.DEGREES)
|
|
70
|
-
),
|
|
71
|
-
degLonDec: Patterning.merge(
|
|
72
|
-
Patterning.capture(
|
|
73
|
-
/(?:180(?:\.0{1,9})?)/,
|
|
74
|
-
// 180[.0]
|
|
75
|
-
/|/,
|
|
76
|
-
/(?:0*(?:\d{1,2}|1[0-7]\d)(?:\.\d{1,9})?)/
|
|
77
|
-
// [00]0[.0]-179[.9]
|
|
78
|
-
),
|
|
79
|
-
Patterning.optional(SYMBOL_PATTERNS.DEGREES)
|
|
80
|
-
),
|
|
81
|
-
degLat: Patterning.merge(
|
|
82
|
-
Patterning.capture(
|
|
83
|
-
/(?:0?90)/,
|
|
84
|
-
// 90
|
|
85
|
-
/|/,
|
|
86
|
-
/(?:0?[0-8]?\d)/
|
|
87
|
-
// [0]0-89
|
|
88
|
-
),
|
|
89
|
-
Patterning.optional(SYMBOL_PATTERNS.DEGREES)
|
|
90
|
-
),
|
|
91
|
-
degLon: Patterning.merge(
|
|
92
|
-
Patterning.capture(
|
|
93
|
-
/(?:180)/,
|
|
94
|
-
// 180
|
|
95
|
-
/|/,
|
|
96
|
-
/(?:0*(?:\d{1,2}|1[0-7]\d))/
|
|
97
|
-
// [00]0-179
|
|
98
|
-
),
|
|
99
|
-
Patterning.optional(SYMBOL_PATTERNS.DEGREES)
|
|
100
|
-
),
|
|
101
|
-
min: Patterning.merge(
|
|
102
|
-
Patterning.optional(
|
|
103
|
-
Patterning.capture(
|
|
104
|
-
/(?:0?[0-5]?\d)?/
|
|
105
|
-
// [0]0-59
|
|
106
|
-
),
|
|
107
|
-
Patterning.optional(SYMBOL_PATTERNS.MINUTES)
|
|
108
|
-
)
|
|
109
|
-
),
|
|
110
|
-
minDec: decimalSecAndMin(SYMBOL_PATTERNS.MINUTES),
|
|
111
|
-
secDec: decimalSecAndMin(SYMBOL_PATTERNS.SECONDS)
|
|
63
|
+
" ": /\s*/,
|
|
64
|
+
"/": capture(SYMBOL_PATTERNS.DIVIDER),
|
|
65
|
+
NS: optional(capture(SYMBOL_PATTERNS.LAT)),
|
|
66
|
+
EW: optional(capture(SYMBOL_PATTERNS.LON)),
|
|
67
|
+
degLatDec: merge(capture(/0*(?:90(?:\.0{1,9})?)/, /|/, /(?:0?[0-8]?\d(?:\.\d{1,9})?)/), optional(SYMBOL_PATTERNS.DEGREES)),
|
|
68
|
+
degLonDec: merge(capture(/(?:180(?:\.0{1,9})?)/, /|/, /(?:0*(?:\d{1,2}|1[0-7]\d)(?:\.\d{1,9})?)/), optional(SYMBOL_PATTERNS.DEGREES)),
|
|
69
|
+
degLat: merge(capture(/(?:0?90)/, /|/, /(?:0?[0-8]?\d)/), optional(SYMBOL_PATTERNS.DEGREES)),
|
|
70
|
+
degLon: merge(capture(/(?:180)/, /|/, /(?:0*(?:\d{1,2}|1[0-7]\d))/), optional(SYMBOL_PATTERNS.DEGREES)),
|
|
71
|
+
min: merge(optional(capture(/(?:0?[0-5]?\d)?/), optional(SYMBOL_PATTERNS.MINUTES))),
|
|
72
|
+
minDec: decimalSecAndMin(SYMBOL_PATTERNS.MINUTES),
|
|
73
|
+
secDec: decimalSecAndMin(SYMBOL_PATTERNS.SECONDS)
|
|
112
74
|
};
|
|
113
75
|
|
|
76
|
+
//#endregion
|
|
114
77
|
export { BEARINGS, FORMATS, FORMATS_DEFAULT, LIMITS, PARTIAL_PATTERNS, SYMBOLS, SYMBOL_PATTERNS };
|
|
115
|
-
//# sourceMappingURL=index.js.map
|
|
116
78
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Patterning.optional","Patterning.capture","Patterning.merge"],"sources":["../../../../src/coordinates/latlon/internal/index.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 * as Patterning from '@/patterning';\n\nexport type Axes = 'LAT' | 'LON';\nexport type Compass = 'N' | 'S' | 'E' | 'W';\nexport type Errors = string[];\nexport type Format = (typeof FORMATS)[number];\n\n/**\n * Bearings are the consistent/explicit identifiers of directionality of a\n * coordinate component; this library has opted for these over implicit\n * indication by number sign not because there is an inherent superiority\n * but because something had to be chosen.\n *\n * NOTE: these arrays are position-important; negative values are [1] and\n * positive values are [0] so that they can be consistently indexed using\n * an `isNegative` boolean to reference the negative bearing of each axis\n */\nexport const BEARINGS = {\n LAT: ['N', 'S'],\n LON: ['E', 'W'],\n LATLON: [\n ['N', 'S'],\n ['E', 'W'],\n ],\n LONLAT: [\n ['E', 'W'],\n ['N', 'S'],\n ],\n} as const;\n\nexport const FORMATS = ['LATLON', 'LONLAT'] as const;\nexport const FORMATS_DEFAULT = FORMATS[0];\n\nexport const LIMITS = { LATLON: [90, 180], LONLAT: [180, 90] } as const;\n\nexport const SYMBOLS = {\n DEGREES: '°',\n MINUTES: \"'\",\n SECONDS: '\"',\n DIVIDER: '/',\n};\n\nexport const SYMBOL_PATTERNS = {\n LAT: new RegExp(`[${BEARINGS.LAT.join('')}]`),\n LON: new RegExp(`[${BEARINGS.LON.join('')}]`),\n NSEW: new RegExp(`[${[...BEARINGS.LAT, ...BEARINGS.LON].join('')}]`),\n NEGATIVE_BEARINGS: /[SW]/i,\n NEGATIVE_SIGN: /-/,\n\n DEGREES: new RegExp(SYMBOLS.DEGREES),\n MINUTES: new RegExp(SYMBOLS.MINUTES),\n SECONDS: new RegExp(SYMBOLS.SECONDS),\n\n DIVIDER: new RegExp(SYMBOLS.DIVIDER),\n\n DMS: new RegExp(\n `[${[SYMBOLS.DEGREES, SYMBOLS.MINUTES, SYMBOLS.SECONDS].join('')}]`,\n ),\n\n // divider: {\n // first: /(?<NAMED_SEPARATOR>:?)/,\n // follow: new RegExp(`\\\\s?\\\\k<${'NAMED_SEPARATOR'}>\\\\s?`),\n // },\n} as const;\n\nconst decimalSecAndMin = (symbol: RegExp) =>\n Patterning.optional(\n // Negative lookbehind\n // to ensure that the match is not preceded by a digit,\n // avoiding partial matches within larger numbers.\n /(?<!\\d)/,\n\n // 0-59 including 9 decimal places and leading zeros or no number before\n // acceptable values: 0, 0.123456789, .987654321, 001, 59.999999999\n /([-+]?0*(?:[0-5]?\\d|\\.\\d{1,9})(?:\\.\\d{1,9})?)/,\n\n Patterning.optional(symbol),\n\n // Negative lookahead\n // to ensure that the match is not followed by a digit,\n // avoiding partial matches within larger numbers.\n /(?!\\d)/,\n );\n\nexport const PARTIAL_PATTERNS = {\n ' ': /\\s*/,\n '/': Patterning.capture(SYMBOL_PATTERNS.DIVIDER),\n NS: Patterning.optional(Patterning.capture(SYMBOL_PATTERNS.LAT)),\n EW: Patterning.optional(Patterning.capture(SYMBOL_PATTERNS.LON)),\n\n degLatDec: Patterning.merge(\n Patterning.capture(\n /0*(?:90(?:\\.0{1,9})?)/, // 90[.0]\n /|/,\n /(?:0?[0-8]?\\d(?:\\.\\d{1,9})?)/, // [0]0[.0]-89[.9]\n ),\n Patterning.optional(SYMBOL_PATTERNS.DEGREES),\n ),\n degLonDec: Patterning.merge(\n Patterning.capture(\n /(?:180(?:\\.0{1,9})?)/, // 180[.0]\n /|/,\n /(?:0*(?:\\d{1,2}|1[0-7]\\d)(?:\\.\\d{1,9})?)/, // [00]0[.0]-179[.9]\n ),\n Patterning.optional(SYMBOL_PATTERNS.DEGREES),\n ),\n degLat: Patterning.merge(\n Patterning.capture(\n /(?:0?90)/, // 90\n /|/,\n /(?:0?[0-8]?\\d)/, // [0]0-89\n ),\n Patterning.optional(SYMBOL_PATTERNS.DEGREES),\n ),\n degLon: Patterning.merge(\n Patterning.capture(\n /(?:180)/, // 180\n /|/,\n /(?:0*(?:\\d{1,2}|1[0-7]\\d))/, // [00]0-179\n ),\n Patterning.optional(SYMBOL_PATTERNS.DEGREES),\n ),\n min: Patterning.merge(\n Patterning.optional(\n Patterning.capture(\n /(?:0?[0-5]?\\d)?/, // [0]0-59\n ),\n Patterning.optional(SYMBOL_PATTERNS.MINUTES),\n ),\n ),\n minDec: decimalSecAndMin(SYMBOL_PATTERNS.MINUTES),\n secDec: decimalSecAndMin(SYMBOL_PATTERNS.SECONDS),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,WAAW;CACtB,KAAK,CAAC,KAAK,IAAI;CACf,KAAK,CAAC,KAAK,IAAI;CACf,QAAQ,CACN,CAAC,KAAK,IAAI,EACV,CAAC,KAAK,IAAI,CACX;CACD,QAAQ,CACN,CAAC,KAAK,IAAI,EACV,CAAC,KAAK,IAAI,CACX;CACF;AAED,MAAa,UAAU,CAAC,UAAU,SAAS;AAC3C,MAAa,kBAAkB,QAAQ;AAEvC,MAAa,SAAS;CAAE,QAAQ,CAAC,IAAI,IAAI;CAAE,QAAQ,CAAC,KAAK,GAAG;CAAE;AAE9D,MAAa,UAAU;CACrB,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACV;AAED,MAAa,kBAAkB;CAC7B,qBAAK,IAAI,OAAO,IAAI,SAAS,IAAI,KAAK,GAAG,CAAC,GAAG;CAC7C,qBAAK,IAAI,OAAO,IAAI,SAAS,IAAI,KAAK,GAAG,CAAC,GAAG;CAC7C,sBAAM,IAAI,OAAO,IAAI,CAAC,GAAG,SAAS,KAAK,GAAG,SAAS,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG;CACpE,mBAAmB;CACnB,eAAe;CAEf,SAAS,IAAI,OAAO,QAAQ,QAAQ;CACpC,SAAS,IAAI,OAAO,QAAQ,QAAQ;CACpC,SAAS,IAAI,OAAO,QAAQ,QAAQ;CAEpC,SAAS,IAAI,OAAO,QAAQ,QAAQ;CAEpC,qBAAK,IAAI,OACP,IAAI;EAAC,QAAQ;EAAS,QAAQ;EAAS,QAAQ;EAAQ,CAAC,KAAK,GAAG,CAAC,GAClE;CAMF;AAED,MAAM,oBAAoB,WACxBA,SAIE,WAIA,iDAEAA,SAAoB,OAAO,EAK3B,SACD;AAEH,MAAa,mBAAmB;CAC9B,KAAK;CACL,KAAKC,QAAmB,gBAAgB,QAAQ;CAChD,IAAID,SAAoBC,QAAmB,gBAAgB,IAAI,CAAC;CAChE,IAAID,SAAoBC,QAAmB,gBAAgB,IAAI,CAAC;CAEhE,WAAWC,MACTD,QACE,yBACA,KACA,+BACD,EACDD,SAAoB,gBAAgB,QAAQ,CAC7C;CACD,WAAWE,MACTD,QACE,wBACA,KACA,2CACD,EACDD,SAAoB,gBAAgB,QAAQ,CAC7C;CACD,QAAQE,MACND,QACE,YACA,KACA,iBACD,EACDD,SAAoB,gBAAgB,QAAQ,CAC7C;CACD,QAAQE,MACND,QACE,WACA,KACA,6BACD,EACDD,SAAoB,gBAAgB,QAAQ,CAC7C;CACD,KAAKE,MACHF,SACEC,QACE,kBACD,EACDD,SAAoB,gBAAgB,QAAQ,CAC7C,CACF;CACD,QAAQ,iBAAiB,gBAAgB,QAAQ;CACjD,QAAQ,iBAAiB,gBAAgB,QAAQ;CAClD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/coordinates/latlon/internal/lexer.d.ts
|
|
1
2
|
type Tokens = ReturnType<typeof lexer>;
|
|
2
3
|
/**
|
|
3
4
|
* Take an input string - possibly from user input - and clean it up enough to
|
|
@@ -16,5 +17,6 @@ type Tokens = ReturnType<typeof lexer>;
|
|
|
16
17
|
* lexer(` + 89 ° 59 59.999 " N, 179° 59 59.999" `) === ['89', '59', '59.999', 'N', '/', '179', '59', '59.999', 'E']
|
|
17
18
|
*/
|
|
18
19
|
declare function lexer(input: string): string[];
|
|
19
|
-
|
|
20
|
-
export {
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Tokens, lexer };
|
|
22
|
+
//# sourceMappingURL=lexer.d.ts.map
|
|
@@ -1,45 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
*/
|
|
3
12
|
|
|
13
|
+
|
|
14
|
+
import { capture, group, merge, optional } from "../../../patterning.js";
|
|
15
|
+
import { SYMBOLS, SYMBOL_PATTERNS } from "./index.js";
|
|
16
|
+
|
|
17
|
+
//#region src/coordinates/latlon/internal/lexer.ts
|
|
18
|
+
/**
|
|
19
|
+
* Separating latitude from longitude portions of a coordinate. At this level
|
|
20
|
+
* of pattern matching this list can not include the "space" character since
|
|
21
|
+
* that is valid between components of either side of a divider; higher level
|
|
22
|
+
* parsers will be able to make up for this shortcoming and be more intelligent
|
|
23
|
+
* about deducing where a divider could be added or would not be valid.
|
|
24
|
+
*/
|
|
4
25
|
const DIVIDERS = /[,/]/g;
|
|
5
26
|
const FLOATS = /^(-?)([\d.]+)([^.\d]?)$/;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"g"
|
|
9
|
-
);
|
|
27
|
+
/** Positional indicators for: degrees, minutes, and seconds */
|
|
28
|
+
const POSITIONAL = new RegExp(merge(/\s*/, capture(SYMBOL_PATTERNS.DMS), /\s*/), "g");
|
|
10
29
|
const POSITIVE = /\+/g;
|
|
11
30
|
const SIGNS = /([-+])\s*/g;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Patterning.group(
|
|
21
|
-
// left of decimal REQUIRED, right of decimal optional
|
|
22
|
-
/(?:\d+(?:\.\d*)?)|/,
|
|
23
|
-
// left of decimal omitted, right of decimal REQUIRED
|
|
24
|
-
/(?:\.\d+)/
|
|
25
|
-
),
|
|
26
|
-
Patterning.optional(SYMBOL_PATTERNS.DMS)
|
|
27
|
-
)
|
|
28
|
-
),
|
|
29
|
-
"gi"
|
|
30
|
-
);
|
|
31
|
+
/**
|
|
32
|
+
* Any recognizably significant tokens anywhere (non-positional-y) within a
|
|
33
|
+
* string; because at this level (lexing) actual position is not important.
|
|
34
|
+
*
|
|
35
|
+
* - [Regex Vis](https://regex-vis.com/?r=%2F%5B%2C%2F%5D%7C%5BNSEW%5D%7C%28%3F%3A%5B-%2B%5D%3F%28%3F%3A%28%3F%3A%5Cd%2B%28%3F%3A%5C.%5Cd*%29%3F%29%7C%28%3F%3A%5C.%5Cd%2B%29%29%28%3F%3A%5B%C2%B0%27%22%5D%29%3F%29%2Fgi)
|
|
36
|
+
* - [Nodexr](https://www.nodexr.net/?parse=%2F%5B,%2F%5D%7C%5BNSEW%5D%7C(%3F%3A%5B-%2B%5D%3F(%3F%3A(%3F%3A%5Cd%2B(%3F%3A%5C.%5Cd*)%3F)%7C(%3F%3A%5C.%5Cd%2B))%5B%C2%B0%27%22%5D%3F)%2Fgi)
|
|
37
|
+
*/
|
|
38
|
+
const TOKENS = new RegExp(merge(DIVIDERS, /|/, SYMBOL_PATTERNS.NSEW, /|/, group(/[-+]?/, group(/(?:\d+(?:\.\d*)?)|/, /(?:\.\d+)/), optional(SYMBOL_PATTERNS.DMS))), "gi");
|
|
31
39
|
function fixLeadingAndTrailing(t) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
40
|
+
const [sign, num, pos] = (FLOATS.exec(t) ?? []).slice(1);
|
|
41
|
+
if (num) return `${sign}${Number.parseFloat(num)}${pos}`;
|
|
42
|
+
return t;
|
|
37
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Take an input string - possibly from user input - and clean it up enough to
|
|
46
|
+
* be something to work with at a higher level of processing (with more
|
|
47
|
+
* information) than is available at this level. Generating a list of "tokens"
|
|
48
|
+
* that are potentially valid parts of a coordinate. The values being looked
|
|
49
|
+
* for are: numbers (with positional indicators) and axes (NSEW).
|
|
50
|
+
*
|
|
51
|
+
* NOTE: No validation is done at this level to keep it simple as agnostic.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* pure function
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* lexer('N 55,E 44') === ['N' '55', '/', 'E', '44']
|
|
58
|
+
* lexer(` + 89 ° 59 59.999 " N, 179° 59 59.999" `) === ['89', '59', '59.999', 'N', '/', '179', '59', '59.999', 'E']
|
|
59
|
+
*/
|
|
38
60
|
function lexer(input) {
|
|
39
|
-
|
|
40
|
-
return tokens;
|
|
61
|
+
return input.trim().toUpperCase().replace(POSITIVE, "").replace(POSITIONAL, "$1 ").replace(SIGNS, "$1").replace(DIVIDERS, SYMBOLS.DIVIDER).match(TOKENS)?.map(fixLeadingAndTrailing)?.slice() ?? [];
|
|
41
62
|
}
|
|
42
63
|
|
|
64
|
+
//#endregion
|
|
43
65
|
export { lexer };
|
|
44
|
-
//# sourceMappingURL=lexer.js.map
|
|
45
66
|
//# sourceMappingURL=lexer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"lexer.js","names":["Patterning.merge","Patterning.capture","Patterning.group","Patterning.optional"],"sources":["../../../../src/coordinates/latlon/internal/lexer.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 * as Patterning from '@/patterning';\nimport { SYMBOL_PATTERNS, SYMBOLS } from '.';\n\nexport type Tokens = ReturnType<typeof lexer>;\n\n/**\n * Separating latitude from longitude portions of a coordinate. At this level\n * of pattern matching this list can not include the \"space\" character since\n * that is valid between components of either side of a divider; higher level\n * parsers will be able to make up for this shortcoming and be more intelligent\n * about deducing where a divider could be added or would not be valid.\n */\nconst DIVIDERS = /[,/]/g;\nconst FLOATS = /^(-?)([\\d.]+)([^.\\d]?)$/;\n/** Positional indicators for: degrees, minutes, and seconds */\nconst POSITIONAL = new RegExp(\n Patterning.merge(/\\s*/, Patterning.capture(SYMBOL_PATTERNS.DMS), /\\s*/),\n 'g',\n);\nconst POSITIVE = /\\+/g;\nconst SIGNS = /([-+])\\s*/g;\n/**\n * Any recognizably significant tokens anywhere (non-positional-y) within a\n * string; because at this level (lexing) actual position is not important.\n *\n * - [Regex Vis](https://regex-vis.com/?r=%2F%5B%2C%2F%5D%7C%5BNSEW%5D%7C%28%3F%3A%5B-%2B%5D%3F%28%3F%3A%28%3F%3A%5Cd%2B%28%3F%3A%5C.%5Cd*%29%3F%29%7C%28%3F%3A%5C.%5Cd%2B%29%29%28%3F%3A%5B%C2%B0%27%22%5D%29%3F%29%2Fgi)\n * - [Nodexr](https://www.nodexr.net/?parse=%2F%5B,%2F%5D%7C%5BNSEW%5D%7C(%3F%3A%5B-%2B%5D%3F(%3F%3A(%3F%3A%5Cd%2B(%3F%3A%5C.%5Cd*)%3F)%7C(%3F%3A%5C.%5Cd%2B))%5B%C2%B0%27%22%5D%3F)%2Fgi)\n */\n// NOTE: the links (above) for \"Regex Vis\" and \"Nodexr\" would need to be updated if/when the pattern is changed.\nconst TOKENS = new RegExp(\n Patterning.merge(\n DIVIDERS,\n /|/,\n SYMBOL_PATTERNS.NSEW,\n /|/,\n Patterning.group(\n /[-+]?/,\n Patterning.group(\n // left of decimal REQUIRED, right of decimal optional\n /(?:\\d+(?:\\.\\d*)?)|/,\n // left of decimal omitted, right of decimal REQUIRED\n /(?:\\.\\d+)/,\n ),\n Patterning.optional(SYMBOL_PATTERNS.DMS),\n ),\n ),\n 'gi',\n);\n\n// remove trailing zeros '?.0' and ensure leading zero '0.?' in numbers\nfunction fixLeadingAndTrailing(t: string) {\n const [sign, num, pos] = (FLOATS.exec(t) ?? []).slice(1);\n\n if (num) {\n return `${sign}${Number.parseFloat(num)}${pos}`;\n }\n\n return t;\n}\n\n/**\n * Take an input string - possibly from user input - and clean it up enough to\n * be something to work with at a higher level of processing (with more\n * information) than is available at this level. Generating a list of \"tokens\"\n * that are potentially valid parts of a coordinate. The values being looked\n * for are: numbers (with positional indicators) and axes (NSEW).\n *\n * NOTE: No validation is done at this level to keep it simple as agnostic.\n *\n * @remarks\n * pure function\n *\n * @example\n * lexer('N 55,E 44') === ['N' '55', '/', 'E', '44']\n * lexer(` + 89 ° 59 59.999 \" N, 179° 59 59.999\" `) === ['89', '59', '59.999', 'N', '/', '179', '59', '59.999', 'E']\n */\nexport function lexer(input: string) {\n const tokens =\n input\n .trim()\n .toUpperCase()\n .replace(POSITIVE, '') // positive signs are redundant\n .replace(POSITIONAL, '$1 ') // group positional indicators with numbers\n .replace(SIGNS, '$1') // group signs with numbers\n .replace(DIVIDERS, SYMBOLS.DIVIDER) // standardize the divider\n .match(TOKENS)\n ?.map(fixLeadingAndTrailing)\n ?.slice() ?? [];\n\n return tokens;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,WAAW;AACjB,MAAM,SAAS;;AAEf,MAAM,aAAa,IAAI,OACrBA,MAAiB,OAAOC,QAAmB,gBAAgB,IAAI,EAAE,MAAM,EACvE,IACD;AACD,MAAM,WAAW;AACjB,MAAM,QAAQ;;;;;;;;AASd,MAAM,SAAS,IAAI,OACjBD,MACE,UACA,KACA,gBAAgB,MAChB,KACAE,MACE,SACAA,MAEE,sBAEA,YACD,EACDC,SAAoB,gBAAgB,IAAI,CACzC,CACF,EACD,KACD;AAGD,SAAS,sBAAsB,GAAW;CACxC,MAAM,CAAC,MAAM,KAAK,QAAQ,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE;AAExD,KAAI,IACF,QAAO,GAAG,OAAO,OAAO,WAAW,IAAI,GAAG;AAG5C,QAAO;;;;;;;;;;;;;;;;;;AAmBT,SAAgB,MAAM,OAAe;AAanC,QAXE,MACG,MAAM,CACN,aAAa,CACb,QAAQ,UAAU,GAAG,CACrB,QAAQ,YAAY,MAAM,CAC1B,QAAQ,OAAO,KAAK,CACpB,QAAQ,UAAU,QAAQ,QAAQ,CAClC,MAAM,OAAO,EACZ,IAAI,sBAAsB,EAC1B,OAAO,IAAI,EAAE"}
|