or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-8/

Text Formatter

A utility module for formatting text into fixed-width columns with custom alignment and padding characters.

Capabilities

Format text with center alignment

  • When given the string "Hello" and width 15, returns the string centered with spaces on both sides @test
  • When given the string "Test" and width 10 with padding character "-", returns the string centered with "-" characters @test
  • When the string length equals the target width, returns the string unchanged @test

Format text with left padding

  • When given the string "42" and width 5, returns the string with spaces added to the left @test
  • When given the string "ID" and width 8 with padding character "0", returns the string with "0" characters added to the left @test

Format text with right padding

  • When given the string "Name" and width 10, returns the string with spaces added to the right @test
  • When given the string "Code" and width 12 with padding character "", returns the string with "" characters added to the right @test

Handle edge cases

  • When the string length exceeds the target width, returns the original string @test
  • When given an empty string with a target width, returns a string of padding characters @test

Implementation

@generates

API

/**
 * Formats a string to a fixed width with center alignment
 *
 * @param {string} text - The text to format
 * @param {number} width - The target width
 * @param {string} [padChar=' '] - The character to use for padding
 * @returns {string} The centered text
 */
function formatCenter(text, width, padChar = ' ');

/**
 * Formats a string to a fixed width by adding padding to the left
 *
 * @param {string} text - The text to format
 * @param {number} width - The target width
 * @param {string} [padChar=' '] - The character to use for padding
 * @returns {string} The left-padded text
 */
function formatLeft(text, width, padChar = ' ');

/**
 * Formats a string to a fixed width by adding padding to the right
 *
 * @param {string} text - The text to format
 * @param {number} width - The target width
 * @param {string} [padChar=' '] - The character to use for padding
 * @returns {string} The right-padded text
 */
function formatRight(text, width, padChar = ' ');

module.exports = {
  formatCenter,
  formatLeft,
  formatRight
};

Dependencies { .dependencies }

lodash { .dependency }

Provides string manipulation utilities for padding text.

@satisfied-by