@bpyd/diff
v1.0.22
Published
bpyd-diff
Downloads
11
Readme
myers-diff
文本对比工具,参考git diff
安装
$ npm imstall @bpyd/diff --save
# OR
$ yarn add @bpyd/diff
使用
import { diff, diffArticle } from '@bpyd/diff'
const resultDiff = diff('AABCC', 'ABBCC')
// output:
[
{ type: 'keep', code: 'A' },
{ type: 'delete', code: 'A' },
{ type: 'keep', code: 'B' },
{ type: 'add', code: 'B' },
{ type: 'keep', code: 'CC' }
]
const article1 = `窗前明月光
疑是地上霜
举头望明月
低头思故乡
`
const article2 = `窗前明月光
窗前明月光
举头望明月
举头思故乡
`
const resultDiffArticle = diff(article1, article2)
// output:
[
{ type: 'keep', code: [{ type: 'keep', code: '窗前明月光' }] },
{ type: 'delete', code: [{ type: 'delete', code: '疑是地上霜' }] },
{ type: 'add', code: [{ type: 'add', code: '窗前明月光' }] },
{ type: 'keep', code: [{ type: 'keep', code: '举头望明月' }] },
{ type: 'update', code: [{ type: 'delete', code: '低' },{ type: 'add', code: '举' },{ type: 'keep', code: '头思故乡' }] },
{ type: 'keep', code: [{ type: 'keep', code: '' }] }
]