Skip to content

Commit 356414c

Browse files
committed
Updated README file
1 parent e565dea commit 356414c

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,77 @@ The `diff` and `patch` functions are implemented in the following languages:
1515

1616
And the `diffData` object can be used interchangeably between the languages.
1717

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+
1820
More languages will be added in the future, contributions are welcome.
1921

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
88+
obj3 = patch(obj1, diff_data)
89+
```
90+
91+

0 commit comments

Comments
 (0)