@git-diff-view/core
Core diff engine for git diff processing with syntax highlighting

Features
- ✅ Git diff parsing and processing
- ✅ Syntax highlighting with HAST AST
- ✅ Split & Unified view data generation
- ✅ Web Worker / Node.js compatible
- ✅ Bundle-based data transfer
- ✅ Theme support (light/dark)
Installation
npm install @git-diff-view/core
pnpm add @git-diff-view/core
yarn add @git-diff-view/core
Usage
Basic Usage
import { DiffFile } from "@git-diff-view/core";
const file = new DiffFile(
oldFileName,
oldContent,
newFileName,
newContent,
hunks,
oldFileLang,
newFileLang
);
file.initTheme('dark');
file.init();
file.buildSplitDiffLines();
file.buildUnifiedDiffLines();
Advanced: Separate Initialization
file.initRaw();
file.initSyntax();
file.buildSplitDiffLines();
file.buildUnifiedDiffLines();
Worker/Server Pattern
Process diff data in a separate thread or server for better performance:
const file = new DiffFile();
file.initTheme('dark');
file.init();
file.buildSplitDiffLines();
file.buildUnifiedDiffLines();
const bundle = file.getBundle();
import { DiffFile } from "@git-diff-view/core";
const mergedFile = DiffFile.createInstance(data, bundle);
<DiffView diffFile={mergedFile} />
API Reference
DiffFile Class
Constructor
new DiffFile(
oldFileName: string,
oldContent: string,
newFileName: string,
newContent: string,
hunks: string[],
oldFileLang?: string,
newFileLang?: string
)
Methods
initTheme(theme) | Set theme ('light' or 'dark') |
init() | Initialize diff data (calls initRaw + initSyntax) |
initRaw() | Parse git diff without syntax highlighting |
initSyntax() | Apply syntax highlighting |
buildSplitDiffLines() | Generate split view data |
buildUnifiedDiffLines() | Generate unified view data |
getBundle() | Export data for transfer |
Static Methods
createInstance(data, bundle) | Reconstruct DiffFile from bundle |
Use Cases
- Client-side: Direct rendering with UI frameworks
- Worker pattern: Offload processing to Web Worker
- Server-side: Pre-process diffs in Node.js, send to client
- Hybrid: Mix of client and server processing
Related Packages
License
MIT © MrWangJustToDo