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 determines whether a given file path is located within a specific base directory. The validator must correctly distinguish between actual subdirectories and paths that merely share similar names.
Your implementation should:
true if the target path is within the base directoryfalse if the target path is outside the base directory/home/user should not match /home/username)true)/home/user and target path is /home/user/documents, returns true @test/home/user and target path is /home/username/documents, returns false @test/home/user and target path is exactly /home/user, returns true @test/var/log and target path is /var/logfiles/system.log, returns false @test@generates
/**
* Checks if a target path is within a base directory
* @param {string} baseDir - The base directory path
* @param {string} targetPath - The target path to check
* @returns {boolean} True if targetPath is within baseDir, false otherwise
*/
function isWithinDirectory(baseDir, targetPath) {
// Implementation here
}
module.exports = { isWithinDirectory };Provides path manipulation utilities with precise prefix matching capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-tildify