neaps 0.6.0 → 0.7.0

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,10 +1,7 @@
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
- const feetPerMeter = 3.2808399;
7
- const defaultUnits = "meters";
8
5
  /**
9
6
  * Get extremes prediction using the nearest station to the given position.
10
7
  *
@@ -41,14 +38,14 @@ function getWaterLevelAtTime(options) {
41
38
  function nearestStation(options) {
42
39
  const data = (0, _neaps_tide_database.nearest)(options);
43
40
  if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);
44
- return useStation(...data);
41
+ return (0, _neaps_tide_predictor.useStation)(...data);
45
42
  }
46
43
  /**
47
44
  * Find stations near the given position.
48
45
  * @param limit Maximum number of stations to return (default: 10)
49
46
  */
50
47
  function stationsNear(options) {
51
- return (0, _neaps_tide_database.near)(options).map(([station, distance]) => useStation(station, distance));
48
+ return (0, _neaps_tide_database.near)(options).map(([station, distance]) => (0, _neaps_tide_predictor.useStation)(station, distance));
52
49
  }
53
50
  /**
54
51
  * Find a specific station by its ID or source ID.
@@ -61,90 +58,8 @@ function findStation(query) {
61
58
  if (found) break;
62
59
  }
63
60
  if (!found) throw new Error(`Station not found: ${query}`);
64
- return useStation(found);
65
- }
66
- function useStation(station, distance) {
67
- let reference = station;
68
- if (station.type === "subordinate" && station.offsets?.reference) reference = findStation(station.offsets?.reference);
69
- const { datums, harmonic_constituents } = reference;
70
- const defaultDatum = station.chart_datum in datums ? station.chart_datum : void 0;
71
- function getPredictor({ datum = defaultDatum, nodeCorrections } = {}) {
72
- let offset = 0;
73
- if (datum) {
74
- const datumOffset = datums?.[datum];
75
- const mslOffset = datums?.["MSL"];
76
- if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(", ")}`);
77
- if (typeof mslOffset !== "number") throw new Error(`Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`);
78
- offset = mslOffset - datumOffset;
79
- }
80
- return (0, _neaps_tide_predictor.createTidePredictor)(harmonic_constituents, {
81
- offset,
82
- nodeCorrections
83
- });
84
- }
85
- return {
86
- ...station,
87
- distance,
88
- datums,
89
- harmonic_constituents,
90
- defaultDatum,
91
- getExtremesPrediction({ datum = defaultDatum, units = defaultUnits, nodeCorrections, ...options }) {
92
- return {
93
- datum,
94
- units,
95
- station,
96
- distance,
97
- extremes: getPredictor({
98
- datum,
99
- nodeCorrections
100
- }).getExtremesPrediction({
101
- ...options,
102
- offsets: station.offsets
103
- }).map((e) => toPreferredUnits(e, units))
104
- };
105
- },
106
- getTimelinePrediction({ datum = defaultDatum, units = defaultUnits, nodeCorrections, ...options }) {
107
- return {
108
- datum,
109
- units,
110
- station,
111
- distance,
112
- timeline: getPredictor({
113
- datum,
114
- nodeCorrections
115
- }).getTimelinePrediction({
116
- ...options,
117
- offsets: station.offsets
118
- }).map((e) => toPreferredUnits(e, units))
119
- };
120
- },
121
- getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits, nodeCorrections }) {
122
- return {
123
- datum,
124
- units,
125
- station,
126
- distance,
127
- ...toPreferredUnits(getPredictor({
128
- datum,
129
- nodeCorrections
130
- }).getWaterLevelAtTime({
131
- time,
132
- offsets: station.offsets
133
- }), units)
134
- };
135
- }
136
- };
61
+ return (0, _neaps_tide_predictor.useStation)(found);
137
62
  }
138
- function toPreferredUnits(prediction, units) {
139
- let { level } = prediction;
140
- if (units === "feet") level *= feetPerMeter;
141
- else if (units !== "meters") throw new Error(`Unsupported units: ${units}`);
142
- return {
143
- ...prediction,
144
- level
145
- };
146
- }
147
-
148
63
  //#endregion
149
64
  exports.findStation = findStation;
150
65
  exports.getExtremesPrediction = getExtremesPrediction;
@@ -152,5 +67,5 @@ exports.getTimelinePrediction = getTimelinePrediction;
152
67
  exports.getWaterLevelAtTime = getWaterLevelAtTime;
153
68
  exports.nearestStation = nearestStation;
154
69
  exports.stationsNear = stationsNear;
155
- exports.useStation = useStation;
70
+
156
71
  //# 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/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,yCAAe,QAAQ;AAC7B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,QAAQ,GAAG;AACxF,QAAO,WAAW,GAAG,KAAK;;;;;;AAO5B,SAAgB,aAAa,SAAsB;AACjD,uCAAY,QAAQ,CAAC,KAAK,CAAC,SAAS,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C/D,KAAK,MAAM,iBAAiB,GAAG,MAAM,CAAC;IAEW;;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,CAAC;IAEW;;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,MACD;IAEwD;;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"}
1
+ {"version":3,"file":"index.cjs","names":["stations"],"sources":["../src/index.ts"],"sourcesContent":["import {\n stations,\n near,\n nearest,\n type NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport {\n useStation,\n type Station,\n type StationPredictor,\n type StationExtremesOptions,\n type StationTimelineOptions,\n type StationWaterLevelOptions,\n} from \"@neaps/tide-predictor\";\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 & StationExtremesOptions) {\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 & StationTimelineOptions) {\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 & StationWaterLevelOptions) {\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): StationPredictor {\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 return useStation(found);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,sBAAsB,SAAkD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,sBAAsB,OAAO;AAC9D;;;;AAKA,SAAgB,sBAAsB,SAAkD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,sBAAsB,OAAO;AAC9D;;;;AAKA,SAAgB,oBAAoB,SAAoD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,oBAAoB,OAAO;AAC5D;;;;AAKA,SAAgB,eAAe,SAAyB;CACtD,MAAM,QAAA,GAAA,qBAAA,QAAA,CAAe,OAAO;CAC5B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,OAAO,GAAG;CACvF,QAAA,GAAA,sBAAA,WAAA,CAAkB,GAAG,IAAI;AAC3B;;;;;AAMA,SAAgB,aAAa,SAAsB;CACjD,QAAA,GAAA,qBAAA,KAAA,CAAY,OAAO,CAAC,CAAC,KAAK,CAAC,SAAS,eAAA,GAAA,sBAAA,WAAA,CAAyB,SAAS,QAAQ,CAAC;AACjF;;;;AAKA,SAAgB,YAAY,OAAiC;CAC3D,MAAM,WAAW,EAAE,MAAe,EAAE,OAAO,QAAQ,MAAe,EAAE,OAAO,OAAO,KAAK;CAEvF,IAAI,QAA6B,KAAA;CAEjC,KAAK,MAAM,UAAU,UAAU;EAC7B,QAAQA,qBAAAA,SAAS,KAAK,MAAM;EAC5B,IAAI,OAAO;CACb;CAEA,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,sBAAsB,OAAO;CACzD,QAAA,GAAA,sBAAA,WAAA,CAAkB,KAAK;AACzB"}
package/dist/index.d.cts CHANGED
@@ -1,19 +1,7 @@
1
- import * as _neaps_tide_database0 from "@neaps/tide-database";
2
- import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
3
- import { ExtremesInput, TimelineInput } from "@neaps/tide-predictor";
1
+ import { NearOptions, NearestOptions } from "@neaps/tide-database";
2
+ import { StationExtremesOptions, StationPredictor, StationTimelineOptions, StationWaterLevelOptions } from "@neaps/tide-predictor";
4
3
 
5
4
  //#region src/index.d.ts
6
- type Units = "meters" | "feet";
7
- type PredictionOptions = {
8
- /** Datum to return predictions in. Defaults to the nearest station's datum. */datum?: string; /** Units for returned water levels. Defaults to 'meters'. */
9
- units?: Units; /** Nodal correction fundamentals. Defaults to 'iho'. */
10
- nodeCorrections?: "iho" | "schureman";
11
- };
12
- type ExtremesOptions = ExtremesInput & PredictionOptions;
13
- type TimelineOptions = TimelineInput & PredictionOptions;
14
- type WaterLevelOptions = {
15
- time: Date;
16
- } & PredictionOptions;
17
5
  /**
18
6
  * Get extremes prediction using the nearest station to the given position.
19
7
  *
@@ -29,337 +17,28 @@ type WaterLevelOptions = {
29
17
  * datum: 'MLLW', // optional, defaults to station's datum
30
18
  * })
31
19
  */
32
- declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
33
- datum: any;
34
- units: any;
35
- station: Station;
36
- distance: number | undefined;
37
- extremes: any;
38
- };
20
+ declare function getExtremesPrediction(options: NearestOptions & StationExtremesOptions): import("@neaps/tide-predictor").StationExtremesPrediction;
39
21
  /**
40
22
  * Get timeline prediction using the nearest station to the given position.
41
23
  */
42
- declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
43
- datum: any;
44
- units: any;
45
- station: Station;
46
- distance: number | undefined;
47
- timeline: any;
48
- };
24
+ declare function getTimelinePrediction(options: NearestOptions & StationTimelineOptions): import("@neaps/tide-predictor").StationTimelinePrediction;
49
25
  /**
50
26
  * Get water level at a specific time using the nearest station to the given position.
51
27
  */
52
- declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
28
+ declare function getWaterLevelAtTime(options: NearestOptions & StationWaterLevelOptions): import("@neaps/tide-predictor").StationWaterLevelPrediction;
53
29
  /**
54
30
  * Find the nearest station to the given position.
55
31
  */
56
- declare function nearestStation(options: NearestOptions): {
57
- distance: number | undefined;
58
- datums: Record<string, number>;
59
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
60
- defaultDatum: string | undefined;
61
- getExtremesPrediction({
62
- datum,
63
- units,
64
- nodeCorrections,
65
- ...options
66
- }: ExtremesOptions): {
67
- datum: any;
68
- units: any;
69
- station: Station;
70
- distance: number | undefined;
71
- extremes: any;
72
- };
73
- getTimelinePrediction({
74
- datum,
75
- units,
76
- nodeCorrections,
77
- ...options
78
- }: TimelineOptions): {
79
- datum: any;
80
- units: any;
81
- station: Station;
82
- distance: number | undefined;
83
- timeline: any;
84
- };
85
- getWaterLevelAtTime({
86
- time,
87
- datum,
88
- units,
89
- nodeCorrections
90
- }: WaterLevelOptions): any;
91
- id: string;
92
- name: string;
93
- continent: string;
94
- country: string;
95
- region?: string;
96
- timezone: string;
97
- disclaimers: string;
98
- type: "reference" | "subordinate";
99
- latitude: number;
100
- longitude: number;
101
- source: {
102
- name: string;
103
- id: string;
104
- published_harmonics: boolean;
105
- url: string;
106
- };
107
- license: {
108
- type: string;
109
- commercial_use: boolean;
110
- url: string;
111
- notes?: string;
112
- };
113
- offsets?: {
114
- reference: string;
115
- height: {
116
- high: number;
117
- low: number;
118
- type: "ratio" | "fixed";
119
- };
120
- time: {
121
- high: number;
122
- low: number;
123
- };
124
- };
125
- chart_datum: string;
126
- epoch?: {
127
- start: string;
128
- end: string;
129
- };
130
- };
32
+ declare function nearestStation(options: NearestOptions): StationPredictor;
131
33
  /**
132
34
  * Find stations near the given position.
133
35
  * @param limit Maximum number of stations to return (default: 10)
134
36
  */
135
- declare function stationsNear(options: NearOptions): {
136
- distance: number | undefined;
137
- datums: Record<string, number>;
138
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
139
- defaultDatum: string | undefined;
140
- getExtremesPrediction({
141
- datum,
142
- units,
143
- nodeCorrections,
144
- ...options
145
- }: ExtremesOptions): {
146
- datum: any;
147
- units: any;
148
- station: Station;
149
- distance: number | undefined;
150
- extremes: any;
151
- };
152
- getTimelinePrediction({
153
- datum,
154
- units,
155
- nodeCorrections,
156
- ...options
157
- }: TimelineOptions): {
158
- datum: any;
159
- units: any;
160
- station: Station;
161
- distance: number | undefined;
162
- timeline: any;
163
- };
164
- getWaterLevelAtTime({
165
- time,
166
- datum,
167
- units,
168
- nodeCorrections
169
- }: WaterLevelOptions): any;
170
- id: string;
171
- name: string;
172
- continent: string;
173
- country: string;
174
- region?: string;
175
- timezone: string;
176
- disclaimers: string;
177
- type: "reference" | "subordinate";
178
- latitude: number;
179
- longitude: number;
180
- source: {
181
- name: string;
182
- id: string;
183
- published_harmonics: boolean;
184
- url: string;
185
- };
186
- license: {
187
- type: string;
188
- commercial_use: boolean;
189
- url: string;
190
- notes?: string;
191
- };
192
- offsets?: {
193
- reference: string;
194
- height: {
195
- high: number;
196
- low: number;
197
- type: "ratio" | "fixed";
198
- };
199
- time: {
200
- high: number;
201
- low: number;
202
- };
203
- };
204
- chart_datum: string;
205
- epoch?: {
206
- start: string;
207
- end: string;
208
- };
209
- }[];
37
+ declare function stationsNear(options: NearOptions): StationPredictor[];
210
38
  /**
211
39
  * Find a specific station by its ID or source ID.
212
40
  */
213
- declare function findStation(query: string): {
214
- distance: number | undefined;
215
- datums: Record<string, number>;
216
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
217
- defaultDatum: string | undefined;
218
- getExtremesPrediction({
219
- datum,
220
- units,
221
- nodeCorrections,
222
- ...options
223
- }: ExtremesOptions): {
224
- datum: any;
225
- units: any;
226
- station: Station;
227
- distance: number | undefined;
228
- extremes: any;
229
- };
230
- getTimelinePrediction({
231
- datum,
232
- units,
233
- nodeCorrections,
234
- ...options
235
- }: TimelineOptions): {
236
- datum: any;
237
- units: any;
238
- station: Station;
239
- distance: number | undefined;
240
- timeline: any;
241
- };
242
- getWaterLevelAtTime({
243
- time,
244
- datum,
245
- units,
246
- nodeCorrections
247
- }: WaterLevelOptions): any;
248
- id: string;
249
- name: string;
250
- continent: string;
251
- country: string;
252
- region?: string;
253
- timezone: string;
254
- disclaimers: string;
255
- type: "reference" | "subordinate";
256
- latitude: number;
257
- longitude: number;
258
- source: {
259
- name: string;
260
- id: string;
261
- published_harmonics: boolean;
262
- url: string;
263
- };
264
- license: {
265
- type: string;
266
- commercial_use: boolean;
267
- url: string;
268
- notes?: string;
269
- };
270
- offsets?: {
271
- reference: string;
272
- height: {
273
- high: number;
274
- low: number;
275
- type: "ratio" | "fixed";
276
- };
277
- time: {
278
- high: number;
279
- low: number;
280
- };
281
- };
282
- chart_datum: string;
283
- epoch?: {
284
- start: string;
285
- end: string;
286
- };
287
- };
288
- declare function useStation(station: Station, distance?: number): {
289
- distance: number | undefined;
290
- datums: Record<string, number>;
291
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
292
- defaultDatum: string | undefined;
293
- getExtremesPrediction({
294
- datum,
295
- units,
296
- nodeCorrections,
297
- ...options
298
- }: ExtremesOptions): {
299
- datum: any;
300
- units: any;
301
- station: Station;
302
- distance: number | undefined;
303
- extremes: any;
304
- };
305
- getTimelinePrediction({
306
- datum,
307
- units,
308
- nodeCorrections,
309
- ...options
310
- }: TimelineOptions): {
311
- datum: any;
312
- units: any;
313
- station: Station;
314
- distance: number | undefined;
315
- timeline: any;
316
- };
317
- getWaterLevelAtTime({
318
- time,
319
- datum,
320
- units,
321
- nodeCorrections
322
- }: WaterLevelOptions): any;
323
- id: string;
324
- name: string;
325
- continent: string;
326
- country: string;
327
- region?: string;
328
- timezone: string;
329
- disclaimers: string;
330
- type: "reference" | "subordinate";
331
- latitude: number;
332
- longitude: number;
333
- source: {
334
- name: string;
335
- id: string;
336
- published_harmonics: boolean;
337
- url: string;
338
- };
339
- license: {
340
- type: string;
341
- commercial_use: boolean;
342
- url: string;
343
- notes?: string;
344
- };
345
- offsets?: {
346
- reference: string;
347
- height: {
348
- high: number;
349
- low: number;
350
- type: "ratio" | "fixed";
351
- };
352
- time: {
353
- high: number;
354
- low: number;
355
- };
356
- };
357
- chart_datum: string;
358
- epoch?: {
359
- start: string;
360
- end: string;
361
- };
362
- };
41
+ declare function findStation(query: string): StationPredictor;
363
42
  //#endregion
364
- export { ExtremesOptions, TimelineOptions, WaterLevelOptions, findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear, useStation };
43
+ export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear };
365
44
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,19 +1,7 @@
1
- import * as _neaps_tide_database0 from "@neaps/tide-database";
2
- import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
3
- import { ExtremesInput, TimelineInput } from "@neaps/tide-predictor";
1
+ import { NearOptions, NearestOptions } from "@neaps/tide-database";
2
+ import { StationExtremesOptions, StationPredictor, StationTimelineOptions, StationWaterLevelOptions } from "@neaps/tide-predictor";
4
3
 
5
4
  //#region src/index.d.ts
6
- type Units = "meters" | "feet";
7
- type PredictionOptions = {
8
- /** Datum to return predictions in. Defaults to the nearest station's datum. */datum?: string; /** Units for returned water levels. Defaults to 'meters'. */
9
- units?: Units; /** Nodal correction fundamentals. Defaults to 'iho'. */
10
- nodeCorrections?: "iho" | "schureman";
11
- };
12
- type ExtremesOptions = ExtremesInput & PredictionOptions;
13
- type TimelineOptions = TimelineInput & PredictionOptions;
14
- type WaterLevelOptions = {
15
- time: Date;
16
- } & PredictionOptions;
17
5
  /**
18
6
  * Get extremes prediction using the nearest station to the given position.
19
7
  *
@@ -29,337 +17,28 @@ type WaterLevelOptions = {
29
17
  * datum: 'MLLW', // optional, defaults to station's datum
30
18
  * })
31
19
  */
32
- declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
33
- datum: any;
34
- units: any;
35
- station: Station;
36
- distance: number | undefined;
37
- extremes: any;
38
- };
20
+ declare function getExtremesPrediction(options: NearestOptions & StationExtremesOptions): import("@neaps/tide-predictor").StationExtremesPrediction;
39
21
  /**
40
22
  * Get timeline prediction using the nearest station to the given position.
41
23
  */
42
- declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
43
- datum: any;
44
- units: any;
45
- station: Station;
46
- distance: number | undefined;
47
- timeline: any;
48
- };
24
+ declare function getTimelinePrediction(options: NearestOptions & StationTimelineOptions): import("@neaps/tide-predictor").StationTimelinePrediction;
49
25
  /**
50
26
  * Get water level at a specific time using the nearest station to the given position.
51
27
  */
52
- declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
28
+ declare function getWaterLevelAtTime(options: NearestOptions & StationWaterLevelOptions): import("@neaps/tide-predictor").StationWaterLevelPrediction;
53
29
  /**
54
30
  * Find the nearest station to the given position.
55
31
  */
56
- declare function nearestStation(options: NearestOptions): {
57
- distance: number | undefined;
58
- datums: Record<string, number>;
59
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
60
- defaultDatum: string | undefined;
61
- getExtremesPrediction({
62
- datum,
63
- units,
64
- nodeCorrections,
65
- ...options
66
- }: ExtremesOptions): {
67
- datum: any;
68
- units: any;
69
- station: Station;
70
- distance: number | undefined;
71
- extremes: any;
72
- };
73
- getTimelinePrediction({
74
- datum,
75
- units,
76
- nodeCorrections,
77
- ...options
78
- }: TimelineOptions): {
79
- datum: any;
80
- units: any;
81
- station: Station;
82
- distance: number | undefined;
83
- timeline: any;
84
- };
85
- getWaterLevelAtTime({
86
- time,
87
- datum,
88
- units,
89
- nodeCorrections
90
- }: WaterLevelOptions): any;
91
- id: string;
92
- name: string;
93
- continent: string;
94
- country: string;
95
- region?: string;
96
- timezone: string;
97
- disclaimers: string;
98
- type: "reference" | "subordinate";
99
- latitude: number;
100
- longitude: number;
101
- source: {
102
- name: string;
103
- id: string;
104
- published_harmonics: boolean;
105
- url: string;
106
- };
107
- license: {
108
- type: string;
109
- commercial_use: boolean;
110
- url: string;
111
- notes?: string;
112
- };
113
- offsets?: {
114
- reference: string;
115
- height: {
116
- high: number;
117
- low: number;
118
- type: "ratio" | "fixed";
119
- };
120
- time: {
121
- high: number;
122
- low: number;
123
- };
124
- };
125
- chart_datum: string;
126
- epoch?: {
127
- start: string;
128
- end: string;
129
- };
130
- };
32
+ declare function nearestStation(options: NearestOptions): StationPredictor;
131
33
  /**
132
34
  * Find stations near the given position.
133
35
  * @param limit Maximum number of stations to return (default: 10)
134
36
  */
135
- declare function stationsNear(options: NearOptions): {
136
- distance: number | undefined;
137
- datums: Record<string, number>;
138
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
139
- defaultDatum: string | undefined;
140
- getExtremesPrediction({
141
- datum,
142
- units,
143
- nodeCorrections,
144
- ...options
145
- }: ExtremesOptions): {
146
- datum: any;
147
- units: any;
148
- station: Station;
149
- distance: number | undefined;
150
- extremes: any;
151
- };
152
- getTimelinePrediction({
153
- datum,
154
- units,
155
- nodeCorrections,
156
- ...options
157
- }: TimelineOptions): {
158
- datum: any;
159
- units: any;
160
- station: Station;
161
- distance: number | undefined;
162
- timeline: any;
163
- };
164
- getWaterLevelAtTime({
165
- time,
166
- datum,
167
- units,
168
- nodeCorrections
169
- }: WaterLevelOptions): any;
170
- id: string;
171
- name: string;
172
- continent: string;
173
- country: string;
174
- region?: string;
175
- timezone: string;
176
- disclaimers: string;
177
- type: "reference" | "subordinate";
178
- latitude: number;
179
- longitude: number;
180
- source: {
181
- name: string;
182
- id: string;
183
- published_harmonics: boolean;
184
- url: string;
185
- };
186
- license: {
187
- type: string;
188
- commercial_use: boolean;
189
- url: string;
190
- notes?: string;
191
- };
192
- offsets?: {
193
- reference: string;
194
- height: {
195
- high: number;
196
- low: number;
197
- type: "ratio" | "fixed";
198
- };
199
- time: {
200
- high: number;
201
- low: number;
202
- };
203
- };
204
- chart_datum: string;
205
- epoch?: {
206
- start: string;
207
- end: string;
208
- };
209
- }[];
37
+ declare function stationsNear(options: NearOptions): StationPredictor[];
210
38
  /**
211
39
  * Find a specific station by its ID or source ID.
212
40
  */
213
- declare function findStation(query: string): {
214
- distance: number | undefined;
215
- datums: Record<string, number>;
216
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
217
- defaultDatum: string | undefined;
218
- getExtremesPrediction({
219
- datum,
220
- units,
221
- nodeCorrections,
222
- ...options
223
- }: ExtremesOptions): {
224
- datum: any;
225
- units: any;
226
- station: Station;
227
- distance: number | undefined;
228
- extremes: any;
229
- };
230
- getTimelinePrediction({
231
- datum,
232
- units,
233
- nodeCorrections,
234
- ...options
235
- }: TimelineOptions): {
236
- datum: any;
237
- units: any;
238
- station: Station;
239
- distance: number | undefined;
240
- timeline: any;
241
- };
242
- getWaterLevelAtTime({
243
- time,
244
- datum,
245
- units,
246
- nodeCorrections
247
- }: WaterLevelOptions): any;
248
- id: string;
249
- name: string;
250
- continent: string;
251
- country: string;
252
- region?: string;
253
- timezone: string;
254
- disclaimers: string;
255
- type: "reference" | "subordinate";
256
- latitude: number;
257
- longitude: number;
258
- source: {
259
- name: string;
260
- id: string;
261
- published_harmonics: boolean;
262
- url: string;
263
- };
264
- license: {
265
- type: string;
266
- commercial_use: boolean;
267
- url: string;
268
- notes?: string;
269
- };
270
- offsets?: {
271
- reference: string;
272
- height: {
273
- high: number;
274
- low: number;
275
- type: "ratio" | "fixed";
276
- };
277
- time: {
278
- high: number;
279
- low: number;
280
- };
281
- };
282
- chart_datum: string;
283
- epoch?: {
284
- start: string;
285
- end: string;
286
- };
287
- };
288
- declare function useStation(station: Station, distance?: number): {
289
- distance: number | undefined;
290
- datums: Record<string, number>;
291
- harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
292
- defaultDatum: string | undefined;
293
- getExtremesPrediction({
294
- datum,
295
- units,
296
- nodeCorrections,
297
- ...options
298
- }: ExtremesOptions): {
299
- datum: any;
300
- units: any;
301
- station: Station;
302
- distance: number | undefined;
303
- extremes: any;
304
- };
305
- getTimelinePrediction({
306
- datum,
307
- units,
308
- nodeCorrections,
309
- ...options
310
- }: TimelineOptions): {
311
- datum: any;
312
- units: any;
313
- station: Station;
314
- distance: number | undefined;
315
- timeline: any;
316
- };
317
- getWaterLevelAtTime({
318
- time,
319
- datum,
320
- units,
321
- nodeCorrections
322
- }: WaterLevelOptions): any;
323
- id: string;
324
- name: string;
325
- continent: string;
326
- country: string;
327
- region?: string;
328
- timezone: string;
329
- disclaimers: string;
330
- type: "reference" | "subordinate";
331
- latitude: number;
332
- longitude: number;
333
- source: {
334
- name: string;
335
- id: string;
336
- published_harmonics: boolean;
337
- url: string;
338
- };
339
- license: {
340
- type: string;
341
- commercial_use: boolean;
342
- url: string;
343
- notes?: string;
344
- };
345
- offsets?: {
346
- reference: string;
347
- height: {
348
- high: number;
349
- low: number;
350
- type: "ratio" | "fixed";
351
- };
352
- time: {
353
- high: number;
354
- low: number;
355
- };
356
- };
357
- chart_datum: string;
358
- epoch?: {
359
- start: string;
360
- end: string;
361
- };
362
- };
41
+ declare function findStation(query: string): StationPredictor;
363
42
  //#endregion
364
- export { ExtremesOptions, TimelineOptions, WaterLevelOptions, findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear, useStation };
43
+ export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear };
365
44
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import { near, nearest, stations } from "@neaps/tide-database";
2
- import { createTidePredictor } from "@neaps/tide-predictor";
3
-
2
+ import { useStation } from "@neaps/tide-predictor";
4
3
  //#region src/index.ts
5
- const feetPerMeter = 3.2808399;
6
- const defaultUnits = "meters";
7
4
  /**
8
5
  * Get extremes prediction using the nearest station to the given position.
9
6
  *
@@ -62,88 +59,7 @@ function findStation(query) {
62
59
  if (!found) throw new Error(`Station not found: ${query}`);
63
60
  return useStation(found);
64
61
  }
65
- function useStation(station, distance) {
66
- let reference = station;
67
- if (station.type === "subordinate" && station.offsets?.reference) reference = findStation(station.offsets?.reference);
68
- const { datums, harmonic_constituents } = reference;
69
- const defaultDatum = station.chart_datum in datums ? station.chart_datum : void 0;
70
- function getPredictor({ datum = defaultDatum, nodeCorrections } = {}) {
71
- let offset = 0;
72
- if (datum) {
73
- const datumOffset = datums?.[datum];
74
- const mslOffset = datums?.["MSL"];
75
- if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(", ")}`);
76
- if (typeof mslOffset !== "number") throw new Error(`Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`);
77
- offset = mslOffset - datumOffset;
78
- }
79
- return createTidePredictor(harmonic_constituents, {
80
- offset,
81
- nodeCorrections
82
- });
83
- }
84
- return {
85
- ...station,
86
- distance,
87
- datums,
88
- harmonic_constituents,
89
- defaultDatum,
90
- getExtremesPrediction({ datum = defaultDatum, units = defaultUnits, nodeCorrections, ...options }) {
91
- return {
92
- datum,
93
- units,
94
- station,
95
- distance,
96
- extremes: getPredictor({
97
- datum,
98
- nodeCorrections
99
- }).getExtremesPrediction({
100
- ...options,
101
- offsets: station.offsets
102
- }).map((e) => toPreferredUnits(e, units))
103
- };
104
- },
105
- getTimelinePrediction({ datum = defaultDatum, units = defaultUnits, nodeCorrections, ...options }) {
106
- return {
107
- datum,
108
- units,
109
- station,
110
- distance,
111
- timeline: getPredictor({
112
- datum,
113
- nodeCorrections
114
- }).getTimelinePrediction({
115
- ...options,
116
- offsets: station.offsets
117
- }).map((e) => toPreferredUnits(e, units))
118
- };
119
- },
120
- getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits, nodeCorrections }) {
121
- return {
122
- datum,
123
- units,
124
- station,
125
- distance,
126
- ...toPreferredUnits(getPredictor({
127
- datum,
128
- nodeCorrections
129
- }).getWaterLevelAtTime({
130
- time,
131
- offsets: station.offsets
132
- }), units)
133
- };
134
- }
135
- };
136
- }
137
- function toPreferredUnits(prediction, units) {
138
- let { level } = prediction;
139
- if (units === "feet") level *= feetPerMeter;
140
- else if (units !== "meters") throw new Error(`Unsupported units: ${units}`);
141
- return {
142
- ...prediction,
143
- level
144
- };
145
- }
146
-
147
62
  //#endregion
148
- export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear, useStation };
63
+ export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear };
64
+
149
65
  //# 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 *= fe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AChB,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 NearOptions,\n type NearestOptions,\n} from \"@neaps/tide-database\";\nimport {\n useStation,\n type Station,\n type StationPredictor,\n type StationExtremesOptions,\n type StationTimelineOptions,\n type StationWaterLevelOptions,\n} from \"@neaps/tide-predictor\";\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 & StationExtremesOptions) {\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 & StationTimelineOptions) {\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 & StationWaterLevelOptions) {\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): StationPredictor {\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 return useStation(found);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,SAAgB,sBAAsB,SAAkD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,sBAAsB,OAAO;AAC9D;;;;AAKA,SAAgB,sBAAsB,SAAkD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,sBAAsB,OAAO;AAC9D;;;;AAKA,SAAgB,oBAAoB,SAAoD;CACtF,OAAO,eAAe,OAAO,CAAC,CAAC,oBAAoB,OAAO;AAC5D;;;;AAKA,SAAgB,eAAe,SAAyB;CACtD,MAAM,OAAO,QAAQ,OAAO;CAC5B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mCAAmC,KAAK,UAAU,OAAO,GAAG;CACvF,OAAO,WAAW,GAAG,IAAI;AAC3B;;;;;AAMA,SAAgB,aAAa,SAAsB;CACjD,OAAO,KAAK,OAAO,CAAC,CAAC,KAAK,CAAC,SAAS,cAAc,WAAW,SAAS,QAAQ,CAAC;AACjF;;;;AAKA,SAAgB,YAAY,OAAiC;CAC3D,MAAM,WAAW,EAAE,MAAe,EAAE,OAAO,QAAQ,MAAe,EAAE,OAAO,OAAO,KAAK;CAEvF,IAAI,QAA6B,KAAA;CAEjC,KAAK,MAAM,UAAU,UAAU;EAC7B,QAAQ,SAAS,KAAK,MAAM;EAC5B,IAAI,OAAO;CACb;CAEA,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,sBAAsB,OAAO;CACzD,OAAO,WAAW,KAAK;AACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neaps",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
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.8",
38
+ "@neaps/tide-predictor": "^0.10.0"
39
39
  }
40
40
  }