Getting Started

Installation

Get started with jscpd.

Quick Installation

Using npm

Install jscpd globally:

Terminal
npm install -g jscpd

Using npx (No Installation)

Run jscpd directly without installing:

Terminal
npx jscpd /path/to/source

Using yarn

Terminal
yarn global add jscpd

Using pnpm

Terminal
pnpm add -g jscpd

Basic Usage

Scan a directory

Run jscpd on your source code directory:

Terminal
jscpd /path/to/source

Use pattern matching

Scan specific file patterns:

Terminal
jscpd --pattern "src/**/*.js"

Generate HTML report

Create an HTML report of duplications:

Terminal
jscpd /path/to/source --reporters html

Configuration

Create a .jscpd.json file in your project root:

.jscpd.json
{
  "threshold": 0,
  "reporters": ["html", "console"],
  "ignore": ["**/__snapshots__/**", "**/node_modules/**"],
  "absolute": true
}

Programming API

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);
})();

JSCPD Server

Install and run the standalone server:

Terminal
npm install -g jscpd-server
jscpd-server

Then check code for duplication:

Terminal
curl -X POST http://localhost:3000/api/check \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"hello\");\nconsole.log(\"world\");",
    "format": "javascript"
  }'