(fallback: 'latest' | 'latestReleased' = 'latest')
| 2 | |
| 3 | |
| 4 | export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest'): string { |
| 5 | switch (fallback) { |
| 6 | case 'latestReleased': |
| 7 | return useLatestReleasedVersion(); |
| 8 | case 'latest': { |
| 9 | const version = useActiveVersion('default'); |
| 10 | return version?.name ?? useLatestVersion('default')?.name; |
| 11 | } |
| 12 | default: |
| 13 | // The following line ensures that if `fallback` is not 'latest' or 'latestReleased', |
| 14 | // an error is thrown. This can be useful for catching unexpected states. |
| 15 | throw new Error(`Unhandled fallback type: ${fallback}`); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | export function useLatestReleasedVersion(): string { |
| 20 | const allVersions = useVersions('default'); |
no test coverage detected