当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript diff-sequences.default函数代码示例

本文整理汇总了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');
};
开发者ID:elliottsj,项目名称:jest,代码行数:40,代码来源:diffStrings.ts

示例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;
};
开发者ID:facebook,项目名称:jest,代码行数:39,代码来源:diffStrings.ts

示例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;
  }
//.........这里部分代码省略.........
开发者ID:elliottsj,项目名称:jest,代码行数:101,代码来源:diffStrings.ts


注:本文中的diff-sequences.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。