Skip to content

getFileNameValidationMessage

Validates a single file or folder name against every naming rule this module owns.

The rules, checked in this order, and the first one broken names the message:

  1. The name is not empty. 2. It holds no control character (U+0000 to U+001F). 3. It holds none of the characters getOsAndObsidianUnsafePathCharsRegExp matches. 4. It does not end with a dot or a space (hasWindowsTrailingChars). 5. It is not an MS-DOS device name (isWindowsReservedName), with or without an extension.

Only rule 3 depends on the platform. Rules 2, 4 and 5 apply on every platform, because a vault is synced, and a name created on macOS or Linux that Windows refuses breaks the vault there. The character set follows the platform because it is Obsidian’s own refusal set, which differs per platform: a name such as a?b is accepted on macOS, where Obsidian creates it.

Import:

import { getFileNameValidationMessage } from '@mnaoumov/obsidian-lib/validation';

Signature:

function getFileNameValidationMessage(name: string, isWindows: boolean | undefined, isAndroid: boolean | undefined): string

Parameters:

Parameter Type Description
name string The name to validate. A single path segment, with or without its extension.
isWindows boolean | undefined Whether to use the Windows character set. Defaults to Platform.isWin.
isAndroid boolean | undefined Whether to use the Android character set when isWindows is false. Defaults to Platform.isAndroidApp.

Returns: string — A message describing the first broken rule, or an empty string if the name is valid.


Links to this page: