Detect duplications in code string:
import {
JSCPD,
IClone,
IOptions,
} from 'jscpd';
const options: IOptions = {};
const cpd = new JSCPD(options);
const code = '...string with my code...';
cpd.detect(code, { id: 'test', format: 'markup' })
.then((clones: IClone[]) => console.log(clones));
Detect duplications in files:
import {
JSCPD,
IClone,
IOptions,
} from 'jscpd';
const options: IOptions = {};
const cpd = new JSCPD(options);
cpd.detectInFiles(['./src', './tests'])
.then((clones: IClone[]) => console.log(clones));
export interface IOptions {
executionId?: string;
minLines?: number;
maxLines?: number;
maxSize?: string;
minTokens?: number;
threshold?: number;
xslHref?: string;
formatsExts?: { [key: string]: string[] };
output?: string;
path?: string[];
mode?: string | ((token: IToken) => boolean);
storeOptions?: IStoreManagerOptions;
config?: string;
ignore?: string[];
format?: string[];
reporters?: string[];
listeners?: string[];
blame?: boolean;
cache?: boolean;
silent?: boolean;
debug?: boolean;
list?: boolean;
absolute?: boolean;
gitignore?: boolean;
}
During the detections process JSCPD
emit following events:
New source detection started event
cpd.on(MATCH_SOURCE_EVENT, (source) => {
console.log(source);
});
Clone found event
cpd.on(CLONE_FOUND_EVENT, (clone: IClone) => {
console.log(clone);
});
Skipped source event (see max-size, min-lines and max-lines options)
cpd.on(SOURCE_SKIPPED_EVENT, (stat) => {
console.log(stat);
});
Detection process finished event
cpd.on(END_EVENT, (clones: IClone[]) => {
console.log(clones);
});
TODO
TODO