@ git- diff- view/ file (英语)
在 @git-diff-view/core上建起的文件内容比较引擎
直接比较两个文件内容而不使用 git diff hunks 。 这个包包包 diff 财务报告和审定财务报表 @git-diff-view/core 以方便文件对文件的比较.
特征
- QQ 直接文件内容比较( 不需要 git)
- 使用 diff 生成自动
diff图书馆 - 与 @ git-diff- view/ core 相同的 API
- 使用 HAST AST 突出显示语法
- & 统一视图支持
- QQ 主题支持( 浅/ 暗)
安装
npm install @git-diff-view/file
# or
pnpm add @git-diff-view/file
# or
yarn add @git-diff-view/file
使用量
基本用途
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 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 参考
生成 DiffFile ()
从文件内容生成 DiffFile 实例 .
function generateDiffFile(
oldFileName: string,
oldContent: string,
newFileName: string,
newContent: string,
oldFileLang?: string,
newFileLang?: string
): DiffFile
DiffFile 方法
与 @ git- diff- 视图/ 核心数字 :
| 方法 | 说明 |
|---|---|
initTheme(theme) | 设定主题 ("光" 或" 暗") |
init() | 初始化 diff 数据 |
buildSplitDiffLines() | 生成分割视图数据 |
buildUnifiedDiffLines() | 生成统一视图数据 |
getBundle() | 用于转让的导出数据 |
与 @git-diff- view/ core 的区别
| 软件包 | 使用大小写 | 投入 |
|---|---|---|
@git-diff-view/core | Git diff 可视化 | Git diff 猎人 |
@git-diff-view/file | 文件比较 | 原始文件内容 |
使用大小写
- 不使用 git 来比较文件版本
- Diff 编辑器集成
- 在线代码比较工具
- 文件上传比较
- 生活代码 diff
相关软件包
- @ git- diff- 视图/ 核心 - Git diff 模式
- @ git- diff- 视图/ 反应 - 反应组件
- @git-diff-view/vue (英语) - Vue 组件
- 微调 - 地下 Diff 图书馆
许可证
麻省理工学院 万正东先生