About this project

jsdiff is a JavaScript text differencing library based on the Myers O(ND) difference algorithm. It provides a comprehensive API for comparing text at multiple granularities: - **Character-level diffing** (`diffChars`): Treats each Unicode code point as a token, with optional case-insensitive comparison. - **Word-level diffing** (`diffWords`, `diffWordsWithSpace`): Treats words and punctuation as tokens, with optional `Intl.Segmenter` support for better non-English word segmentation. - **Line-level diffing** (`diffLines`): Treats each line as a token, with options for ignoring whitespace, handling trailing CR characters, and treating newlines as separate tokens. - **Sentence-level diffing** (`diffSentences`): Treats sentences and inter-sentence whitespace as tokens. - **CSS diffing** (`diffCss`): Compares CSS tokens. - **JSON diffing** (`diffJson`): Serializes objects to formatted JSON and diffs line-by-line, with alphabetical property ordering. - **Array diffing** (`diffArrays`): Compares arrays of tokens with strict equality or a custom comparator. The library also provides patch management capabilities: - **Patch creation**: `createPatch` and `createTwoFilesPatch` generate unified diff format patches with configurable context lines and header options. - **Structured patches**: `structuredPatch` returns a data structure with hunk objects suitable for programmatic processing. - **Patch application**: `applyPatch` and `applyPatches` apply unified diff patches with fuzz factor support, automatic line ending conversion, and custom line comparison callbacks. - **Patch parsing**: `parsePatch` parses unified diff format (including Git-specific extended headers for renames, copies, creates, deletes, and binary files) into structured objects. - **Patch reversal**: `reversePatch` generates an inverse patch. - **Format conversion**: `convertChangesToXML` and `convertChangesToDMP` convert change objects to XML or Google's diff-match-patch format. Universal options include async callback mode, maximum edit length limits, timeout support, and per-token change object granularity. The library also supports custom diffing behaviors through the `Diff` class, allowing users to override input casting, tokenization, empty token removal, equality checking, and joining functions. The library is available via npm (`npm install diff`) and supports both ESM and CommonJS imports, as well as direct browser usage via `dist/diff.js`.