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
Create a utility that formats absolute file system paths for display by converting home directory paths to a more compact tilde notation.
Implement a function that takes an absolute file path and returns a formatted version suitable for display:
~~ (without trailing separator)The formatter should handle these scenarios:
/Users/username/documents to ~/documents/Users/username/documents/ are converted to ~/documents (no trailing separator)/Users/username/ to ~ (not ~/)/var/log/system.log unchanged@generates
/**
* Formats an absolute path by replacing the home directory with a tilde.
* Handles trailing separators correctly to ensure clean output.
*
* @param {string} absolutePath - An absolute file system path
* @returns {string} The formatted path with home directory replaced by ~, or the original path if not in home directory
*/
function formatPath(absolutePath) {
// IMPLEMENTATION HERE
}
module.exports = formatPath;/Users/username/documents, returns ~/documents @test/Users/username/documents/ (with trailing separator), returns ~/documents (without trailing separator) @test/Users/username/ (home directory with trailing separator), returns ~ @test/Users/username (home directory without trailing separator), returns ~ @testProvides path tildification support for converting absolute paths to tilde notation.
Install with Tessl CLI
npx tessl i tessl/npm-tildify