How to use the diff.diffArrays function in diff

To help you get started, we’ve selected a few diff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brodybits / prettierx / src / main / core.js View on Github external
};
    }

    // diff old and new cursor node texts, with a special cursor
    // symbol inserted to find out where it moves to

    const oldCursorNodeCharArray = oldCursorNodeText.split("");
    oldCursorNodeCharArray.splice(
      cursorOffsetRelativeToOldCursorNode,
      0,
      CURSOR
    );

    const newCursorNodeCharArray = newCursorNodeText.split("");

    const cursorNodeDiff = diff.diffArrays(
      oldCursorNodeCharArray,
      newCursorNodeCharArray
    );

    let cursorOffset = newCursorNodeStart;
    for (const entry of cursorNodeDiff) {
      if (entry.removed) {
        if (entry.value.indexOf(CURSOR) > -1) {
          break;
        }
      } else {
        cursorOffset += entry.count;
      }
    }

    return { formatted: result.formatted, cursorOffset };
github indico / indico / bin / maintenance / update_browsers.js View on Github external
function updateBrowserslist() {
  console.log(chalk.whiteBright('Checking browserslist'));
  console.log();
  const data = browserslist.readConfig(BROWSERSLIST_PATH);
  const production = browserslist(null, {
    env: 'production-template',
    config: BROWSERSLIST_PATH,
  });

  const d = diff.diffArrays(data.production, production);
  d.forEach(part => {
    // green for additions, red for deletions
    // grey for common parts
    if (part.added) {
      console.log(chalk.green(part.value.join('\n')));
    } else if (part.removed) {
      console.log(chalk.red(part.value.join('\n')));
    } else {
      console.log(chalk.grey(part.value.join('\n')));
    }
  });
  console.log();

  const oldConfig = dumpConfig(data);
  const newConfig = dumpConfig({...data, production});
  if (oldConfig !== newConfig) {
github vtex / toolbelt / src / modules / utils.ts View on Github external
export const matchedDepsDiffTable = (title1: string, title2: string, deps1: string[], deps2: string[]) => {
  const depsDiff = diffArrays(deps1, deps2)
  // Get deduplicated names (no version) of the changed deps.
  const depNames = [
    ...new Set(
      R.compose(
        R.map(k => R.head(R.split('@', k))),
        R.flatten,
        R.pluck('value'),
        R.filter((k: any) => !!k.removed || !!k.added)
      )(depsDiff)
    ),
  ].sort()
  const produceStartValues = () => R.map(_ => [])(depNames) as any
  // Each of the following objects will start as a { `depName`: [] }, ... }-like.
  const addedDeps = R.zipObj(depNames, produceStartValues())
  const removedDeps = R.zipObj(depNames, produceStartValues())
github gedex / wp-tools / src / commands / release-wporg.js View on Github external
function removeFilesFromDiff( base, from, to ) {
	diffArrays( from, to ).forEach( d => {
		if ( d.removed && d.value ) {
			d.value.forEach( f => {
				rimraf.sync( resolve( base, f ) );
			} );
		}
	} );
}