@git-diff-view/file

中文文档
0.1.8发布于 2026/10/15MITTypeScriptESM + CJS近 30 天下载 48.6万

@git-diff-view/file

原始使用文档
文档目录12 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Usage
  5. Worker/Server Pattern
  6. API Reference
  7. generateDiffFile()
  8. DiffFile Methods
  9. Difference from @git-diff-view/core
  10. Use Cases
  11. Related Packages
  12. License

@git-diff-view/file

File content comparison engine built on top of @git-diff-view/core

npm version npm downloads

Compare two file contents directly without git diff hunks. This package wraps diff and @git-diff-view/core to provide easy file-to-file comparison.

Features

  • ✅ Direct file content comparison (no git required)
  • ✅ Automatic diff generation using diff library
  • ✅ Same API as @git-diff-view/core
  • ✅ Syntax highlighting with HAST AST
  • ✅ Split & Unified view support
  • ✅ Theme support (light/dark)

Installation

npm install @git-diff-view/file
# or
pnpm add @git-diff-view/file
# or
yarn add @git-diff-view/file

Usage

Basic Usage

import { generateDiffFile } from "@git-diff-view/file";

// Generate diff from file contents
const file = generateDiffFile(
  "old.ts",      // old file name
  oldContent,    // old file content
  "new.ts",      // new file name
  newContent,    // new file content
  "typescript",  // old file language
  "typescript"   // new file language
);

// Initialize theme
file.initTheme('dark');

// Initialize diff
file.init();

// Build views
file.buildSplitDiffLines();
file.buildUnifiedDiffLines();

Worker/Server Pattern

// Worker/Server side
import { generateDiffFile, DiffFile } from "@git-diff-view/file";

const file = generateDiffFile(
  oldFileName, oldContent,
  newFileName, newContent,
  oldLang, newLang
);

file.initTheme('dark');
file.init();
file.buildSplitDiffLines();
file.buildUnifiedDiffLines();

const bundle = file.getBundle();
// Send bundle to main thread/client

// Main thread/Client side
const mergedFile = DiffFile.createInstance(data, bundle);

// Use with UI components
<DiffView diffFile={mergedFile} />

API Reference

generateDiffFile()

Generate a DiffFile instance from file contents.

function generateDiffFile(
  oldFileName: string,
  oldContent: string,
  newFileName: string,
  newContent: string,
  oldFileLang?: string,
  newFileLang?: string
): DiffFile

DiffFile Methods

Same as @git-diff-view/core:

MethodDescription
initTheme(theme)Set theme ('light' or 'dark')
init()Initialize diff data
buildSplitDiffLines()Generate split view data
buildUnifiedDiffLines()Generate unified view data
getBundle()Export data for transfer

Difference from @git-diff-view/core

PackageUse CaseInput
@git-diff-view/coreGit diff visualizationGit diff hunks
@git-diff-view/fileFile comparisonRaw file contents

Use Cases

  • Compare file versions without git
  • Diff editor integration
  • Online code comparison tools
  • File upload comparison
  • Live code diff

License

MIT © MrWangJustToDo

版本与发布记录

@git-diff-view/file 共发布 38 个版本,首次发布于 2024/04/22;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.1.8latest2026/10/151 个月前
0.1.72026/07/134 个月前
0.1.62026/06/214 个月前
0.1.52026/05/265 个月前
0.1.42026/05/185 个月前
0.1.32026/03/207 个月前

关于 @git-diff-view/file 的常见问题

@git-diff-view/file 是什么?

@git-diff-view/file

如何安装 @git-diff-view/file?

在项目目录运行 npm install @git-diff-view/file,或使用 pnpm add / yarn add / bun add。

@git-diff-view/file 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@git-diff-view/file 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@git-diff-view/file 可以商用吗?

@git-diff-view/file 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@git-diff-view/file 的下载量有多少?

根据 npm 官方下载统计,@git-diff-view/file 在 2026/10/17 – 2026/11/15 这 30 天内被下载 485,840 次,日均约 16,195 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@git-diff-view/file 还在维护吗?

最新版本 0.1.8 发布于 2026/10/15(1 个月前);至今共发布 38 个版本,其中过去 12 个月发布了 14 个;首次发布于 2024/04/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。