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

code-snipper

v0.0.23

Published

Export code snippets as PNG

Downloads

125

Readme

Code Snipper

Export your code as PNG, and use them in blog posts, or wherever it is you wanna use them

npm npm

Example Image

TOC

Installation

We are sticking with yarn for its speed but you can use npm.

$ yarn add code-snipper

For npm,

$ npm install -g code-snipper

Note: If you want to use it as a library in your project, you can remove the optional -g flag above.

Command Line Usage

Let's say you have a JS file with the following contents:

const success = 'false';
while(!success){
    keepWorking();
}

To generate an Image for the above code snippet:

$ copper index.js

This will save an image named index.js.png with the above JS code.

image.js.png

Example Image

Syntax

The basic syntax for the copper command is,

$ copper (filename) [options|flags]

filename : Can be any source code file. (.js, .html, .sh, .cc, etc.,)

options : a CLI option (used as --flag value)

Options

-o, --output : define output path

Define the output filepath for image. Defaults to: location/of/file.png

$ copper index.js --output ~/index.png

-t, --theme : defines theme

To change the theme, pass this argument. To see the available themes, see themes.md

$ copper index.js -t hybrid //uses 'hybrid' instead of default theme

-f, --font : defines font

You can use any font pre-installed in your system. (Google Fonts support is on the list of things to be added.)

$ copper index.js -f Raleway //uses 'Raleway' instead of 'Source Code Pro'

-r, --resolution : defines resolution(zoomFactor)

This flag changes the size of the image.

$ copper index.js -r 2

--fontSize : defines font size

Change the default font size. (Don't pass in units, or it won't work.)

$ copper index.js --fontSize 25 Raleway //uses '25px' instead of '20px'

Module Usage

Step 1. Require the module

const copper = require('code-snipper');

Step 2. Use it.

copper(fileName, options);

fileName required

Name of the file containing the code snippet.

options optional

An object via which you can pass in the following parameters.

  • theme – See Available Themes
  • font – Any font installed on your machine.
  • fontSize – Without units.
  • resolution – Make the image fatter
Default options object
{
    resolution: 1,
    theme: 'hybrid',
    font: 'Source Code Pro',
    fontSize: 20,
    background: '#fff',
    prettify: true, // use prettify to format `js`
    style: null, // override code styles injected by theme
    webshotCustomConfig: { // Using webshot default options
        shotSize: {
            width: 'window',
            height: 'window'
        },
        windowSize: {
            width: 1024,
            height: 768
        },
        shotOffset: {
            top: 0,
            right: 0,
            bottom: 0,
            left: 0
        }
    }

See webshot for a description of webshot options.

Available Themes

All the themes available in hightlight.js can be used. The list can be found at Themes.md

To check out how each theme looks, check this Highlight.js demo:

Contributing

You're welcome to fix any bugs, or add new features. Just fork the project, work on your local copy, and send a PR against master branch.

1. Fork this repo. (That button in the top-right corner of this page.)

2. Make a local copy, by cloning your forked copy.

3. Fix whatever it is you think needs fixing. (or Add new features!)

4. Send a PR against master branch.