@@ -3,6 +3,7 @@ import {ReactElement, JSX} from 'react';
33import cn from 'classnames' ;
44
55import { computeLineInformation , DiffInformation , DiffMethod , DiffType , LineInformation , } from './compute-lines' ;
6+ import { Change } from 'diff' ;
67import computeStyles , { ReactDiffViewerStyles , ReactDiffViewerStylesOverride , } from './styles' ;
78import { Block , computeHiddenBlocks } from "./compute-hidden-blocks" ;
89import { Expand } from "./expand" ;
@@ -29,7 +30,7 @@ export interface ReactDiffViewerProps {
2930 // Enable/Disable word diff.
3031 disableWordDiff ?: boolean ;
3132 // JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
32- compareMethod ?: DiffMethod ;
33+ compareMethod ?: DiffMethod | ( ( oldStr : string , newStr : string ) => Change [ ] ) ;
3334 // Number of unmodified lines surrounding each line diff.
3435 extraLinesSurroundingDiff ?: number ;
3536 // Show/hide line number.
@@ -596,11 +597,12 @@ class DiffViewer extends React.Component<
596597 leftTitle,
597598 rightTitle,
598599 splitView,
600+ compareMethod,
599601 hideLineNumbers,
600602 nonce,
601603 } = this . props ;
602604
603- if ( this . props . compareMethod !== DiffMethod . JSON ) {
605+ if ( typeof ( compareMethod ) === 'string' && compareMethod !== DiffMethod . JSON ) {
604606 if ( typeof oldValue !== 'string' || typeof newValue !== 'string' ) {
605607 throw Error ( '"oldValue" and "newValue" should be strings' ) ;
606608 }
0 commit comments