fileFormat
uses node:path
The format of a file kept in the codebase as written (not code), from its name: its extension, or undefined.
import path from "node:path"; export function fileFormat(file: string): string | undefined { const ext = path.extname(file).slice(1).toLowerCase(); // anything but TypeScript, the code a scratch file holds: shell scripts, configuration, … (text or bytes, by // their content) return ext && !/^(m|c)?tsx?$/.test(ext) ? ext : undefined; }