diff --git a/src/filters/texts.js b/src/filters/texts.js index cd3c085c..535a6799 100644 --- a/src/filters/texts.js +++ b/src/filters/texts.js @@ -69,6 +69,16 @@ export const diffFilter = function textsDiffFilter(context) { context.setResult([context.left, context.right]).exit(); return; } + + // if the user specified a max length for character diffing, don't use the text-diff algorithm + let maxLength = (context.options && + context.options.textDiff && + context.options.textDiff.maxLength) || Number.POSITIVE_INFINITY; + if (context.left.length > maxLength || context.right.length > maxLength) { + context.setResult([context.left, context.right]).exit(); + return; + } + // large text, try to use a text-diff algorithm let diffMatchPatch = getDiffMatchPatch(); if (!diffMatchPatch) { diff --git a/src/index.d.ts b/src/index.d.ts index d580f95f..75ef7a49 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -24,6 +24,8 @@ export interface Config { textDiff?: { // default 60, minimum string length (left and right sides) to use text diff algorythm: google-diff-match-patch minLength: number, + // optional character max (left and right sides) at which google-diff-match-patch will not be used + maxLength?: number, }; /* this optional function can be specified to ignore object properties (eg. volatile data)