npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

catage

v1.1.3

Published

Node package and CLI tool to convert code into image with syntax highlighting

Downloads

67

Readme

catage (cat to image)

Node package and CLI tool to convert code into image with syntax highlighting.

npm-version dependencies downloads license

example

Install using NPM

npm install --save catage
npm install --global catage

API

const path = require( 'path' );

// import `convert` function and constants
const { convert, IMAGE_FORMATS, LANGUAGES, THEMES } = require( 'catage' );

// convert a code file to an image file
convert( options );

options

| Name | Use | default Value | | ---- | --- | ------------- | | inputFile | Required: Relative or absolue path of a code (text) file. | undefined | | outputFile | Required: Relative or absolue of the output image file. | undefined | | language | Language of the code file. | LANGUAGES.DART | | theme | Theme for the syntax highlighting. | THEMES.FIREWATCH | | format | Format of the output image file. | IMAGE_FORMATS.PNG | | ignoreLineNumbers | Avoid adding line numbers to the code. | false | | scale | DPI scale factor of the output image. | 2 | | hasFrame | Add OSX window frame in the output image. | true | | execute | Execute a command with inputFile and inject result in output image file. | null | | displayCommand | An alternative command to display in the output image. | execute option value |

Supported themes: https://iterm2colorschemes.com/ Supported languages: https://github.com/highlightjs/highlight.js/tree/master/src/languages Supported image formats: png,jpeg

Example

const path = require( 'path' );

// import library functions and constants
const { convert, IMAGE_FORMATS, LANGUAGES, THEMES } = require( '../' );

// create image of a code file
convert( {

    // by ignoring `outputFile` option, promise resolution will return an image buffer
    outputFile: path.resolve( __dirname, 'set-data-structure.png' ),

    inputFile: path.resolve( __dirname, 'set-data-structure.dart' ),
    language: LANGUAGES.DART,
    format: IMAGE_FORMATS.PNG,
    theme: THEMES.FIREWATCH,
    ignoreLineNumbers: false,
    scale: 2,
    hasFrame: true,
    frameTitle: 'Dart Sets Data Structure',
    execute: 'dart __FILE__', // `__FILE__` placeholder is mandatory
    displayCommand: 'dart sets.dart',
} ).then( () => {
    console.log( 'DONE!' );
} );

Output Image

example

CLI

$ catage --help
Usage: catage [options] <inputFile> <outputFile>

Convert code (text) file to an image file

Options:
  -v, --version                       Prints current CLI version.
  -l, --language <language>           Language of the code in the input file
  -t, --theme <theme>                 Theme for the syntax highlighting
  -f, --format <format>               Format of the output image file ( png / jpeg / jpg / svg ).
  -s, --scale <scale>                 DPI scale factor of the output image
  --no-line-numbers                   Ignore line numbers in the code
  --no-frame                          Ignore OSX window frame in the output image
  --frame-title <frameTitle>          Title of the OSX window frame
  --execute <execute>                 Command to execute with the code file. You must provide `__FILE__` placeholder in the command string.
  --display-command <displayCommand>  An alternative command to display in the output result.
  -h, --help                          output usage information

1. Example

catage recursive-function.py recursive-function.png -l python -t "Builtin Solarized Light" --frame-title "Recursive Function" --execute="python3 __FILE__" --display-command="python recursive-function.py"

Output Image

2. Simplest example

catage go-defer.go go-defer.jpg -l go -t AtomOneLight -f jpeg --no-line-numbers --no-frame

Output Image

Tricks

  • If you want to take screenshot of a plain text file (no-language), provide any value to the language option that does not listed in supported languages. Since it is a plain text file, you can not use execute option. Also the code won't be syntax highlighted.
  • If you are using another program to trigger catage command, then make sure your program is inheriting STDIO of the shell process which started it. This is necessary for syntax highlighting.

Warning

This tool is dependent puppeteer NPM package which has external dependency on headless Chromium browser. After installation, puppeteer downloads Chromium browser which could be more than 100MB in zipped format.