# cardinal

> Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.

Latest version **2.1.1** (published 2018-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install cardinal
pnpm add cardinal
yarn add cardinal
bun add cardinal
```

Provides the command `cdl`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2018-05-22 |
| First published | 2012-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/cardinal) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 64.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 174 |
| Author | Thorsten Lorenz |
| Maintainers | thlorenz |
| Keywords | syntax, highlight, theme, javascript, json, terminal, console, print, output |

## Links

- npm: https://www.npmjs.com/package/cardinal
- Repository: https://github.com/thlorenz/cardinal
- Homepage: https://github.com/thlorenz/cardinal#readme
- Issues: https://github.com/thlorenz/cardinal/issues
- npm.io page: https://npm.io/package/cardinal

## Dependencies (2)

- [redeyed](https://npm.io/package/redeyed.md) ~2.1.0
- [ansicolors](https://npm.io/package/ansicolors.md) ~0.3.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.1 (latest) — 2018-05-22
- 2.1.0 — 2018-05-21
- 2.0.1 — 2018-04-23
- 2.0.0 — 2018-04-23
- 1.0.0 — 2016-08-30
- 0.7.1 — 2016-03-31
- 0.7.0 — 2016-03-29
- 0.6.0 — 2015-11-12
- 0.5.0 — 2015-03-04
- 0.4.4 — 2014-01-07
- 0.4.3 — 2013-12-15
- 0.4.2 — 2013-08-01
- 0.4.1 — 2013-07-31
- 0.4.0 — 2013-07-30
- 0.3.2 — 2013-04-05
- … 7 more at https://npm.io/package/cardinal/versions

## README

# cardinal [![Build Status](https://secure.travis-ci.org/thlorenz/cardinal.svg)](http://travis-ci.org/thlorenz/cardinal)

<a href="https://www.patreon.com/bePatron?u=8663953"><img alt="become a patron" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="35px"></a>

[![NPM](https://nodei.co/npm/cardinal.png?downloads=true&stars=true)](https://nodei.co/npm/cardinal/)

**car·di·nal** *(kärdn-l, kärdnl)* - crested thick-billed North American finch having bright red plumage in the male.

![screenshot](https://github.com/thlorenz/cardinal/raw/master/assets/screen-shot.png)

## Features

- highlights JavaScript code with ANSI colors to improve terminal output
- theming support, see [custom color themes](https://github.com/thlorenz/cardinal/tree/master/themes)
- optionally print line numbers
- API and command line interface (`cdl`)
- `.cardinalrc` config to customize settings
- supports UNIX pipes

***

**Table of Contents**  *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [Installation](#installation)
  - [As library](#as-library)
  - [As Commandline Tool](#as-commandline-tool)
- [Commandline](#commandline)
  - [Highlight a file](#highlight-a-file)
  - [As part of a UNIX pipe](#as-part-of-a-unix-pipe)
  - [Theme](#theme)
- [API](#api)
  - [*highlight(code[, opts])*](#highlightcode-opts)
  - [*highlightFileSync(fullPath[, opts])*](#highlightfilesyncfullpath-opts)
  - [*highlightFile(fullPath[, opts], callback)*](#highlightfilefullpath-opts-callback)
  - [opts](#opts)
- [Examples ([*browse*](https://github.com/thlorenz/cardinal/tree/master/examples))](#examples-[browse]https://githubcom/thlorenz/cardinal/tree/master/examples)


## Installation

### As library

    npm install cardinal

### As Commandline Tool

    [sudo] npm install -g cardinal

**Note:**

When installed globally, cardinal exposes itself as the `cdl` command.

## Commandline

### Highlight a file

    cdl <file.js> [options]

**options**:
  - `--nonum`: turns off line number printing (relevant if it is turned on inside `~/.cardinalrc`

### As part of a UNIX pipe

    cat file.js | grep console | cdl

**Note:**

Not all code lines may be parsable JavaScript. In these cases the line is printed to the terminal without
highlighting it.

### Theme

The default theme will be used for highlighting.

To use a different theme, include a `.cardinalrc` file in your `HOME` directory.

This is a JSON file of the following form:

```json
{
  "theme": "hide-semicolons",
  "linenos": true|false
}
```

- `theme` can be the name of any of the [built-in themes](https://github.com/thlorenz/cardinal/tree/master/themes) or the
full path to a custom theme anywhere on your computer.
- linenos toggles line number printing

## API

### *highlight(code[, opts])*

- returns the highlighted version of the passed code ({String}) or throws an error if it was not able to parse it
- opts (see below)

### *highlightFileSync(fullPath[, opts])*

- returns the highlighted version of the file whose fullPath ({String}) was passed or throws an error if it was not able
  to parse it
- opts (see below)

### *highlightFile(fullPath[, opts], callback)*

- calls back with the highlighted version of the file whose fullPath ({String}) was passed or with an error if it was not able
  to parse it
- opts (see below)
- `callback` ({Function}) has the following signature: `function (err, highlighted) { .. }`

### opts

opts is an {Object} with the following properties:

- `theme` {Object} is used to optionally override the theme used to highlight
- `linenos` {Boolean} if `true` line numbers are included in the highlighted code
- `firstline` {Integer} sets line number of the first line when line numbers are printed
- `jsx` {Boolean} if `true` _JSX_ syntax is supported, otherwise cardinal will raise an error
    when encountering _JSX_ (default: `false`)

**Note** The `json` option is obsoleted and not necessary anymore as cardinal properly understands both JSON and JavaScript.

## Examples ([*browse*](https://github.com/thlorenz/cardinal/tree/master/examples))

- [sample .cardinalrc](https://github.com/thlorenz/cardinal/blob/master/examples/.cardinalrc)
- [highlighting a code snippet](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-string.js) via
  ***highlight()***
- [file that highlights itself](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-self.js) via
  ***highlightFile()*** including line numbers
- [file that highlights itself hiding all
  semicolons](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-self-hide-semicolons.js) via
  ***highlightFileSync()***

---
_Source: https://npm.io/package/cardinal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
