blame-js compares an array of source codes and outputs information about where each line originates from. Its behaviour is similar to the blame functionality that is integrated in Git.
npm install --save blame-js
Pay attention to the order of items in the array: the first one in the array is the newest. The items can either be simple texts or objects.
The latter requires to pass an getCode
and getOrigin
function to be passed in the options (see example 2).
const blamejs = require('blame-js');
// or alternatively in ES6 syntax:
// import blamejs from 'blame-js';
/*
Result:
[ { origin: 0, value: 'a' },
{ origin: 0, value: 'b' },
{ origin: 2, value: 'c' } ]
*/
blamejs([`a
b
c`,
`c`,
`a
b
c`
])
/*
Result:
[ { origin: 'Commit #3', value: 'a' },
{ origin: 'Commit #3', value: 'b' },
{ origin: 'Commit #1', value: 'c' } ]
*/
blamejs(
[
{
commit: 'Commit #3',
code: `a
b
c`,
},
{
commit: 'Commit #2',
code: `c`,
},
{
commit: 'Commit #1',
code: `a
b
c`,
},
],
{
getCode: item => item.code,
getOrigin: item => item.commit,
},
)
Mocha tests are implemented and you can run all tests via
npm run test
- diff - a javascript text differencing implementation
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Julian Hundeloh - Initial work - jaulz
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.