Install jscpd globally:
npm install -g jscpd
Run jscpd directly without installing:
npx jscpd /path/to/source
yarn global add jscpd
pnpm add -g jscpd
Run jscpd on your source code directory:
jscpd /path/to/source
Scan specific file patterns:
jscpd --pattern "src/**/*.js"
Create an HTML report of duplications:
jscpd /path/to/source --reporters html
Create a .jscpd.json file in your project root:
{
"threshold": 0,
"reporters": ["html", "console"],
"ignore": ["**/__snapshots__/**", "**/node_modules/**"],
"absolute": true
}
For integration into your application:
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';
const clones: Promise<IClone[]> = jscpd(process.argv);
Or with async/await:
import { IClone } from '@jscpd/core';
import { jscpd } from 'jscpd';
(async () => {
const clones: IClone[] = await jscpd(['', '', __dirname, '-r', 'json']);
console.log(clones);
})();
Install and run the standalone server:
npm install -g jscpd-server
jscpd-server
Then check code for duplication:
curl -X POST http://localhost:3000/api/check \
-H "Content-Type: application/json" \
-d '{
"code": "console.log(\"hello\");\nconsole.log(\"world\");",
"format": "javascript"
}'