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-7/

Path Prefix Validator

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.

Requirements

Your implementation should:

  1. Accept two path strings as input: a base directory and a target path
  2. Return true if the target path is within the base directory
  3. Return false if the target path is outside the base directory
  4. Correctly handle paths that look similar but aren't actual subdirectories (e.g., /home/user should not match /home/username)
  5. Work correctly when the target path exactly equals the base directory (should return true)
  6. Use appropriate path separator handling for accurate matching

Test Cases

  • When base directory is /home/user and target path is /home/user/documents, returns true @test
  • When base directory is /home/user and target path is /home/username/documents, returns false @test
  • When base directory is /home/user and target path is exactly /home/user, returns true @test
  • When base directory is /var/log and target path is /var/logfiles/system.log, returns false @test

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

tildify { .dependency }

Provides path manipulation utilities with precise prefix matching capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-tildify

tile.json