Text Generation & ASCII Art
Relevant source files
The following files were used as context for generating this wiki page:
The Text Generation and ASCII Art module within DevUtils provides a suite of creative and utility-focused tools designed to generate stylized text and mock data. These tools are integrated into the broader "Fun Tools" and "Utility Tools" categories of the application, offering developers ways to generate banners, placeholder content, and humorous Git history.
The system leverages specialized libraries like figlet for font rendering and standard React hooks for state management and UI responsiveness. Its primary goal is to provide a "Swiss Army Knife" experience for modern developers, as described in the project's documentation.
Sources: README.md:1-10, components/tool-content.tsx:30-45
ASCII Art Generation (ASCII Art Cork)
The ASCIIArtCork component is a dedicated tool for transforming standard plaintext into stylized ASCII art banners. It allows users to customize the output through font selection, padding adjustments, and structural framing.
Architecture and Logic
The component utilizes the figlet library to perform the core text-to-ASCII transformation. Because font files can be large, the system implements a lazy-loading mechanism using dynamic imports to fetch font modules only when required.
This diagram illustrates the reactive flow from user input to the final rendered ASCII output, including the lazy-loading font cycle.
Sources: components/tools/ascii-art-cork.tsx:24-38, components/tools/ascii-art-cork.tsx:64-75
Key Configuration Options
Users can manipulate the ASCII output through several state-driven controls:
| Option | Data Type | Description |
|---|---|---|
| Font | FontOption | Choice of Standard, Slant, Big, Ghost, or Doom fonts. |
| Padding | string | Adds leading/trailing spaces (0, 1, 2, or 4). |
| Uppercase | boolean | Forces all input characters to uppercase. |
| Frame | boolean | Wraps the ASCII art in a box made of +, -, and |. |
Sources: components/tools/ascii-art-cork.tsx:44-59, components/tools/ascii-art-cork.tsx:82-95
Implementation Snippet: Framing Logic
The framing logic calculates the maximum width of the rendered ASCII lines to ensure a perfectly aligned border.
const withFrame = useCallback(
(ascii: string): string => {
if (!frame) return ascii;
const lines = ascii.split("\n");
const width = Math.max(...lines.map((l) => l.length));
const topBottom = `+${"-".repeat(width + 2)}+`;
const padded = lines.map((line) => `| ${line.padEnd(width, " ")} |`);
return [topBottom, ...padded, topBottom].join("\n");
},
[frame],
);
Sources: components/tools/ascii-art-cork.tsx:77-87
Blame History Generation (Blame Intern)
The "Blame The Intern Stapler" tool is a specialized text generator that creates fictional Git commit histories. Its purpose is to generate a "totally legitimate" log that attributes bugs to a scapegoat, default-named "Jordan".
Generation Logic
The tool uses a randomized algorithm to build a sequence of GitCommit objects. It mixes standard professional messages with humorous "buggy" messages (e.g., "works on my machine", "trust me bro") and assigns the "Intern" role to specific commits in the sequence.
The sequence shows the process of creating a fake history, from the user trigger to the state update and UI rendering.
Sources: components/tools/blame-intern.tsx:112-140, components/tools/blame-intern.tsx:165-180
Data Structures
The tool relies on the GitCommit interface to maintain consistency across the generated log:
| Field | Type | Description |
|---|---|---|
hash | string | A 7-character hexadecimal string. |
author | string | The name of the person responsible for the commit. |
date | string | ISO formatted date with randomized time. |
message | string | The commit description. |
filesChanged | string[] | List of simulated file paths affected. |
Sources: components/tools/blame-intern.tsx:40-46
Integration and Localization
All text generation tools are integrated into the main application via toolComponents in the ToolContent manager. They also utilize the i18next framework for multi-language support, ensuring that labels, placeholders, and descriptions are available in English, Simplified Chinese, and Traditional Chinese.
- Registry Key (ASCII):
ascii-corkmaps toASCIIArtCork. - Registry Key (Blame):
blame-internmaps toBlameIntern. - Translation Namespace: Both tools use the
toolsnamespace withinen.json,zh.json, andzh-TW.json.
Sources: components/tool-content.tsx:30-40, messages/en.json:490-530
Conclusion
Text Generation and ASCII Art in DevUtils provide developers with a mix of utility and humor. Whether creating high-impact text banners using figlet or generating satirical Git logs to "blame the intern," the module emphasizes ease of use through a reactive UI and quick-copy functionality. The modular architecture allows for the easy addition of more text-based tools in the future.
Sources: README.md:15-30, components/tool-content.tsx:115-130