Sign In

node-diff3

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-diff3 - npm Package Compare versions

Comparing version
2.0.1
to
2.1.0
+9
.github/dependabot.yml
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
+9
-0

@@ -19,3 +19,12 @@ # What's New

-->
## 2.1.0
##### 2020-jul-17
* ([#39]) Added a `mergeDiff3` function to help print out Diff3 merge result
* ([#37]) Fixed error in TypeScript definition for `MergeRegion`
[#39]: https://github.com/bhousel/node-diff3/issues/39
[#37]: https://github.com/bhousel/node-diff3/issues/37
## 2.0.1

@@ -22,0 +31,0 @@ ##### 2020-may-18

@@ -378,3 +378,36 @@ (function (global, factory) {

function mergeDiff3(a, o, b, options) {
var defaults = {
excludeFalseConflicts: true,
stringSeparator: /\s+/,
label: {}
};
options = Object.assign(defaults, options);
var mergeResult = diff3Merge(a, o, b, options);
var conflict = false;
var lines = [];
mergeResult.forEach(function (result) {
if (result.ok) {
lines = lines.concat(result.ok);
} else if (result.conflict) {
conflict = true;
lines.push(("<<<<<<<" + (options.label.a ? (" " + (options.label.a)) : '')));
lines = lines.concat(result.conflict.a);
lines.push(("|||||||" + (options.label.o ? (" " + (options.label.o)) : '')));
lines = lines.concat(result.conflict.o);
lines.push('=======');
lines = lines.concat(result.conflict.b);
lines.push((">>>>>>>" + (options.label.b ? (" " + (options.label.b)) : '')));
}
});
return {
conflict: conflict,
result: lines
};
}
function merge(a, o, b, options) {

@@ -502,2 +535,3 @@ var defaults = {

exports.merge = merge;
exports.mergeDiff3 = mergeDiff3;
exports.mergeDigIn = mergeDigIn;

@@ -504,0 +538,0 @@ exports.patch = patch;

@@ -378,3 +378,36 @@ (function (global, factory) {

function mergeDiff3(a, o, b, options) {
let defaults = {
excludeFalseConflicts: true,
stringSeparator: /\s+/,
label: {}
};
options = Object.assign(defaults, options);
const mergeResult = diff3Merge(a, o, b, options);
let conflict = false;
let lines = [];
mergeResult.forEach(result => {
if (result.ok) {
lines = lines.concat(result.ok);
} else if (result.conflict) {
conflict = true;
lines.push(`<<<<<<<${options.label.a ? ` ${options.label.a}` : ''}`);
lines = lines.concat(result.conflict.a);
lines.push(`|||||||${options.label.o ? ` ${options.label.o}` : ''}`);
lines = lines.concat(result.conflict.o);
lines.push('=======');
lines = lines.concat(result.conflict.b);
lines.push(`>>>>>>>${options.label.b ? ` ${options.label.b}` : ''}`);
}
});
return {
conflict: conflict,
result: lines
};
}
function merge(a, o, b, options) {

@@ -502,2 +535,3 @@ let defaults = {

exports.merge = merge;
exports.mergeDiff3 = mergeDiff3;
exports.mergeDigIn = mergeDigIn;

@@ -504,0 +538,0 @@ exports.patch = patch;

+22
-5

@@ -113,4 +113,5 @@ export interface ILCSResult {

export interface IMergeConflictRegion<T> {
conflict: {
export interface MergeRegion<T> {
ok?: T[];
conflict?: {
a: T[];

@@ -125,3 +126,6 @@ aIndex: number;

export type MergeRegion<T> = T[] | IMergeConflictRegion<T>;
export interface MergeResult {
conflict: boolean;
result: string[];
}

@@ -157,4 +161,17 @@ export interface IMergeOptions {

options?: IMergeOptions
): string[];
): MergeResult;
export function mergeDiff3<T>(
a: string | T[],
o: string | T[],
b: string | T[],
options?: IMergeOptions & {
label?: {
a?: string;
o?: string;
b?: string;
}
}
): MergeResult;
export function mergeDigIn<T>(

@@ -165,2 +182,2 @@ a: string | T[],

options?: IMergeOptions
): string[];
): MergeResult;

@@ -8,2 +8,3 @@ export {

diff3Merge,
mergeDiff3,
merge,

@@ -388,3 +389,36 @@ mergeDigIn,

function mergeDiff3(a, o, b, options) {
let defaults = {
excludeFalseConflicts: true,
stringSeparator: /\s+/,
label: {}
};
options = Object.assign(defaults, options);
const mergeResult = diff3Merge(a, o, b, options);
let conflict = false;
let lines = [];
mergeResult.forEach(result => {
if (result.ok) {
lines = lines.concat(result.ok);
} else if (result.conflict) {
conflict = true;
lines.push(`<<<<<<<${options.label.a ? ` ${options.label.a}` : ''}`);
lines = lines.concat(result.conflict.a);
lines.push(`|||||||${options.label.o ? ` ${options.label.o}` : ''}`);
lines = lines.concat(result.conflict.o);
lines.push('=======');
lines = lines.concat(result.conflict.b);
lines.push(`>>>>>>>${options.label.b ? ` ${options.label.b}` : ''}`);
}
});
return {
conflict: conflict,
result: lines
};
}
function merge(a, o, b, options) {

@@ -391,0 +425,0 @@ let defaults = {

+8
-9
{
"name": "node-diff3",
"version": "2.0.1",
"version": "2.1.0",
"license": "MIT",
"repository": "bhousel/node-diff3",
"author": "Bryan Housel <bhousel@gmail.com>",
"description": "A node.js module for text diffing and three-way-merge.",
"keywords": [
"diff",
"diff3",
"merge"
"keywords": ["diff", "diff3", "merge"],
"contributors": [
"Bryan Housel <bhousel@gmail.com> (https://github.com/bhousel)"
],

@@ -20,3 +18,3 @@ "main": "dist/index.js",

"eslint": "^7.0.0",
"npm-run-all": "^4.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^2.0.6",

@@ -26,7 +24,8 @@ "tap": "^14.10.6"

"scripts": {
"build": "npm-run-all -s dist:**",
"all": "npm run test",
"build": "run-s dist:**",
"dist:js": "rollup --config config/rollup.config.js",
"dist:es5": "rollup --config config/rollup.config.es5.js",
"lint": "eslint index.mjs test/*.js",
"test": "npm run lint && npm run build && tap --reporter terse --cov test/*.js"
"test": "npm run lint && npm run build && tap --reporter terse --cov test/*.js"
},

@@ -33,0 +32,0 @@ "engines": {

+71
-17
[![npm version](https://badge.fury.io/js/node-diff3.svg)](https://badge.fury.io/js/node-diff3)
[![Build Status](https://travis-ci.org/bhousel/node-diff3.svg?branch=master)](https://travis-ci.org/bhousel/node-diff3)
[![Build Status](https://travis-ci.org/bhousel/node-diff3.svg?branch=main)](https://travis-ci.org/bhousel/node-diff3)

@@ -41,3 +41,3 @@ # node-diff3

```html
<script type="module" src="https://cdn.jsdelivr.net/npm/node-diff3@2/index.min.mjs"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/node-diff3@2/index.min.mjs"></script>
```

@@ -47,3 +47,3 @@

```html
<script src="https://cdn.jsdelivr.net/npm/node-diff3@2/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-diff3@2/dist/index.min.js"></script>
```

@@ -53,3 +53,3 @@

```html
<script src="https://cdn.jsdelivr.net/npm/node-diff3@2/dist/index.es5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-diff3@2/dist/index.es5.min.js"></script>
```

@@ -64,2 +64,3 @@

* [merge](#merge)
* [mergeDiff3](#mergeDiff3)
* [mergeDigIn](#mergeDigIn)

@@ -89,3 +90,3 @@ * [diff3MergeRegions](#diff3MergeRegions)

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diff3Merge.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3Merge.test.js

@@ -116,3 +117,3 @@ ```js

See examples: https://github.com/bhousel/node-diff3/blob/master/test/merge.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/merge.test.js

@@ -151,2 +152,55 @@ ```js

<a name="mergeDiff3" href="#mergeDiff3">#</a> <i>Diff3</i>.<b>mergeDiff3</b>(<i>a</i>, <i>o</i>, <i>b</i>, <i>options</i>)
Passes arguments to [diff3Merge](#diff3Merge) to generate a diff3-style merge result with original (similar to [git-diff3](https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging)).
See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDiff3.test.js
```js
const r = Diff3.mergeDiff3(a, o, b, { label: { a: 'a', o: 'o', b: 'b' } });
const result = r.result;
// [
// 'AA',
// '<<<<<<< a',
// 'a',
// 'b',
// 'c',
// '||||||| o',
// '=======',
// 'a',
// 'd',
// 'c',
// '>>>>>>> b',
// 'ZZ',
// '<<<<<<< a',
// 'new',
// '00',
// 'a',
// 'a',
// '||||||| o',
// '00',
// '=======',
// '11',
// '>>>>>>> b',
// 'M',
// 'z',
// 'z',
// '99'
// ]
```
Extra options:
```js
{
// labels for conflict marker lines
label: {
a: 'a',
o: 'o',
b: 'b'
},
}
```
&nbsp;
<a name="mergeDigIn" href="#mergeDigIn">#</a> <i>Diff3</i>.<b>mergeDigIn</b>(<i>a</i>, <i>o</i>, <i>b</i>, <i>options</i>)

@@ -156,3 +210,3 @@

See examples: https://github.com/bhousel/node-diff3/blob/master/test/mergeDigIn.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/mergeDigIn.test.js

@@ -165,3 +219,3 @@ &nbsp;

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diff3MergeRegions.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diff3MergeRegions.test.js

@@ -180,3 +234,3 @@

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js

@@ -196,3 +250,3 @@ ```js

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js

@@ -208,6 +262,6 @@ ```js

Strips some extra information from the patch, returning a new patch without modifying the original.
Strips some extra information from the patch, returning a new patch without modifying the original.
The "stripped" patch can still patch `buffer1` -> `buffer2`, but can no londer be inverted.
See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js

@@ -225,3 +279,3 @@ ```js

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffPatch.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffPatch.test.js

@@ -239,3 +293,3 @@ ```js

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffComm.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffComm.test.js

@@ -248,3 +302,3 @@ &nbsp;

See examples: https://github.com/bhousel/node-diff3/blob/master/test/diffIndices.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/diffIndices.test.js

@@ -263,7 +317,7 @@

See also:
See also:
* http://www.cs.dartmouth.edu/~doug/
* https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
See examples: https://github.com/bhousel/node-diff3/blob/master/test/LCS.test.js
See examples: https://github.com/bhousel/node-diff3/blob/main/test/LCS.test.js

@@ -270,0 +324,0 @@