The tmp package with promises support and disposers.
93
Build a text file processor that processes multiple text contents by writing them to temporary files, applying transformations, and collecting results. The processor should use a temporary workspace with automatic cleanup.
The processor should:
The implementation must guarantee cleanup in all scenarios, including exceptions during processing.
interface TextTask {
content: string;
processor: (text: string) => string;
}
interface ProcessingResult {
success: boolean;
output?: string;
error?: string;
}
/**
* Processes multiple text contents in a temporary workspace with automatic cleanup.
*
* @param tasks - Array of text tasks to process
* @returns Promise resolving to array of processing results
*/
export async function processTexts(tasks: TextTask[]): Promise<ProcessingResult[]>;@generates
Given a single task with content "hello world" and an uppercase processor, the result should indicate success with output "HELLO WORLD" @test
Given two tasks with different processors (uppercase and reverse), both results should indicate success with their respective processed outputs @test
Given three tasks where the second processor throws an error, the first and third should succeed, the second should have success=false with an error message @test
Provides temporary file and directory management with automatic cleanup support.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-tmp-promisedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10