Skip to content

Allow user to specify a maxLength for character diffing #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/filters/texts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down