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

Home Path Shortener

Create a utility that converts file system paths to a more user-friendly format by replacing the home directory prefix with a tilde symbol.

Requirements

Your task is to implement a function that takes an absolute file path as input and returns a shortened version where the user's home directory is replaced with ~.

Core Functionality

The function should handle the following scenarios:

  1. Exact home directory match: When the input path is exactly the user's home directory, return just ~
  2. Paths within home: When a path starts with the home directory, replace that prefix with ~
  3. Paths outside home: When a path is not within the home directory, return it unchanged

Behavior Specification

  • The function must work with absolute paths
  • The function should normalize paths before processing
  • Only paths that truly start with the home directory should be modified
  • The tilde replacement should only occur at the beginning of the path

Test Cases

  • When given the exact home directory path, the function returns ~ @test
  • When given a path inside the home directory, the function replaces the home prefix with ~ @test
  • When given a path outside the home directory, the function returns it unchanged @test

Implementation

@generates

API

/**
 * Converts an absolute path to a tilde path by replacing the home directory.
 *
 * @param {string} absolutePath - An absolute file system path
 * @returns {string} The path with home directory replaced by ~ if applicable
 */
function tildifyPath(absolutePath) {
  // Implementation here
}

module.exports = tildifyPath;

Dependencies { .dependencies }

tildify { .dependency }

Provides functionality to convert absolute paths to tilde paths.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-tildify

tile.json