neaps 0.6.0 → 0.6.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/dist/index.cjs CHANGED
@@ -1,7 +1,6 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _neaps_tide_database = require("@neaps/tide-database");
3
3
  let _neaps_tide_predictor = require("@neaps/tide-predictor");
4
-
5
4
  //#region src/index.ts
6
5
  const feetPerMeter = 3.2808399;
7
6
  const defaultUnits = "meters";
@@ -144,7 +143,6 @@ function toPreferredUnits(prediction, units) {
144
143
  level
145
144
  };
146
145
  }
147
-
148
146
  //#endregion
149
147
  exports.findStation = findStation;
150
148
  exports.getExtremesPrediction = getExtremesPrediction;
@@ -153,4 +151,5 @@ exports.getWaterLevelAtTime = getWaterLevelAtTime;
153
151
  exports.nearestStation = nearestStation;
154
152
  exports.stationsNear = stationsNear;
155
153
  exports.useStation = useStation;
154
+
156
155
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["stations"],"sources":["../src/index.ts"],"sourcesContent":["import {\n stations,\n near,\n nearest,\n type Station,\n type NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport { createTidePredictor, type ExtremesInput, type TimelineInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to the nearest station's datum. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n\n /** Nodal correction fundamentals. Defaults to 'iho'. */\n nodeCorrections?: \"iho\" | \"schureman\";\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimelineInput & PredictionOptions;\nexport type WaterLevelOptions = { time: Date } & PredictionOptions;\n\nconst feetPerMeter = 3.2808399;\nconst defaultUnits: Units = \"meters\";\n\n/**\n * Get extremes prediction using the nearest station to the given position.\n *\n * @example\n * ```ts\n * import { getExtremesPrediction } from 'neaps'\n *\n * const prediction = getExtremesPrediction({\n * latitude: 26.7, // or `lat`\n * longitude: -80.05, // or `lng` or `lon`\n * start: new Date('2025-12-17'),\n * end: new Date('2025-12-18'),\n * datum: 'MLLW', // optional, defaults to station's datum\n * })\n */\nexport function getExtremesPrediction(options: NearestOptions & ExtremesOptions) {\n return nearestStation(options).getExtremesPrediction(options);\n}\n\n/**\n * Get timeline prediction using the nearest station to the given position.\n */\nexport function getTimelinePrediction(options: NearestOptions & TimelineOptions) {\n return nearestStation(options).getTimelinePrediction(options);\n}\n\n/**\n * Get water level at a specific time using the nearest station to the given position.\n */\nexport function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions) {\n return nearestStation(options).getWaterLevelAtTime(options);\n}\n\n/**\n * Find the nearest station to the given position.\n */\nexport function nearestStation(options: NearestOptions) {\n const data = nearest(options);\n if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);\n return useStation(...data);\n}\n\n/**\n * Find stations near the given position.\n * @param limit Maximum number of stations to return (default: 10)\n */\nexport function stationsNear(options: NearOptions) {\n return near(options).map(([station, distance]) => useStation(station, distance));\n}\n\n/**\n * Find a specific station by its ID or source ID.\n */\nexport function findStation(query: string) {\n const searches = [(s: Station) => s.id === query, (s: Station) => s.source.id === query];\n\n let found: Station | undefined = undefined;\n\n for (const search of searches) {\n found = stations.find(search);\n if (found) break;\n }\n\n if (!found) throw new Error(`Station not found: ${query}`);\n\n return useStation(found);\n}\n\nexport function useStation(station: Station, distance?: number) {\n // If subordinate station, use the reference station for datums and constituents\n let reference = station;\n if (station.type === \"subordinate\" && station.offsets?.reference) {\n reference = findStation(station.offsets?.reference);\n }\n const { datums, harmonic_constituents } = reference;\n\n // Use station chart datum as the default datum if available\n const defaultDatum = station.chart_datum in datums ? station.chart_datum : undefined;\n\n function getPredictor({ datum = defaultDatum, nodeCorrections }: PredictionOptions = {}) {\n let offset = 0;\n\n if (datum) {\n const datumOffset = datums?.[datum];\n const mslOffset = datums?.[\"MSL\"];\n\n if (typeof datumOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(\", \")}`,\n );\n }\n\n if (typeof mslOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`,\n );\n }\n\n offset = mslOffset - datumOffset;\n }\n\n return createTidePredictor(harmonic_constituents, { offset, nodeCorrections });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum, nodeCorrections })\n .getExtremesPrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, extremes };\n },\n\n getTimelinePrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: TimelineOptions) {\n const timeline = getPredictor({ datum, nodeCorrections })\n .getTimelinePrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({\n time,\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n }: WaterLevelOptions) {\n const prediction = toPreferredUnits(\n getPredictor({ datum, nodeCorrections }).getWaterLevelAtTime({\n time,\n offsets: station.offsets,\n }),\n units,\n );\n\n return { datum, units, station, distance, ...prediction };\n },\n };\n}\n\nfunction toPreferredUnits<T extends { level: number }>(prediction: T, units: Units): T {\n let { level } = prediction;\n if (units === \"feet\") level *= feetPerMeter;\n else if (units !== \"meters\") throw new Error(`Unsupported units: ${units}`);\n return { ...prediction, level };\n}\n"],"mappings":";;;;;AA0BA,MAAM,eAAe;AACrB,MAAM,eAAsB;;;;;;;;;;;;;;;;AAiB5B,SAAgB,sBAAsB,SAA2C;AAC/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n near,\n nearest,\n type Station,\n type NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport { createTidePredictor, type ExtremesInput, type TimelineInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to the nearest station's datum. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n\n /** Nodal correction fundamentals. Defaults to 'iho'. */\n nodeCorrections?: \"iho\" | \"schureman\";\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimelineInput & PredictionOptions;\nexport type WaterLevelOptions = { time: Date } & PredictionOptions;\n\nconst feetPerMeter = 3.2808399;\nconst defaultUnits: Units = \"meters\";\n\n/**\n * Get extremes prediction using the nearest station to the given position.\n *\n * @example\n * ```ts\n * import { getExtremesPrediction } from 'neaps'\n *\n * const prediction = getExtremesPrediction({\n * latitude: 26.7, // or `lat`\n * longitude: -80.05, // or `lng` or `lon`\n * start: new Date('2025-12-17'),\n * end: new Date('2025-12-18'),\n * datum: 'MLLW', // optional, defaults to station's datum\n * })\n */\nexport function getExtremesPrediction(options: NearestOptions & ExtremesOptions) {\n return nearestStation(options).getExtremesPrediction(options);\n}\n\n/**\n * Get timeline prediction using the nearest station to the given position.\n */\nexport function getTimelinePrediction(options: NearestOptions & TimelineOptions) {\n return nearestStation(options).getTimelinePrediction(options);\n}\n\n/**\n * Get water level at a specific time using the nearest station to the given position.\n */\nexport function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions) {\n return nearestStation(options).getWaterLevelAtTime(options);\n}\n\n/**\n * Find the nearest station to the given position.\n */\nexport function nearestStation(options: NearestOptions) {\n const data = nearest(options);\n if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);\n return useStation(...data);\n}\n\n/**\n * Find stations near the given position.\n * @param limit Maximum number of stations to return (default: 10)\n */\nexport function stationsNear(options: NearOptions) {\n return near(options).map(([station, distance]) => useStation(station, distance));\n}\n\n/**\n * Find a specific station by its ID or source ID.\n */\nexport function findStation(query: string) {\n const searches = [(s: Station) => s.id === query, (s: Station) => s.source.id === query];\n\n let found: Station | undefined = undefined;\n\n for (const search of searches) {\n found = stations.find(search);\n if (found) break;\n }\n\n if (!found) throw new Error(`Station not found: ${query}`);\n\n return useStation(found);\n}\n\nexport function useStation(station: Station, distance?: number) {\n // If subordinate station, use the reference station for datums and constituents\n let reference = station;\n if (station.type === \"subordinate\" && station.offsets?.reference) {\n reference = findStation(station.offsets?.reference);\n }\n const { datums, harmonic_constituents } = reference;\n\n // Use station chart datum as the default datum if available\n const defaultDatum = station.chart_datum in datums ? station.chart_datum : undefined;\n\n function getPredictor({ datum = defaultDatum, nodeCorrections }: PredictionOptions = {}) {\n let offset = 0;\n\n if (datum) {\n const datumOffset = datums?.[datum];\n const mslOffset = datums?.[\"MSL\"];\n\n if (typeof datumOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(\", \")}`,\n );\n }\n\n if (typeof mslOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`,\n );\n }\n\n offset = mslOffset - datumOffset;\n }\n\n return createTidePredictor(harmonic_constituents, { offset, nodeCorrections });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum, nodeCorrections })\n .getExtremesPrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, extremes };\n },\n\n getTimelinePrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: TimelineOptions) {\n const timeline = getPredictor({ datum, nodeCorrections })\n .getTimelinePrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({\n time,\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n }: WaterLevelOptions) {\n const prediction = toPreferredUnits(\n getPredictor({ datum, nodeCorrections }).getWaterLevelAtTime({\n time,\n offsets: station.offsets,\n }),\n units,\n );\n\n return { datum, units, station, distance, ...prediction };\n },\n };\n}\n\nfunction toPreferredUnits<T extends { level: number }>(prediction: T, units: Units): T {\n let { level } = prediction;\n if (units === \"feet\") level *= feetPerMeter;\n else if (units !== \"meters\") throw new Error(`Unsupported units: ${units}`);\n return { ...prediction, level };\n}\n"],"mappings":";;;;AA0BA,MAAM,eAAe;AACrB,MAAM,eAAsB;;;;;;;;;;;;;;;;AAiB5B,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,oBAAoB,SAA6C;AAC/E,QAAO,eAAe,QAAQ,CAAC,oBAAoB,QAAQ;;;;;AAM7D,SAAgB,eAAe,SAAyB;CACtD,MAAM,QAAA,GAAA,qBAAA,SAAe,QAAQ;AAC7B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,QAAQ,GAAG;AACxF,QAAO,WAAW,GAAG,KAAK;;;;;;AAO5B,SAAgB,aAAa,SAAsB;AACjD,SAAA,GAAA,qBAAA,MAAY,QAAQ,CAAC,KAAK,CAAC,SAAS,cAAc,WAAW,SAAS,SAAS,CAAC;;;;;AAMlF,SAAgB,YAAY,OAAe;CACzC,MAAM,WAAW,EAAE,MAAe,EAAE,OAAO,QAAQ,MAAe,EAAE,OAAO,OAAO,MAAM;CAExF,IAAI,QAA6B,KAAA;AAEjC,MAAK,MAAM,UAAU,UAAU;AAC7B,UAAQA,qBAAAA,SAAS,KAAK,OAAO;AAC7B,MAAI,MAAO;;AAGb,KA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AAS,QAAQ;KAAS,CAAC,CAC/D,KAAK,MAAM,iBAAiB,GAAG,MAAM,CAEU;IAAE;;EAGtD,oBAAoB,EAClB,MACA,QAAQ,cACR,QAAQ,cACR,mBACoB;AASpB,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,GARvB,iBACjB,aAAa;KAAE;KAAO;KAAiB,CAAC,CAAC,oBAAoB;KAC3D;KACA,SAAS,QAAQ;KAClB,CAAC,EACF,MAGqD;IAAE;;EAE5D;;AAGH,SAAS,iBAA8C,YAAe,OAAiB;CACrF,IAAI,EAAE,UAAU;AAChB,KAAI,UAAU,OAAQ,UAAS;UACtB,UAAU,SAAU,OAAM,IAAI,MAAM,sBAAsB,QAAQ;AAC3E,QAAO;EAAE,GAAG;EAAY;EAAO"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import * as _neaps_tide_database0 from "@neaps/tide-database";
2
- import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
1
+ import * as _$_neaps_tide_predictor0 from "@neaps/tide-predictor";
3
2
  import { ExtremesInput, TimelineInput } from "@neaps/tide-predictor";
3
+ import * as _$_neaps_tide_database0 from "@neaps/tide-database";
4
+ import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
4
5
 
5
6
  //#region src/index.d.ts
6
7
  type Units = "meters" | "feet";
@@ -30,33 +31,41 @@ type WaterLevelOptions = {
30
31
  * })
31
32
  */
32
33
  declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
33
- datum: any;
34
- units: any;
34
+ datum: string | undefined;
35
+ units: Units;
35
36
  station: Station;
36
37
  distance: number | undefined;
37
- extremes: any;
38
+ extremes: _$_neaps_tide_predictor0.Extreme[];
38
39
  };
39
40
  /**
40
41
  * Get timeline prediction using the nearest station to the given position.
41
42
  */
42
43
  declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
43
- datum: any;
44
- units: any;
44
+ datum: string | undefined;
45
+ units: Units;
45
46
  station: Station;
46
47
  distance: number | undefined;
47
- timeline: any;
48
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
48
49
  };
49
50
  /**
50
51
  * Get water level at a specific time using the nearest station to the given position.
51
52
  */
52
- declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
53
+ declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): {
54
+ time: Date;
55
+ hour: number;
56
+ level: number;
57
+ datum: string | undefined;
58
+ units: Units;
59
+ station: Station;
60
+ distance: number | undefined;
61
+ };
53
62
  /**
54
63
  * Find the nearest station to the given position.
55
64
  */
56
65
  declare function nearestStation(options: NearestOptions): {
57
66
  distance: number | undefined;
58
67
  datums: Record<string, number>;
59
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
68
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
60
69
  defaultDatum: string | undefined;
61
70
  getExtremesPrediction({
62
71
  datum,
@@ -64,11 +73,11 @@ declare function nearestStation(options: NearestOptions): {
64
73
  nodeCorrections,
65
74
  ...options
66
75
  }: ExtremesOptions): {
67
- datum: any;
68
- units: any;
76
+ datum: string | undefined;
77
+ units: Units;
69
78
  station: Station;
70
79
  distance: number | undefined;
71
- extremes: any;
80
+ extremes: _$_neaps_tide_predictor0.Extreme[];
72
81
  };
73
82
  getTimelinePrediction({
74
83
  datum,
@@ -76,18 +85,26 @@ declare function nearestStation(options: NearestOptions): {
76
85
  nodeCorrections,
77
86
  ...options
78
87
  }: TimelineOptions): {
79
- datum: any;
80
- units: any;
88
+ datum: string | undefined;
89
+ units: Units;
81
90
  station: Station;
82
91
  distance: number | undefined;
83
- timeline: any;
92
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
84
93
  };
85
94
  getWaterLevelAtTime({
86
95
  time,
87
96
  datum,
88
97
  units,
89
98
  nodeCorrections
90
- }: WaterLevelOptions): any;
99
+ }: WaterLevelOptions): {
100
+ time: Date;
101
+ hour: number;
102
+ level: number;
103
+ datum: string | undefined;
104
+ units: Units;
105
+ station: Station;
106
+ distance: number | undefined;
107
+ };
91
108
  id: string;
92
109
  name: string;
93
110
  continent: string;
@@ -135,7 +152,7 @@ declare function nearestStation(options: NearestOptions): {
135
152
  declare function stationsNear(options: NearOptions): {
136
153
  distance: number | undefined;
137
154
  datums: Record<string, number>;
138
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
155
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
139
156
  defaultDatum: string | undefined;
140
157
  getExtremesPrediction({
141
158
  datum,
@@ -143,11 +160,11 @@ declare function stationsNear(options: NearOptions): {
143
160
  nodeCorrections,
144
161
  ...options
145
162
  }: ExtremesOptions): {
146
- datum: any;
147
- units: any;
163
+ datum: string | undefined;
164
+ units: Units;
148
165
  station: Station;
149
166
  distance: number | undefined;
150
- extremes: any;
167
+ extremes: _$_neaps_tide_predictor0.Extreme[];
151
168
  };
152
169
  getTimelinePrediction({
153
170
  datum,
@@ -155,18 +172,26 @@ declare function stationsNear(options: NearOptions): {
155
172
  nodeCorrections,
156
173
  ...options
157
174
  }: TimelineOptions): {
158
- datum: any;
159
- units: any;
175
+ datum: string | undefined;
176
+ units: Units;
160
177
  station: Station;
161
178
  distance: number | undefined;
162
- timeline: any;
179
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
163
180
  };
164
181
  getWaterLevelAtTime({
165
182
  time,
166
183
  datum,
167
184
  units,
168
185
  nodeCorrections
169
- }: WaterLevelOptions): any;
186
+ }: WaterLevelOptions): {
187
+ time: Date;
188
+ hour: number;
189
+ level: number;
190
+ datum: string | undefined;
191
+ units: Units;
192
+ station: Station;
193
+ distance: number | undefined;
194
+ };
170
195
  id: string;
171
196
  name: string;
172
197
  continent: string;
@@ -213,7 +238,7 @@ declare function stationsNear(options: NearOptions): {
213
238
  declare function findStation(query: string): {
214
239
  distance: number | undefined;
215
240
  datums: Record<string, number>;
216
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
241
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
217
242
  defaultDatum: string | undefined;
218
243
  getExtremesPrediction({
219
244
  datum,
@@ -221,11 +246,11 @@ declare function findStation(query: string): {
221
246
  nodeCorrections,
222
247
  ...options
223
248
  }: ExtremesOptions): {
224
- datum: any;
225
- units: any;
249
+ datum: string | undefined;
250
+ units: Units;
226
251
  station: Station;
227
252
  distance: number | undefined;
228
- extremes: any;
253
+ extremes: _$_neaps_tide_predictor0.Extreme[];
229
254
  };
230
255
  getTimelinePrediction({
231
256
  datum,
@@ -233,18 +258,26 @@ declare function findStation(query: string): {
233
258
  nodeCorrections,
234
259
  ...options
235
260
  }: TimelineOptions): {
236
- datum: any;
237
- units: any;
261
+ datum: string | undefined;
262
+ units: Units;
238
263
  station: Station;
239
264
  distance: number | undefined;
240
- timeline: any;
265
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
241
266
  };
242
267
  getWaterLevelAtTime({
243
268
  time,
244
269
  datum,
245
270
  units,
246
271
  nodeCorrections
247
- }: WaterLevelOptions): any;
272
+ }: WaterLevelOptions): {
273
+ time: Date;
274
+ hour: number;
275
+ level: number;
276
+ datum: string | undefined;
277
+ units: Units;
278
+ station: Station;
279
+ distance: number | undefined;
280
+ };
248
281
  id: string;
249
282
  name: string;
250
283
  continent: string;
@@ -288,7 +321,7 @@ declare function findStation(query: string): {
288
321
  declare function useStation(station: Station, distance?: number): {
289
322
  distance: number | undefined;
290
323
  datums: Record<string, number>;
291
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
324
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
292
325
  defaultDatum: string | undefined;
293
326
  getExtremesPrediction({
294
327
  datum,
@@ -296,11 +329,11 @@ declare function useStation(station: Station, distance?: number): {
296
329
  nodeCorrections,
297
330
  ...options
298
331
  }: ExtremesOptions): {
299
- datum: any;
300
- units: any;
332
+ datum: string | undefined;
333
+ units: Units;
301
334
  station: Station;
302
335
  distance: number | undefined;
303
- extremes: any;
336
+ extremes: _$_neaps_tide_predictor0.Extreme[];
304
337
  };
305
338
  getTimelinePrediction({
306
339
  datum,
@@ -308,18 +341,26 @@ declare function useStation(station: Station, distance?: number): {
308
341
  nodeCorrections,
309
342
  ...options
310
343
  }: TimelineOptions): {
311
- datum: any;
312
- units: any;
344
+ datum: string | undefined;
345
+ units: Units;
313
346
  station: Station;
314
347
  distance: number | undefined;
315
- timeline: any;
348
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
316
349
  };
317
350
  getWaterLevelAtTime({
318
351
  time,
319
352
  datum,
320
353
  units,
321
354
  nodeCorrections
322
- }: WaterLevelOptions): any;
355
+ }: WaterLevelOptions): {
356
+ time: Date;
357
+ hour: number;
358
+ level: number;
359
+ datum: string | undefined;
360
+ units: Units;
361
+ station: Station;
362
+ distance: number | undefined;
363
+ };
323
364
  id: string;
324
365
  name: string;
325
366
  continent: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import * as _neaps_tide_database0 from "@neaps/tide-database";
1
+ import * as _$_neaps_tide_database0 from "@neaps/tide-database";
2
2
  import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
3
+ import * as _$_neaps_tide_predictor0 from "@neaps/tide-predictor";
3
4
  import { ExtremesInput, TimelineInput } from "@neaps/tide-predictor";
4
5
 
5
6
  //#region src/index.d.ts
@@ -30,33 +31,41 @@ type WaterLevelOptions = {
30
31
  * })
31
32
  */
32
33
  declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
33
- datum: any;
34
- units: any;
34
+ datum: string | undefined;
35
+ units: Units;
35
36
  station: Station;
36
37
  distance: number | undefined;
37
- extremes: any;
38
+ extremes: _$_neaps_tide_predictor0.Extreme[];
38
39
  };
39
40
  /**
40
41
  * Get timeline prediction using the nearest station to the given position.
41
42
  */
42
43
  declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
43
- datum: any;
44
- units: any;
44
+ datum: string | undefined;
45
+ units: Units;
45
46
  station: Station;
46
47
  distance: number | undefined;
47
- timeline: any;
48
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
48
49
  };
49
50
  /**
50
51
  * Get water level at a specific time using the nearest station to the given position.
51
52
  */
52
- declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
53
+ declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): {
54
+ time: Date;
55
+ hour: number;
56
+ level: number;
57
+ datum: string | undefined;
58
+ units: Units;
59
+ station: Station;
60
+ distance: number | undefined;
61
+ };
53
62
  /**
54
63
  * Find the nearest station to the given position.
55
64
  */
56
65
  declare function nearestStation(options: NearestOptions): {
57
66
  distance: number | undefined;
58
67
  datums: Record<string, number>;
59
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
68
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
60
69
  defaultDatum: string | undefined;
61
70
  getExtremesPrediction({
62
71
  datum,
@@ -64,11 +73,11 @@ declare function nearestStation(options: NearestOptions): {
64
73
  nodeCorrections,
65
74
  ...options
66
75
  }: ExtremesOptions): {
67
- datum: any;
68
- units: any;
76
+ datum: string | undefined;
77
+ units: Units;
69
78
  station: Station;
70
79
  distance: number | undefined;
71
- extremes: any;
80
+ extremes: _$_neaps_tide_predictor0.Extreme[];
72
81
  };
73
82
  getTimelinePrediction({
74
83
  datum,
@@ -76,18 +85,26 @@ declare function nearestStation(options: NearestOptions): {
76
85
  nodeCorrections,
77
86
  ...options
78
87
  }: TimelineOptions): {
79
- datum: any;
80
- units: any;
88
+ datum: string | undefined;
89
+ units: Units;
81
90
  station: Station;
82
91
  distance: number | undefined;
83
- timeline: any;
92
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
84
93
  };
85
94
  getWaterLevelAtTime({
86
95
  time,
87
96
  datum,
88
97
  units,
89
98
  nodeCorrections
90
- }: WaterLevelOptions): any;
99
+ }: WaterLevelOptions): {
100
+ time: Date;
101
+ hour: number;
102
+ level: number;
103
+ datum: string | undefined;
104
+ units: Units;
105
+ station: Station;
106
+ distance: number | undefined;
107
+ };
91
108
  id: string;
92
109
  name: string;
93
110
  continent: string;
@@ -135,7 +152,7 @@ declare function nearestStation(options: NearestOptions): {
135
152
  declare function stationsNear(options: NearOptions): {
136
153
  distance: number | undefined;
137
154
  datums: Record<string, number>;
138
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
155
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
139
156
  defaultDatum: string | undefined;
140
157
  getExtremesPrediction({
141
158
  datum,
@@ -143,11 +160,11 @@ declare function stationsNear(options: NearOptions): {
143
160
  nodeCorrections,
144
161
  ...options
145
162
  }: ExtremesOptions): {
146
- datum: any;
147
- units: any;
163
+ datum: string | undefined;
164
+ units: Units;
148
165
  station: Station;
149
166
  distance: number | undefined;
150
- extremes: any;
167
+ extremes: _$_neaps_tide_predictor0.Extreme[];
151
168
  };
152
169
  getTimelinePrediction({
153
170
  datum,
@@ -155,18 +172,26 @@ declare function stationsNear(options: NearOptions): {
155
172
  nodeCorrections,
156
173
  ...options
157
174
  }: TimelineOptions): {
158
- datum: any;
159
- units: any;
175
+ datum: string | undefined;
176
+ units: Units;
160
177
  station: Station;
161
178
  distance: number | undefined;
162
- timeline: any;
179
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
163
180
  };
164
181
  getWaterLevelAtTime({
165
182
  time,
166
183
  datum,
167
184
  units,
168
185
  nodeCorrections
169
- }: WaterLevelOptions): any;
186
+ }: WaterLevelOptions): {
187
+ time: Date;
188
+ hour: number;
189
+ level: number;
190
+ datum: string | undefined;
191
+ units: Units;
192
+ station: Station;
193
+ distance: number | undefined;
194
+ };
170
195
  id: string;
171
196
  name: string;
172
197
  continent: string;
@@ -213,7 +238,7 @@ declare function stationsNear(options: NearOptions): {
213
238
  declare function findStation(query: string): {
214
239
  distance: number | undefined;
215
240
  datums: Record<string, number>;
216
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
241
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
217
242
  defaultDatum: string | undefined;
218
243
  getExtremesPrediction({
219
244
  datum,
@@ -221,11 +246,11 @@ declare function findStation(query: string): {
221
246
  nodeCorrections,
222
247
  ...options
223
248
  }: ExtremesOptions): {
224
- datum: any;
225
- units: any;
249
+ datum: string | undefined;
250
+ units: Units;
226
251
  station: Station;
227
252
  distance: number | undefined;
228
- extremes: any;
253
+ extremes: _$_neaps_tide_predictor0.Extreme[];
229
254
  };
230
255
  getTimelinePrediction({
231
256
  datum,
@@ -233,18 +258,26 @@ declare function findStation(query: string): {
233
258
  nodeCorrections,
234
259
  ...options
235
260
  }: TimelineOptions): {
236
- datum: any;
237
- units: any;
261
+ datum: string | undefined;
262
+ units: Units;
238
263
  station: Station;
239
264
  distance: number | undefined;
240
- timeline: any;
265
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
241
266
  };
242
267
  getWaterLevelAtTime({
243
268
  time,
244
269
  datum,
245
270
  units,
246
271
  nodeCorrections
247
- }: WaterLevelOptions): any;
272
+ }: WaterLevelOptions): {
273
+ time: Date;
274
+ hour: number;
275
+ level: number;
276
+ datum: string | undefined;
277
+ units: Units;
278
+ station: Station;
279
+ distance: number | undefined;
280
+ };
248
281
  id: string;
249
282
  name: string;
250
283
  continent: string;
@@ -288,7 +321,7 @@ declare function findStation(query: string): {
288
321
  declare function useStation(station: Station, distance?: number): {
289
322
  distance: number | undefined;
290
323
  datums: Record<string, number>;
291
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
324
+ harmonic_constituents: _$_neaps_tide_database0.HarmonicConstituent[];
292
325
  defaultDatum: string | undefined;
293
326
  getExtremesPrediction({
294
327
  datum,
@@ -296,11 +329,11 @@ declare function useStation(station: Station, distance?: number): {
296
329
  nodeCorrections,
297
330
  ...options
298
331
  }: ExtremesOptions): {
299
- datum: any;
300
- units: any;
332
+ datum: string | undefined;
333
+ units: Units;
301
334
  station: Station;
302
335
  distance: number | undefined;
303
- extremes: any;
336
+ extremes: _$_neaps_tide_predictor0.Extreme[];
304
337
  };
305
338
  getTimelinePrediction({
306
339
  datum,
@@ -308,18 +341,26 @@ declare function useStation(station: Station, distance?: number): {
308
341
  nodeCorrections,
309
342
  ...options
310
343
  }: TimelineOptions): {
311
- datum: any;
312
- units: any;
344
+ datum: string | undefined;
345
+ units: Units;
313
346
  station: Station;
314
347
  distance: number | undefined;
315
- timeline: any;
348
+ timeline: _$_neaps_tide_predictor0.TimelinePoint[];
316
349
  };
317
350
  getWaterLevelAtTime({
318
351
  time,
319
352
  datum,
320
353
  units,
321
354
  nodeCorrections
322
- }: WaterLevelOptions): any;
355
+ }: WaterLevelOptions): {
356
+ time: Date;
357
+ hour: number;
358
+ level: number;
359
+ datum: string | undefined;
360
+ units: Units;
361
+ station: Station;
362
+ distance: number | undefined;
363
+ };
323
364
  id: string;
324
365
  name: string;
325
366
  continent: string;
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { near, nearest, stations } from "@neaps/tide-database";
2
2
  import { createTidePredictor } from "@neaps/tide-predictor";
3
-
4
3
  //#region src/index.ts
5
4
  const feetPerMeter = 3.2808399;
6
5
  const defaultUnits = "meters";
@@ -143,7 +142,7 @@ function toPreferredUnits(prediction, units) {
143
142
  level
144
143
  };
145
144
  }
146
-
147
145
  //#endregion
148
146
  export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear, useStation };
147
+
149
148
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n stations,\n near,\n nearest,\n type Station,\n type NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport { createTidePredictor, type ExtremesInput, type TimelineInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to the nearest station's datum. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n\n /** Nodal correction fundamentals. Defaults to 'iho'. */\n nodeCorrections?: \"iho\" | \"schureman\";\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimelineInput & PredictionOptions;\nexport type WaterLevelOptions = { time: Date } & PredictionOptions;\n\nconst feetPerMeter = 3.2808399;\nconst defaultUnits: Units = \"meters\";\n\n/**\n * Get extremes prediction using the nearest station to the given position.\n *\n * @example\n * ```ts\n * import { getExtremesPrediction } from 'neaps'\n *\n * const prediction = getExtremesPrediction({\n * latitude: 26.7, // or `lat`\n * longitude: -80.05, // or `lng` or `lon`\n * start: new Date('2025-12-17'),\n * end: new Date('2025-12-18'),\n * datum: 'MLLW', // optional, defaults to station's datum\n * })\n */\nexport function getExtremesPrediction(options: NearestOptions & ExtremesOptions) {\n return nearestStation(options).getExtremesPrediction(options);\n}\n\n/**\n * Get timeline prediction using the nearest station to the given position.\n */\nexport function getTimelinePrediction(options: NearestOptions & TimelineOptions) {\n return nearestStation(options).getTimelinePrediction(options);\n}\n\n/**\n * Get water level at a specific time using the nearest station to the given position.\n */\nexport function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions) {\n return nearestStation(options).getWaterLevelAtTime(options);\n}\n\n/**\n * Find the nearest station to the given position.\n */\nexport function nearestStation(options: NearestOptions) {\n const data = nearest(options);\n if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);\n return useStation(...data);\n}\n\n/**\n * Find stations near the given position.\n * @param limit Maximum number of stations to return (default: 10)\n */\nexport function stationsNear(options: NearOptions) {\n return near(options).map(([station, distance]) => useStation(station, distance));\n}\n\n/**\n * Find a specific station by its ID or source ID.\n */\nexport function findStation(query: string) {\n const searches = [(s: Station) => s.id === query, (s: Station) => s.source.id === query];\n\n let found: Station | undefined = undefined;\n\n for (const search of searches) {\n found = stations.find(search);\n if (found) break;\n }\n\n if (!found) throw new Error(`Station not found: ${query}`);\n\n return useStation(found);\n}\n\nexport function useStation(station: Station, distance?: number) {\n // If subordinate station, use the reference station for datums and constituents\n let reference = station;\n if (station.type === \"subordinate\" && station.offsets?.reference) {\n reference = findStation(station.offsets?.reference);\n }\n const { datums, harmonic_constituents } = reference;\n\n // Use station chart datum as the default datum if available\n const defaultDatum = station.chart_datum in datums ? station.chart_datum : undefined;\n\n function getPredictor({ datum = defaultDatum, nodeCorrections }: PredictionOptions = {}) {\n let offset = 0;\n\n if (datum) {\n const datumOffset = datums?.[datum];\n const mslOffset = datums?.[\"MSL\"];\n\n if (typeof datumOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(\", \")}`,\n );\n }\n\n if (typeof mslOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`,\n );\n }\n\n offset = mslOffset - datumOffset;\n }\n\n return createTidePredictor(harmonic_constituents, { offset, nodeCorrections });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum, nodeCorrections })\n .getExtremesPrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, extremes };\n },\n\n getTimelinePrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: TimelineOptions) {\n const timeline = getPredictor({ datum, nodeCorrections })\n .getTimelinePrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({\n time,\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n }: WaterLevelOptions) {\n const prediction = toPreferredUnits(\n getPredictor({ datum, nodeCorrections }).getWaterLevelAtTime({\n time,\n offsets: station.offsets,\n }),\n units,\n );\n\n return { datum, units, station, distance, ...prediction };\n },\n };\n}\n\nfunction toPreferredUnits<T extends { level: number }>(prediction: T, units: Units): T {\n let { level } = prediction;\n if (units === \"feet\") level *= feetPerMeter;\n else if (units !== \"meters\") throw new Error(`Unsupported units: ${units}`);\n return { ...prediction, level };\n}\n"],"mappings":";;;;AA0BA,MAAM,eAAe;AACrB,MAAM,eAAsB;;;;;;;;;;;;;;;;AAiB5B,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,oBAAoB,SAA6C;AAC/E,QAAO,eAAe,QAAQ,CAAC,oBAAoB,QAAQ;;;;;AAM7D,SAAgB,eAAe,SAAyB;CACtD,MAAM,OAAO,QAAQ,QAAQ;AAC7B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,QAAQ,GAAG;AACxF,QAAO,WAAW,GAAG,KAAK;;;;;;AAO5B,SAAgB,aAAa,SAAsB;AACjD,QAAO,KAAK,QAAQ,CAAC,KAAK,CAAC,SAAS,cAAc,WAAW,SAAS,SAAS,CAAC;;;;;AAMlF,SAAgB,YAAY,OAAe;CACzC,MAAM,WAAW,EAAE,MAAe,EAAE,OAAO,QAAQ,MAAe,EAAE,OAAO,OAAO,MAAM;CAExF,IAAI,QAA6B;AAEjC,MAAK,MAAM,UAAU,UAAU;AAC7B,UAAQ,SAAS,KAAK,OAAO;AAC7B,MAAI,MAAO;;AAGb,KAAI,CAAC,MAAO,OAAM,IAAI,MAAM,sBAAsB,QAAQ;AAE1D,QAAO,WAAW,MAAM;;AAG1B,SAAgB,WAAW,SAAkB,UAAmB;CAE9D,IAAI,YAAY;AAChB,KAAI,QAAQ,SAAS,iBAAiB,QAAQ,SAAS,UACrD,aAAY,YAAY,QAAQ,SAAS,UAAU;CAErD,MAAM,EAAE,QAAQ,0BAA0B;CAG1C,MAAM,eAAe,QAAQ,eAA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;;AAGH,SAAS,iBAA8C,YAAe,OAAiB;CACrF,IAAI,EAAE,UAAU;AAChB,KAAI,UAAU,OAAQ,UAAS;UACtB,UAAU,SAAU,OAAM,IAAI,MAAM,sBAAsB,QAAQ;AAC3E,QAAO;EAAE,GAAG;EAAY;EAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n stations,\n near,\n nearest,\n type Station,\n type NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport { createTidePredictor, type ExtremesInput, type TimelineInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to the nearest station's datum. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n\n /** Nodal correction fundamentals. Defaults to 'iho'. */\n nodeCorrections?: \"iho\" | \"schureman\";\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimelineInput & PredictionOptions;\nexport type WaterLevelOptions = { time: Date } & PredictionOptions;\n\nconst feetPerMeter = 3.2808399;\nconst defaultUnits: Units = \"meters\";\n\n/**\n * Get extremes prediction using the nearest station to the given position.\n *\n * @example\n * ```ts\n * import { getExtremesPrediction } from 'neaps'\n *\n * const prediction = getExtremesPrediction({\n * latitude: 26.7, // or `lat`\n * longitude: -80.05, // or `lng` or `lon`\n * start: new Date('2025-12-17'),\n * end: new Date('2025-12-18'),\n * datum: 'MLLW', // optional, defaults to station's datum\n * })\n */\nexport function getExtremesPrediction(options: NearestOptions & ExtremesOptions) {\n return nearestStation(options).getExtremesPrediction(options);\n}\n\n/**\n * Get timeline prediction using the nearest station to the given position.\n */\nexport function getTimelinePrediction(options: NearestOptions & TimelineOptions) {\n return nearestStation(options).getTimelinePrediction(options);\n}\n\n/**\n * Get water level at a specific time using the nearest station to the given position.\n */\nexport function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions) {\n return nearestStation(options).getWaterLevelAtTime(options);\n}\n\n/**\n * Find the nearest station to the given position.\n */\nexport function nearestStation(options: NearestOptions) {\n const data = nearest(options);\n if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);\n return useStation(...data);\n}\n\n/**\n * Find stations near the given position.\n * @param limit Maximum number of stations to return (default: 10)\n */\nexport function stationsNear(options: NearOptions) {\n return near(options).map(([station, distance]) => useStation(station, distance));\n}\n\n/**\n * Find a specific station by its ID or source ID.\n */\nexport function findStation(query: string) {\n const searches = [(s: Station) => s.id === query, (s: Station) => s.source.id === query];\n\n let found: Station | undefined = undefined;\n\n for (const search of searches) {\n found = stations.find(search);\n if (found) break;\n }\n\n if (!found) throw new Error(`Station not found: ${query}`);\n\n return useStation(found);\n}\n\nexport function useStation(station: Station, distance?: number) {\n // If subordinate station, use the reference station for datums and constituents\n let reference = station;\n if (station.type === \"subordinate\" && station.offsets?.reference) {\n reference = findStation(station.offsets?.reference);\n }\n const { datums, harmonic_constituents } = reference;\n\n // Use station chart datum as the default datum if available\n const defaultDatum = station.chart_datum in datums ? station.chart_datum : undefined;\n\n function getPredictor({ datum = defaultDatum, nodeCorrections }: PredictionOptions = {}) {\n let offset = 0;\n\n if (datum) {\n const datumOffset = datums?.[datum];\n const mslOffset = datums?.[\"MSL\"];\n\n if (typeof datumOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(\", \")}`,\n );\n }\n\n if (typeof mslOffset !== \"number\") {\n throw new Error(\n `Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`,\n );\n }\n\n offset = mslOffset - datumOffset;\n }\n\n return createTidePredictor(harmonic_constituents, { offset, nodeCorrections });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum, nodeCorrections })\n .getExtremesPrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, extremes };\n },\n\n getTimelinePrediction({\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n ...options\n }: TimelineOptions) {\n const timeline = getPredictor({ datum, nodeCorrections })\n .getTimelinePrediction({ ...options, offsets: station.offsets })\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({\n time,\n datum = defaultDatum,\n units = defaultUnits,\n nodeCorrections,\n }: WaterLevelOptions) {\n const prediction = toPreferredUnits(\n getPredictor({ datum, nodeCorrections }).getWaterLevelAtTime({\n time,\n offsets: station.offsets,\n }),\n units,\n );\n\n return { datum, units, station, distance, ...prediction };\n },\n };\n}\n\nfunction toPreferredUnits<T extends { level: number }>(prediction: T, units: Units): T {\n let { level } = prediction;\n if (units === \"feet\") level *= feetPerMeter;\n else if (units !== \"meters\") throw new Error(`Unsupported units: ${units}`);\n return { ...prediction, level };\n}\n"],"mappings":";;;AA0BA,MAAM,eAAe;AACrB,MAAM,eAAsB;;;;;;;;;;;;;;;;AAiB5B,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,eAAe,QAAQ,CAAC,sBAAsB,QAAQ;;;;;AAM/D,SAAgB,oBAAoB,SAA6C;AAC/E,QAAO,eAAe,QAAQ,CAAC,oBAAoB,QAAQ;;;;;AAM7D,SAAgB,eAAe,SAAyB;CACtD,MAAM,OAAO,QAAQ,QAAQ;AAC7B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,QAAQ,GAAG;AACxF,QAAO,WAAW,GAAG,KAAK;;;;;;AAO5B,SAAgB,aAAa,SAAsB;AACjD,QAAO,KAAK,QAAQ,CAAC,KAAK,CAAC,SAAS,cAAc,WAAW,SAAS,SAAS,CAAC;;;;;AAMlF,SAAg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,MAAM,CAEU;IAAE;;EAGtD,sBAAsB,EACpB,QAAQ,cACR,QAAQ,cACR,iBACA,GAAG,WACe;AAKlB,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,UAJzB,aAAa;KAAE;KAAO;KAAiB,CAAC,CACtD,sBAAsB;KAAE,GAAG;KAAS,SAAS,QAAQ;KAAS,CAAC,CAC/D,KAAK,MAAM,iBAAiB,GAAG,MAAM,CAEU;IAAE;;EAGtD,oBAAoB,EAClB,MACA,QAAQ,cACR,QAAQ,cACR,mBACoB;AASpB,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,GARvB,iBACjB,aAAa;KAAE;KAAO;KAAiB,CAAC,CAAC,oBAAoB;KAC3D;KACA,SAAS,QAAQ;KAClB,CAAC,EACF,MAGqD;IAAE;;EAE5D;;AAGH,SAAS,iBAA8C,YAAe,OAAiB;CACrF,IAAI,EAAE,UAAU;AAChB,KAAI,UAAU,OAAQ,UAAS;UACtB,UAAU,SAAU,OAAM,IAAI,MAAM,sBAAsB,QAAQ;AAC3E,QAAO;EAAE,GAAG;EAAY;EAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neaps",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Tide predictions",
5
5
  "keywords": [
6
6
  "tides",
@@ -34,7 +34,7 @@
34
34
  "prepack": "npm run build"
35
35
  },
36
36
  "dependencies": {
37
- "@neaps/tide-database": "0.6",
38
- "@neaps/tide-predictor": "^0.8.0"
37
+ "@neaps/tide-database": "0.7",
38
+ "@neaps/tide-predictor": "^0.9.0"
39
39
  }
40
40
  }