signalk-tides
Version:
Tidal predictions for the vessel's position from various online sources.
40 lines (39 loc) • 1.34 kB
JavaScript
import { getExtremesPrediction } from "neaps";
import moment from 'moment';
export default function (app) {
return {
id: 'neaps',
title: 'Neaps',
properties: {},
start() {
app.debug("Using Neaps");
return async ({ position, date = moment().subtract(1, "days").toISOString() }) => {
const { station, extremes } = getExtremesPrediction({
...position,
start: new Date(date),
end: moment(date).add(7, "days").toDate(),
labels: {
high: "High",
low: "Low"
}
});
return {
station: {
name: station.name,
position: {
latitude: station.latitude,
longitude: station.longitude,
},
},
extremes: extremes.map(({ time, level, label }) => {
return {
type: label,
value: level,
time: time.toISOString(),
};
}),
};
};
}
};
}