test/1114/app/lib/utils.ts

39 lines
1.0 KiB
TypeScript

import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export const formatTemperature = (
temp: number,
unit: 'celsius' | 'fahrenheit' = 'celsius'
): string => {
const value = unit === 'fahrenheit' ? (temp * 9) / 5 + 32 : temp;
const symbol = unit === 'fahrenheit' ? '°F' : '°C';
return '${Math.round(value)}${symbol}';
};
export const getWindDirection = (direction: string): string => {
const directionMap: { [key: string]: string } = {
'N': '北',
'NNE': '北东北',
'NE': '东北',
'ENE': '东东北',
'E': '东',
'ESE': '东东南',
'SE': '东南',
'SSE': '南东南',
'S': '南',
'SSW': '南西南',
'SW': '西南',
'WSW': '西西南',
'W': '西',
'WNW': '西西北',
'NW': '西北',
'NNW': '北西北',
};
return (directionMap[direction] || direction) + '风';
};