CLI-High: Terminal Syntax Highlighter

0.4.3 · active · verified Wed Apr 22

cli-high is a lightweight, MIT-licensed JavaScript library providing syntax highlighting specifically designed for terminal output. It is currently at version 0.4.3 and appears to be in active development, having been introduced around 2024. As a "tiny" utility, it prioritizes minimal dependencies and a focused scope, primarily offering a single `highlight` function for programmatic use. The library ships with TypeScript types, enabling a robust development experience in TypeScript projects. While its release cadence isn't explicitly defined, as a 0.x.x version, users should anticipate potential API changes in minor or even patch releases. Its primary differentiators are its small footprint and dedicated purpose for aesthetic CLI output, rather than complex, browser-based highlighting solutions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic use of `cli-high` to syntax-highlight JavaScript and JSON code for terminal output, including specifying language and theme options.

import { highlight, type Options } from 'cli-high';

const javascriptCode = `
function greet(name: string) {
  console.log("Hello, " + name + "!");
}

greet("World");
`;

const options: Options = {
  language: 'js', // Or 'typescript', 'json', etc.
  theme: 'dark' // Or 'light'
};

const highlightedCode = highlight(javascriptCode, options);
console.log(highlightedCode);

// Example of highlighting a different language
const jsonConfig = `{
  "name": "cli-high-project",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  }
}`;

const highlightedJson = highlight(jsonConfig, { language: 'json' });
console.log('\n' + highlightedJson);

view raw JSON →