bc6c31374ebe423fa96795490397e9888909a404.svn-base
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# diff-frag
Take a big diff with a 2-line header and turn it into frags with only a
reasonable amount of context
For example, you might have a program that spits out a diff like this:
```diff
some header data
Author: Bobo The Cat <bobo@cat.kitty>
Date: Wed Nov 20 20:13:08 2019 -0800
diff --git a/bowl.txt b/bowl.txt
index glorp..prolg 100655
--- a/bowl.txt
+++ b/bowl.txt
space-prefixed lines are the same in both
but we were sloppy in what got included in the diff
so you get 1000 lines of identical output ...
but dumping that all to ta teerminal is so ruuuuuude
-what you want
+what you want is just this bit
+ just the changes
more more more more more.... it goes on and on for a long time...
```
In that case, what you'd really prefer is something like:
```diff
some header data
Author: Bobo The Cat <bobo@cat.kitty>
Date: Wed Nov 20 20:13:08 2019 -0800
diff --git a/bowl.txt b/bowl.txt
index glorp..prolg 100655
--- a/bowl.txt
+++ b/bowl.txt
@@ -1000,6 +1000,7 @@ so you get 1000 lines of identical...
but dumping that all to ta teerminal is so ruuuuuude
-what you want
+what you want is just this bit
+just the changes
more more more more more.... it goes on and on for a long time...
@@ -2456,5 +2567,5 @@ another bit of context here
+ added line
- removed line
+ well, you get
- the idea
just the changes, is what I'm saying, not the 1000 lines between.
```
This function will take the first kind of string, and turn it into the
second. It's useful for [test frameworks](https://node-tap.org) that
pretty-print object diffs, for object matching assertions, and want to make
them prettier when the object is really big.
## USAGE
```js
const diffFrag = require('diff-frag')
const fraggedDiff = diffFrag(rawDiff)
// that's it, it's just the one function
```