markmv
Version:
TypeScript CLI for markdown file operations with intelligent link refactoring
89 lines • 3.84 kB
TypeScript
/**
* Utility class 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.
*
* @category Utilities
*
* @example
* Path resolution
* ```typescript
* // Resolve various path formats
* PathUtils.resolvePath('~/docs/file.md'); // Home directory
* PathUtils.resolvePath('../guide.md', '/current/dir'); // Relative
* PathUtils.resolvePath('/absolute/path.md'); // Absolute
* ```
*
* @example
* Relative path updates for moved files
* ```typescript
* // 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'
* ```
*/
export declare class PathUtils {
/**
* Resolve a path that may be relative, absolute, or use home directory notation.
*
* @example
* ```typescript
* PathUtils.resolvePath('~/docs/file.md');
* // Returns: '/Users/username/docs/file.md'
*
* PathUtils.resolvePath('../file.md', '/current/working/dir');
* // Returns: '/current/working/file.md'
* ```;
*
* @param path - The path to resolve (supports ~/, relative, and absolute paths)
* @param basePath - Optional base directory for relative path resolution
*
* @returns Resolved absolute path
*/
static resolvePath(path: string, basePath?: string): string;
/** Convert an absolute path back to a relative path from a base directory */
static makeRelative(absolutePath: string, fromDir: string): string;
/** Update a relative path when a file is moved */
static updateRelativePath(originalLinkPath: string, sourceFilePath: string, newSourceFilePath: string): string;
/** Update a Claude import path when a file is moved */
static updateClaudeImportPath(originalImportPath: string, sourceFilePath: string, newSourceFilePath: string): string;
/** Normalize path separators for cross-platform compatibility */
static normalizePath(path: string): string;
/** Check if a path is within a given directory */
static isWithinDirectory(filePath: string, directoryPath: string): boolean;
/** Generate a unique filename if a file already exists */
static generateUniqueFilename(desiredPath: string): string;
/** Validate that a path is safe for file operations */
static validatePath(path: string): {
valid: boolean;
reason?: string;
};
/** Extract directory depth from a path */
static getDirectoryDepth(path: string): number;
/** Find common base directory for multiple paths */
static findCommonBase(paths: string[]): string;
/** Convert Windows paths to Unix-style for markdown links */
static toUnixPath(path: string): string;
/** Get file extension with fallback handling */
static getExtension(path: string): string;
/** Check if path represents a markdown file */
static isMarkdownFile(path: string): boolean;
/** Safely join paths, handling edge cases */
static safejoin(...parts: string[]): string;
/** Check if a path is a directory */
static isDirectory(path: string): boolean;
/** Check if a path looks like a directory (ends with / or ) */
static looksLikeDirectory(path: string): boolean;
/**
* Resolve destination path when target might be a directory If destination is a directory,
* preserves the source filename
*/
static resolveDestination(sourcePath: string, destinationPath: string): string;
}
//# sourceMappingURL=path-utils.d.ts.map