Skip to content

Commit bd13027

Browse files
committed
Update docs
1 parent 7f0cbc2 commit bd13027

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,13 @@ node.update({
191191

192192
The `update` method reconciles the new content with the existing document, preserving comments, indentation, and spacing.
193193

194-
To merge two documents while preserving comments, use the `merge` method:
194+
For single updates, prefer the `set` method for better performance:
195+
196+
```ts
197+
node.set('version', '2.0.0');
198+
```
199+
200+
To merge two documents while preserving comments and formatting from both, use the `merge` method:
195201

196202
```ts
197203

@@ -214,7 +220,9 @@ const sourceCode = `{
214220
const source = JsonParser.parse(sourceCode, JsonObjectNode);
215221
const destination = JsonParser.parse(destinationCode, JsonObjectNode);
216222

217-
console.log(JsonObjectNode.merge(source, destination).toString());
223+
destination.merge(source)
224+
225+
console.log(destination.toString());
218226
```
219227

220228
Output:
@@ -230,8 +238,6 @@ Output:
230238
}
231239
```
232240

233-
The `merge` method removes any existing destination properties that clash with source, along with their leading/trailing trivia, to avoid duplicate keys.
234-
235241
## Contributing
236242

237243
Contributions are welcome!

0 commit comments

Comments
 (0)