Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 46x 46x 30x 24x 24x 19x 19x | import { parse } from "content-disposition";
/** Everything up to the last path separator on any desktop platform. */
const FOLDER_PREFIX = /^.*[/\\]/s;
/** Names that point at a folder rather than a file. */
const FOLDER_NAMES: ReadonlySet<string> = new Set(["", ".", ".."]);
/** The file name a `Content-Disposition` header gives (`filename*` first), cut to its last path segment; null when there is none. */
export function attachmentFileName(header: string | null): string | null {
if (!header) return null;
const name = parse(header).parameters.filename;
if (name === undefined) return null;
const base = name.replace(FOLDER_PREFIX, "");
return FOLDER_NAMES.has(base) ? null : base;
}
|