1.1.1 • Published 7 years ago

svg-labels v1.1.1

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

npm version

svg-labels

:label: Generate GitHub-style labels in SVG

What is it?

If you've ever tried to recreate a GitHub label in a markdown document or issue, you'll discover you can't do it! Markdown doesn't let you style text and colors.

We can get around this by styling the text and colors in an SVG "image" and embedding that instead:

bug duplicate enhancement help wanted invalid question wontfix

The code for this is hosted on labl.es.

It works just like similar badge generator sites like shields.io or badge.fury.io

What's included

makeLabel(options) - does what it says on the tin

optiontypedefaultdescription
option.textstring'bug'Label text - will appear centered on the label.
option.fontfamilystring'Helvetica,Arial'Text font - we just pass this directly into the SVG file.
option.fontsizenumber12Font size in px - this affects the overall size of the label.
option.fontweightnumber600Font weight as a number (over 500 is considered 'bold').
option.widthnumbercalculatedLabel width - calculated based on fontsize, but you can override it.
option.strokeopacitynumber0.12Opacity for the shadow outline.
option.strokewidthnumbercalculatedShadow stroke width - also calculated but you can override it.
option.bgcolorhex#ee0701Background color of the label.
option.fgcolorhex#333026 / #ffffffForeground color of the label - calculated for light/dark backgrounds but you can override it.
option.strokecolorhex#273135Stroke color for the shadow outline.

All hex colors can be passed either as 3 or 6 characters, and the '#' is optional.

Server

server.js contains a simple microservice built on the koa.js framework.

npm run start will start the server on port 3000.

This is the same code that serves up labl.es.

Bugs

There may be bugs !

Report any issues here: https://github.com/bhousel/svg-labels/issues

License

svg-labels is available under the ISC License. See the LICENSE.md file for more details.