Diff Checker

Utility

Compare texts line by line and find differences.

Import

Import
import { diff } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
diffCheckoldText: string, newText: string{ lines, stats }Compare two strings line by line
diffUnifiedoldText: string, newText: string, oldLabel?, newLabel?stringGenerate unified diff string
diffIsSamea: string, b: stringbooleanCheck if two strings are identical

Examples

Line-by-Line Diff
import { diffCheck } from 'toolmetry';

const result = diffCheck('Hello\nWorld', 'Hello\nEarth');
// { lines: [...], stats: { added: 1, removed: 1, unchanged: 1 } }
Unified Diff
import { diffUnified } from 'toolmetry';

const unified = diffUnified('Hello\nWorld', 'Hello\nEarth');
// "--- original\n+++ modified\n  Hello\n- World\n+ Earth"
Quick Comparison
import { diffIsSame } from 'toolmetry';

diffIsSame('hello', 'hello'); // true
diffIsSame('hello', 'world'); // false

Try It Live