virtual-react-json-diff 1.0.15 β†’ 1.0.16

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 CHANGED
@@ -1,4 +1,4 @@
1
- # πŸ“˜ virtual-react-json-diff
1
+ # virtual-react-json-diff
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![Downloads][download-badge]][npm-url]
@@ -7,16 +7,57 @@
7
7
 
8
8
  πŸ‘‰ [Try it now](https://virtual-react-json-diff.netlify.app)
9
9
 
10
- A high-performance React component for visually comparing large JSON objects. Built on top of [json-diff-kit](https://www.npmjs.com/package/json-diff-kit), this viewer supports virtual scrolling, search functionality, dual minimap, and customizable theming.
10
+ A high-performance React JSON diff viewer for **large, real-world JSON data**.
11
11
 
12
- ## Features
12
+ Built to handle **tens of thousands of lines without freezing the UI**, it uses virtualized rendering to stay fast and responsive even in production-scale scenarios.
13
13
 
14
- - **Virtualized Rendering** – Efficient DOM updates using `react-window`
15
- - **Search Highlighting** – Find matches and scroll directly to them
16
- - **Dual Mini Map** – Scrollable minimap for better navigation
17
- - **Line Count Statistics** – Display added, removed, and modified line counts
18
- - **Object Count Statistics** – Count objects when using compare-key method
19
- - **Customizable Styles** – Add your own class names and themes
14
+ Powered by [json-diff-kit](https://www.npmjs.com/package/json-diff-kit), it supports virtual scrolling, advanced comparison options, search, dual minimaps, and customizable theming.
15
+
16
+ ## Why virtual-react-json-diff exists
17
+
18
+ Most JSON diff viewers work well for **small examples**, but start breaking down in real-world scenarios:
19
+
20
+ * Large JSON files cause the UI to freeze or crash
21
+ * Rendering thousands of DOM nodes makes scrolling unusable
22
+ * Array changes are hard to reason about without object-level comparison
23
+ * It’s difficult to understand the *impact* of changes beyond raw diffs
24
+
25
+ **virtual-react-json-diff** was built to solve these problems.
26
+
27
+ It is designed for internal dashboards and developer tools that need to compare **large, deeply nested JSON objects** efficiently and interactively.
28
+
29
+ ## Key Features
30
+
31
+ virtual-react-json-diff is designed for scenarios where traditional diff viewers become unusable due to size or complexity.
32
+
33
+ ### Built for Large JSONs
34
+
35
+ * **Virtualized rendering** powered by `react-window`
36
+ * Smooth scrolling and interaction even with very large diffs
37
+
38
+ ### Navigate Complex Changes
39
+
40
+ * **Dual minimap** with visual change indicators
41
+ * Jump directly to changes using **search highlighting**
42
+ * Optional single minimap for compact layouts
43
+
44
+ ### Understand Change Impact
45
+
46
+ * **Line count statistics** for added, removed, and modified lines
47
+ * **Object-level statistics** when using compare-key array diffs
48
+ * Quickly assess how big or risky a change really is
49
+
50
+ ### Advanced Comparison Control
51
+
52
+ * Ignore specific keys or paths anywhere in the JSON tree
53
+ * Multiple comparison strategies (`strict`, `loose`, `type-aware`)
54
+ * Fine-grained control over how values are considered equal
55
+
56
+ ### Customizable & Extensible
57
+
58
+ * Custom class names for theming
59
+ * Inline diff customization
60
+ * Access raw diff data for advanced use cases
20
61
 
21
62
  ## Demo
22
63
 
@@ -55,91 +96,131 @@ export default function App() {
55
96
  }
56
97
  ```
57
98
 
58
- ## Line Count Statistics
99
+ ## Understanding Diff Configuration
100
+
101
+ The viewer exposes **two different configuration layers**, each serving a distinct purpose.
102
+
103
+ ### Quick Mental Model
104
+
105
+ * **`differOptions`** β†’ Controls **how the diff is generated**
106
+ * **`comparisonOptions`** β†’ Controls **what is compared and how values are matched**
107
+
108
+ ### `differOptions` β€” *How the diff works*
59
109
 
60
- Enable line-level statistics with `showLineCount={true}`:
110
+ These options are passed directly to the underlying diff engine.
111
+
112
+ Use them to:
113
+
114
+ * Choose how arrays are compared (`compare-key`, positional, etc.)
115
+ * Define comparison keys for object arrays
116
+ * Control depth, circular detection, and modification behavior
61
117
 
62
118
  ```jsx
63
- <VirtualDiffViewer
64
- oldValue={oldData}
65
- newValue={newData}
66
- showLineCount={true}
67
- />;
119
+ differOptions={{
120
+ arrayDiffMethod: "compare-key",
121
+ compareKey: "id",
122
+ maxDepth: 999
123
+ }}
68
124
  ```
69
125
 
70
- Displays: `+5 added lines, -3 removed lines, ~2 modified lines, 10 total line changes`
126
+ ### `comparisonOptions` β€” *What is considered equal or ignored*
71
127
 
72
- ## Object Count Statistics
128
+ These options affect comparison behavior **without changing the diff structure**.
73
129
 
74
- Enable object-level counting when using compare-key method:
130
+ Use them to:
131
+
132
+ * Ignore volatile fields (timestamps, metadata)
133
+ * Exclude specific paths
134
+ * Compare values across types
135
+
136
+ ```jsx
137
+ comparisonOptions={{
138
+ ignoreKeys: ["updatedAt", "__typename"],
139
+ ignorePaths: ["meta.timestamp"],
140
+ compareStrategy: "type-aware"
141
+ }}
142
+ ```
143
+
144
+ ### Using Both Together
75
145
 
76
146
  ```jsx
77
147
  <VirtualDiffViewer
78
148
  oldValue={oldData}
79
149
  newValue={newData}
80
- showObjectCountStats={true}
81
150
  differOptions={{
82
151
  arrayDiffMethod: "compare-key",
83
152
  compareKey: "id"
84
153
  }}
85
- />;
154
+ comparisonOptions={{
155
+ ignoreKeys: ["updatedAt"],
156
+ compareStrategy: "type-aware"
157
+ }}
158
+ />
86
159
  ```
87
160
 
88
- Displays: `+2 added objects, -1 removed objects, ~3 modified objects, 6 total object changes`
89
-
90
- **Requirements:** Only works with `arrayDiffMethod: "compare-key"` and requires a valid `compareKey`.
161
+ This separation keeps the diff engine flexible while allowing precise control over comparison behavior.
91
162
 
92
163
  ## Props
93
164
 
94
- | Prop | Type | Default | Description |
95
- | ---------------------- | -------------------------------------------------- | ------------------ | ---------------------------------------------------------------------- |
96
- | `oldValue` | `object` | β€” | The original JSON object to compare (left side). |
97
- | `newValue` | `object` | β€” | The updated JSON object to compare (right side). |
98
- | `height` | `number` | β€” | Height of the diff viewer in pixels. |
99
- | `hideSearch` | `boolean` | `false` | Hides the search bar if set to `true`. |
100
- | `searchTerm` | `string` | `""` | Initial search keyword to highlight within the diff. |
101
- | `leftTitle` | `string` | β€” | Optional title to display above the left diff panel. |
102
- | `rightTitle` | `string` | β€” | Optional title to display above the right diff panel. |
103
- | `onSearchMatch` | `(index: number) => void` | β€” | Callback fired when a search match is found. Receives the match index. |
104
- | `differOptions` | `DifferOptions` | `Default config` | Advanced options passed to the diffing engine. |
105
- | `showSingleMinimap` | `boolean` | `false` | If `true`, shows only one minimap instead of two. |
106
- | `className` | `string` | β€” | Custom CSS class for styling the viewer container. |
107
- | `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
108
- | `inlineDiffOptions` | `InlineDiffOptions` | `{'mode': 'char'}` | Options for fine-tuning inline diff rendering. |
109
- | `showLineCount` | `boolean` | `false` | Display line count statistics (added, removed, modified lines). |
110
- | `showObjectCountStats` | `boolean` | `false` | Display object count statistics when using compare-key method. |
111
- | `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | - | Get difference data and make operations |
112
-
113
- ## Advanced Usage
114
-
115
- ### Custom Differ Options
165
+ ### Required
116
166
 
117
- ```jsx
118
- const differOptions = {
119
- detectCircular: true,
120
- maxDepth: 999,
121
- showModifications: true,
122
- arrayDiffMethod: "compare-key",
123
- compareKey: "userId",
124
- ignoreCase: false,
125
- recursiveEqual: false,
126
- };
167
+ | Prop | Type | Description |
168
+ | ---------- | -------- | --------------------------------- |
169
+ | `oldValue` | `object` | Original JSON object (left side). |
170
+ | `newValue` | `object` | Updated JSON object (right side). |
127
171
 
128
- <VirtualDiffViewer
129
- oldValue={oldData}
130
- newValue={newData}
131
- differOptions={differOptions}
132
- />;
133
- ```
172
+ ---
134
173
 
135
- ### Utility Functions
174
+ ### Layout & Display
136
175
 
137
- ```jsx
138
- import { calculateObjectCountStats } from "virtual-react-json-diff";
176
+ | Prop | Type | Default | Description |
177
+ | ------------ | -------- | ------- | ----------------------------------------------- |
178
+ | `height` | `number` | β€” | Height of the diff viewer in pixels. |
179
+ | `leftTitle` | `string` | β€” | Optional title shown above the left panel. |
180
+ | `rightTitle` | `string` | β€” | Optional title shown above the right panel. |
181
+ | `className` | `string` | β€” | Custom CSS class applied to the root container. |
139
182
 
140
- const stats = calculateObjectCountStats(oldValue, newValue, "userId");
141
- // Returns: { added: 2, removed: 1, modified: 3, total: 6 }
142
- ```
183
+ ---
184
+
185
+ ### Search & Navigation
186
+
187
+ | Prop | Type | Default | Description |
188
+ | ------------------- | ------------------------- | ------- | ----------------------------------------------- |
189
+ | `hideSearch` | `boolean` | `false` | Hides the search bar when set to `true`. |
190
+ | `searchTerm` | `string` | `""` | Initial search term to highlight in the diff. |
191
+ | `onSearchMatch` | `(index: number) => void` | β€” | Callback fired when a search match is found. |
192
+ | `showSingleMinimap` | `boolean` | `false` | Show a single minimap instead of dual minimaps. |
193
+ | `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
194
+
195
+ ---
196
+
197
+ ### Statistics & Insights
198
+
199
+ | Prop | Type | Default | Description |
200
+ | ---------------------- | --------- | ------- | -------------------------------------------------------------------- |
201
+ | `showLineCount` | `boolean` | `false` | Display added, removed, and modified **line** counts. |
202
+ | `showObjectCountStats` | `boolean` | `false` | Display **object-level** stats (requires compare-key array diffing). |
203
+
204
+ > **Note:** `showObjectCountStats` only works when
205
+ > `differOptions.arrayDiffMethod = "compare-key"` and `compareKey` is provided.
206
+
207
+ ---
208
+
209
+ ### Diff Configuration
210
+
211
+ | Prop | Type | Default | Description |
212
+ | ------------------- | ----------------------- | ------------------ | ------------------------------------------------------------- |
213
+ | `differOptions` | `DifferOptions` | Engine defaults | Controls **how the diff is generated** (arrays, depth, keys). |
214
+ | `comparisonOptions` | `DiffComparisonOptions` | β€” | Controls **what is compared and how values match**. |
215
+ | `inlineDiffOptions` | `InlineDiffOptions` | `{ mode: "char" }` | Fine-tune inline diff rendering behavior. |
216
+
217
+ ---
218
+
219
+ ### Advanced & Utility
220
+
221
+ | Prop | Type | Default | Description |
222
+ | ------------- | -------------------------------------------------- | ------- | ----------------------------------------------------------- |
223
+ | `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | β€” | Access raw diff results for custom processing or analytics. |
143
224
 
144
225
  ## Styling
145
226
 
@@ -149,11 +230,11 @@ The component exposes a root container with class `diff-viewer-container`. You c
149
230
 
150
231
  Built on top of the awesome [json-diff-kit](https://www.npmjs.com/package/json-diff-kit).
151
232
 
152
- ## πŸ“„ License
233
+ ## License
153
234
 
154
235
  MIT Β© Utku AkyΓΌz
155
236
 
156
- ## πŸ› οΈ Contributing
237
+ ## Contributing
157
238
 
158
239
  Pull requests, suggestions, and issues are welcome!
159
240