Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

@tandil/diffparse

NPM Package VersionLicenseConventional Commits

Simple parser for Diff files (unified diff format)

Features

  • Parse a diff file from its filepath
  • Parse a diff directly from a string
  • Error reporting: If there are parsing errors, the partial result is returned and the list of detected errors including line numbers

Usage

Parse from file

Async with Promises

Given a filepath it returns a Promise that resolves to a JS object with the diff content parsed and easily accessible programmatically.

constparser=require('@tandil/diffparse');parser.parseDiffFile('./examples/example1.diff').then(diff=>{console.log(diff);});

Sync

constparser=require('@tandil/diffparse');constdiff=parser.parseDiffFileSync('./examples/example1.diff');console.log(diff);

Parse from string

Given a diff string it returns a JS object with the diff content parsed and easily accessible programmatically.

constparser=require('@tandil/diffparse');constdiffStr=`diff --git a/.gitignore b/.gitignorenew file mode 100644index 0000000..2ccbe46--- /dev/null+++ b/.gitignore@@ -0,0 +1 @@+/node_modules/`;constdiff=parser.parseDiffString(diffStr);console.log(diff);

Outputs

{header: [],files: [{header: 'diff --git a/.gitignore b/.gitignore',fileMode: 'new file mode 100644',oldMode: null,newMode: null,index: 'index 0000000..2ccbe46',oldFile: '--- /dev/null',newFile: '+++ b/.gitignore',chunks: [{header: '@@ -0,0 +1 @@',content: ['+/node_modules/']}]}],errors: []}

Having issues?

Feel free to report any issues or feature request in Github repo.

About

Simple parser for Diff files (unified diff format)

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages