27 lines
874 B
TypeScript
27 lines
874 B
TypeScript
export function splitPathKeepFilename(full: string) {
|
|
if (!full) return { prefix: '', filename: '' };
|
|
const norm = full.replaceAll('\\', '/');
|
|
const idx = norm.lastIndexOf('/');
|
|
if (idx < 0) return { prefix: '', filename: norm };
|
|
return {
|
|
prefix: norm.slice(0, idx),
|
|
filename: norm.slice(idx + 1),
|
|
};
|
|
}
|
|
|
|
export function elideStart(input: string, keepTail = 16): string {
|
|
if (!input) return '';
|
|
if (input.length <= keepTail) return input;
|
|
return '…' + input.slice(input.length - keepTail);
|
|
}
|
|
|
|
export function elideFilenameSmart(name: string, minHead = 6): string {
|
|
if (!name) return '';
|
|
const dot = name.lastIndexOf('.');
|
|
if (dot <= 0) return elideStart(name, Math.max(minHead, 8));
|
|
const head = name.slice(0, dot);
|
|
const ext = name.slice(dot);
|
|
if (head.length <= minHead) return name;
|
|
return head.slice(0, minHead) + '…' + ext;
|
|
}
|