gnss-js 0.1.2 → 1.0.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.
Files changed (87) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +171 -5
  3. package/dist/analysis.cjs +1488 -0
  4. package/dist/analysis.d.cts +211 -0
  5. package/dist/analysis.d.ts +211 -0
  6. package/dist/analysis.js +14 -0
  7. package/dist/antex.cjs +239 -0
  8. package/dist/antex.d.cts +77 -0
  9. package/dist/antex.d.ts +77 -0
  10. package/dist/antex.js +8 -0
  11. package/dist/chunk-37QNKGTC.js +65 -0
  12. package/dist/chunk-4YN353Q7.js +440 -0
  13. package/dist/chunk-5CMSYIYM.js +214 -0
  14. package/dist/chunk-5S5MONFK.js +0 -0
  15. package/dist/chunk-6FAL6P4G.js +12 -0
  16. package/dist/chunk-7NOFXKET.js +433 -0
  17. package/dist/chunk-BJHTBYNG.js +154 -0
  18. package/dist/chunk-HBLU2EJ4.js +802 -0
  19. package/dist/chunk-HKN3PUGN.js +800 -0
  20. package/dist/chunk-LEEU5OIO.js +75 -0
  21. package/dist/chunk-LWNTWBHB.js +268 -0
  22. package/dist/chunk-MIIM4LDY.js +239 -0
  23. package/dist/chunk-SO3POWWR.js +502 -0
  24. package/dist/chunk-W4YMQKWH.js +622 -0
  25. package/dist/chunk-WP2JFDLA.js +1475 -0
  26. package/dist/chunk-YDMYO3YK.js +220 -0
  27. package/dist/constants.cjs +423 -0
  28. package/dist/constants.d.cts +14 -0
  29. package/dist/constants.d.ts +14 -0
  30. package/dist/constants.js +103 -0
  31. package/dist/coordinates.cjs +337 -0
  32. package/dist/coordinates.d.cts +81 -0
  33. package/dist/coordinates.d.ts +81 -0
  34. package/dist/coordinates.js +39 -0
  35. package/dist/ecef-CF0uAysr.d.cts +40 -0
  36. package/dist/ecef-CF0uAysr.d.ts +40 -0
  37. package/dist/ephemeris-C10stHhM.d.cts +114 -0
  38. package/dist/ephemeris-C10stHhM.d.ts +114 -0
  39. package/dist/gnss-BT6ulR17.d.cts +56 -0
  40. package/dist/gnss-C-tgoYNa.d.ts +56 -0
  41. package/dist/index.cjs +5940 -78
  42. package/dist/index.d.cts +17 -96
  43. package/dist/index.d.ts +17 -96
  44. package/dist/index.js +352 -415
  45. package/dist/nav-BAI1a9vK.d.cts +108 -0
  46. package/dist/nav-BAI1a9vK.d.ts +108 -0
  47. package/dist/nmea.cjs +247 -0
  48. package/dist/nmea.d.cts +37 -0
  49. package/dist/nmea.d.ts +37 -0
  50. package/dist/nmea.js +12 -0
  51. package/dist/ntrip.cjs +180 -0
  52. package/dist/ntrip.d.cts +98 -0
  53. package/dist/ntrip.d.ts +98 -0
  54. package/dist/ntrip.js +10 -0
  55. package/dist/orbit.cjs +511 -0
  56. package/dist/orbit.d.cts +117 -0
  57. package/dist/orbit.d.ts +117 -0
  58. package/dist/orbit.js +29 -0
  59. package/dist/parser-JPjjFgeP.d.cts +73 -0
  60. package/dist/parser-JPjjFgeP.d.ts +73 -0
  61. package/dist/rinex.cjs +1469 -0
  62. package/dist/rinex.d.cts +116 -0
  63. package/dist/rinex.d.ts +116 -0
  64. package/dist/rinex.js +37 -0
  65. package/dist/rtcm3.cjs +1512 -0
  66. package/dist/rtcm3.d.cts +143 -0
  67. package/dist/rtcm3.d.ts +143 -0
  68. package/dist/rtcm3.js +31 -0
  69. package/dist/signals.cjs +858 -0
  70. package/dist/signals.d.cts +93 -0
  71. package/dist/signals.d.ts +93 -0
  72. package/dist/signals.js +70 -0
  73. package/dist/time-DnI1VpE8.d.cts +33 -0
  74. package/dist/time-DnI1VpE8.d.ts +33 -0
  75. package/dist/time.cjs +585 -0
  76. package/dist/time.d.cts +307 -0
  77. package/dist/time.d.ts +307 -0
  78. package/dist/time.js +154 -0
  79. package/package.json +112 -14
  80. package/.prettierrc +0 -5
  81. package/jest.config.ts +0 -9
  82. package/test/functions.test.ts +0 -63
  83. package/test/gnss-scales.test.ts +0 -95
  84. package/test/julian.test.ts +0 -145
  85. package/test/rinex.test.ts +0 -11
  86. package/test/test.ts +0 -10
  87. package/test/utc.test.ts +0 -25
@@ -0,0 +1,154 @@
1
+ // src/ntrip/index.ts
2
+ function parseStreamEntry(fields) {
3
+ if (fields.length < 19) return null;
4
+ return {
5
+ type: "STR",
6
+ mountpoint: fields[1] ?? "",
7
+ identifier: fields[2] ?? "",
8
+ format: fields[3] ?? "",
9
+ formatDetails: fields[4] ?? "",
10
+ carrier: parseInt(fields[5] ?? "0") || 0,
11
+ navSystem: fields[6] ?? "",
12
+ network: fields[7] ?? "",
13
+ country: fields[8] ?? "",
14
+ latitude: parseFloat(fields[9] ?? "0") || 0,
15
+ longitude: parseFloat(fields[10] ?? "0") || 0,
16
+ nmea: parseInt(fields[11] ?? "0") || 0,
17
+ solution: parseInt(fields[12] ?? "0") || 0,
18
+ generator: fields[13] ?? "",
19
+ compression: fields[14] ?? "",
20
+ authentication: fields[15] ?? "N",
21
+ fee: fields[16] ?? "N",
22
+ bitrate: parseInt(fields[17] ?? "0") || 0,
23
+ misc: fields[18] ?? ""
24
+ };
25
+ }
26
+ function parseCasterEntry(fields) {
27
+ if (fields.length < 12) return null;
28
+ return {
29
+ type: "CAS",
30
+ host: fields[1] ?? "",
31
+ port: parseInt(fields[2] ?? "0") || 0,
32
+ identifier: fields[3] ?? "",
33
+ operator: fields[4] ?? "",
34
+ nmea: parseInt(fields[5] ?? "0") || 0,
35
+ country: fields[6] ?? "",
36
+ latitude: parseFloat(fields[7] ?? "0") || 0,
37
+ longitude: parseFloat(fields[8] ?? "0") || 0,
38
+ fallbackHost: fields[9] ?? "",
39
+ fallbackPort: parseInt(fields[10] ?? "0") || 0,
40
+ misc: fields[11] ?? ""
41
+ };
42
+ }
43
+ function parseNetworkEntry(fields) {
44
+ if (fields.length < 9) return null;
45
+ return {
46
+ type: "NET",
47
+ identifier: fields[1] ?? "",
48
+ operator: fields[2] ?? "",
49
+ authentication: fields[3] ?? "",
50
+ fee: fields[4] ?? "",
51
+ webUrl: fields[5] ?? "",
52
+ streamUrl: fields[6] ?? "",
53
+ registrationUrl: fields[7] ?? "",
54
+ misc: fields[8] ?? ""
55
+ };
56
+ }
57
+ function parseSourcetable(text) {
58
+ const streams = [];
59
+ const casters = [];
60
+ const networks = [];
61
+ for (const rawLine of text.split("\n")) {
62
+ const line = rawLine.trim();
63
+ if (!line || line === "ENDSOURCETABLE") continue;
64
+ const fields = line.split(";");
65
+ const entryType = fields[0]?.toUpperCase();
66
+ if (entryType === "STR") {
67
+ const entry = parseStreamEntry(fields);
68
+ if (entry) streams.push(entry);
69
+ } else if (entryType === "CAS") {
70
+ const entry = parseCasterEntry(fields);
71
+ if (entry) casters.push(entry);
72
+ } else if (entryType === "NET") {
73
+ const entry = parseNetworkEntry(fields);
74
+ if (entry) networks.push(entry);
75
+ }
76
+ }
77
+ return { streams, casters, networks, raw: text };
78
+ }
79
+ function buildAuthHeader(username, password) {
80
+ if (!username) return null;
81
+ return "Basic " + btoa(`${username}:${password ?? ""}`);
82
+ }
83
+ function ntripHeaders(info) {
84
+ const headers = {
85
+ "Ntrip-Version": info.version === "2.0" ? "Ntrip/2.0" : "Ntrip/1.0",
86
+ "User-Agent": "NTRIP gnss-js/1.0",
87
+ "X-Ntrip-Host": info.host,
88
+ "X-Ntrip-Port": String(info.port)
89
+ };
90
+ const auth = buildAuthHeader(info.username, info.password);
91
+ if (auth) headers["Authorization"] = auth;
92
+ return headers;
93
+ }
94
+ async function ntripFetch(proxyUrl, path, headers, signal) {
95
+ const url = `${proxyUrl}${path}`;
96
+ try {
97
+ return await fetch(url, { headers, signal });
98
+ } catch (err) {
99
+ if (err instanceof Error && err.name === "AbortError") throw err;
100
+ const message = err instanceof Error ? err.message : "The service may be temporarily unavailable.";
101
+ throw new Error(`Could not reach the NTRIP proxy: ${message}`, {
102
+ cause: err
103
+ });
104
+ }
105
+ }
106
+ async function fetchSourcetable(proxyUrl, info, signal) {
107
+ const headers = ntripHeaders(info);
108
+ const res = await ntripFetch(proxyUrl, "/", headers, signal);
109
+ if (res.status === 401) {
110
+ throw new Error(
111
+ "Authentication required. Please provide valid credentials."
112
+ );
113
+ }
114
+ if (!res.ok) {
115
+ throw new Error(`Caster returned ${res.status} ${res.statusText}`);
116
+ }
117
+ const text = await res.text();
118
+ return parseSourcetable(text);
119
+ }
120
+ async function connectToMountpoint(proxyUrl, info, signal) {
121
+ const headers = ntripHeaders(info);
122
+ const controller = new AbortController();
123
+ const combinedSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
124
+ const res = await ntripFetch(
125
+ proxyUrl,
126
+ `/${info.mountpoint}`,
127
+ headers,
128
+ combinedSignal
129
+ );
130
+ if (res.status === 401) {
131
+ throw new Error("Authentication required for this mountpoint.");
132
+ }
133
+ if (res.status === 404) {
134
+ throw new Error(`Mountpoint "/${info.mountpoint}" not found on caster.`);
135
+ }
136
+ if (!res.ok) {
137
+ throw new Error(`Caster returned ${res.status} ${res.statusText}`);
138
+ }
139
+ if (!res.body) {
140
+ throw new Error(
141
+ "No response body \u2014 streaming not supported by this environment."
142
+ );
143
+ }
144
+ return {
145
+ reader: res.body.getReader(),
146
+ abort: () => controller.abort()
147
+ };
148
+ }
149
+
150
+ export {
151
+ parseSourcetable,
152
+ fetchSourcetable,
153
+ connectToMountpoint
154
+ };