From 7d4502fd96178d48ac9823ed535a51bc93f13929 Mon Sep 17 00:00:00 2001 From: Phil Nova Date: Fri, 22 Feb 2019 11:51:42 -0800 Subject: [PATCH 1/3] Allow max length --- src/filters/texts.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/filters/texts.js b/src/filters/texts.js index cd3c085c..af9e19f9 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); + if (maxLength && (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) { From 05ade7b0c1297bff47acf5912da6f67c9be859c0 Mon Sep 17 00:00:00 2001 From: Phil Nova Date: Fri, 22 Feb 2019 11:52:59 -0800 Subject: [PATCH 2/3] Add to typings --- src/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) 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) From cffca97184c1f8643a72dc8441eb1ef08dd486ad Mon Sep 17 00:00:00 2001 From: Phil Nova Date: Fri, 22 Feb 2019 11:53:42 -0800 Subject: [PATCH 3/3] Simpler --- src/filters/texts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filters/texts.js b/src/filters/texts.js index af9e19f9..535a6799 100644 --- a/src/filters/texts.js +++ b/src/filters/texts.js @@ -73,8 +73,8 @@ export const diffFilter = function textsDiffFilter(context) { // 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); - if (maxLength && (context.left.length > maxLength || context.right.length > maxLength)) { + context.options.textDiff.maxLength) || Number.POSITIVE_INFINITY; + if (context.left.length > maxLength || context.right.length > maxLength) { context.setResult([context.left, context.right]).exit(); return; }