Check license info for a package and its dependencies
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Flexible output formatting system supporting multiple formats for different integration needs including programmatic consumption, reporting, and human-readable display.
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. SchlueterDirectly 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
});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: 1Exports 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"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) - ISCExample 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 utilityThe customFormat parameter allows controlling which fields are included in CSV and Markdown output:
interface CustomFormat {
[fieldName: string]: string | boolean;
}Field Options:
false: Exclude field from output entirely"": Include field if present in package, empty if missingAvailable Fields:
name - Package nameversion - Package versionlicenses - License identifier(s)repository - Repository URLpublisher - Author/publisher nameemail - Author emailurl - Author/package URLpath - Package filesystem pathlicenseFile - License file pathlicenseText - Full license text contentcopyright - Copyright informationdescription - Package descriptionhomepage - Package homepage URLkeywords - Package keywords arrayCustom 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);
});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.csvThe CLI automatically applies appropriate formatting based on flags and handles file output, colored terminal display, and format-specific options like CSV component prefixes.