Convert an absolute path to a tilde path by replacing the user's home directory with ~
93
Evaluation — 93%
↑ 1.09xAgent success when using this tile
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
Your implementation should:
~/**
* 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
}/Users/username/Documents/file.txt), it returns the path with ~ replacing the home directory prefix (e.g., ~/Documents/file.txt) @test/Users/username), it returns just ~ @test/var/log/system.log), it returns the original path unchanged @test/Users/usernamefoo/file.txt when home is /Users/username), it returns the original path unchanged @testProvides path conversion utilities for home directory handling.
Install with Tessl CLI
npx tessl i tessl/npm-tildify