feat(archive): add double-extension-aware filename parsing helper
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import path from 'node:path';
|
||||
|
||||
const DOUBLE_EXTENSIONS = ['tar.gz', 'tar.bz2', 'tar.7z'];
|
||||
|
||||
export function extractExtension(filename) {
|
||||
const lower = filename.toLowerCase();
|
||||
const match = DOUBLE_EXTENSIONS.find((ext) => lower.endsWith(`.${ext}`));
|
||||
return match ?? path.extname(filename).slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
export function stripExtension(filename) {
|
||||
const ext = extractExtension(filename);
|
||||
return filename.slice(0, filename.length - ext.length - 1);
|
||||
}
|
||||
Reference in New Issue
Block a user