Socket
Socket
Sign inDemoInstall

cardinal

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardinal - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

examples/.cardinalrc

4

examples/highlight-self-hide-semicolons.js
/*
* This file will highlight itself using the custom theme when run via: "node highlight-self-hide-semicolons"
* It is using a custom theme that highlights semicolons as 'black', therfore hiding them
* This file will highlight itself using a custom theme when run via: "node highlight-self-hide-semicolons"
* The custom theme highlights semicolons as 'black', thus hiding them.
*/

@@ -5,0 +5,0 @@

@@ -1,2 +0,2 @@

// This file will highlight itself using the custom theme when run via: "node highlight-self"
// This file will highlight itself using the default theme when run via: "node highlight-self"

@@ -3,0 +3,0 @@ var cardinal = require('..');

{
"name": "cardinal",
"version": "0.1.0",
"version": "0.1.1",
"description": "Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.",
"main": "cardinal.js",
"scripts": {
"test": "tap ./test/*.js"
"test": "tap ./test/*.js",
"demo": "node examples/highlight-string.js; node examples/highlight-self; node examples/highlight-self-hide-semicolons;"
},

@@ -9,0 +10,0 @@ "bin": {

# cardinal [![Build Status](https://secure.travis-ci.org/thlorenz/cardinal.png)](http://travis-ci.org/thlorenz/cardinal)
Syntax highlights your code with ANSI colors to be printed to the terminal.
**car·di·nal** *(kärdn-l, kärdnl)* - A North American finch (Cardinalis cardinalis) having a crested head, a short thick
bill, and bright red plumage
![cardinal](http://www.decodedstuff.com/wp-content/uploads/2010/06/northern-cardinal.jpg)
```javascript
var cardinal = require('cardinal');
function highlight () {
cardinal.highlightFile(__filename, function (err, res) {
if (err) return console.error(err);
console.log(res);
});
}
highlight();
```
![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)
- API and command line interface
- `.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[, theme])](#highlightcode-theme)
- [highlightFileSync(fullPath[, theme])](#highlightfilesyncfullpath-theme)
- [highlightFile(fullPath[, theme], callback)](#highlightfilefullpath-theme-callback)
- [Examples](#examples-browse)
## Installation
### As library
npm install cardinal
### As Commandline Tool
[sudo] npm install -g cardinal
## Commandline
### Highlight a file
cardinal file.js
### As part of a UNIX pipe
cat file.js | grep console | cardinal
**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"
}
```
`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.
## API
### *highlight(code[, theme])*
- returns the highlighted version of the passed code ({String}) or throws an error if it was not able to parse it
- `theme` ({Object}) is used to optionally override the theme used to highlight
### *highlightFileSync(fullPath[, theme])*
- returns the highlighted version of the file whose fullPath ({String}) was passed or throws an error if it was not able
to parse it
- `theme` ({Object}) is used to optionally override the theme used to highlight
### *highlightFile(fullPath[, theme], 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
- `theme` ({Object}) is used to optionally override the theme used to highlight
- `callback` ({Function}) has the following signature: `function (err, highlighted) { .. }`
## 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()***
- [file that highlights itself hiding all
semicolons](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-self-hide-semicolons.js) via
***highlightFileSync()***

@@ -1,7 +0,1 @@

/*
* Copy this file and use it as a starting point for your custom cardinal color theme.
* Just fill in or change the entries for the tokens you want to color
* Keep in mind that more specific configurations override less specific ones.
*/
// Don't touch this definition

@@ -8,0 +2,0 @@ var colorNums = {

@@ -1,7 +0,1 @@

/*
* Copy this file and use it as a starting point for your custom cardinal color theme.
* Just fill in or change the entries for the tokens you want to color
* Keep in mind that more specific configurations override less specific ones.
*/
// Don't touch this definition

@@ -103,3 +97,5 @@ var colorNums = {

, 'Punctuator': {
// setting semicolon's color to the same as the terminal background makes it invisible
';': colors.black
, '.': colors.green

@@ -106,0 +102,0 @@ , ',': colors.green

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