Display differences clearly so people can review changes confidently
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The main diff function handles any JavaScript values by detecting types and routing to appropriate comparison methods. It provides automatic serialization, type checking, and colorized output.
Compares any two JavaScript values and returns formatted diff string with automatic type detection and routing.
/**
* Generate a string that will highlight the difference between two values
* with green and red coloring (similar to how GitHub does code diffing)
* @param a - First value to compare (any type)
* @param b - Second value to compare (any type)
* @param options - Optional formatting configuration
* @returns Formatted diff string or null if no meaningful diff
*/
function diff(a: any, b: any, options?: DiffOptions): string | null;Behavior by Type:
Usage Examples:
import { diff } from "jest-diff";
// Object comparison
const user1 = { name: "Alice", age: 25, active: true };
const user2 = { name: "Alice", age: 26, active: false };
console.log(diff(user1, user2));
// Array comparison
const arr1 = [1, 2, 3];
const arr2 = [1, 3, 4];
console.log(diff(arr1, arr2));
// Primitive comparison
console.log(diff(42, 43));
console.log(diff(true, false));
// Type mismatch
console.log(diff("string", 123));
// Output: "Comparing two different types of values. Expected string but received number."
// No difference
console.log(diff("same", "same"));
// Output: "Compared values have no visual difference."Special Handling: