You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-6Lines changed: 31 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -327,8 +327,8 @@ You can resolve the conflict by keeping the first or last row of the duplicates:
327
327
```Typescript
328
328
import { diff } from'tabular-data-differ';
329
329
conststats=awaitdiff({
330
-
oldSource: './tests/a.csv',
331
-
newSource: './tests/b.csv',
330
+
oldSource: './tests/a2.csv',
331
+
newSource: './tests/b2.csv',
332
332
keys: ['id'],
333
333
duplicateKeyHandling: 'keepFirstRow', // or 'keepLastRow'
334
334
}).to('console');
@@ -339,17 +339,34 @@ Or, if you need more control in the row selection, then you can provide your own
339
339
```Typescript
340
340
import { diff } from'tabular-data-differ';
341
341
conststats=awaitdiff({
342
-
oldSource: './tests/a.csv',
343
-
newSource: './tests/b.csv',
342
+
oldSource: './tests/a2.csv',
343
+
newSource: './tests/b2.csv',
344
344
keys: ['id'],
345
345
duplicateKeyHandling: (rows) =>rows[0], // same as 'keepFirstRow'
346
346
duplicateRowBufferSize: 2000,
347
-
}).to('console');
347
+
}).to('null');
348
348
console.log(stats);
349
349
```
350
350
351
351
Note that you can specify the size of the buffer if you know that it cannot exceed this quantity, otherwise you can enable the **duplicateRowBufferOverflow** option,
352
-
which will remove the first entries when it exceeds the allocated capacity, to avoid a failure.
352
+
which will remove the first entries when it exceeds the allocated capacity, to avoid any failure.
353
+
354
+
Finally, you can inspect the source stats to check the duplication metrics:
355
+
```Typescript
356
+
import { diff } from'tabular-data-differ';
357
+
constctx=awaitdiff({
358
+
oldSource: './tests/a2.csv',
359
+
newSource: './tests/b2.csv',
360
+
keys: ['id'],
361
+
duplicateKeyHandling: 'keepFirstRow', // or 'keepLastRow'
362
+
}).start();
363
+
conststats=awaitctx.to('null');
364
+
console.log(stats);
365
+
console.log(ctx.oldStats);
366
+
console.log(ctx.newStats);
367
+
368
+
```
369
+
353
370
354
371
### Order 2 CSV files and diff them on the console
355
372
@@ -632,6 +649,14 @@ Returns the current column names.
632
649
633
650
Returns the currents stats.
634
651
652
+
#### oldSourceStats
653
+
654
+
Returns the stats accumulated while parsing the old source.
655
+
656
+
#### newSourceStats
657
+
658
+
Returns the stats accumulated while parsing the new source.
659
+
635
660
#### to
636
661
637
662
Initiates the comparison between the old and new sources and sends the diffs to the specified output.
thrownewUniqueKeyViolationError(`Expected rows to be unique by "${cols}" in ${source} source but received:\n previous=${previous}\n current=${current}`);
778
+
thrownewUniqueKeyViolationError(`Expected rows to be unique by "${cols}" in ${source} source but received:\n previous=${previous}\n current=${current}\nNote that you can resolve this conflict automatically using the duplicateKeyHandling option.`);
0 commit comments