本文整理汇总了TypeScript中diff-sequences.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: formatDelete
const diffExpand = (
aLinesUn: Array<string>,
bLinesUn: Array<string>,
aLinesIn: Array<string>,
bLinesIn: Array<string>,
): string => {
const isCommon: Callbacks['isCommon'] = (aIndex, bIndex) =>
aLinesUn[aIndex] === bLinesUn[bIndex];
const array: string[] = [];
const put = (line: string) => {
array.push(line);
};
let aStart = 0;
let bStart = 0;
const foundSubsequence: Callbacks['foundSubsequence'] = (
nCommon,
aCommon,
bCommon,
) => {
formatDelete(aStart, aCommon, aLinesUn, aLinesIn, put);
formatInsert(bStart, bCommon, bLinesUn, bLinesIn, put);
formatCommon(nCommon, aCommon, bCommon, aLinesIn, bLinesUn, bLinesIn, put);
aStart = aCommon + nCommon;
bStart = bCommon + nCommon;
};
const aLength = aLinesUn.length;
const bLength = bLinesUn.length;
diff(aLength, bLength, isCommon, foundSubsequence);
// After the last common subsequence, format remaining change lines.
formatDelete(aStart, aLength, aLinesUn, aLinesIn, put);
formatInsert(bStart, bLength, bLinesUn, bLinesIn, put);
return array.join('\n');
};
示例2: Diff
const diffStrings = (a: string, b: string): Array<Diff> | null => {
const isCommon = (aIndex: number, bIndex: number) => a[aIndex] === b[bIndex];
let aIndex = 0;
let bIndex = 0;
const diffs: Array<Diff> = [];
const foundSubsequence = (
nCommon: number,
aCommon: number,
bCommon: number,
) => {
if (aIndex !== aCommon) {
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
}
if (bIndex !== bCommon) {
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
}
aIndex = aCommon + nCommon; // number of characters compared in a
bIndex = bCommon + nCommon; // number of characters compared in b
diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
};
diffSequences(a.length, b.length, isCommon, foundSubsequence);
// After the last common subsequence, push remaining change items.
if (aIndex !== a.length) {
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
}
if (bIndex !== b.length) {
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
}
cleanupSemantic(diffs);
// Assume it has a change string, but does it have a common string?
return diffs.some(diff => diff[0] === DIFF_EQUAL) ? diffs : null;
};
示例3: formatCommon
const diffNoExpand = (
aLinesUn: Array<string>,
bLinesUn: Array<string>,
aLinesIn: Array<string>,
bLinesIn: Array<string>,
nContextLines: number,
): string => {
const isCommon: Callbacks['isCommon'] = (aIndex, bIndex) =>
aLinesUn[aIndex] === bLinesUn[bIndex];
let iPatchMark = 0; // index of placeholder line for patch mark
const array = [''];
const put = (line: string) => {
array.push(line);
};
let isAtEnd = false;
const aLength = aLinesUn.length;
const bLength = bLinesUn.length;
const nContextLines2 = nContextLines + nContextLines;
// Initialize the first patch for changes at the start,
// especially for edge case in which there is no common subsequence.
let aStart = 0;
let aEnd = 0;
let bStart = 0;
let bEnd = 0;
// Given the number of items and starting indexes of each common subsequence,
// format any preceding change lines, and then common context lines.
const foundSubsequence: Callbacks['foundSubsequence'] = (
nCommon,
aStartCommon,
bStartCommon,
) => {
const aEndCommon = aStartCommon + nCommon;
const bEndCommon = bStartCommon + nCommon;
isAtEnd = aEndCommon === aLength && bEndCommon === bLength;
// If common subsequence is at start, re-initialize the first patch.
if (aStartCommon === 0 && bStartCommon === 0) {
const nLines = nContextLines < nCommon ? nContextLines : nCommon;
aStart = aEndCommon - nLines;
bStart = bEndCommon - nLines;
formatCommon(nLines, aStart, bStart, aLinesIn, bLinesUn, bLinesIn, put);
aEnd = aEndCommon;
bEnd = bEndCommon;
return;
}
// Format preceding change lines.
formatDelete(aEnd, aStartCommon, aLinesUn, aLinesIn, put);
formatInsert(bEnd, bStartCommon, bLinesUn, bLinesIn, put);
aEnd = aStartCommon;
bEnd = bStartCommon;
// If common subsequence is at end, then context follows preceding changes;
// else context follows preceding changes AND precedes following changes.
const maxContextLines = isAtEnd ? nContextLines : nContextLines2;
if (nCommon <= maxContextLines) {
// The patch includes all lines in the common subsequence.
formatCommon(nCommon, aEnd, bEnd, aLinesIn, bLinesUn, bLinesIn, put);
aEnd += nCommon;
bEnd += nCommon;
return;
}
// The patch ends because context is less than number of common lines.
formatCommon(nContextLines, aEnd, bEnd, aLinesIn, bLinesUn, bLinesIn, put);
aEnd += nContextLines;
bEnd += nContextLines;
array[iPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd);
// If common subsequence is not at end, another patch follows it.
if (!isAtEnd) {
iPatchMark = array.length; // index of placeholder line
array[iPatchMark] = '';
const nLines = nContextLines < nCommon ? nContextLines : nCommon;
aStart = aEndCommon - nLines;
bStart = bEndCommon - nLines;
formatCommon(nLines, aStart, bStart, aLinesIn, bLinesUn, bLinesIn, put);
aEnd = aEndCommon;
bEnd = bEndCommon;
}
};
diff(aLength, bLength, isCommon, foundSubsequence);
// If no common subsequence or last was not at end, format remaining change lines.
if (!isAtEnd) {
formatDelete(aEnd, aLength, aLinesUn, aLinesIn, put);
formatInsert(bEnd, bLength, bLinesUn, bLinesIn, put);
aEnd = aLength;
bEnd = bLength;
}
//.........这里部分代码省略.........