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

openbadge

v1.0.4

Published

Create SVG badges programatically

Downloads

322

Readme

The OpenBadge Project

Why

SVG badges are pretty awesome, but the current solutions (eg: shield.io, fury.io) are somewhat heavy.

Sometimes you need to run custom functionality, sometimes the source data to generate lives behind firewalls, and sometimes hackers just want to hack.

The Open Badge project gives you a module that produces custom SVG badges, giving you full control over fonts, sizes, padding, colors, etc. It's pretty lightweight, so you can include it as part of your projects. Pure SVG solution. Does not require canvas libraries to be installed on your system.

Runnable Example usage in an express app:

var app = require('express')(),
    openBadge = require('./');

/**
 * A simple badge using config defaults.
 * We only specify the text on the left and the text on the right
 */
app.get('/simple.svg', function (req, res) {
    openBadge({text: ['Accident Free', '20 Days']}, function (err, badgeSvg) {
        /* TODO: Check for err */
        res.set('Content-Type', 'image/svg+xml');
        res.send(badgeSvg);
    });
});

/**
 * Changing fonts:
 * Example: Comic Sans. Just because you can, doesn't mean you should...
 */
app.get('/font.svg', function (req, res) {
    openBadge({text: ['Favorite Font', 'Comic Sans'], font: {fontFace: 'fonts/comic-sans/comic-sans.ttf'}}, function (err, badgeSvg) {
        /* TODO: Check for err */
        res.set('Content-Type', 'image/svg+xml');
        res.send(badgeSvg);
    });
});

/**
 * Changing Colors:
 * Individual control over both halves, the font and its dropshadow
 */
app.get('/colors.svg', function (req, res) {
    openBadge({text: ['Pretty', 'Colors!'], color:{left:"#ccc",right:"#cc99ff",font:"#333",shadow:"#fff"}}, function (err, badgeSvg) {
        /* TODO: Check for err */
        res.set('Content-Type', 'image/svg+xml');
        res.send(badgeSvg);
    });
});

app.get('/defaults.svg', function (req, res) {

    // Note: This is an exaggerated configuration showing all the defaults
    // In reality you *DON'T* needs to set all of these, and can get away
    // with just specifying the `text` parameter.

    var badgeConfig = {
        badge: 'baseBadge',                 // baseBadge is the only one we have for now.
        text: ['Hello', 'World'],           // Array with the copy on either side of the badge
        color: {
            left: '#555',                   // Background color on the left
            right: '#4c1',                  // Background color on the right
            font: '#fff',                   // Badge font color
            shadow: '#010101'               // Text shadow color. (Defaults to 0.3 opacity)
        },
        font: {
            fontFace: 'fonts/Open_Sans/OpenSans-Bold.ttf', // Path to the font to use.
            fontSize: 11                    // Font size in pixels
        },
        paddingX: 6,                       // Horizontal padding (in pixels) around text
        paddingY: 6                         // Vertical padding (in pixels) around text
    };

    openBadge(badgeConfig, function (err, badgeSvg) {
        /* TODO: Check for err */
        res.set('Content-Type', 'image/svg+xml');
        res.send(badgeSvg);
    });
});

app.get('/', function (req, res) {
    res.send(
        '<html>' +
        '<head>' +
        '<style>' +
        '   img {vertical-align: top} ' +
        '   * {line-height: 25px}' +
        '</style>' +
        '</head>' +
        '<body style="font-family: monospace">' +
        'Default Confg: <img src="defaults.svg"/><br>' +
        'A Basic Badge: <img src="simple.svg"/><br>' +
        'Changed Fonts: <img src="font.svg"/><br>' +
        'Changed Color: <img src="colors.svg"/><br>' +
        '</body>' +
        '</html>'
    )
});

app.listen(1337, function (err) {
    console.log('Listening on http://localhost:1337/');
});