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

parse-diff

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-diff

Unified diff parser

  • 0.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
534K
decreased by-35.23%
Maintainers
1
Weekly downloads
 
Created

What is parse-diff?

The `parse-diff` npm package is a utility for parsing unified diffs. It allows you to analyze and manipulate diff data, which is useful for applications that need to process changes between file versions, such as code review tools, version control systems, and more.

What are parse-diff's main functionalities?

Parse a diff string

This feature allows you to parse a unified diff string into a structured format. The code sample demonstrates how to parse a diff string and log the resulting file changes.

const parse = require('parse-diff');
const diffString = `diff --git a/file1.txt b/file1.txt
index 83db48f..f735c2d 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1,3 +1,3 @@
-Hello World
+Hello parse-diff
 This is a test file.
 It has multiple lines.`;
const files = parse(diffString);
console.log(files);

Access file changes

This feature allows you to access detailed information about file changes, including chunks and individual changes. The code sample demonstrates how to iterate through the parsed diff data and log the file, chunk, and change details.

const parse = require('parse-diff');
const diffString = `diff --git a/file1.txt b/file1.txt
index 83db48f..f735c2d 100644
--- a/file1.txt
+++ b/file1.txt
@@ -1,3 +1,3 @@
-Hello World
+Hello parse-diff
 This is a test file.
 It has multiple lines.`;
const files = parse(diffString);
files.forEach(file => {
  console.log(`File: ${file.to}`);
  file.chunks.forEach(chunk => {
    console.log(`Chunk: ${chunk.content}`);
    chunk.changes.forEach(change => {
      console.log(`Change: ${change.content}`);
    });
  });
});

Other packages similar to parse-diff

Keywords

FAQs

Package last updated on 16 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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