json-diff-ts 4.8.0 → 4.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
[](https://www.typescriptlang.org/)
|
|
11
11
|
[](http://makeapullrequest.com)
|
|
12
12
|
[](https://opensource.org/licenses/MIT)
|
|
13
|
-
[](https://nodejs.org/)
|
|
14
13
|
|
|
15
14
|
## Overview
|
|
16
15
|
|
|
@@ -18,9 +17,9 @@
|
|
|
18
17
|
|
|
19
18
|
### 🚀 **Why Choose json-diff-ts?**
|
|
20
19
|
|
|
21
|
-
- **🔥 Zero dependencies** - Lightweight bundle size
|
|
20
|
+
- **🔥 Zero dependencies** - Lightweight bundle size
|
|
22
21
|
- **⚡ High performance** - Optimized algorithms for fast JSON diffing and patching
|
|
23
|
-
- **🎯
|
|
22
|
+
- **🎯 95%+ test coverage** - Thoroughly tested with comprehensive test suite
|
|
24
23
|
- **📦 Modern ES modules** - Full TypeScript support with tree-shaking
|
|
25
24
|
- **🔧 Flexible API** - Compare, diff, patch, and atomic operations
|
|
26
25
|
- **🌐 Universal** - Works in browsers, Node.js, and edge environments
|
|
@@ -117,6 +116,14 @@ const newData = {
|
|
|
117
116
|
};
|
|
118
117
|
|
|
119
118
|
const diffs = diff(oldData, newData, { embeddedObjKeys: { characters: 'id' } });
|
|
119
|
+
console.log(diffs);
|
|
120
|
+
// First operations:
|
|
121
|
+
// [
|
|
122
|
+
// { type: 'UPDATE', key: 'location', value: 'Yavin Base', oldValue: 'Tatooine' },
|
|
123
|
+
// { type: 'UPDATE', key: 'mission', value: 'Destroy Death Star', oldValue: 'Rescue Princess' },
|
|
124
|
+
// { type: 'UPDATE', key: 'status', value: 'Complete', oldValue: 'In Progress' },
|
|
125
|
+
// ...
|
|
126
|
+
// ]
|
|
120
127
|
```
|
|
121
128
|
|
|
122
129
|
#### Advanced Options
|
|
@@ -245,10 +252,14 @@ Apply or revert changes to JSON objects.
|
|
|
245
252
|
import { applyChangeset, revertChangeset } from 'json-diff-ts';
|
|
246
253
|
|
|
247
254
|
// Apply changes
|
|
248
|
-
applyChangeset(oldData, diffs);
|
|
249
|
-
|
|
250
|
-
//
|
|
251
|
-
|
|
255
|
+
const updated = applyChangeset(oldData, diffs);
|
|
256
|
+
console.log(updated);
|
|
257
|
+
// { location: 'Yavin Base', mission: 'Destroy Death Star', status: 'Complete', ... }
|
|
258
|
+
|
|
259
|
+
// Revert changes
|
|
260
|
+
const reverted = revertChangeset(newData, diffs);
|
|
261
|
+
console.log(reverted);
|
|
262
|
+
// { location: 'Tatooine', mission: 'Rescue Princess', status: 'In Progress', ... }
|
|
252
263
|
```
|
|
253
264
|
|
|
254
265
|
## API Reference
|
|
@@ -282,6 +293,12 @@ interface Options {
|
|
|
282
293
|
}
|
|
283
294
|
```
|
|
284
295
|
|
|
296
|
+
| Option | Type | Description |
|
|
297
|
+
| ------ | ---- | ----------- |
|
|
298
|
+
| `embeddedObjKeys` | `Record<string, string | Function>` or `Map<string | RegExp, string | Function>` | Map paths of arrays to a key or resolver function used to match elements when diffing. Use a `Map` for regex paths. |
|
|
299
|
+
| `keysToSkip` | `string[]` | Dotted paths to exclude from comparison, e.g. `"meta.info"`. |
|
|
300
|
+
| `treatTypeChangeAsReplace` | `boolean` | When `true` (default), a type change results in a REMOVE/ADD pair. Set to `false` to treat it as an UPDATE. |
|
|
301
|
+
|
|
285
302
|
### Change Types
|
|
286
303
|
|
|
287
304
|
```typescript
|
|
@@ -294,6 +311,7 @@ enum Operation {
|
|
|
294
311
|
|
|
295
312
|
## Release Notes
|
|
296
313
|
|
|
314
|
+
- **v4.8.1:** Improved documentation with working examples and detailed options.
|
|
297
315
|
- **v4.8.0:** Significantly reduced bundle size by completely removing es-toolkit dependency and implementing custom utility functions. This change eliminates external dependencies while maintaining identical functionality and improving performance.
|
|
298
316
|
|
|
299
317
|
- **v4.7.0:** Optimized bundle size and performance by replacing es-toolkit/compat with es-toolkit for difference, intersection, and keyBy functions
|
|
@@ -388,4 +406,4 @@ This project takes inspiration and code from [diff-json](https://www.npmjs.com/p
|
|
|
388
406
|
|
|
389
407
|
json-diff-ts is open-sourced software licensed under the [MIT license](LICENSE).
|
|
390
408
|
|
|
391
|
-
The original diff-json project is also under the MIT License. For more information, refer to its [license details](https://www.npmjs.com/package/diff-json#license).
|
|
409
|
+
The original diff-json project is also under the MIT License. For more information, refer to its [license details](https://www.npmjs.com/package/diff-json#license).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-diff-ts",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "Modern TypeScript JSON diff library - Zero dependencies, high performance, ESM + CommonJS support. Calculate and apply differences between JSON objects with advanced features like key-based array diffing, JSONPath support, and atomic changesets.",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|