Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-diff-view

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-diff-view - npm Package Compare versions

Comparing version 1.4.0-beta.2 to 1.4.0-beta.3

2

package.json
{
"name": "react-diff-view",
"version": "1.4.0-beta.2",
"version": "1.4.0-beta.3",
"description": "A git diff component to consume the git unified diff output.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -66,2 +66,23 @@ import leven from 'leven';

const createFindChangeByLineNumberFunction = side => {
const computeLineNumber = side === 'old' ? computeOldLineNumber : computeNewLineNumber;
const startProperty = side + 'Start';
const linesProperty = side + 'Lines';
const isInHunk = createIsInHunkFunction(startProperty, linesProperty);
return (hunks, lineNumber) => {
const containerHunk = hunks.find(hunk => isInHunk(hunk, lineNumber));
if (!containerHunk) {
return undefined;
}
return containerHunk.changes.find(change => computeLineNumber(change) === lineNumber);
};
};
export const findChangeByOldLineNumber = createFindChangeByLineNumberFunction('old');
export const findChangeByNewLineNumber = createFindChangeByLineNumberFunction('new');
const createCorrespondingLineNumberComputeFunction = baseSide => {

@@ -73,2 +94,4 @@ const anotherSide = baseSide === 'old' ? 'new' : 'old';

const correspondingLines = anotherSide + 'Lines';
const baseLineNumber = baseSide === 'old' ? computeOldLineNumber : computeNewLineNumber;
const correspondingLineNumber = baseSide === 'old' ? computeOldLineNumber : computeNewLineNumber;
const isInHunk = createIsInHunkFunction(baseStart, baseLines);

@@ -97,4 +120,33 @@ const isBetweenHunks = createIsBetweenHunksFunction(baseStart, baseLines);

// Within current hunk or between 2 hunks
if (isInHunk(currentHunk, lineNumber) || isBetweenHunks(currentHunk, nextHunk, lineNumber)) {
// Within current hunk
if (isInHunk(currentHunk, lineNumber)) {
const changeIndex = currentHunk.changes.findIndex(change => baseLineNumber(change) === lineNumber);
const change = currentHunk.changes[changeIndex];
if (change.isNormal) {
return correspondingLineNumber(change);
}
// For changes of type "insert" and "delete", the sibling change can be the corresponding one,
// or they can have no corresponding change
//
// Git diff always put delete change before insert change
//
// Note that `nearbySequences: "zip"` option can affect this function
const possibleCorrespondingChangeIndex = change.isDelete ? changeIndex + 1 : changeIndex - 1;
const possibleCorrespondingChange = currentHunk.changes[possibleCorrespondingChangeIndex];
if (!possibleCorrespondingChange) {
return -1;
}
const negativeChangeType = change.isInsert ? 'delete' : 'insert';
return possibleCorrespondingChange.type === negativeChangeType
? correspondingLineNumber(possibleCorrespondingChange)
: -1;
}
// Between 2 hunks
if (isBetweenHunks(currentHunk, nextHunk, lineNumber)) {
const spanFromEnd = lineNumber - currentHunk[baseStart] - currentHunk[baseLines];

@@ -101,0 +153,0 @@ return currentHunk[correspondingStart] + currentHunk[correspondingLines] + spanFromEnd;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc