File size: 1,652 Bytes
0e11366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
export const sevColor = (sev?: string): string => {
  switch ((sev || "").toLowerCase()) {
    case "extreme":
      return "#6f00ff";
    case "severe":
      return "#d7191c";
    case "moderate":
      return "#fdae61";
    case "minor":
      return "#ffff99";
    default:
      return "#9e9e9e";
  }
};

export const eonetEmoji = (p: any) => {
  const s = (
    p?.category ||
    p?.categories?.[0]?.title ||
    p?.title ||
    ""
  ).toLowerCase();
  if (s.includes("wildfire")) return "πŸ”₯";
  if (s.includes("volcano")) return "πŸŒ‹";
  if (s.includes("earthquake") || s.includes("seismic")) return "πŸ’₯";
  if (
    s.includes("storm") ||
    s.includes("cyclone") ||
    s.includes("hurricane") ||
    s.includes("typhoon")
  )
    return "πŸŒ€";
  if (s.includes("flood")) return "🌊";
  if (s.includes("landslide")) return "πŸ”οΈ";
  if (s.includes("drought")) return "🌡";
  if (s.includes("ice") || s.includes("snow") || s.includes("blizzard"))
    return "❄️";
  if (s.includes("dust") || s.includes("smoke") || s.includes("haze"))
    return "🌫️";
  return "⚠️";
};

export const toQuery = (o: Record<string, any>) =>
  "?" +
  Object.entries(o)
    .map(
      ([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`
    )
    .join("&");

export const formatAgo = (iso?: string) => {
  if (!iso) return "";
  const t = new Date(iso);
  const s = Math.max(0, (Date.now() - t.getTime()) / 1000);
  if (s < 60) return `${Math.floor(s)}s ago`;
  if (s < 3600) return `${Math.floor(s / 60)}m ago`;
  if (s < 86400) return `${Math.floor(s / 3600)}h ago`;
  return `${Math.floor(s / 86400)}d ago`;
};