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

readme-button-generator

v2.0.0

Published

Generates button images for use in readmes

Downloads

13

Readme

readme-button-generator

Build Status

Node module that generates a button for use in a readme.

Getting started

Note: You'll need Node.js 12.20 or later as this module uses ES modules.

$ npm i --save readme-button-generator

Usage

const ButtonGenerator = require('readme-button-generator')

// Synchronous
const generator = new ButtonGenerator()

// Asynchronous (only for default template)
const generator = await ButtonGenerator.createAsync()

let svg = await generator.generate({
  text: 'Join Slack',
  images: {
    icon: {
      url: 'https://upload.wikimedia.org/wikipedia/commons/7/76/Slack_Icon.png'
    }
  }
})

Result:

Join Slack

You can then take the output and send it to svgo, svg2png, output it to a file, as an HTTP response - whatever you want!

Default template options

  • text - Text to display.
  • icon - Optional. Data URL for icon to display.
  • width - Width of button in pixels. Defaults to 96.

Automatic image embedding and resizing

Since this module is meant to output a button, it wouldn't make sense for it to reference an external URL or include an outrageously huge icon. Therefore, automatic image processing is supported for all templates when using the images property of the options object.

The default template uses an icon property which is meant to include the data URL which will be placed directly into the SVG output. So let's say our image is larger and sourced from either the filesystem or a remote URL. This can be handled really simply:

let svg = await generator.generate({
  // ...
  images: {
    icon: { // Name of data URL property the template is expecting
      url: 'https://remote.url', // OR
      src: 'local.file',
      width: 32, // Optional. Width to resize to. Defaults to 32.
      height: 32 // Optional. Height to resize to. Defaults to 32.
    }
  }
})

Custom templates

Don't like the default template? You can pass in a custom template:

const fs = require('fs-extra')
const ButtonGenerator = require('readme-button-generator')

const template = await fs.readFile('my-template.svg', 'utf8')
const generator = new ButtonGenerator(template)

Behind the scenes, the module uses Handlebars and just-handlebars-helpers, so you can accept whatever options you would like instead of the default template's text, icon, and width.

The only reserved property is images, as it is used as noted above to automatically process images. However, you can use whatever property you would like and use the image processing feature to accept a data URL for an arbitrary image.

Feel free to take a look at the default template for inspiration!

Licence

MIT