CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tildify

Convert an absolute path to a tilde path by replacing the user's home directory with ~

93

1.09x

Evaluation93%

1.09x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-3/

Path Display Formatter

Build a utility that formats file paths for display in CLI applications. The utility should present paths in a user-friendly format by shortening home directory references, while ensuring proper handling across different operating systems.

@generates

Requirements

Your implementation should:

  1. Convert absolute paths that start with the user's home directory into a shortened notation using ~
  2. Handle platform-specific path conventions correctly (Windows, Linux, macOS)
  3. Leave paths outside the home directory unchanged
  4. Properly handle edge cases including:
    • Paths that exactly match the home directory
    • Paths with similar but non-matching prefixes to the home directory
    • Relative paths

API

/**
 * Formats a file path for display by converting home directory paths to tilde notation
 * @param {string} absolutePath - The file system path to format
 * @returns {string} The formatted path
 */
export function formatPath(absolutePath) {
  // IMPLEMENTATION HERE
}

Test Cases

  • When given a path inside the user's home directory (e.g., /Users/username/Documents/file.txt), it returns the path with ~ replacing the home directory prefix (e.g., ~/Documents/file.txt) @test
  • When given a path that exactly matches the user's home directory (e.g., /Users/username), it returns just ~ @test
  • When given a path outside the home directory (e.g., /var/log/system.log), it returns the original path unchanged @test
  • When given a path with a similar but non-matching prefix to the home directory (e.g., /Users/usernamefoo/file.txt when home is /Users/username), it returns the original path unchanged @test

Dependencies { .dependencies }

tildify { .dependency }

Provides path conversion utilities for home directory handling.

Install with Tessl CLI

npx tessl i tessl/npm-tildify

tile.json