2020-09-04 18:02:20 +00:00
|
|
|
'use strict';
|
2020-09-08 20:56:12 +00:00
|
|
|
/* spell-checker: disable */
|
2020-09-04 18:02:20 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const icons = (() => {
|
|
|
|
|
|
|
|
const getWeatherRegionalIconFromIconLink = (link, isNightTime) => {
|
2020-09-08 20:56:12 +00:00
|
|
|
// extract day or night if not provided
|
2020-09-04 18:02:20 +00:00
|
|
|
if (isNightTime === undefined) isNightTime = link.indexOf('/night/') >=0;
|
2020-09-08 20:56:12 +00:00
|
|
|
// internal function to add path to returned icon
|
|
|
|
const addPath = (icon) => `images/r/${icon}`;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
|
|
|
// grab everything after the last slash ending at any of these: ?&,
|
|
|
|
const afterLastSlash = link.toLowerCase().match(/[^/]+$/)[0];
|
|
|
|
let conditionName = afterLastSlash.match(/(.*?)[,?&.]/)[1];
|
|
|
|
|
|
|
|
// if a 'DualImage' is captured, adjust to just the j parameter
|
|
|
|
if (conditionName === 'dualimage') {
|
|
|
|
const match = link.match(/&j=(.*)&/);
|
|
|
|
conditionName = match[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// find the icon
|
|
|
|
switch (conditionName + (isNightTime?'-n':'')) {
|
|
|
|
case 'skc':
|
|
|
|
case 'hot':
|
|
|
|
case 'haze':
|
|
|
|
return addPath('Sunny.gif');
|
|
|
|
|
|
|
|
case 'skc-n':
|
|
|
|
case 'nskc':
|
|
|
|
case 'nskc-n':
|
|
|
|
return addPath('Clear-1992.gif');
|
|
|
|
|
|
|
|
case 'bkn':
|
|
|
|
return addPath('Mostly-Cloudy-1994-2.gif');
|
|
|
|
|
|
|
|
case 'bkn-n':
|
|
|
|
case 'few-n':
|
|
|
|
case 'nfew-n':
|
|
|
|
case 'nfew':
|
|
|
|
return addPath('Partly-Clear-1994-2.gif');
|
|
|
|
|
|
|
|
case 'sct':
|
|
|
|
case 'few':
|
|
|
|
return addPath('Partly-Cloudy.gif');
|
|
|
|
|
|
|
|
case 'sct-n':
|
|
|
|
case 'nsct':
|
|
|
|
case 'nsct-n':
|
|
|
|
return addPath('Mostly-Clear.gif');
|
|
|
|
|
|
|
|
case 'ovc':
|
2020-09-09 01:07:09 +00:00
|
|
|
case 'ovc-n':
|
2020-09-04 18:02:20 +00:00
|
|
|
return addPath('Cloudy.gif');
|
|
|
|
|
|
|
|
case 'fog':
|
2020-09-09 20:23:19 +00:00
|
|
|
case 'fog-n':
|
2020-09-04 18:02:20 +00:00
|
|
|
return addPath('Fog.gif');
|
|
|
|
|
|
|
|
case 'rain_sleet':
|
|
|
|
return addPath('Sleet.gif');
|
|
|
|
|
|
|
|
case 'rain_showers':
|
|
|
|
case 'rain_showers_high':
|
|
|
|
return addPath('Scattered-Showers-1994-2.gif');
|
|
|
|
|
|
|
|
case 'rain_showers-n':
|
|
|
|
case 'rain_showers_high-n':
|
|
|
|
return addPath('Scattered-Showers-Night-1994-2.gif');
|
|
|
|
|
|
|
|
case 'rain':
|
|
|
|
return addPath('Rain-1992.gif');
|
|
|
|
|
|
|
|
// case 'snow':
|
|
|
|
// return addPath('Light-Snow.gif');
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// case 'cc_snowshowers.gif':
|
|
|
|
// //case "heavy-snow.gif":
|
|
|
|
// return addPath('AM-Snow-1994.gif');
|
|
|
|
// break;
|
|
|
|
|
|
|
|
case 'snow':
|
|
|
|
return addPath('Heavy-Snow-1994-2.gif');
|
|
|
|
|
|
|
|
case 'rain_snow':
|
|
|
|
return addPath('Rain-Snow-1992.gif');
|
|
|
|
|
|
|
|
case 'snow_fzra':
|
|
|
|
return addPath('Freezing-Rain-Snow-1992.gif');
|
|
|
|
|
|
|
|
case 'fzra':
|
|
|
|
return addPath('Freezing-Rain-1992.gif');
|
|
|
|
|
|
|
|
case 'snow_sleet':
|
|
|
|
return addPath('Wintry-Mix-1992.gif');
|
|
|
|
|
|
|
|
case 'tsra_sct':
|
|
|
|
case 'tsra':
|
|
|
|
return addPath('Scattered-Tstorms-1994-2.gif');
|
|
|
|
|
|
|
|
case 'tsra_sct-n':
|
|
|
|
case 'tsra-n':
|
|
|
|
return addPath('Scattered-Tstorms-Night-1994-2.gif');
|
|
|
|
|
|
|
|
case 'tsra_hi':
|
|
|
|
case 'tsra_hi-n':
|
|
|
|
case 'hurricane':
|
|
|
|
return addPath('Thunderstorm.gif');
|
|
|
|
|
|
|
|
case 'wind_few':
|
|
|
|
case 'wind_sct':
|
|
|
|
case 'wind_bkn':
|
|
|
|
case 'wind_ovc':
|
|
|
|
return addPath('Wind.gif');
|
|
|
|
|
|
|
|
case 'wind_skc':
|
|
|
|
return addPath('Sunny-Wind-1994.gif');
|
|
|
|
|
|
|
|
case 'wind_skc-n':
|
|
|
|
return addPath('Clear-Wind-1994.gif');
|
|
|
|
|
|
|
|
case 'blizzard':
|
|
|
|
return addPath('Blowing Snow.gif');
|
|
|
|
|
|
|
|
default:
|
2020-09-09 20:23:19 +00:00
|
|
|
console.log(`Unable to locate regional icon for ${conditionName} ${link} ${isNightTime}`);
|
2020-09-04 18:02:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
const getWeatherIconFromIconLink = function (link, isNightTime = false) {
|
|
|
|
// internal function to add path to returned icon
|
|
|
|
const addPath = (icon) => `images/${icon}`;
|
|
|
|
// extract day or night if not provided
|
|
|
|
if (isNightTime === undefined) isNightTime = link.indexOf('/night/') >=0;
|
|
|
|
|
|
|
|
// grab everything after the last slash ending at any of these: ?&,
|
2020-09-04 18:02:20 +00:00
|
|
|
const afterLastSlash = link.toLowerCase().match(/[^/]+$/)[0];
|
|
|
|
let conditionName = afterLastSlash.match(/(.*?)[,?&.]/)[1];
|
|
|
|
|
|
|
|
// if a 'DualImage' is captured, adjust to just the j parameter
|
|
|
|
if (conditionName === 'dualimage') {
|
|
|
|
const match = link.match(/&j=(.*)&/);
|
|
|
|
conditionName = match[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// find the icon
|
2020-09-08 20:56:12 +00:00
|
|
|
switch (conditionName + (isNightTime?'-n':'')) {
|
2020-09-04 18:02:20 +00:00
|
|
|
case 'skc':
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'hot':
|
|
|
|
case 'haze':
|
|
|
|
return addPath('CC_Clear1.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
|
|
|
case 'skc-n':
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'nskc':
|
|
|
|
case 'nskc-n':
|
|
|
|
return addPath('CC_Clear0.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'sct':
|
|
|
|
case 'few':
|
|
|
|
case 'bkn':
|
|
|
|
return addPath('CC_PartlyCloudy1.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'bkn-n':
|
|
|
|
case 'few-n':
|
|
|
|
case 'nfew-n':
|
|
|
|
case 'nfew':
|
|
|
|
case 'sct-n':
|
|
|
|
case 'nsct':
|
|
|
|
case 'nsct-n':
|
|
|
|
return addPath('CC_PartlyCloudy0.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'ovc':
|
|
|
|
case 'novc':
|
|
|
|
case 'ovc-n':
|
|
|
|
return addPath('CC_Cloudy.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'fog':
|
|
|
|
return addPath('CC_Fog.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'rain_sleet':
|
2020-09-04 18:02:20 +00:00
|
|
|
return addPath('Sleet.gif');
|
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'rain_showers':
|
|
|
|
case 'rain_showers_high':
|
|
|
|
return addPath('CC_Showers.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'rain_showers-n':
|
|
|
|
case 'rain_showers_high-n':
|
|
|
|
return addPath('CC_Showers.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'rain':
|
|
|
|
return addPath('CC_Rain.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
// case 'snow':
|
|
|
|
// return addPath('Light-Snow.gif');
|
|
|
|
// break;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
// case 'cc_snowshowers.gif':
|
|
|
|
// //case "heavy-snow.gif":
|
|
|
|
// return addPath('AM-Snow-1994.gif');
|
|
|
|
// break;
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'snow':
|
|
|
|
return addPath('CC_Snow.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'rain_snow':
|
|
|
|
return addPath('CC_RainSnow.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'snow_fzra':
|
|
|
|
case 'fzra':
|
|
|
|
return addPath('CC_FreezingRain.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'snow_sleet':
|
|
|
|
return addPath('Snow-Sleet.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'tsra_sct':
|
|
|
|
case 'tsra':
|
|
|
|
return addPath('EF_ScatTstorms.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'tsra_sct-n':
|
|
|
|
case 'tsra-n':
|
|
|
|
return addPath('CC_TStorm.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'tsra_hi':
|
|
|
|
case 'tsra_hi-n':
|
|
|
|
case 'hurricane':
|
2020-09-09 19:29:03 +00:00
|
|
|
return addPath('CC_TStorm.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'wind_few':
|
|
|
|
case 'wind_sct':
|
|
|
|
case 'wind_bkn':
|
|
|
|
case 'wind_ovc':
|
|
|
|
return addPath('CC_Windy.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'wind_skc':
|
|
|
|
return addPath('CC_Windy.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'wind_skc-n':
|
|
|
|
return addPath('CC_Windy.gif');
|
2020-09-04 18:02:20 +00:00
|
|
|
|
2020-09-08 20:56:12 +00:00
|
|
|
case 'blizzard':
|
2020-09-04 18:02:20 +00:00
|
|
|
return addPath('Blowing-Snow.gif');
|
|
|
|
|
|
|
|
default:
|
2020-09-09 20:23:19 +00:00
|
|
|
console.log(`Unable to locate icon for ${conditionName} ${link} ${isNightTime}`);
|
2020-09-04 18:02:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-20 21:37:11 +00:00
|
|
|
const getHourlyIcon = (skyCover, visibility, iceAccumulation, probabilityOfPrecipitation, snowfallAmount, windSpeed, isNight = false) => {
|
|
|
|
// internal function to add path to returned icon
|
|
|
|
const addPath = (icon) => `images/r/${icon}`;
|
|
|
|
|
|
|
|
// first item in list is highest priority, units are metric where applicable
|
|
|
|
if (iceAccumulation > 0) return addPath('Freezing-Rain-1992.gif');
|
|
|
|
if (snowfallAmount > 10) {
|
|
|
|
if (windSpeed > 30) return addPath('Blowing Snow.gif');
|
|
|
|
return addPath('Heavy-Snow-1994.gif');
|
|
|
|
}
|
|
|
|
if (snowfallAmount > 0) return addPath('Light-Snow.gif');
|
|
|
|
if (probabilityOfPrecipitation > 70) return addPath('Rain-1992.gif');
|
|
|
|
if (probabilityOfPrecipitation > 50) return addPath('Shower.gif');
|
|
|
|
if (probabilityOfPrecipitation > 30) {
|
|
|
|
if (!isNight) return addPath('Scattered-Showers-1994.gif');
|
|
|
|
return addPath('Scattered-Showers-Night.gif');
|
|
|
|
}
|
|
|
|
if (skyCover > 70) return addPath('Cloudy.gif');
|
|
|
|
if (skyCover > 50) {
|
|
|
|
if (!isNight) return addPath('Mostly-Cloudy-1994.gif');
|
|
|
|
return addPath('Partly-Clear-1994.gif');
|
|
|
|
}
|
|
|
|
if (skyCover > 30) {
|
|
|
|
if (!isNight) return addPath('Partly-Cloudy.gif');
|
|
|
|
return addPath('Mostly-Clear.gif');
|
|
|
|
}
|
|
|
|
if (isNight) return addPath('Clear-1992.gif');
|
|
|
|
return addPath('Sunny.gif');
|
|
|
|
};
|
|
|
|
|
2020-09-04 18:02:20 +00:00
|
|
|
return {
|
|
|
|
getWeatherIconFromIconLink,
|
|
|
|
getWeatherRegionalIconFromIconLink,
|
2020-10-20 21:37:11 +00:00
|
|
|
getHourlyIcon,
|
2020-09-04 18:02:20 +00:00
|
|
|
};
|
|
|
|
})();
|