worktree-tool
Version:
A command-line tool for managing Git worktrees with integrated tmux/shell session management
115 lines • 3.78 kB
TypeScript
export interface ValidationOptions {
required?: boolean;
maxLength?: number;
minLength?: number;
pattern?: RegExp;
errorMessage?: string;
sanitizer?: (value: string) => string;
}
/**
* Validates and sanitizes a string according to the specified options.
*
* @param value - The value to validate
* @param fieldName - The name of the field being validated (used in error messages)
* @param options - Validation options
* @returns The validated and processed string
* @throws {ValidationError} When validation fails
*
* @example
* ```typescript
* validateString("test", "Username"); // "test"
* validateString(" test ", "Username"); // "test" (trimmed)
* validateString(undefined, "Username"); // throws ValidationError
* ```
*/
export declare function validateString(value: string | undefined, fieldName: string, options?: ValidationOptions): string;
/**
* Validates and sanitizes a worktree name.
*
* @param name - The worktree name to validate
* @returns The sanitized worktree name
* @throws {ValidationError} When the name is invalid
*
* @example
* ```typescript
* validateWorktreeName("feature-branch"); // "feature-branch"
* validateWorktreeName("Feature Branch!"); // "feature-branch"
* validateWorktreeName(""); // throws ValidationError
* ```
*/
export declare function validateWorktreeName(name: string): string;
/**
* Validates and sanitizes a git branch name.
*
* @param name - The branch name to validate
* @returns The sanitized branch name
* @throws {ValidationError} When the name is invalid
*
* @example
* ```typescript
* validateBranchName("feature/new-ui"); // "feature/new-ui"
* validateBranchName("feature branch"); // "feature-branch"
* ```
*/
export declare function validateBranchName(name: string): string;
/**
* Validates and sanitizes a project name.
*
* @param name - The project name to validate
* @returns The sanitized project name
* @throws {ValidationError} When the name is invalid
*
* @example
* ```typescript
* validateProjectName("my-project"); // "my-project"
* validateProjectName("@myorg/package"); // "package"
* ```
*/
export declare function validateProjectName(name: string): string;
/**
* Validates that a command is a non-empty string.
*
* @param name - The name of the command (used in error messages)
* @param command - The command string to validate
* @throws {ValidationError} When the command is invalid
*
* @example
* ```typescript
* validateCommand("test", "npm test"); // OK
* validateCommand("test", ""); // throws ValidationError
* ```
*/
export declare function validateCommand(name: string, command: string): void;
/**
* Validates that a port number is within the valid range (1-65535).
*
* @param port - The port number to validate
* @param fieldName - The name of the field (used in error messages)
* @returns The validated port number
* @throws {ValidationError} When the port is invalid
*
* @example
* ```typescript
* validatePort(8080); // 8080
* validatePort("3000"); // 3000
* validatePort(0); // throws ValidationError
* ```
*/
export declare function validatePort(port: number | string, fieldName?: string): number;
/**
* Validates that a path is non-empty and doesn't contain invalid characters.
*
* @param path - The path to validate
* @param fieldName - The name of the field (used in error messages)
* @returns The validated path
* @throws {ValidationError} When the path is invalid
*
* @example
* ```typescript
* validatePath("/path/to/file"); // "/path/to/file"
* validatePath(" /path "); // "/path" (trimmed)
* validatePath(""); // throws ValidationError
* ```
*/
export declare function validatePath(path: string, fieldName?: string): string;
//# sourceMappingURL=validation.d.ts.map