neaps 0.1.1 → 0.3.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 +34 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -125
- package/dist/index.d.ts +90 -125
- package/dist/index.js +34 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.cjs
CHANGED
|
@@ -25,13 +25,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
let geolib = require("geolib");
|
|
29
28
|
let _neaps_tide_database = require("@neaps/tide-database");
|
|
30
|
-
_neaps_tide_database = __toESM(_neaps_tide_database);
|
|
31
29
|
let _neaps_tide_predictor = require("@neaps/tide-predictor");
|
|
32
30
|
_neaps_tide_predictor = __toESM(_neaps_tide_predictor);
|
|
33
31
|
|
|
34
32
|
//#region src/index.ts
|
|
33
|
+
const feetPerMeter = 3.2808399;
|
|
34
|
+
const defaultUnits = "meters";
|
|
35
35
|
/**
|
|
36
36
|
* Get extremes prediction using the nearest station to the given position.
|
|
37
37
|
*
|
|
@@ -65,18 +65,17 @@ function getWaterLevelAtTime(options) {
|
|
|
65
65
|
/**
|
|
66
66
|
* Find the nearest station to the given position.
|
|
67
67
|
*/
|
|
68
|
-
function nearestStation(
|
|
69
|
-
|
|
68
|
+
function nearestStation(options) {
|
|
69
|
+
const data = (0, _neaps_tide_database.nearest)(options);
|
|
70
|
+
if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);
|
|
71
|
+
return useStation(...data);
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* Find stations near the given position.
|
|
73
75
|
* @param limit Maximum number of stations to return (default: 10)
|
|
74
76
|
*/
|
|
75
|
-
function stationsNear(
|
|
76
|
-
return _neaps_tide_database.
|
|
77
|
-
station,
|
|
78
|
-
distance: (0, geolib.getDistance)(position, station)
|
|
79
|
-
})).sort((a, b) => a.distance - b.distance).slice(0, limit).map(({ station, distance }) => useStation(station, distance));
|
|
77
|
+
function stationsNear(options) {
|
|
78
|
+
return (0, _neaps_tide_database.near)(options).map(([station, distance]) => useStation(station, distance));
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
82
81
|
* Find a specific station by its ID or source ID.
|
|
@@ -85,7 +84,7 @@ function findStation(query) {
|
|
|
85
84
|
const searches = [(s) => s.id === query, (s) => s.source.id === query];
|
|
86
85
|
let found = void 0;
|
|
87
86
|
for (const search of searches) {
|
|
88
|
-
found = _neaps_tide_database.
|
|
87
|
+
found = _neaps_tide_database.stations.find(search);
|
|
89
88
|
if (found) break;
|
|
90
89
|
}
|
|
91
90
|
if (!found) throw new Error(`Station not found: ${query}`);
|
|
@@ -93,7 +92,7 @@ function findStation(query) {
|
|
|
93
92
|
}
|
|
94
93
|
function useStation(station, distance) {
|
|
95
94
|
let reference = station;
|
|
96
|
-
if (station.type === "subordinate") reference = findStation(station.offsets?.reference
|
|
95
|
+
if (station.type === "subordinate" && station.offsets?.reference) reference = findStation(station.offsets?.reference);
|
|
97
96
|
const { datums, harmonic_constituents } = reference;
|
|
98
97
|
const defaultDatum = "MLLW" in datums ? "MLLW" : void 0;
|
|
99
98
|
function getPredictor({ datum = defaultDatum } = {}) {
|
|
@@ -101,14 +100,11 @@ function useStation(station, distance) {
|
|
|
101
100
|
if (datum) {
|
|
102
101
|
const datumOffset = datums?.[datum];
|
|
103
102
|
const mslOffset = datums?.["MSL"];
|
|
104
|
-
if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums
|
|
103
|
+
if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(", ")}`);
|
|
105
104
|
if (typeof mslOffset !== "number") throw new Error(`Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`);
|
|
106
105
|
offset = mslOffset - datumOffset;
|
|
107
106
|
}
|
|
108
|
-
return (0, _neaps_tide_predictor.default)(harmonic_constituents, {
|
|
109
|
-
phaseKey: "phase_UTC",
|
|
110
|
-
offset
|
|
111
|
-
});
|
|
107
|
+
return (0, _neaps_tide_predictor.default)(harmonic_constituents, { offset });
|
|
112
108
|
}
|
|
113
109
|
return {
|
|
114
110
|
...station,
|
|
@@ -116,35 +112,49 @@ function useStation(station, distance) {
|
|
|
116
112
|
datums,
|
|
117
113
|
harmonic_constituents,
|
|
118
114
|
defaultDatum,
|
|
119
|
-
getExtremesPrediction({ datum = defaultDatum, ...
|
|
115
|
+
getExtremesPrediction({ datum = defaultDatum, units = defaultUnits, ...options }) {
|
|
120
116
|
return {
|
|
121
117
|
datum,
|
|
122
|
-
|
|
118
|
+
units,
|
|
123
119
|
station,
|
|
120
|
+
distance,
|
|
124
121
|
extremes: getPredictor({ datum }).getExtremesPrediction({
|
|
125
|
-
...
|
|
122
|
+
...options,
|
|
126
123
|
offsets: station.offsets
|
|
127
|
-
})
|
|
124
|
+
}).map((e) => toPreferredUnits(e, units))
|
|
128
125
|
};
|
|
129
126
|
},
|
|
130
|
-
getTimelinePrediction({ datum = defaultDatum, ...
|
|
127
|
+
getTimelinePrediction({ datum = defaultDatum, units = defaultUnits, ...options }) {
|
|
131
128
|
if (station.type === "subordinate") throw new Error(`Timeline predictions are not supported for subordinate stations.`);
|
|
132
129
|
return {
|
|
133
130
|
datum,
|
|
131
|
+
units,
|
|
134
132
|
station,
|
|
135
|
-
|
|
133
|
+
distance,
|
|
134
|
+
timeline: getPredictor({ datum }).getTimelinePrediction(options).map((e) => toPreferredUnits(e, units))
|
|
136
135
|
};
|
|
137
136
|
},
|
|
138
|
-
getWaterLevelAtTime({ time, datum = defaultDatum }) {
|
|
137
|
+
getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits }) {
|
|
139
138
|
if (station.type === "subordinate") throw new Error(`Water level predictions are not supported for subordinate stations.`);
|
|
140
139
|
return {
|
|
141
140
|
datum,
|
|
141
|
+
units,
|
|
142
142
|
station,
|
|
143
|
-
|
|
143
|
+
distance,
|
|
144
|
+
...toPreferredUnits(getPredictor({ datum }).getWaterLevelAtTime({ time }), units)
|
|
144
145
|
};
|
|
145
146
|
}
|
|
146
147
|
};
|
|
147
148
|
}
|
|
149
|
+
function toPreferredUnits(prediction, units) {
|
|
150
|
+
let { level } = prediction;
|
|
151
|
+
if (units === "feet") level *= feetPerMeter;
|
|
152
|
+
else if (units !== "meters") throw new Error(`Unsupported units: ${units}`);
|
|
153
|
+
return {
|
|
154
|
+
...prediction,
|
|
155
|
+
level
|
|
156
|
+
};
|
|
157
|
+
}
|
|
148
158
|
|
|
149
159
|
//#endregion
|
|
150
160
|
exports.findStation = findStation;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["stations"
|
|
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 tidePredictor, { type TimeSpan, type ExtremesInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to 'MLLW' if available for the nearest station. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimeSpan & 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 MLLW if available\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 MLLW as the default datum if available\n const defaultDatum = \"MLLW\" in datums ? \"MLLW\" : undefined;\n\n function getPredictor({ datum = defaultDatum }: 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 tidePredictor(harmonic_constituents, { offset });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum })\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 ...options\n }: TimelineOptions) {\n if (station.type === \"subordinate\") {\n throw new Error(`Timeline predictions are not supported for subordinate stations.`);\n }\n const timeline = getPredictor({ datum })\n .getTimelinePrediction(options)\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits }: WaterLevelOptions) {\n if (station.type === \"subordinate\") {\n throw new Error(`Water level predictions are not supported for subordinate stations.`);\n }\n\n const prediction = toPreferredUnits(\n getPredictor({ datum }).getWaterLevelAtTime({ time }),\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,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,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AAuB,EAAE,QAAQ,CAAC;;AAGzD,QAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACA,sBAAsB,EACpB,QAAQ,cACR,QAAQ,cACR,GAAG,WACe;AAKlB,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,UAJzB,aAAa,EAAE,OAAO,CAAC,CACrC,sBAAsB;KAAE,GAAG;KAAS,SAAS,QAAQ;KAAS,CAAC,CAC/D,KAAK,MAAM,iBAAiB,GAAG,MAAM,CAAC;IAEW;;EAGtD,sBAAsB,EACpB,QAAQ,cACR,QAAQ,cACR,GAAG,WACe;AAClB,OAAI,QAAQ,SAAS,cACnB,OAAM,IAAI,MAAM,mEAAmE;AAMrF,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,UAJzB,aAAa,EAAE,OAAO,CAAC,CACrC,sBAAsB,QAAQ,CAC9B,KAAK,MAAM,iBAAiB,GAAG,MAAM,CAAC;IAEW;;EAGtD,oBAAoB,EAAE,MAAM,QAAQ,cAAc,QAAQ,gBAAmC;AAC3F,OAAI,QAAQ,SAAS,cACnB,OAAM,IAAI,MAAM,sEAAsE;AAQxF,UAAO;IAAE;IAAO;IAAO;IAAS;IAAU,GALvB,iBACjB,aAAa,EAAE,OAAO,CAAC,CAAC,oBAAoB,EAAE,MAAM,CAAC,EACrD,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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _neaps_tide_database0 from "@neaps/tide-database";
|
|
2
|
+
import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
|
|
2
3
|
import { ExtremesInput, TimeSpan } from "@neaps/tide-predictor";
|
|
3
|
-
import { Station } from "@neaps/tide-database";
|
|
4
|
-
import { GeolibInputCoordinates } from "geolib/es/types";
|
|
5
4
|
|
|
6
5
|
//#region src/index.d.ts
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
datum?: string;
|
|
6
|
+
type Units = "meters" | "feet";
|
|
7
|
+
type PredictionOptions = {
|
|
8
|
+
/** Datum to return predictions in. Defaults to 'MLLW' if available for the nearest station. */datum?: string; /** Units for returned water levels. Defaults to 'meters'. */
|
|
9
|
+
units?: Units;
|
|
10
10
|
};
|
|
11
|
-
type ExtremesOptions = ExtremesInput &
|
|
12
|
-
type TimelineOptions = TimeSpan &
|
|
11
|
+
type ExtremesOptions = ExtremesInput & PredictionOptions;
|
|
12
|
+
type TimelineOptions = TimeSpan & PredictionOptions;
|
|
13
13
|
type WaterLevelOptions = {
|
|
14
14
|
time: Date;
|
|
15
|
-
} &
|
|
15
|
+
} & PredictionOptions;
|
|
16
16
|
/**
|
|
17
17
|
* Get extremes prediction using the nearest station to the given position.
|
|
18
18
|
*
|
|
@@ -28,77 +28,67 @@ type WaterLevelOptions = {
|
|
|
28
28
|
* datum: 'MLLW', // optional, defaults to MLLW if available
|
|
29
29
|
* })
|
|
30
30
|
*/
|
|
31
|
-
declare function getExtremesPrediction(options:
|
|
32
|
-
datum:
|
|
33
|
-
|
|
31
|
+
declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
|
|
32
|
+
datum: any;
|
|
33
|
+
units: any;
|
|
34
34
|
station: Station;
|
|
35
|
-
|
|
35
|
+
distance: number | undefined;
|
|
36
|
+
extremes: any;
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
39
|
* Get timeline prediction using the nearest station to the given position.
|
|
39
40
|
*/
|
|
40
|
-
declare function getTimelinePrediction(options:
|
|
41
|
-
datum:
|
|
41
|
+
declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
|
|
42
|
+
datum: any;
|
|
43
|
+
units: any;
|
|
42
44
|
station: Station;
|
|
43
|
-
|
|
45
|
+
distance: number | undefined;
|
|
46
|
+
timeline: any;
|
|
44
47
|
};
|
|
45
48
|
/**
|
|
46
49
|
* Get water level at a specific time using the nearest station to the given position.
|
|
47
50
|
*/
|
|
48
|
-
declare function getWaterLevelAtTime(options:
|
|
49
|
-
time: Date;
|
|
50
|
-
hour: number;
|
|
51
|
-
level: number;
|
|
52
|
-
datum: string | undefined;
|
|
53
|
-
station: Station;
|
|
54
|
-
};
|
|
51
|
+
declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
|
|
55
52
|
/**
|
|
56
53
|
* Find the nearest station to the given position.
|
|
57
54
|
*/
|
|
58
|
-
declare function nearestStation(
|
|
55
|
+
declare function nearestStation(options: NearestOptions): {
|
|
59
56
|
distance: number | undefined;
|
|
60
57
|
datums: Record<string, number>;
|
|
61
|
-
harmonic_constituents:
|
|
62
|
-
name: string;
|
|
63
|
-
description?: string;
|
|
64
|
-
amplitude: number;
|
|
65
|
-
phase_UTC: number;
|
|
66
|
-
phase_local: number;
|
|
67
|
-
speed?: number;
|
|
68
|
-
}[];
|
|
58
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
69
59
|
defaultDatum: string | undefined;
|
|
70
60
|
getExtremesPrediction({
|
|
71
61
|
datum,
|
|
72
|
-
|
|
62
|
+
units,
|
|
63
|
+
...options
|
|
73
64
|
}: ExtremesOptions): {
|
|
74
|
-
datum:
|
|
75
|
-
|
|
65
|
+
datum: any;
|
|
66
|
+
units: any;
|
|
76
67
|
station: Station;
|
|
77
|
-
|
|
68
|
+
distance: number | undefined;
|
|
69
|
+
extremes: any;
|
|
78
70
|
};
|
|
79
71
|
getTimelinePrediction({
|
|
80
72
|
datum,
|
|
81
|
-
|
|
73
|
+
units,
|
|
74
|
+
...options
|
|
82
75
|
}: TimelineOptions): {
|
|
83
|
-
datum:
|
|
76
|
+
datum: any;
|
|
77
|
+
units: any;
|
|
84
78
|
station: Station;
|
|
85
|
-
|
|
79
|
+
distance: number | undefined;
|
|
80
|
+
timeline: any;
|
|
86
81
|
};
|
|
87
82
|
getWaterLevelAtTime({
|
|
88
83
|
time,
|
|
89
|
-
datum
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
hour: number;
|
|
93
|
-
level: number;
|
|
94
|
-
datum: string | undefined;
|
|
95
|
-
station: Station;
|
|
96
|
-
};
|
|
84
|
+
datum,
|
|
85
|
+
units
|
|
86
|
+
}: WaterLevelOptions): any;
|
|
97
87
|
id: string;
|
|
98
88
|
name: string;
|
|
99
89
|
continent: string;
|
|
100
90
|
country: string;
|
|
101
|
-
region
|
|
91
|
+
region?: string;
|
|
102
92
|
timezone: string;
|
|
103
93
|
disclaimers: string;
|
|
104
94
|
type: "reference" | "subordinate";
|
|
@@ -109,7 +99,6 @@ declare function nearestStation(position: GeolibInputCoordinates): {
|
|
|
109
99
|
id: string;
|
|
110
100
|
published_harmonics: boolean;
|
|
111
101
|
url: string;
|
|
112
|
-
source_url: string;
|
|
113
102
|
};
|
|
114
103
|
license: {
|
|
115
104
|
type: string;
|
|
@@ -134,50 +123,43 @@ declare function nearestStation(position: GeolibInputCoordinates): {
|
|
|
134
123
|
* Find stations near the given position.
|
|
135
124
|
* @param limit Maximum number of stations to return (default: 10)
|
|
136
125
|
*/
|
|
137
|
-
declare function stationsNear(
|
|
126
|
+
declare function stationsNear(options: NearOptions): {
|
|
138
127
|
distance: number | undefined;
|
|
139
128
|
datums: Record<string, number>;
|
|
140
|
-
harmonic_constituents:
|
|
141
|
-
name: string;
|
|
142
|
-
description?: string;
|
|
143
|
-
amplitude: number;
|
|
144
|
-
phase_UTC: number;
|
|
145
|
-
phase_local: number;
|
|
146
|
-
speed?: number;
|
|
147
|
-
}[];
|
|
129
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
148
130
|
defaultDatum: string | undefined;
|
|
149
131
|
getExtremesPrediction({
|
|
150
132
|
datum,
|
|
151
|
-
|
|
133
|
+
units,
|
|
134
|
+
...options
|
|
152
135
|
}: ExtremesOptions): {
|
|
153
|
-
datum:
|
|
154
|
-
|
|
136
|
+
datum: any;
|
|
137
|
+
units: any;
|
|
155
138
|
station: Station;
|
|
156
|
-
|
|
139
|
+
distance: number | undefined;
|
|
140
|
+
extremes: any;
|
|
157
141
|
};
|
|
158
142
|
getTimelinePrediction({
|
|
159
143
|
datum,
|
|
160
|
-
|
|
144
|
+
units,
|
|
145
|
+
...options
|
|
161
146
|
}: TimelineOptions): {
|
|
162
|
-
datum:
|
|
147
|
+
datum: any;
|
|
148
|
+
units: any;
|
|
163
149
|
station: Station;
|
|
164
|
-
|
|
150
|
+
distance: number | undefined;
|
|
151
|
+
timeline: any;
|
|
165
152
|
};
|
|
166
153
|
getWaterLevelAtTime({
|
|
167
154
|
time,
|
|
168
|
-
datum
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
hour: number;
|
|
172
|
-
level: number;
|
|
173
|
-
datum: string | undefined;
|
|
174
|
-
station: Station;
|
|
175
|
-
};
|
|
155
|
+
datum,
|
|
156
|
+
units
|
|
157
|
+
}: WaterLevelOptions): any;
|
|
176
158
|
id: string;
|
|
177
159
|
name: string;
|
|
178
160
|
continent: string;
|
|
179
161
|
country: string;
|
|
180
|
-
region
|
|
162
|
+
region?: string;
|
|
181
163
|
timezone: string;
|
|
182
164
|
disclaimers: string;
|
|
183
165
|
type: "reference" | "subordinate";
|
|
@@ -188,7 +170,6 @@ declare function stationsNear(position: GeolibInputCoordinates, limit?: number):
|
|
|
188
170
|
id: string;
|
|
189
171
|
published_harmonics: boolean;
|
|
190
172
|
url: string;
|
|
191
|
-
source_url: string;
|
|
192
173
|
};
|
|
193
174
|
license: {
|
|
194
175
|
type: string;
|
|
@@ -215,47 +196,40 @@ declare function stationsNear(position: GeolibInputCoordinates, limit?: number):
|
|
|
215
196
|
declare function findStation(query: string): {
|
|
216
197
|
distance: number | undefined;
|
|
217
198
|
datums: Record<string, number>;
|
|
218
|
-
harmonic_constituents:
|
|
219
|
-
name: string;
|
|
220
|
-
description?: string;
|
|
221
|
-
amplitude: number;
|
|
222
|
-
phase_UTC: number;
|
|
223
|
-
phase_local: number;
|
|
224
|
-
speed?: number;
|
|
225
|
-
}[];
|
|
199
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
226
200
|
defaultDatum: string | undefined;
|
|
227
201
|
getExtremesPrediction({
|
|
228
202
|
datum,
|
|
229
|
-
|
|
203
|
+
units,
|
|
204
|
+
...options
|
|
230
205
|
}: ExtremesOptions): {
|
|
231
|
-
datum:
|
|
232
|
-
|
|
206
|
+
datum: any;
|
|
207
|
+
units: any;
|
|
233
208
|
station: Station;
|
|
234
|
-
|
|
209
|
+
distance: number | undefined;
|
|
210
|
+
extremes: any;
|
|
235
211
|
};
|
|
236
212
|
getTimelinePrediction({
|
|
237
213
|
datum,
|
|
238
|
-
|
|
214
|
+
units,
|
|
215
|
+
...options
|
|
239
216
|
}: TimelineOptions): {
|
|
240
|
-
datum:
|
|
217
|
+
datum: any;
|
|
218
|
+
units: any;
|
|
241
219
|
station: Station;
|
|
242
|
-
|
|
220
|
+
distance: number | undefined;
|
|
221
|
+
timeline: any;
|
|
243
222
|
};
|
|
244
223
|
getWaterLevelAtTime({
|
|
245
224
|
time,
|
|
246
|
-
datum
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
hour: number;
|
|
250
|
-
level: number;
|
|
251
|
-
datum: string | undefined;
|
|
252
|
-
station: Station;
|
|
253
|
-
};
|
|
225
|
+
datum,
|
|
226
|
+
units
|
|
227
|
+
}: WaterLevelOptions): any;
|
|
254
228
|
id: string;
|
|
255
229
|
name: string;
|
|
256
230
|
continent: string;
|
|
257
231
|
country: string;
|
|
258
|
-
region
|
|
232
|
+
region?: string;
|
|
259
233
|
timezone: string;
|
|
260
234
|
disclaimers: string;
|
|
261
235
|
type: "reference" | "subordinate";
|
|
@@ -266,7 +240,6 @@ declare function findStation(query: string): {
|
|
|
266
240
|
id: string;
|
|
267
241
|
published_harmonics: boolean;
|
|
268
242
|
url: string;
|
|
269
|
-
source_url: string;
|
|
270
243
|
};
|
|
271
244
|
license: {
|
|
272
245
|
type: string;
|
|
@@ -290,47 +263,40 @@ declare function findStation(query: string): {
|
|
|
290
263
|
declare function useStation(station: Station, distance?: number): {
|
|
291
264
|
distance: number | undefined;
|
|
292
265
|
datums: Record<string, number>;
|
|
293
|
-
harmonic_constituents:
|
|
294
|
-
name: string;
|
|
295
|
-
description?: string;
|
|
296
|
-
amplitude: number;
|
|
297
|
-
phase_UTC: number;
|
|
298
|
-
phase_local: number;
|
|
299
|
-
speed?: number;
|
|
300
|
-
}[];
|
|
266
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
301
267
|
defaultDatum: string | undefined;
|
|
302
268
|
getExtremesPrediction({
|
|
303
269
|
datum,
|
|
304
|
-
|
|
270
|
+
units,
|
|
271
|
+
...options
|
|
305
272
|
}: ExtremesOptions): {
|
|
306
|
-
datum:
|
|
307
|
-
|
|
273
|
+
datum: any;
|
|
274
|
+
units: any;
|
|
308
275
|
station: Station;
|
|
309
|
-
|
|
276
|
+
distance: number | undefined;
|
|
277
|
+
extremes: any;
|
|
310
278
|
};
|
|
311
279
|
getTimelinePrediction({
|
|
312
280
|
datum,
|
|
313
|
-
|
|
281
|
+
units,
|
|
282
|
+
...options
|
|
314
283
|
}: TimelineOptions): {
|
|
315
|
-
datum:
|
|
284
|
+
datum: any;
|
|
285
|
+
units: any;
|
|
316
286
|
station: Station;
|
|
317
|
-
|
|
287
|
+
distance: number | undefined;
|
|
288
|
+
timeline: any;
|
|
318
289
|
};
|
|
319
290
|
getWaterLevelAtTime({
|
|
320
291
|
time,
|
|
321
|
-
datum
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
hour: number;
|
|
325
|
-
level: number;
|
|
326
|
-
datum: string | undefined;
|
|
327
|
-
station: Station;
|
|
328
|
-
};
|
|
292
|
+
datum,
|
|
293
|
+
units
|
|
294
|
+
}: WaterLevelOptions): any;
|
|
329
295
|
id: string;
|
|
330
296
|
name: string;
|
|
331
297
|
continent: string;
|
|
332
298
|
country: string;
|
|
333
|
-
region
|
|
299
|
+
region?: string;
|
|
334
300
|
timezone: string;
|
|
335
301
|
disclaimers: string;
|
|
336
302
|
type: "reference" | "subordinate";
|
|
@@ -341,7 +307,6 @@ declare function useStation(station: Station, distance?: number): {
|
|
|
341
307
|
id: string;
|
|
342
308
|
published_harmonics: boolean;
|
|
343
309
|
url: string;
|
|
344
|
-
source_url: string;
|
|
345
310
|
};
|
|
346
311
|
license: {
|
|
347
312
|
type: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as _neaps_tide_database0 from "@neaps/tide-database";
|
|
2
|
+
import { NearOptions, NearestOptions, Station } from "@neaps/tide-database";
|
|
3
3
|
import { ExtremesInput, TimeSpan } from "@neaps/tide-predictor";
|
|
4
|
-
import { GeolibInputCoordinates } from "geolib/es/types";
|
|
5
4
|
|
|
6
5
|
//#region src/index.d.ts
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
datum?: string;
|
|
6
|
+
type Units = "meters" | "feet";
|
|
7
|
+
type PredictionOptions = {
|
|
8
|
+
/** Datum to return predictions in. Defaults to 'MLLW' if available for the nearest station. */datum?: string; /** Units for returned water levels. Defaults to 'meters'. */
|
|
9
|
+
units?: Units;
|
|
10
10
|
};
|
|
11
|
-
type ExtremesOptions = ExtremesInput &
|
|
12
|
-
type TimelineOptions = TimeSpan &
|
|
11
|
+
type ExtremesOptions = ExtremesInput & PredictionOptions;
|
|
12
|
+
type TimelineOptions = TimeSpan & PredictionOptions;
|
|
13
13
|
type WaterLevelOptions = {
|
|
14
14
|
time: Date;
|
|
15
|
-
} &
|
|
15
|
+
} & PredictionOptions;
|
|
16
16
|
/**
|
|
17
17
|
* Get extremes prediction using the nearest station to the given position.
|
|
18
18
|
*
|
|
@@ -28,77 +28,67 @@ type WaterLevelOptions = {
|
|
|
28
28
|
* datum: 'MLLW', // optional, defaults to MLLW if available
|
|
29
29
|
* })
|
|
30
30
|
*/
|
|
31
|
-
declare function getExtremesPrediction(options:
|
|
32
|
-
datum:
|
|
33
|
-
|
|
31
|
+
declare function getExtremesPrediction(options: NearestOptions & ExtremesOptions): {
|
|
32
|
+
datum: any;
|
|
33
|
+
units: any;
|
|
34
34
|
station: Station;
|
|
35
|
-
|
|
35
|
+
distance: number | undefined;
|
|
36
|
+
extremes: any;
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
39
|
* Get timeline prediction using the nearest station to the given position.
|
|
39
40
|
*/
|
|
40
|
-
declare function getTimelinePrediction(options:
|
|
41
|
-
datum:
|
|
41
|
+
declare function getTimelinePrediction(options: NearestOptions & TimelineOptions): {
|
|
42
|
+
datum: any;
|
|
43
|
+
units: any;
|
|
42
44
|
station: Station;
|
|
43
|
-
|
|
45
|
+
distance: number | undefined;
|
|
46
|
+
timeline: any;
|
|
44
47
|
};
|
|
45
48
|
/**
|
|
46
49
|
* Get water level at a specific time using the nearest station to the given position.
|
|
47
50
|
*/
|
|
48
|
-
declare function getWaterLevelAtTime(options:
|
|
49
|
-
time: Date;
|
|
50
|
-
hour: number;
|
|
51
|
-
level: number;
|
|
52
|
-
datum: string | undefined;
|
|
53
|
-
station: Station;
|
|
54
|
-
};
|
|
51
|
+
declare function getWaterLevelAtTime(options: NearestOptions & WaterLevelOptions): any;
|
|
55
52
|
/**
|
|
56
53
|
* Find the nearest station to the given position.
|
|
57
54
|
*/
|
|
58
|
-
declare function nearestStation(
|
|
55
|
+
declare function nearestStation(options: NearestOptions): {
|
|
59
56
|
distance: number | undefined;
|
|
60
57
|
datums: Record<string, number>;
|
|
61
|
-
harmonic_constituents:
|
|
62
|
-
name: string;
|
|
63
|
-
description?: string;
|
|
64
|
-
amplitude: number;
|
|
65
|
-
phase_UTC: number;
|
|
66
|
-
phase_local: number;
|
|
67
|
-
speed?: number;
|
|
68
|
-
}[];
|
|
58
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
69
59
|
defaultDatum: string | undefined;
|
|
70
60
|
getExtremesPrediction({
|
|
71
61
|
datum,
|
|
72
|
-
|
|
62
|
+
units,
|
|
63
|
+
...options
|
|
73
64
|
}: ExtremesOptions): {
|
|
74
|
-
datum:
|
|
75
|
-
|
|
65
|
+
datum: any;
|
|
66
|
+
units: any;
|
|
76
67
|
station: Station;
|
|
77
|
-
|
|
68
|
+
distance: number | undefined;
|
|
69
|
+
extremes: any;
|
|
78
70
|
};
|
|
79
71
|
getTimelinePrediction({
|
|
80
72
|
datum,
|
|
81
|
-
|
|
73
|
+
units,
|
|
74
|
+
...options
|
|
82
75
|
}: TimelineOptions): {
|
|
83
|
-
datum:
|
|
76
|
+
datum: any;
|
|
77
|
+
units: any;
|
|
84
78
|
station: Station;
|
|
85
|
-
|
|
79
|
+
distance: number | undefined;
|
|
80
|
+
timeline: any;
|
|
86
81
|
};
|
|
87
82
|
getWaterLevelAtTime({
|
|
88
83
|
time,
|
|
89
|
-
datum
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
hour: number;
|
|
93
|
-
level: number;
|
|
94
|
-
datum: string | undefined;
|
|
95
|
-
station: Station;
|
|
96
|
-
};
|
|
84
|
+
datum,
|
|
85
|
+
units
|
|
86
|
+
}: WaterLevelOptions): any;
|
|
97
87
|
id: string;
|
|
98
88
|
name: string;
|
|
99
89
|
continent: string;
|
|
100
90
|
country: string;
|
|
101
|
-
region
|
|
91
|
+
region?: string;
|
|
102
92
|
timezone: string;
|
|
103
93
|
disclaimers: string;
|
|
104
94
|
type: "reference" | "subordinate";
|
|
@@ -109,7 +99,6 @@ declare function nearestStation(position: GeolibInputCoordinates): {
|
|
|
109
99
|
id: string;
|
|
110
100
|
published_harmonics: boolean;
|
|
111
101
|
url: string;
|
|
112
|
-
source_url: string;
|
|
113
102
|
};
|
|
114
103
|
license: {
|
|
115
104
|
type: string;
|
|
@@ -134,50 +123,43 @@ declare function nearestStation(position: GeolibInputCoordinates): {
|
|
|
134
123
|
* Find stations near the given position.
|
|
135
124
|
* @param limit Maximum number of stations to return (default: 10)
|
|
136
125
|
*/
|
|
137
|
-
declare function stationsNear(
|
|
126
|
+
declare function stationsNear(options: NearOptions): {
|
|
138
127
|
distance: number | undefined;
|
|
139
128
|
datums: Record<string, number>;
|
|
140
|
-
harmonic_constituents:
|
|
141
|
-
name: string;
|
|
142
|
-
description?: string;
|
|
143
|
-
amplitude: number;
|
|
144
|
-
phase_UTC: number;
|
|
145
|
-
phase_local: number;
|
|
146
|
-
speed?: number;
|
|
147
|
-
}[];
|
|
129
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
148
130
|
defaultDatum: string | undefined;
|
|
149
131
|
getExtremesPrediction({
|
|
150
132
|
datum,
|
|
151
|
-
|
|
133
|
+
units,
|
|
134
|
+
...options
|
|
152
135
|
}: ExtremesOptions): {
|
|
153
|
-
datum:
|
|
154
|
-
|
|
136
|
+
datum: any;
|
|
137
|
+
units: any;
|
|
155
138
|
station: Station;
|
|
156
|
-
|
|
139
|
+
distance: number | undefined;
|
|
140
|
+
extremes: any;
|
|
157
141
|
};
|
|
158
142
|
getTimelinePrediction({
|
|
159
143
|
datum,
|
|
160
|
-
|
|
144
|
+
units,
|
|
145
|
+
...options
|
|
161
146
|
}: TimelineOptions): {
|
|
162
|
-
datum:
|
|
147
|
+
datum: any;
|
|
148
|
+
units: any;
|
|
163
149
|
station: Station;
|
|
164
|
-
|
|
150
|
+
distance: number | undefined;
|
|
151
|
+
timeline: any;
|
|
165
152
|
};
|
|
166
153
|
getWaterLevelAtTime({
|
|
167
154
|
time,
|
|
168
|
-
datum
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
hour: number;
|
|
172
|
-
level: number;
|
|
173
|
-
datum: string | undefined;
|
|
174
|
-
station: Station;
|
|
175
|
-
};
|
|
155
|
+
datum,
|
|
156
|
+
units
|
|
157
|
+
}: WaterLevelOptions): any;
|
|
176
158
|
id: string;
|
|
177
159
|
name: string;
|
|
178
160
|
continent: string;
|
|
179
161
|
country: string;
|
|
180
|
-
region
|
|
162
|
+
region?: string;
|
|
181
163
|
timezone: string;
|
|
182
164
|
disclaimers: string;
|
|
183
165
|
type: "reference" | "subordinate";
|
|
@@ -188,7 +170,6 @@ declare function stationsNear(position: GeolibInputCoordinates, limit?: number):
|
|
|
188
170
|
id: string;
|
|
189
171
|
published_harmonics: boolean;
|
|
190
172
|
url: string;
|
|
191
|
-
source_url: string;
|
|
192
173
|
};
|
|
193
174
|
license: {
|
|
194
175
|
type: string;
|
|
@@ -215,47 +196,40 @@ declare function stationsNear(position: GeolibInputCoordinates, limit?: number):
|
|
|
215
196
|
declare function findStation(query: string): {
|
|
216
197
|
distance: number | undefined;
|
|
217
198
|
datums: Record<string, number>;
|
|
218
|
-
harmonic_constituents:
|
|
219
|
-
name: string;
|
|
220
|
-
description?: string;
|
|
221
|
-
amplitude: number;
|
|
222
|
-
phase_UTC: number;
|
|
223
|
-
phase_local: number;
|
|
224
|
-
speed?: number;
|
|
225
|
-
}[];
|
|
199
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
226
200
|
defaultDatum: string | undefined;
|
|
227
201
|
getExtremesPrediction({
|
|
228
202
|
datum,
|
|
229
|
-
|
|
203
|
+
units,
|
|
204
|
+
...options
|
|
230
205
|
}: ExtremesOptions): {
|
|
231
|
-
datum:
|
|
232
|
-
|
|
206
|
+
datum: any;
|
|
207
|
+
units: any;
|
|
233
208
|
station: Station;
|
|
234
|
-
|
|
209
|
+
distance: number | undefined;
|
|
210
|
+
extremes: any;
|
|
235
211
|
};
|
|
236
212
|
getTimelinePrediction({
|
|
237
213
|
datum,
|
|
238
|
-
|
|
214
|
+
units,
|
|
215
|
+
...options
|
|
239
216
|
}: TimelineOptions): {
|
|
240
|
-
datum:
|
|
217
|
+
datum: any;
|
|
218
|
+
units: any;
|
|
241
219
|
station: Station;
|
|
242
|
-
|
|
220
|
+
distance: number | undefined;
|
|
221
|
+
timeline: any;
|
|
243
222
|
};
|
|
244
223
|
getWaterLevelAtTime({
|
|
245
224
|
time,
|
|
246
|
-
datum
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
hour: number;
|
|
250
|
-
level: number;
|
|
251
|
-
datum: string | undefined;
|
|
252
|
-
station: Station;
|
|
253
|
-
};
|
|
225
|
+
datum,
|
|
226
|
+
units
|
|
227
|
+
}: WaterLevelOptions): any;
|
|
254
228
|
id: string;
|
|
255
229
|
name: string;
|
|
256
230
|
continent: string;
|
|
257
231
|
country: string;
|
|
258
|
-
region
|
|
232
|
+
region?: string;
|
|
259
233
|
timezone: string;
|
|
260
234
|
disclaimers: string;
|
|
261
235
|
type: "reference" | "subordinate";
|
|
@@ -266,7 +240,6 @@ declare function findStation(query: string): {
|
|
|
266
240
|
id: string;
|
|
267
241
|
published_harmonics: boolean;
|
|
268
242
|
url: string;
|
|
269
|
-
source_url: string;
|
|
270
243
|
};
|
|
271
244
|
license: {
|
|
272
245
|
type: string;
|
|
@@ -290,47 +263,40 @@ declare function findStation(query: string): {
|
|
|
290
263
|
declare function useStation(station: Station, distance?: number): {
|
|
291
264
|
distance: number | undefined;
|
|
292
265
|
datums: Record<string, number>;
|
|
293
|
-
harmonic_constituents:
|
|
294
|
-
name: string;
|
|
295
|
-
description?: string;
|
|
296
|
-
amplitude: number;
|
|
297
|
-
phase_UTC: number;
|
|
298
|
-
phase_local: number;
|
|
299
|
-
speed?: number;
|
|
300
|
-
}[];
|
|
266
|
+
harmonic_constituents: _neaps_tide_database0.HarmonicConstituent[];
|
|
301
267
|
defaultDatum: string | undefined;
|
|
302
268
|
getExtremesPrediction({
|
|
303
269
|
datum,
|
|
304
|
-
|
|
270
|
+
units,
|
|
271
|
+
...options
|
|
305
272
|
}: ExtremesOptions): {
|
|
306
|
-
datum:
|
|
307
|
-
|
|
273
|
+
datum: any;
|
|
274
|
+
units: any;
|
|
308
275
|
station: Station;
|
|
309
|
-
|
|
276
|
+
distance: number | undefined;
|
|
277
|
+
extremes: any;
|
|
310
278
|
};
|
|
311
279
|
getTimelinePrediction({
|
|
312
280
|
datum,
|
|
313
|
-
|
|
281
|
+
units,
|
|
282
|
+
...options
|
|
314
283
|
}: TimelineOptions): {
|
|
315
|
-
datum:
|
|
284
|
+
datum: any;
|
|
285
|
+
units: any;
|
|
316
286
|
station: Station;
|
|
317
|
-
|
|
287
|
+
distance: number | undefined;
|
|
288
|
+
timeline: any;
|
|
318
289
|
};
|
|
319
290
|
getWaterLevelAtTime({
|
|
320
291
|
time,
|
|
321
|
-
datum
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
hour: number;
|
|
325
|
-
level: number;
|
|
326
|
-
datum: string | undefined;
|
|
327
|
-
station: Station;
|
|
328
|
-
};
|
|
292
|
+
datum,
|
|
293
|
+
units
|
|
294
|
+
}: WaterLevelOptions): any;
|
|
329
295
|
id: string;
|
|
330
296
|
name: string;
|
|
331
297
|
continent: string;
|
|
332
298
|
country: string;
|
|
333
|
-
region
|
|
299
|
+
region?: string;
|
|
334
300
|
timezone: string;
|
|
335
301
|
disclaimers: string;
|
|
336
302
|
type: "reference" | "subordinate";
|
|
@@ -341,7 +307,6 @@ declare function useStation(station: Station, distance?: number): {
|
|
|
341
307
|
id: string;
|
|
342
308
|
published_harmonics: boolean;
|
|
343
309
|
url: string;
|
|
344
|
-
source_url: string;
|
|
345
310
|
};
|
|
346
311
|
license: {
|
|
347
312
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import stations from "@neaps/tide-database";
|
|
1
|
+
import { near, nearest, stations } from "@neaps/tide-database";
|
|
3
2
|
import tidePredictor from "@neaps/tide-predictor";
|
|
4
3
|
|
|
5
4
|
//#region src/index.ts
|
|
5
|
+
const feetPerMeter = 3.2808399;
|
|
6
|
+
const defaultUnits = "meters";
|
|
6
7
|
/**
|
|
7
8
|
* Get extremes prediction using the nearest station to the given position.
|
|
8
9
|
*
|
|
@@ -36,18 +37,17 @@ function getWaterLevelAtTime(options) {
|
|
|
36
37
|
/**
|
|
37
38
|
* Find the nearest station to the given position.
|
|
38
39
|
*/
|
|
39
|
-
function nearestStation(
|
|
40
|
-
|
|
40
|
+
function nearestStation(options) {
|
|
41
|
+
const data = nearest(options);
|
|
42
|
+
if (!data) throw new Error(`No stations found with options: ${JSON.stringify(options)}`);
|
|
43
|
+
return useStation(...data);
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Find stations near the given position.
|
|
44
47
|
* @param limit Maximum number of stations to return (default: 10)
|
|
45
48
|
*/
|
|
46
|
-
function stationsNear(
|
|
47
|
-
return
|
|
48
|
-
station,
|
|
49
|
-
distance: getDistance(position, station)
|
|
50
|
-
})).sort((a, b) => a.distance - b.distance).slice(0, limit).map(({ station, distance }) => useStation(station, distance));
|
|
49
|
+
function stationsNear(options) {
|
|
50
|
+
return near(options).map(([station, distance]) => useStation(station, distance));
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Find a specific station by its ID or source ID.
|
|
@@ -64,7 +64,7 @@ function findStation(query) {
|
|
|
64
64
|
}
|
|
65
65
|
function useStation(station, distance) {
|
|
66
66
|
let reference = station;
|
|
67
|
-
if (station.type === "subordinate") reference = findStation(station.offsets?.reference
|
|
67
|
+
if (station.type === "subordinate" && station.offsets?.reference) reference = findStation(station.offsets?.reference);
|
|
68
68
|
const { datums, harmonic_constituents } = reference;
|
|
69
69
|
const defaultDatum = "MLLW" in datums ? "MLLW" : void 0;
|
|
70
70
|
function getPredictor({ datum = defaultDatum } = {}) {
|
|
@@ -72,14 +72,11 @@ function useStation(station, distance) {
|
|
|
72
72
|
if (datum) {
|
|
73
73
|
const datumOffset = datums?.[datum];
|
|
74
74
|
const mslOffset = datums?.["MSL"];
|
|
75
|
-
if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums
|
|
75
|
+
if (typeof datumOffset !== "number") throw new Error(`Station ${station.id} missing ${datum} datum. Available datums: ${Object.keys(datums).join(", ")}`);
|
|
76
76
|
if (typeof mslOffset !== "number") throw new Error(`Station ${station.id} missing MSL datum, so predictions can't be given in ${datum}.`);
|
|
77
77
|
offset = mslOffset - datumOffset;
|
|
78
78
|
}
|
|
79
|
-
return tidePredictor(harmonic_constituents, {
|
|
80
|
-
phaseKey: "phase_UTC",
|
|
81
|
-
offset
|
|
82
|
-
});
|
|
79
|
+
return tidePredictor(harmonic_constituents, { offset });
|
|
83
80
|
}
|
|
84
81
|
return {
|
|
85
82
|
...station,
|
|
@@ -87,35 +84,49 @@ function useStation(station, distance) {
|
|
|
87
84
|
datums,
|
|
88
85
|
harmonic_constituents,
|
|
89
86
|
defaultDatum,
|
|
90
|
-
getExtremesPrediction({ datum = defaultDatum, ...
|
|
87
|
+
getExtremesPrediction({ datum = defaultDatum, units = defaultUnits, ...options }) {
|
|
91
88
|
return {
|
|
92
89
|
datum,
|
|
93
|
-
|
|
90
|
+
units,
|
|
94
91
|
station,
|
|
92
|
+
distance,
|
|
95
93
|
extremes: getPredictor({ datum }).getExtremesPrediction({
|
|
96
|
-
...
|
|
94
|
+
...options,
|
|
97
95
|
offsets: station.offsets
|
|
98
|
-
})
|
|
96
|
+
}).map((e) => toPreferredUnits(e, units))
|
|
99
97
|
};
|
|
100
98
|
},
|
|
101
|
-
getTimelinePrediction({ datum = defaultDatum, ...
|
|
99
|
+
getTimelinePrediction({ datum = defaultDatum, units = defaultUnits, ...options }) {
|
|
102
100
|
if (station.type === "subordinate") throw new Error(`Timeline predictions are not supported for subordinate stations.`);
|
|
103
101
|
return {
|
|
104
102
|
datum,
|
|
103
|
+
units,
|
|
105
104
|
station,
|
|
106
|
-
|
|
105
|
+
distance,
|
|
106
|
+
timeline: getPredictor({ datum }).getTimelinePrediction(options).map((e) => toPreferredUnits(e, units))
|
|
107
107
|
};
|
|
108
108
|
},
|
|
109
|
-
getWaterLevelAtTime({ time, datum = defaultDatum }) {
|
|
109
|
+
getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits }) {
|
|
110
110
|
if (station.type === "subordinate") throw new Error(`Water level predictions are not supported for subordinate stations.`);
|
|
111
111
|
return {
|
|
112
112
|
datum,
|
|
113
|
+
units,
|
|
113
114
|
station,
|
|
114
|
-
|
|
115
|
+
distance,
|
|
116
|
+
...toPreferredUnits(getPredictor({ datum }).getWaterLevelAtTime({ time }), units)
|
|
115
117
|
};
|
|
116
118
|
}
|
|
117
119
|
};
|
|
118
120
|
}
|
|
121
|
+
function toPreferredUnits(prediction, units) {
|
|
122
|
+
let { level } = prediction;
|
|
123
|
+
if (units === "feet") level *= feetPerMeter;
|
|
124
|
+
else if (units !== "meters") throw new Error(`Unsupported units: ${units}`);
|
|
125
|
+
return {
|
|
126
|
+
...prediction,
|
|
127
|
+
level
|
|
128
|
+
};
|
|
129
|
+
}
|
|
119
130
|
|
|
120
131
|
//#endregion
|
|
121
132
|
export { findStation, getExtremesPrediction, getTimelinePrediction, getWaterLevelAtTime, nearestStation, stationsNear, useStation };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
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 tidePredictor, { type TimeSpan, type ExtremesInput } from \"@neaps/tide-predictor\";\n\ntype Units = \"meters\" | \"feet\";\ntype PredictionOptions = {\n /** Datum to return predictions in. Defaults to 'MLLW' if available for the nearest station. */\n datum?: string;\n\n /** Units for returned water levels. Defaults to 'meters'. */\n units?: Units;\n};\n\nexport type ExtremesOptions = ExtremesInput & PredictionOptions;\nexport type TimelineOptions = TimeSpan & 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 MLLW if available\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 MLLW as the default datum if available\n const defaultDatum = \"MLLW\" in datums ? \"MLLW\" : undefined;\n\n function getPredictor({ datum = defaultDatum }: 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 tidePredictor(harmonic_constituents, { offset });\n }\n\n return {\n ...station,\n distance,\n datums,\n harmonic_constituents,\n defaultDatum,\n getExtremesPrediction({\n datum = defaultDatum,\n units = defaultUnits,\n ...options\n }: ExtremesOptions) {\n const extremes = getPredictor({ datum })\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 ...options\n }: TimelineOptions) {\n if (station.type === \"subordinate\") {\n throw new Error(`Timeline predictions are not supported for subordinate stations.`);\n }\n const timeline = getPredictor({ datum })\n .getTimelinePrediction(options)\n .map((e) => toPreferredUnits(e, units));\n\n return { datum, units, station, distance, timeline };\n },\n\n getWaterLevelAtTime({ time, datum = defaultDatum, units = defaultUnits }: WaterLevelOptions) {\n if (station.type === \"subordinate\") {\n throw new Error(`Water level predictions are not supported for subordinate stations.`);\n }\n\n const prediction = toPreferredUnits(\n getPredictor({ datum }).getWaterLevelAtTime({ time }),\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":";;;;AAuBA,MAAM,eAAe;AACrB,MAAM,eAAsB;;;;;;;;;;;;;;;;AAiB5B,SAAgB,sBAAsB,SAA2C;AAC/E,QAAO,e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|
"name": "neaps",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Tide predictions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tides",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"prepack": "npm run build"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@neaps/tide-
|
|
38
|
-
"@neaps/tide-
|
|
39
|
-
"geolib": "^3.3.4"
|
|
37
|
+
"@neaps/tide-database": "0.3",
|
|
38
|
+
"@neaps/tide-predictor": "^0.5.0"
|
|
40
39
|
}
|
|
41
40
|
}
|