snow-forecast-sfr
Version:
An NPM module that scrapes snow-forecast for the relevant resort and returns its information.
49 lines (48 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const pRoundTo = function (multiple, value) {
const rem = Math.round(value % multiple);
if (rem <= multiple / 2) {
return Math.round(value - rem);
}
else {
return Math.round(value + multiple - rem);
}
};
const UnitUtil = {
TO_MPH: 1.609344,
TO_KPH: 0.62137,
TO_CM: 0.3937,
TO_IN: 2.54,
TO_FT: 3.2808399,
TO_M: 0.3048,
speedToMetric(speed) {
const kph = speed / this.TO_KPH;
return Math.round(kph);
},
speedToImperial(speed) {
const mph = speed / this.TO_MPH;
return pRoundTo(5, Math.round(mph));
},
distanceToMetric(distance) {
return pRoundTo(50, Math.round(distance * this.TO_M));
},
distanceToImperial(distance) {
return pRoundTo(100, Math.round(distance * this.TO_FT));
},
volumeToMetric(volume) {
return Math.round((volume / this.TO_CM) * 10) / 10;
},
volumeToImperial(volume) {
return Math.round((volume / this.TO_IN) * 10) / 10;
},
temperatureToMetric(temp) {
const temperature = ((temp - 32) * 5) / 9;
return pRoundTo(1, Math.round(temperature));
},
temperatureToImperial(temp) {
const temperature = (temp * 9) / 5 + 32;
return pRoundTo(1, Math.round(temperature));
},
};
exports.default = UnitUtil;