You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72Lines changed: 72 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -15,5 +15,77 @@ The `diff` and `patch` functions are implemented in the following languages:
15
15
16
16
And the `diffData` object can be used interchangeably between the languages.
17
17
18
+
`diffData` can be serialized to JSON and deserialized back to an object. It aims to be as small as possible, and is designed to be used in a networked environment.
19
+
18
20
More languages will be added in the future, contributions are welcome.
19
21
22
+
## Usage
23
+
24
+
### TypeScript
25
+
26
+
```typescript
27
+
import { diff, patch } from'@fsoft/diff-patch';
28
+
29
+
const obj1 = {
30
+
a: 1,
31
+
b: 2,
32
+
c: {
33
+
d: 3,
34
+
e: 4,
35
+
},
36
+
};
37
+
38
+
const obj2 = {
39
+
a: 1,
40
+
b: 2,
41
+
c: {
42
+
d: 3,
43
+
e: 5, // changed
44
+
},
45
+
};
46
+
47
+
// create the diff data
48
+
const diffData =diff(obj1, obj2);
49
+
50
+
// show the diff data for debugging
51
+
console.log( "diffData: ", diffData);
52
+
53
+
// apply the diff data to obj1 to get an object that is the same as obj2
54
+
const obj3 =patch(obj1, diffData);
55
+
```
56
+
57
+
### Python3
58
+
59
+
```python
60
+
61
+
from diff_patch import diff, patch
62
+
63
+
obj1 = {
64
+
'a': 1,
65
+
'b': 2,
66
+
'c': {
67
+
'd': 3,
68
+
'e': 4,
69
+
},
70
+
}
71
+
72
+
obj2 = {
73
+
'a': 1,
74
+
'b': 2,
75
+
'c': {
76
+
'd': 3,
77
+
'e': 5, # changed
78
+
},
79
+
}
80
+
81
+
# create the diff data
82
+
diff_data = diff(obj1, obj2)
83
+
84
+
# show the diff data for debugging
85
+
print("diff_data: ", diff_data)
86
+
87
+
# apply the diff data to obj1 to get an object that is the same as obj2
0 commit comments