virtual-react-json-diff 1.0.14 β†’ 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,72 +1,83 @@
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]
5
5
  ![bundle size](https://badgen.net/bundlephobia/minzip/virtual-react-json-diff)
6
6
  [![BuyMeACoffee](https://raw.githubusercontent.com/pachadotdev/buymeacoffee-badges/main/bmc-yellow.svg)](https://www.buymeacoffee.com/utkuakyuz)
7
7
 
8
- πŸ‘‰ [Try it now](https://virtual-react-json-diff.netlify.app) (See the New Demo Page Including AceEditor)
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:
10
+ A high-performance React JSON diff viewer for **large, real-world JSON data**.
11
11
 
12
- - Virtual scrolling for better performance (especially for large diffs)
13
- - Custom theming (Soon new themes will be available)
14
- - Dual Mini Map
15
- - πŸ” Search functionality
16
- - βš›οΈ Optimized for React (uses `react-window`)
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.
17
13
 
18
- This component is developed for dealing with thousands of lines of Json Files, and seamlessly compare then render them on UI. Json Compare is a concept that has insufficient FE components available. This component brings solution to the issues of current diff viewers. Virtualized scroll gives a smooth experience while dual minimap and search ability simplifies the process of comparing JSON objects.
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.
19
15
 
20
- ## Features
16
+ ## Why virtual-react-json-diff exists
21
17
 
22
- - **Compare Large JSON Objects** – Handles big files without freezing the UI
23
- - **Virtualized Rendering** – Efficient DOM updates using `react-window`
24
- - **Search Highlighting** – Find matches and scroll directly to them
25
- - **Mini Map** – Dual scrollable minimap of Json Diff, scaled to better see comparison result
26
- - **Customizable Styles** – Add your own class names and styles easily (checkout JsonDiffCustomTheme.css)
18
+ Most JSON diff viewers work well for **small examples**, but start breaking down in real-world scenarios:
27
19
 
28
- ## Demo
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
29
24
 
30
- To see how it works, demo available here: https://virtual-react-json-diff.netlify.app
25
+ **virtual-react-json-diff** was built to solve these problems.
31
26
 
32
- ## πŸ“¦ Installation
27
+ It is designed for internal dashboards and developer tools that need to compare **large, deeply nested JSON objects** efficiently and interactively.
33
28
 
34
- ```bash
35
- npm install virtual-react-json-diff
36
- # or
37
- yarn add virtual-react-json-diff
38
- # or
39
- pnpm add virtual-react-json-diff
40
- ```
29
+ ## Key Features
41
30
 
42
- ## Example Screenshot
31
+ virtual-react-json-diff is designed for scenarios where traditional diff viewers become unusable due to size or complexity.
43
32
 
44
- The theme is fully customizable, all colors can be changed. (And soon new themes will be available)
33
+ ### Built for Large JSONs
45
34
 
46
- ![ExampleScreenshot](https://raw.githubusercontent.com/utkuakyuz/virtual-react-json-diff/main/public/image-1.0.11.png)
35
+ * **Virtualized rendering** powered by `react-window`
36
+ * Smooth scrolling and interaction even with very large diffs
47
37
 
48
- ## Usage
38
+ ### Navigate Complex Changes
49
39
 
50
- Modify DifferOptions and InlineDiffOptions and see the output.
40
+ * **Dual minimap** with visual change indicators
41
+ * Jump directly to changes using **search highlighting**
42
+ * Optional single minimap for compact layouts
51
43
 
52
- Dual Minimap is defaultly shown, to hide middle minimap, just pass `ShowSingleMinimap` prop to Viewer.
44
+ ### Understand Change Impact
53
45
 
54
- To change Diff methods please see `DifferOptions`. By default `virtual-react-json-diff` uses following configuration.
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
55
49
 
56
- ```
57
- new Differ({
58
- detectCircular: true,
59
- maxDepth: 20,
60
- showModifications: true,
61
- arrayDiffMethod: "lcs",
62
- preserveKeyOrder: "before",
63
- ...differOptions,
64
- }),
65
- ```
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
66
55
 
67
- Simply pass your json objects into Viewer Component. It will find differences and show.
56
+ ### Customizable & Extensible
57
+
58
+ * Custom class names for theming
59
+ * Inline diff customization
60
+ * Access raw diff data for advanced use cases
61
+
62
+ ## Demo
68
63
 
64
+ πŸ‘‰ [Try it now](https://virtual-react-json-diff.netlify.app) - Interactive demo with live examples
65
+
66
+ ![Example Screenshot](https://raw.githubusercontent.com/utkuakyuz/virtual-react-json-diff/main/public/image-1.0.15.png)
67
+
68
+ ## Installation
69
+
70
+ ```bash
71
+ npm install virtual-react-json-diff
72
+ # or
73
+ yarn add virtual-react-json-diff
74
+ # or
75
+ pnpm add virtual-react-json-diff
69
76
  ```
77
+
78
+ ## Usage
79
+
80
+ ```jsx
70
81
  import { VirtualDiffViewer } from "virtual-react-json-diff";
71
82
 
72
83
  const oldData = { name: "Alice", age: 25 };
@@ -78,86 +89,154 @@ export default function App() {
78
89
  oldValue={oldData}
79
90
  newValue={newData}
80
91
  height={600}
81
- className="my-custom-diff"
92
+ showLineCount={true}
93
+ showObjectCountStats={false}
82
94
  />
83
95
  );
84
96
  }
85
97
  ```
86
98
 
87
- ---
99
+ ## Understanding Diff Configuration
88
100
 
89
- If you need to see or make some calculations on difference objects, you can get the diff data using `getDifferData` callback prop
101
+ The viewer exposes **two different configuration layers**, each serving a distinct purpose.
90
102
 
91
- ```
92
- import { type DiffResult, VirtualDiffViewer } from "virtual-react-json-diff";
103
+ ### Quick Mental Model
93
104
 
94
- const [differData, setDifferData] = useState<[DiffResult[], DiffResult[]]>();
105
+ * **`differOptions`** β†’ Controls **how the diff is generated**
106
+ * **`comparisonOptions`** β†’ Controls **what is compared and how values are matched**
95
107
 
96
- <VirtualDiffViewer {...props} getDiffData={diffData => setDifferData(diffData)} />
108
+ ### `differOptions` β€” *How the diff works*
109
+
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
117
+
118
+ ```jsx
119
+ differOptions={{
120
+ arrayDiffMethod: "compare-key",
121
+ compareKey: "id",
122
+ maxDepth: 999
123
+ }}
97
124
  ```
98
125
 
99
- Or if you have a custom Differ or a custom viewer, you can import `Differ` class to create diff objects using your own differ. Moreover you can pass that differ to `VirtualizedDiffViewer`.
126
+ ### `comparisonOptions` β€” *What is considered equal or ignored*
100
127
 
101
- p.s. This is not recommended because you can modify all variables in Differ using `differOptions` prop in Viewer.
128
+ These options affect comparison behavior **without changing the diff structure**.
129
+
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
+ ```
102
143
 
144
+ ### Using Both Together
145
+
146
+ ```jsx
147
+ <VirtualDiffViewer
148
+ oldValue={oldData}
149
+ newValue={newData}
150
+ differOptions={{
151
+ arrayDiffMethod: "compare-key",
152
+ compareKey: "id"
153
+ }}
154
+ comparisonOptions={{
155
+ ignoreKeys: ["updatedAt"],
156
+ compareStrategy: "type-aware"
157
+ }}
158
+ />
103
159
  ```
104
- import { Differ, VirtualDiffViewer } from "virtual-react-json-diff";
160
+
161
+ This separation keeps the diff engine flexible while allowing precise control over comparison behavior.
162
+
163
+ ## Props
164
+
165
+ ### Required
166
+
167
+ | Prop | Type | Description |
168
+ | ---------- | -------- | --------------------------------- |
169
+ | `oldValue` | `object` | Original JSON object (left side). |
170
+ | `newValue` | `object` | Updated JSON object (right side). |
171
+
105
172
  ---
106
- const differOptions: DifferOptions = {
107
- showModifications: config.showModifications,
108
- arrayDiffMethod: config.arrayDiffMethod,
109
- };
110
- const differ = new Differ(differOptions);
173
+
174
+ ### Layout & Display
175
+
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. |
111
182
 
112
183
  ---
113
184
 
114
- // Pass it into Viewer with 'customDiffer' prop
115
- <VirtualDiffViewer {...props} customDiffer={differ} />
116
- ```
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. |
117
194
 
118
195
  ---
119
196
 
120
- The component exposes a root container with the class:
197
+ ### Statistics & Insights
121
198
 
122
- ```
123
- <div class="diff-viewer-container">...</div>
124
- ```
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). |
125
203
 
126
- You can pass your own class name via the className prop to apply custom themes.
204
+ > **Note:** `showObjectCountStats` only works when
205
+ > `differOptions.arrayDiffMethod = "compare-key"` and `compareKey` is provided.
127
206
 
128
- ## Props
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. |
224
+
225
+ ## Styling
129
226
 
130
- | Prop | Type | Default | Description |
131
- | ------------------- | -------------------------------------------------- | ------------------ | ---------------------------------------------------------------------- |
132
- | `oldValue` | `object` | β€” | The original JSON object to compare (left side). |
133
- | `newValue` | `object` | β€” | The updated JSON object to compare (right side). |
134
- | `height` | `number` | β€” | Height of the diff viewer in pixels. |
135
- | `hideSearch` | `boolean` | `false` | Hides the search bar if set to `true`. |
136
- | `searchTerm` | `string` | `""` | Initial search keyword to highlight within the diff. |
137
- | `leftTitle` | `string` | β€” | Optional title to display above the left diff panel. |
138
- | `rightTitle` | `string` | β€” | Optional title to display above the right diff panel. |
139
- | `onSearchMatch` | `(index: number) => void` | β€” | Callback fired when a search match is found. Receives the match index. |
140
- | `differOptions` | `DifferOptions` | `Given Above` | Advanced options passed to the diffing engine. |
141
- | `showSingleMinimap` | `boolean` | `false` | If `true`, shows only one minimap instead of two. |
142
- | `className` | `string` | β€” | Custom CSS class for styling the viewer container. |
143
- | `overScanCount` | `number` | `28` | Number of rendered rows outside of the viewport for virtualization |
144
- | `miniMapWidth` | `number` | `40` | Width of each minimap in pixels. |
145
- | `inlineDiffOptions` | `InlineDiffOptions` | `{'mode': 'char'}` | Options for fine-tuning inline diff rendering. |
146
- | `getDiffData` | `(diffData: [DiffResult[], DiffResult[]]) => void` | - | Get difference data and make operations |
147
- | `customDiffer` | `Differ` | - | Pass custom differ - not recommended |
227
+ The component exposes a root container with class `diff-viewer-container`. You can pass your own class name via the `className` prop to apply custom themes.
148
228
 
149
229
  ## πŸ™Œ Acknowledgements
150
230
 
151
- Built on top of the awesome json-diff-kit.
231
+ Built on top of the awesome [json-diff-kit](https://www.npmjs.com/package/json-diff-kit).
152
232
 
153
- ## πŸ“„ License
233
+ ## License
154
234
 
155
235
  MIT Β© Utku AkyΓΌz
156
236
 
157
- ## πŸ› οΈ Contributing
237
+ ## Contributing
158
238
 
159
239
  Pull requests, suggestions, and issues are welcome!
160
- Check out the issues or open a PR.
161
240
 
162
241
  [npm-url]: https://npmjs.org/package/virtual-react-json-diff
163
242
  [npm-image]: https://img.shields.io/npm/v/virtual-react-json-diff.svg