markmv - v1.41.7
    Preparing search index...

    Variable PathUtilsConst

    PathUtils: {
        findCommonBase: (paths: readonly string[]) => string;
        generateUniqueFilename: (desiredPath: string) => string;
        getDirectoryDepth: (path: string) => number;
        getExtension: (path: string) => string;
        isDirectory: (path: string) => boolean;
        isMarkdownFile: (path: string) => boolean;
        isWithinDirectory: (filePath: string, directoryPath: string) => boolean;
        looksLikeDirectory: (path: string) => boolean;
        makeRelative: (absolutePath: string, fromDir: string) => string;
        normalizePath: (path: string) => string;
        resolveDestination: (sourcePath: string, destinationPath: string) => string;
        resolvePath: (path: string, basePath?: string) => string;
        safejoin: (...parts: readonly string[]) => string;
        toUnixPath: (path: string) => string;
        updateClaudeImportPath: (
            originalImportPath: string,
            sourceFilePath: string,
            newSourceFilePath: string,
            movedPaths?: Map<string, string>,
        ) => string;
        updateRelativePath: (
            originalLinkPath: string,
            sourceFilePath: string,
            newSourceFilePath: string,
            movedPaths?: Map<string, string>,
        ) => string;
        validatePath: (path: string) => { reason?: string; valid: boolean };
    } = ...

    Utility namespace for path manipulation and resolution operations.

    Provides comprehensive path handling for markdown file operations including relative path updates, home directory resolution, and cross-platform compatibility.

    Type Declaration

    • findCommonBase: (paths: readonly string[]) => string

      Finds the deepest directory shared by all the given paths once resolved. Returns an empty string for no paths, the parent directory for a single path, and the root separator when nothing beyond it is shared.

    • generateUniqueFilename: (desiredPath: string) => string

      Returns the desired path when nothing exists there, otherwise the first free path formed by appending -1, -2 and so on to the file name before its extension.

    • getDirectoryDepth: (path: string) => number

      Counts the segments of a path once resolved to an absolute path.

    • getExtension: (path: string) => string

      Returns the extension of a path including its leading dot, or an empty string when there is none.

    • isDirectory: (path: string) => boolean

      True when the path (resolved with resolvePath) exists and is a directory, and false when it does not exist or cannot be examined.

    • isMarkdownFile: (path: string) => boolean

      True when the path's extension, compared case-insensitively, is .md, .markdown, .mdown, .mkd or .mdx.

    • isWithinDirectory: (filePath: string, directoryPath: string) => boolean

      True when filePath is the directory itself or lies beneath it, judged lexically from the relative path between them. No file system access is made.

    • looksLikeDirectory: (path: string) => boolean

      True when the path text ends in a forward or back slash, indicating a directory without consulting the file system.

    • makeRelative: (absolutePath: string, fromDir: string) => string

      Computes the path from a directory to an absolute path, using the platform's separator.

    • normalizePath: (path: string) => string

      Rewrites every / or `` separator in a path to the platform's separator, without resolving the path.

    • resolveDestination: (sourcePath: string, destinationPath: string) => string

      Resolves a move or copy destination. When it ends in a separator or is an existing directory, the source's file name is appended to it; otherwise the resolved destination is returned unchanged.

    • resolvePath: (path: string, basePath?: string) => string

      Resolves a path to an absolute one. A leading ~/ expands to the home directory, an absolute path is normalised, and a relative path is resolved against basePath when given, otherwise the current working directory.

    • safejoin: (...parts: readonly string[]) => string

      Joins path segments after dropping empty and whitespace-only ones, and resolves the result to an absolute path. Returns an empty string when no segments remain.

    • toUnixPath: (path: string) => string

      Replaces every backslash with a forward slash, for writing Windows paths into markdown links.

    • updateClaudeImportPath: (
          originalImportPath: string,
          sourceFilePath: string,
          newSourceFilePath: string,
          movedPaths?: Map<string, string>,
      ) => string

      Recomputes a relative Claude import path for a source file that is moving, with the same rules as updateRelativePath: absolute and ~/ paths are unchanged, a fragment is preserved and targets in movedPaths follow their move.

    • updateRelativePath: (
          originalLinkPath: string,
          sourceFilePath: string,
          newSourceFilePath: string,
          movedPaths?: Map<string, string>,
      ) => string

      Recomputes a relative link target for a source file that is moving. Absolute and ~/ paths are returned unchanged, an anchor fragment is preserved, and a target that is itself being moved (present in movedPaths, keyed by its resolved absolute path) is pointed at its new location.

    • validatePath: (path: string) => { reason?: string; valid: boolean }

      Checks that a path is safe to use for a file operation. It rejects empty or whitespace-only paths, paths containing null bytes, and paths using .. that resolve outside the current working directory.

      // Resolve various path formats
    PathUtils.resolvePath('~/docs/file.md'); // Home directory
    PathUtils.resolvePath('../guide.md', '/current/dir'); // Relative
    PathUtils.resolvePath('/absolute/path.md'); // Absolute
      // When moving a file, update its relative links
    const originalLink = '../images/diagram.png';
    const updatedLink = PathUtils.updateRelativePath(
    originalLink,
    'docs/guide.md', // old file location
    'tutorials/guide.md' // new file location
    );
    // Result: '../../docs/images/diagram.png'