| Total Complexity | 11 |
| Complexity/F | 1.57 |
| Lines of Code | 36 |
| Function Count | 7 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | export type Theme = 'light' | 'dark'; |
||
| 2 | |||
| 3 | export const DEFAULT_THEME: Theme = 'dark'; |
||
| 4 | |||
| 5 | export function toggleTheme(current: string | null): Theme { |
||
| 6 | return current === 'dark' ? 'light' : 'dark'; |
||
| 7 | } |
||
| 8 | |||
| 9 | export function isValidTheme(theme: string): theme is Theme { |
||
| 10 | return theme === 'light' || theme === 'dark'; |
||
| 11 | } |
||
| 12 | |||
| 13 | export function getThemeOrDefault(theme: string | null): Theme { |
||
| 14 | if (theme && isValidTheme(theme)) { |
||
| 15 | return theme; |
||
| 16 | } |
||
| 17 | return DEFAULT_THEME; |
||
| 18 | } |
||
| 19 | |||
| 20 | export function isDarkMode(theme: string): boolean { |
||
| 21 | return theme === 'dark'; |
||
| 22 | } |
||
| 23 | |||
| 24 | export function getOppositeThemeName(theme: string): string { |
||
| 25 | return theme === 'dark' ? 'light' : 'dark'; |
||
| 26 | } |
||
| 27 | |||
| 28 | export function getAriaPressed(theme: string): 'true' | 'false' { |
||
| 29 | return isDarkMode(theme) ? 'true' : 'false'; |
||
| 30 | } |
||
| 31 | |||
| 32 | export function getThemeToggleLabel(currentTheme: string): string { |
||
| 33 | const opposite = getOppositeThemeName(currentTheme); |
||
| 34 | return `Switch to ${opposite} mode`; |
||
| 35 | } |
||
| 36 |