@tpmjs/tools-diff-text-unified
Creates a unified diff between two text strings, showing additions, deletions, and context lines. Returns the diff in unified format along with statistics about changes. Useful for comparing versions of code, documents, or any text content.
Test @tpmjs/tools-diff-text-unified (diffTextUnified) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-diff-text-unifiedpnpm add @tpmjs/tools-diff-text-unifiedyarn add @tpmjs/tools-diff-text-unifiedbun add @tpmjs/tools-diff-text-unifieddeno add npm:@tpmjs/tools-diff-text-unifiedimport { diffTextUnified } from '@tpmjs/tools-diff-text-unified';import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { diffTextUnified } from '@tpmjs/tools-diff-text-unified';
const result = await generateText({
model: openai('gpt-4o'),
tools: { diffTextUnified },
prompt: 'Your prompt here...',
});
console.log(result.text);Available configuration options
originalstringThe original text to compare from
modifiedstringThe modified text to compare to
contextLinesnumberNumber of context lines to show around changes (default: 3)
Schema extracted: 1/1/2026, 8:18:17 AM
Creates unified diff between two text strings with context lines.
npm install @tpmjs/tools-diff-text-unified
import { diffTextUnified } from '@tpmjs/tools-diff-text-unified'; import { generateText } from 'ai'; const result = await generateText({ model: yourModel, tools: { diffTextUnified, }, prompt: 'Compare these two versions and show me what changed', });
Creates a unified diff between two text strings, showing additions, deletions, and context lines.
Parameters:
original (string, required) - The original text to compare frommodified (string, required) - The modified text to compare tocontextLines (number, optional) - Number of context lines to show around changes (default: 3)Returns:
{ diff: string; // The unified diff string additions: number; // Number of lines added deletions: number; // Number of lines deleted changes: number; // Total changes (additions + deletions) hasChanges: boolean; // Whether any changes were detected summary: string; // Human-readable summary }
{ diff: `--- original +++ modified @@ -1,3 +1,3 @@ function hello() { - console.log('Hello'); + console.log('Hello, World!'); }`, additions: 1, deletions: 1, changes: 2, hasChanges: true, summary: "1 addition, 1 deletion" }
MIT
Downloads/month
0
Quality Score