refactor(utils): add helper to remove extensions from file paths
This commit is contained in:
parent
b422970369
commit
c6be66e595
@ -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
|
// Zustand proxy state structure
|
||||||
interface ProxyState {
|
interface ProxyState {
|
||||||
proxyEnabled: boolean
|
proxyEnabled: boolean
|
||||||
|
|||||||
@ -1,11 +1,28 @@
|
|||||||
import { type ClassValue, clsx } from 'clsx'
|
import { type ClassValue, clsx } from 'clsx'
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
import { ExtensionManager } from './extension'
|
import { ExtensionManager } from './extension'
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
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) {
|
export function getProviderLogo(provider: string) {
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case 'jan':
|
case 'jan':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user