@chatpanel/events 0.295.0 → 0.329.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/weather.js CHANGED
@@ -1,2 +1,2 @@
1
- const m="https://wttr.in",F=7e3;class d extends Error{constructor(r,n){super(n),this.name="WeatherError",this.code=r}}function w(e,{host:r=m}={}){const n=String(e??"").trim();if(y(n))return`${r}/?format=j1`;if(n.length>120)throw new d("BAD_LOCATION","location is too long to be one");return`${r}/${encodeURIComponent(n)}?format=j1`}const f=/^(?:(?:right )?here|near me|nearby|around (?:here|me)|my (?:location|area|city|town|place)|(?:my )?current location|where i am|local(?:ly)?|outside|(?:right )?now|currently|today|tonight|tomorrow|(?:this|next|the) (?:morning|afternoon|evening|night|week|weekend)|(?:this |next |on )?(?:mon|tues|wednes|thurs|fri|satur|sun)day)$/i;function y(e){const r=String(e??"").trim().replace(/[?.!,]+$/,"").replace(/\s+/g," ");return!r||f.test(r)||r.split(/\s*(?:,|\band\b|\bor\b)\s*/).every(n=>f.test(n))}const s=e=>{const r=Number(e);return Number.isFinite(r)?r:null},l=e=>String(e??"").trim(),h=e=>Array.isArray(e)?l(e[0]?.value):l(e);function $(e,{query:r=""}={}){if(!e||typeof e!="object")return null;const n=Array.isArray(e.current_condition)?e.current_condition[0]:null;if(!n)return null;const t=s(n.temp_C),u=s(n.temp_F);if(t===null&&u===null)return null;const i=Array.isArray(e.nearest_area)?e.nearest_area[0]:null,o=i?{name:h(i.areaName),region:h(i.region),country:h(i.country),lat:s(i.latitude),lon:s(i.longitude)}:null,c=(Array.isArray(e.weather)?e.weather:[]).slice(0,3).map(a=>({date:l(a.date),maxC:s(a.maxtempC),maxF:s(a.maxtempF),minC:s(a.mintempC),minF:s(a.mintempF),sunrise:l(a.astronomy?.[0]?.sunrise),sunset:l(a.astronomy?.[0]?.sunset),condition:h(a.hourly?.[4]?.weatherDesc)||h(a.hourly?.[0]?.weatherDesc),chanceOfRain:s(a.hourly?.[4]?.chanceofrain)}));return{query:l(r),area:o,now:{tempC:t,tempF:u,feelsLikeC:s(n.FeelsLikeC),feelsLikeF:s(n.FeelsLikeF),condition:h(n.weatherDesc),humidity:s(n.humidity),windKph:s(n.windspeedKmph),windMph:s(n.windspeedMiles),windDir:l(n.winddir16Point),precipMm:s(n.precipMM),uv:s(n.uvIndex),observedAt:l(n.localObsDateTime)},days:c}}function g(e,r=""){if(!e)return r;const n=[e.name,e.region,e.country].map(l).filter(Boolean),t=new Set;return n.filter(i=>{const o=i.toLowerCase();return t.has(o)?!1:(t.add(o),!0)}).join(", ")||r}function C(e){const r=l(e);return r?!/[,]/.test(r)&&r.split(/\s+/).length<=2:!1}const x=e=>Math.round(e*9/5+32),p=(e,r)=>{const n=e===null&&r!==null?Math.round((r-32)*5/9):e,t=r===null&&e!==null?x(e):r;return n===null&&t===null?"":n===null?`${t}°F`:t===null?`${n}°C`:`${t}°F / ${n}°C`};function k(e){if(!e)return"";const r=g(e.area,e.query),n=[];n.push(`Weather for ${r}${e.query&&r.toLowerCase()!==e.query.toLowerCase()?` (asked: "${e.query}")`:""}`);const t=e.now,u=[`Now: ${p(t.tempC,t.tempF)}`];(t.feelsLikeC!==null||t.feelsLikeF!==null)&&u.push(`feels like ${p(t.feelsLikeC,t.feelsLikeF)}`),t.condition&&u.push(t.condition.toLowerCase()),n.push(u.join(", "));const i=[];t.humidity!==null&&i.push(`humidity ${t.humidity}%`),(t.windMph!==null||t.windKph!==null)&&i.push(`wind ${t.windMph!==null?`${t.windMph} mph`:`${t.windKph} km/h`}${t.windDir?` ${t.windDir}`:""}`),t.precipMm!==null&&i.push(`precip ${t.precipMm} mm`),t.uv!==null&&i.push(`UV ${t.uv}`),i.length&&n.push(i.join(" · "));for(const o of e.days){const c=`${p(o.maxC,o.maxF)} high / ${p(o.minC,o.minF)} low`,a=o.chanceOfRain!==null?`, ${o.chanceOfRain}% rain`:"";n.push(`${o.date}: ${c}${o.condition?`, ${o.condition.toLowerCase()}`:""}${a}`)}return t.observedAt&&n.push(`Observed ${t.observedAt} local. Source: wttr.in`),C(e.query)&&n.push("The place name was ambiguous — TELL THE USER which location this is for, and offer to re-check with a state or country if it is the wrong one."),n.join(`
2
- `)}async function L(e,{fetchJson:r,timeoutMs:n=7e3,host:t=m}={}){let u;try{u=w(e,{host:t})}catch(c){return{ok:!1,reason:c.message}}if(typeof r!="function")return{ok:!1,reason:"no fetch was provided"};let i;try{i=await r(u,{timeoutMs:n})}catch(c){return{ok:!1,reason:c?.message||"the weather service did not answer"}}const o=$(i,{query:e});return o?{ok:!0,weather:o,text:k(o)}:{ok:!1,reason:"the weather service returned nothing usable"}}export{m as WEATHER_HOST,F as WEATHER_TIMEOUT_MS,d as WeatherError,g as areaLabel,k as formatWeather,L as getWeather,C as isAmbiguousLocation,y as isHere,$ as parseWeather,w as weatherUrl};
1
+ const f="https://wttr.in",b=7e3;class g extends Error{constructor(n,t){super(t),this.name="WeatherError",this.code=n}}function C(e,{host:n=f}={}){const t=String(e??"").trim();if(x(t))return`${n}/?format=j1`;if(t.length>120)throw new g("BAD_LOCATION","location is too long to be one");return`${n}/${encodeURIComponent(t)}?format=j1`}const d=/^(?:(?:right )?here|near me|nearby|around (?:here|me)|my (?:location|area|city|town|place)|(?:my )?current location|where i am|local(?:ly)?|outside|(?:right )?now|currently|today|tonight|tomorrow|(?:this|next|the) (?:morning|afternoon|evening|night|week|weekend)|(?:this |next |on )?(?:mon|tues|wednes|thurs|fri|satur|sun)day)$/i;function x(e){const n=String(e??"").trim().replace(/[?.!,]+$/,"").replace(/\s+/g," ");return!n||d.test(n)||n.split(/\s*(?:,|\band\b|\bor\b)\s*/).every(t=>d.test(t))}const s=e=>{const n=Number(e);return Number.isFinite(n)?n:null},l=e=>String(e??"").trim(),h=e=>Array.isArray(e)?l(e[0]?.value):l(e);function k(e,{query:n=""}={}){if(!e||typeof e!="object")return null;const t=Array.isArray(e.current_condition)?e.current_condition[0]:null;if(!t)return null;const r=s(t.temp_C),u=s(t.temp_F);if(r===null&&u===null)return null;const i=Array.isArray(e.nearest_area)?e.nearest_area[0]:null,o=i?{name:h(i.areaName),region:h(i.region),country:h(i.country),lat:s(i.latitude),lon:s(i.longitude)}:null,c=(Array.isArray(e.weather)?e.weather:[]).slice(0,3).map(a=>({date:l(a.date),maxC:s(a.maxtempC),maxF:s(a.maxtempF),minC:s(a.mintempC),minF:s(a.mintempF),sunrise:l(a.astronomy?.[0]?.sunrise),sunset:l(a.astronomy?.[0]?.sunset),condition:h(a.hourly?.[4]?.weatherDesc)||h(a.hourly?.[0]?.weatherDesc),chanceOfRain:s(a.hourly?.[4]?.chanceofrain)}));return{query:l(n),area:o,now:{tempC:r,tempF:u,feelsLikeC:s(t.FeelsLikeC),feelsLikeF:s(t.FeelsLikeF),condition:h(t.weatherDesc),humidity:s(t.humidity),windKph:s(t.windspeedKmph),windMph:s(t.windspeedMiles),windDir:l(t.winddir16Point),precipMm:s(t.precipMM),uv:s(t.uvIndex),observedAt:l(t.localObsDateTime)},days:c}}function E(e,n=""){if(!e)return n;const t=[e.name,e.region,e.country].map(l).filter(Boolean),r=new Set;return t.filter(i=>{const o=i.toLowerCase();return r.has(o)?!1:(r.add(o),!0)}).join(", ")||n}function F(e){const n=l(e);return n?!/[,]/.test(n)&&n.split(/\s+/).length<=2:!1}const A=e=>Math.round(e*9/5+32),m=(e,n)=>{const t=e===null&&n!==null?Math.round((n-32)*5/9):e,r=n===null&&e!==null?A(e):n;return t===null&&r===null?"":t===null?`${r}°F`:r===null?`${t}°C`:`${r}°F / ${t}°C`},L=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function y(e){const n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(String(e||""));return n?L[new Date(Date.UTC(+n[1],+n[2]-1,+n[3])).getUTCDay()]:""}function T(e){if(!e)return"";const n=E(e.area,e.query),t=[];t.push(`Weather for ${n}${e.query&&n.toLowerCase()!==e.query.toLowerCase()?` (asked: "${e.query}")`:""}`);const r=e.now,u=[`Now: ${m(r.tempC,r.tempF)}`];(r.feelsLikeC!==null||r.feelsLikeF!==null)&&u.push(`feels like ${m(r.feelsLikeC,r.feelsLikeF)}`),r.condition&&u.push(r.condition.toLowerCase()),t.push(u.join(", "));const i=[];if(r.humidity!==null&&i.push(`humidity ${r.humidity}%`),(r.windMph!==null||r.windKph!==null)&&i.push(`wind ${r.windMph!==null?`${r.windMph} mph`:`${r.windKph} km/h`}${r.windDir?` ${r.windDir}`:""}`),r.precipMm!==null&&i.push(`precip ${r.precipMm} mm`),r.uv!==null&&i.push(`UV ${r.uv}`),i.length&&t.push(i.join(" · ")),e.days.forEach((o,c)=>{const a=`${m(o.maxC,o.maxF)} high / ${m(o.minC,o.minF)} low`,w=o.chanceOfRain!==null?`, ${o.chanceOfRain}% rain`:"",p=y(o.date),$=c===0?" (today)":c===1?" (tomorrow)":"";t.push(`${p?`${p} `:""}${o.date}${$}: ${a}${o.condition?`, ${o.condition.toLowerCase()}`:""}${w}`)}),e.days.length){const o=y(e.days[e.days.length-1].date);t.push(`This forecast ends ${o?`on ${o}`:"with these days"} — for a later day, say it is not in this forecast.`)}return r.observedAt&&t.push(`Observed ${r.observedAt} local. Source: wttr.in`),F(e.query)&&t.push("The place name was ambiguous — TELL THE USER which location this is for, and offer to re-check with a state or country if it is the wrong one."),t.join(`
2
+ `)}async function M(e,{fetchJson:n,timeoutMs:t=7e3,host:r=f}={}){let u;try{u=C(e,{host:r})}catch(c){return{ok:!1,reason:c.message}}if(typeof n!="function")return{ok:!1,reason:"no fetch was provided"};let i;try{i=await n(u,{timeoutMs:t})}catch(c){return{ok:!1,reason:c?.message||"the weather service did not answer"}}const o=k(i,{query:e});return o?{ok:!0,weather:o,text:T(o)}:{ok:!1,reason:"the weather service returned nothing usable"}}export{f as WEATHER_HOST,b as WEATHER_TIMEOUT_MS,g as WeatherError,E as areaLabel,T as formatWeather,M as getWeather,F as isAmbiguousLocation,x as isHere,k as parseWeather,C as weatherUrl};