refactor(utils): add helper to remove extensions from file paths

This commit is contained in:
Roushan Singh 2025-09-26 14:57:07 +05:30
parent b422970369
commit c6be66e595
2 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,23 @@
// File path utilities
export function basenameNoExt(filePath: string): string {
const VALID_EXTENSIONS = [".tar.gz", ".zip"];
// handle VALID extensions first
for (const ext of VALID_EXTENSIONS) {
if (filePath.toLowerCase().endsWith(ext)) {
return filePath.slice(0, -ext.length);
}
}
// fallback: remove only the last extension
const lastDotIndex = filePath.lastIndexOf('.');
if (lastDotIndex > 0) {
return filePath.slice(0, lastDotIndex);
}
return filePath;
}
// Zustand proxy state structure
interface ProxyState {
proxyEnabled: boolean

View File

@ -1,11 +1,28 @@
import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
import { ExtensionManager } from './extension'
import path from "path"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function basenameNoExt(filePath: string): string {
const base = path.basename(filePath);
const VALID_EXTENSIONS = [".tar.gz", ".zip"];
// handle VALID extensions first
for (const ext of VALID_EXTENSIONS) {
if (base.toLowerCase().endsWith(ext)) {
return base.slice(0, -ext.length);
}
}
// fallback: remove only the last extension
return base.slice(0, -path.extname(base).length);
}
export function getProviderLogo(provider: string) {
switch (provider) {
case 'jan':