Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-highlighter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-highlighter

A fork of cli-highlight

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

cli-highlighter

This package is a fork of felixfbecker's amazing cli-highlight package which seems to be unmaintained.

Syntax highlighting in your terminal

npm

Example

Example Output

CLI Usage

Output a file

highlight package.json

Color output of another program with piping. Example: A database migration script that logs SQL Queries

db-migrate --dry-run | highlight

Command line options:

Usage: highlight [options] [file] Outputs a file or STDIN input with syntax
highlighting Options: --language, -l Set the langugage explicitely If omitted
will try to auto-detect --theme, -t Use a theme defined in a JSON file --help,
-h Show help

Programmatic Usage

You can use this module programmatically to highlight logs of your Node app. Example:

import highlight from 'cli-highlighter';
import Sequelize from 'sequalize';

const db = new Sequelize(process.env.DB, {
  logging(log) {
    console.log(highlight(log, { language: 'sql', ignoreIllegals: true }));
  },
});

Detailed API documentation can be found here.

Themes

You can write your own theme in a JSON file and pass it with --theme. The key must be one of the highlight.js CSS class names or "default", and the value must be one or an array of Chalk styles to be applied to that token.

{
  "keyword": "blue",
  "built_in": ["cyan", "dim"],
  "string": "red",
  "default": "gray"
}

The style for "default" will be applied to any substrings not handled by highlight.js. The specifics depend on the language but this typically includes things like commas in parameter lists, semicolons at the end of lines, etc.

The theme is combined with the default theme. The default theme is still not colored a lot or optimized for many languages, PRs welcome!

Supported Languages

All languages of highlight.js are supported.

Contributing

The module is written in TypeScript and can be compiled with pnpm build. Tests are written with vitest.

Improving language support is done by adding more colors to the tokens in the default theme and writing more tests.

FAQs

Package last updated on 20 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc