worktree-tool
Version:
A command-line tool for managing Git worktrees with integrated tmux/shell session management
154 lines • 4.92 kB
TypeScript
/**
* Configuration options for string sanitization.
*/
export interface SanitizeOptions {
/** Whether to allow spaces in the sanitized string */
allowSpaces?: boolean;
/** Whether to preserve uppercase characters */
allowUppercase?: boolean;
/** Whether to allow dots in the sanitized string */
allowDots?: boolean;
/** Additional special characters to allow (e.g., "-_/") */
allowSpecialChars?: string;
/** Maximum length of the sanitized string */
maxLength?: number;
/** Default value to return if the sanitized string is empty */
defaultValue?: string;
/** Whether to remove leading numbers from the string */
removeLeadingNumbers?: boolean;
}
declare const PRESETS: {
readonly TMUX_SESSION: {
readonly allowSpaces: false;
readonly allowUppercase: false;
readonly allowDots: false;
readonly allowSpecialChars: "-_";
readonly removeLeadingNumbers: true;
readonly maxLength: 30;
};
readonly TMUX_WINDOW: {
readonly allowSpaces: true;
readonly allowUppercase: true;
readonly allowDots: true;
readonly allowSpecialChars: "-_:";
readonly removeLeadingNumbers: false;
};
readonly GIT_BRANCH: {
readonly allowSpaces: false;
readonly allowUppercase: true;
readonly allowDots: true;
readonly allowSpecialChars: "-_/";
readonly maxLength: 100;
readonly removeLeadingNumbers: false;
};
readonly WORKTREE_NAME: {
readonly allowSpaces: false;
readonly allowUppercase: false;
readonly allowDots: false;
readonly allowSpecialChars: "-_";
readonly maxLength: 100;
readonly removeLeadingNumbers: false;
};
readonly PROJECT_NAME: {
readonly allowSpaces: false;
readonly allowUppercase: true;
readonly allowDots: false;
readonly allowSpecialChars: "-_";
readonly maxLength: 50;
readonly removeLeadingNumbers: false;
};
};
/**
* Sanitizes a string according to specified rules and presets.
*
* This function provides a flexible way to clean and normalize strings for different
* contexts like project names, git branches, tmux sessions, etc.
*
* @param input - The string to sanitize
* @param preset - Predefined sanitization preset (PROJECT_NAME, GIT_BRANCH, TMUX_SESSION, etc.)
* @param customOptions - Additional options to override preset defaults
* @returns The sanitized string
*
* @example
* ```typescript
* // Sanitize for project names
* sanitize("My Project!", "PROJECT_NAME"); // "My-Project"
*
* // Sanitize for git branches
* sanitize("feature/test branch", "GIT_BRANCH"); // "feature/test-branch"
*
* // Custom sanitization
* sanitize("Test String", undefined, {
* allowSpaces: false,
* allowUppercase: false,
* maxLength: 10
* }); // "test-strin"
* ```
*/
export declare function sanitize(input: string, preset?: keyof typeof PRESETS, customOptions?: SanitizeOptions): string;
/**
* Sanitizes a string for use as a tmux session name.
*
* @param name - The session name to sanitize
* @returns A sanitized session name suitable for tmux
*
* @example
* ```typescript
* sanitizeTmuxSession("My Project"); // "my-project"
* ```
*/
export declare const sanitizeTmuxSession: (name: string) => string;
/**
* Sanitizes a string for use as a tmux window name.
* Removes quotes and applies appropriate sanitization rules.
*
* @param name - The window name to sanitize
* @returns A sanitized window name suitable for tmux
*
* @example
* ```typescript
* sanitizeTmuxWindow('"My Window"'); // "My Window"
* ```
*/
export declare const sanitizeTmuxWindow: (name: string) => string;
/**
* Sanitizes a string for use as a git branch name.
*
* @param name - The branch name to sanitize
* @returns A sanitized branch name that follows git naming conventions
*
* @example
* ```typescript
* sanitizeGitBranch("feature test"); // "feature-test"
* sanitizeGitBranch("bug#123"); // "bug#123"
* ```
*/
export declare const sanitizeGitBranch: (name: string) => string;
/**
* Sanitizes a string for use as a git worktree name.
*
* @param name - The worktree name to sanitize
* @returns A sanitized worktree name
*
* @example
* ```typescript
* sanitizeWorktreeName("Feature Branch"); // "feature-branch"
* ```
*/
export declare const sanitizeWorktreeName: (name: string) => string;
/**
* Sanitizes a string for use as a project name.
* Handles npm scoped packages and preserves case.
*
* @param name - The project name to sanitize
* @returns A sanitized project name
*
* @example
* ```typescript
* sanitizeProjectName("My Project"); // "My-Project"
* sanitizeProjectName("@myorg/package"); // "package"
* ```
*/
export declare const sanitizeProjectName: (name: string) => string;
export {};
//# sourceMappingURL=sanitize.d.ts.map