Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow programmatic usage #38

Closed
lo1tuma opened this issue Sep 10, 2015 · 4 comments
Closed

Allow programmatic usage #38

lo1tuma opened this issue Sep 10, 2015 · 4 comments

Comments

@lo1tuma
Copy link
Contributor

lo1tuma commented Sep 10, 2015

Hi,

I would like to use jscpd programmatically where I can provide the file content instead of letting jscpd reading the file from the file-system.

Background of this is, that I want to check files retrieved via the github API.


The API could look like this:

var Detector = require('jscpd').Detector;

var detector = new Detector();

detector.addFile('foo.js', 'console.log("hello world")');
detector.addFile('bar.js', 'console.log("hello world")');

var result = detector.run();
@kucherenko
Copy link
Owner

for now you can use program interface, but it is little bit poor, will add this request to plans

@c089
Copy link

c089 commented Sep 11, 2015

The second argument in the addFile method be the contents of the file, right? Then maybe rename it to something more generic to make it clear this is not reading a file, but expecting a string? If it should work on large codebases, maybe instead of strings also consider a stream interface that could then either have files or any other source. Otherwise 👍 on this.

@lo1tuma
Copy link
Contributor Author

lo1tuma commented Sep 11, 2015

It would be also nice to be able to remove files, so you can compare the duplication results of two different versions of your code files.

Example:

var Detector = require('jscpd').Detector;

var detector = new Detector();

// add files of version 1
detector.addFile('foo.js', 'console.log("hello world")');
detector.addFile('bar.js', 'console.log("hello world")');
detector.addFile('baz.js', 'console.log("hello world")');

var resultOfVersion1 = detector.run();

// apply changes for version 2
detector.addFile('bar.js', 'console.log("changed file")');
detector.removeFile('baz.js');
// don’t add 'foo.js' because it didn’t change

var resultOfVersion2 = detector.run();

console.log('Your code duplication increased/decreased by:', compareResults(resultOfVersion1, resultOfVersion2), 'percent');

@kucherenko
Copy link
Owner

https://github.com/kucherenko/jscpd/blob/master/docs/api.md

New version of jscpd released and powerful API there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants