import { type Maybe } from '../value/maybe.type'; /** * How {@link sanitizeFileName} cleans a name. * * - `strict`: keeps only ASCII letters, digits, `.`, `-`, `_` and spaces; drops leading dots. For names that must stay * plain everywhere (e.g. mail attachment names). * - `portable`: keeps Unicode and leading dots; replaces only what a local file system rejects. For mirroring remote * files (e.g. a SharePoint folder) with their names intact. */ export type SanitizeFileNameMode = 'strict' | 'portable'; /** * Default `maxLength` of {@link sanitizeFileName} in `strict` mode, in characters. */ export declare const DEFAULT_SANITIZE_FILE_NAME_STRICT_MAX_LENGTH = 80; /** * Default `maxLength` of {@link sanitizeFileName} in `portable` mode, in UTF-8 bytes (the common file-system limit). */ export declare const DEFAULT_SANITIZE_FILE_NAME_PORTABLE_MAX_BYTES = 255; /** * Default `fallback` of {@link sanitizeFileName}. */ export declare const DEFAULT_SANITIZE_FILE_NAME_FALLBACK = "file"; /** * The longest extension (dot included) that {@link sanitizeFileName} and {@link fileNameWithSuffix} keep apart from the stem. */ export declare const SANITIZE_FILE_NAME_MAX_EXTENSION_LENGTH = 10; export interface SanitizeFileNameConfig { /** * `strict` (default): ASCII letters, digits, `.`, `-`, `_`, space. `portable`: keeps Unicode; replaces only what a * local file system rejects. */ readonly mode?: Maybe; /** * `strict`: characters (default 80). `portable`: UTF-8 bytes (default 255). An extension of up to 10 characters is kept. */ readonly maxLength?: Maybe; /** * Returned when nothing is left. Defaults to `file`. */ readonly fallback?: Maybe; } /** * Makes a name safe to use as one local file name: never a path, never empty. * * `strict` (the default) replaces path separators, control characters, `..` and anything outside ASCII letters, digits, * `.`, `-`, `_` and spaces with `_`, collapses repeated `_`, drops leading dots, underscores and spaces, and caps the * name at `maxLength` characters (default 80), keeping its extension. * * `portable` NFC-normalizes the name and replaces only what a local file system rejects (`/`, `\`, NUL and other control * characters, DEL, and `< > : " | ? *`) with `_`. It trims trailing dots and spaces, prefixes Windows device names * (`CON`, `NUL`, `COM1`, `LPT1`, …, with or without an extension) with `_`, keeps leading dots and Unicode, and caps the * name at `maxLength` UTF-8 bytes (default 255), keeping its extension and never splitting a code point. * * @param name - The raw name, e.g. a remote file's or an attachment's. * @param config - The mode, length cap and fallback. * @returns The safe name; `fallback` (default `file`) when nothing is left. * * @dbxUtil * @dbxUtilCategory file * @dbxUtilTags file, name, sanitize, filename, path, safe, portable * * @example * ```ts * sanitizeFileName('../../etc/passwd'); // 'etc_passwd' * sanitizeFileName('Résumé: draft?.docx', { mode: 'portable' }); // 'Résumé_ draft_.docx' * ``` */ export declare function sanitizeFileName(name: Maybe, config?: Maybe): string; /** * Inserts a suffix before a file name's extension, e.g. to tell apart two names that collide. * The extension is the last `.` part that is not the first character and is at most 10 characters long. * The result is not re-capped: sanitize with room to spare when the suffix must fit a length limit. * * @param name - The file name. * @param suffix - The text to insert. * @returns The name with the suffix before its extension. * * @dbxUtil * @dbxUtilCategory file * @dbxUtilTags file, name, suffix, extension, collision, rename * * @example * ```ts * fileNameWithSuffix('report.pdf', ' (1a2b3c4d)'); // 'report (1a2b3c4d).pdf' * fileNameWithSuffix('.bashrc', ' (1)'); // '.bashrc (1)' * ``` */ export declare function fileNameWithSuffix(name: string, suffix: string): string;