jscpd provides a programming API for integrating copy/paste detection into your applications.
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';
const clones: Promise<IClone[]> = jscpd(process.argv);
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';
(async () => {
const clones: IClone[] = await jscpd(['', '', __dirname, '-r', 'json']);
console.log(clones);
})();
Pass options programmatically:
import { jscpd } from 'jscpd';
const options = [
'', // placeholder for node
'', // placeholder for script
'./src',
'--min-lines', '5',
'--min-tokens', '50',
'--reporters', 'json',
'--output', './reports'
];
const clones = await jscpd(options);
Each detected clone has the following structure:
interface IClone {
format: string;
lines: number;
tokens: number;
firstFile: ISourceLocation;
secondFile: ISourceLocation;
duplicationA: ISourceLines;
duplicationB: ISourceLines;
}
interface ISourceLocation {
name: string;
start: number;
end: number;
startLoc: ILocation;
endLoc: ILocation;
}