Skip to content

validation

Validation utilities.

Interface Description
ValidationMessageHolder Holds a validation message.
Function Description
getOsAndObsidianUnsafePathCharsRegExp Returns a regexp matching all unsafe characters in file names/paths. Includes both OS-specific restrictions and Obsidian-specific ones.
getOsUnsafePathCharsRegExp Returns a regexp matching characters that are not safe to use in file names/paths at the OS level.
hasWindowsTrailingChars Checks whether a name ends with the dots or spaces Windows refuses. Answers for Windows regardless of the platform in use: a vault is synced, so the rules that matter are not necessarily those of the machine asking.
isValidationMessageHolder Type guard to check if a value is a validation message holder.
isWindowsReservedName Checks whether a name is one of the MS-DOS device names Windows refuses. Two steps the caller would otherwise have to know about happen here: trailing dots and spaces are trimmed BEFORE the test, because Windows strips them before deciding and CON is therefore as reserved as CON; and the extension is dropped, because CON.md is reserved too. CONIN$ / CONOUT$ and the superscript COM² forms are deliberately NOT reserved: they are accepted by every Windows version that runs Obsidian, and matching them would rename files that work. Answers for Windows regardless of the platform in use: a vault is synced, so the rules that matter are not necessarily those of the machine asking.
trimWindowsTrailingChars Removes the trailing dots and spaces Windows refuses from the end of a name. Trim before testing for a reserved name, never after: trimming afterwards turns an accepted CON into a rejected CON. isWindowsReservedName already does this internally.
Variable Description
OBSIDIAN_UNSAFE_FILENAME_CHARS Matches characters that are not safe to use in file names within Obsidian.
UNIX_UNSAFE_PATH_CHARS Unix-specific unsafe file name path characters.
WINDOWS_UNSAFE_PATH_CHARS Windows-specific unsafe file name path characters.