Skip to content

Commit 462880b

Browse files
committed
updated readme
1 parent d443b34 commit 462880b

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
diff-patch is a library that exposes two functions, `diff` and `patch`.
66

7-
The `diff` function takes two objects and deep compares them, returning an object that represents the difference between the two (the `diffData`).
7+
The library does not have any dependencies.
88

9-
The `patch` function takes an object and a diff object and applies the diff to the object, returning a new object.
9+
The `diff` function takes two objects (`obj1` and `obj2`) and deep compares them, returning an object that represents the difference between the two (the `diffData`).
10+
`diffData` is an object that can be used to apply the diff to `obj1` to get an object that is the same as `obj2`.
11+
12+
The `patch` function takes an `obj` and a `diffData` object and applies the diff to the object, returning a new object.
1013

1114
The `diff` and `patch` functions are implemented in the following languages:
1215

@@ -70,14 +73,14 @@ console.log( "obj3: ", obj3);
7073
To install the Python3 version of diff-patch, run:
7174

7275
```bash
73-
pip install diff-patch
76+
pip install fsoft-diff-patch
7477
```
7578

7679
Then, in your Python code:
7780

7881
```python
7982

80-
from diff_patch import diff, patch
83+
from fsoft_diff_patch import diff, patch
8184

8285
obj1 = {
8386
'a': 1,
@@ -110,4 +113,35 @@ obj3 = patch(obj1, diff_data)
110113
print("obj3: ", obj3)
111114
```
112115

116+
### Hint
117+
118+
The `diff` function can be used to see if two objects are the same, by comparing the result of `diff` to an empty object.
119+
120+
```python
121+
from diff_patch import diff
122+
123+
obj1 = {
124+
'a': 1,
125+
'b': 2,
126+
'c': {
127+
'd': 3,
128+
'e': 4,
129+
},
130+
}
131+
132+
obj2 = {
133+
'a': 1,
134+
'b': 2,
135+
'c': {
136+
'd': 3,
137+
'e': 4,
138+
},
139+
}
140+
141+
diff_data = diff(obj1, obj2)
142+
143+
# if the objects are the same, diff_data will be an empty object
144+
if not diff_data:
145+
print("The objects are the same")
146+
```
113147

0 commit comments

Comments
 (0)