CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-license-checker

Check license info for a package and its dependencies

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

formatting.mddocs/

Output Formatting

Flexible output formatting system supporting multiple formats for different integration needs including programmatic consumption, reporting, and human-readable display.

Capabilities

Tree Format

Converts license data to hierarchical tree-formatted string for human-readable console output.

/**
 * Convert license data to tree-formatted string
 * @param data - License data from init() callback
 * @returns Tree-formatted string representation
 */
function asTree(data: LicenseData): string;

Usage Example:

const checker = require("license-checker");

checker.init({ start: process.cwd() }, function(err, packages) {
  const treeOutput = checker.asTree(packages);
  console.log(treeOutput);
});

Example Output:

├─ chalk@2.4.2
│  ├─ licenses: MIT
│  ├─ repository: https://github.com/chalk/chalk
│  └─ publisher: Sindre Sorhus
├─ debug@3.2.7
│  ├─ licenses: MIT  
│  ├─ repository: https://github.com/visionmedia/debug
│  └─ publisher: TJ Holowaychuk
└─ nopt@4.0.3
   ├─ licenses: ISC
   ├─ repository: https://github.com/npm/nopt
   └─ publisher: Isaac Z. Schlueter

Console Print

Directly prints license data in tree format to console.

/**
 * Print license data in tree format to console
 * @param data - License data from init() callback
 */
function print(data: LicenseData): void;

Usage Example:

checker.init({ start: process.cwd() }, function(err, packages) {
  checker.print(packages); // Outputs directly to console
});

Summary Format

Generates a summary showing license usage statistics with counts.

/**
 * Convert license data to summary format showing license counts
 * @param data - License data from init() callback
 * @returns Summary string with license usage statistics
 */
function asSummary(data: LicenseData): string;

Usage Example:

checker.init({ start: process.cwd() }, function(err, packages) {
  const summary = checker.asSummary(packages);
  console.log(summary);
});

Example Output:

├─ MIT: 45
├─ ISC: 12
├─ Apache-2.0: 8
├─ BSD-3-Clause: 5
├─ BSD-2-Clause: 3
└─ GPL-3.0: 1

CSV Format

Exports license data as comma-separated values for spreadsheet import and data analysis.

/**
 * Convert license data to CSV format
 * @param data - License data from init() callback
 * @param customFormat - Optional custom field specification
 * @param csvComponentPrefix - Optional prefix for component column
 * @returns CSV-formatted string
 */
function asCSV(data: LicenseData, customFormat?: CustomFormat, csvComponentPrefix?: string): string;

interface CustomFormat {
  [fieldName: string]: string | boolean;
}

Usage Examples:

// Basic CSV output
const csvOutput = checker.asCSV(packages);
console.log(csvOutput);

// CSV with custom format
const customCsv = checker.asCSV(packages, {
  "name": "",
  "version": "", 
  "licenses": "",
  "repository": "",
  "publisher": ""
});

// CSV with component prefix
const prefixedCsv = checker.asCSV(packages, customFormat, "my-app");

Example Output (basic):

"module name","license","repository"
"chalk@2.4.2","MIT","https://github.com/chalk/chalk"
"debug@3.2.7","MIT","https://github.com/visionmedia/debug"
"nopt@4.0.3","ISC","https://github.com/npm/nopt"

Example Output (with custom format):

"module name","name","version","licenses","repository","publisher"
"chalk@2.4.2","chalk","2.4.2","MIT","https://github.com/chalk/chalk","Sindre Sorhus"
"debug@3.2.7","debug","3.2.7","MIT","https://github.com/visionmedia/debug","TJ Holowaychuk"

Example Output (with component prefix):

"component","module name","license","repository"
"my-app","chalk@2.4.2","MIT","https://github.com/chalk/chalk"
"my-app","debug@3.2.7","MIT","https://github.com/visionmedia/debug"

Markdown Format

Converts license data to markdown format for documentation and reports.

/**
 * Convert license data to markdown format
 * @param data - License data from init() callback  
 * @param customFormat - Optional custom field specification
 * @returns Markdown-formatted string
 */
function asMarkDown(data: LicenseData, customFormat?: CustomFormat): string;

Usage Examples:

// Basic markdown output
const mdOutput = checker.asMarkDown(packages);
console.log(mdOutput);

// Markdown with custom format
const customMd = checker.asMarkDown(packages, {
  "licenses": "",
  "publisher": "",
  "description": ""
});

Example Output (basic):

[chalk@2.4.2](https://github.com/chalk/chalk) - MIT
[debug@3.2.7](https://github.com/visionmedia/debug) - MIT  
[nopt@4.0.3](https://github.com/npm/nopt) - ISC

Example Output (with custom format):

- **[chalk@2.4.2](https://github.com/chalk/chalk)**
    - licenses: MIT
    - publisher: Sindre Sorhus
    - description: Terminal string styling done right
 - **[debug@3.2.7](https://github.com/visionmedia/debug)**
    - licenses: MIT
    - publisher: TJ Holowaychuk
    - description: small debugging utility

Custom Format Specification

The customFormat parameter allows controlling which fields are included in CSV and Markdown output:

interface CustomFormat {
  [fieldName: string]: string | boolean;
}

Field Options:

  • String values: Use as default if field missing from package data
  • Boolean false: Exclude field from output entirely
  • Empty string "": Include field if present in package, empty if missing
  • Custom default: Use custom value if field missing

Available Fields:

  • name - Package name
  • version - Package version
  • licenses - License identifier(s)
  • repository - Repository URL
  • publisher - Author/publisher name
  • email - Author email
  • url - Author/package URL
  • path - Package filesystem path
  • licenseFile - License file path
  • licenseText - Full license text content
  • copyright - Copyright information
  • description - Package description
  • homepage - Package homepage URL
  • keywords - Package keywords array
  • Any other field from package.json

Custom Format Example:

const customFormat = {
  "name": "",                    // Include package name
  "version": "",                 // Include version
  "licenses": "",               // Include licenses
  "repository": "",             // Include repository
  "description": "No description", // Default value if missing
  "licenseText": false,         // Exclude license text
  "private": false,             // Exclude private flag
  "customField": "N/A"          // Custom default for missing field
};

checker.init({
  start: process.cwd(),
  customFormat: customFormat
}, function(err, packages) {
  const csv = checker.asCSV(packages, customFormat);
  const md = checker.asMarkDown(packages, customFormat);
});

CLI Integration

All formatting functions integrate with the CLI tool through command-line flags:

# Tree format (default)
license-checker

# JSON format  
license-checker --json

# CSV format
license-checker --csv

# Markdown format
license-checker --markdown

# Summary format
license-checker --summary

# Custom format from file
license-checker --customPath ./custom-format.json

# Output to file
license-checker --json --out licenses.json
license-checker --csv --out licenses.csv

The CLI automatically applies appropriate formatting based on flags and handles file output, colored terminal display, and format-specific options like CSV component prefixes.

docs

file-operations.md

formatting.md

index.md

scanning.md

tile.json