JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17224
  • Score
    100M100P100Q150288F
  • License MIT

diff parsing library

Package Exports

  • what-the-diff

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (what-the-diff) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JavaScript Diff Parser

Credit: @eightballart

Parse unified diffs with JavaScript

Installation

what-the-diff is available via npm

npm install what-the-diff

Usage

let parse = require('what-the-diff')

var str = `diff --git file.txt file.txt
index 83db48f..bf269f4 100644
--- file.txt
+++ file.txt
@@ -1,3 +1,3 @@
line1
-line2
+new line
line3`

parse(diffStr)

// returns
  {
    oldPath: 'file.txt',
    newPath: 'file.txt',
    oldMode: '100644',
    newMode: '100644',
    status: 'modified',
    hunks: [
      {
        oldStartLine: 1,
        oldLineCount: 3,
        newStartLine: 1,
        newLineCount: 3,
        lines: [
          ' line1',
          '-line2',
          '+new line',
          ' line3'
        ]
      }
    ]
  }