Shields.io badge library for generating customizable SVG badges with configurable labels, messages, colors, styles, and logos.
npx @tessl/cli install tessl/npm-badge-maker@5.0.0Badge Maker is a comprehensive SVG badge generation library that enables developers to create customizable badges for various use cases including CI/CD status indicators, version displays, and project metrics. It offers both programmatic API and CLI interfaces for generating SVG badges with configurable labels, messages, colors, styles, and logos, supporting multiple visual themes and color specification methods.
npm install badge-makerimport { makeBadge, ValidationError } from "badge-maker";For CommonJS:
const { makeBadge, ValidationError } = require("badge-maker");import { makeBadge, ValidationError } from "badge-maker";
// Simple badge
const format = {
label: "build",
message: "passing",
color: "brightgreen"
};
const svg = makeBadge(format);
console.log(svg); // SVG string
// Advanced badge with logo and links
const advancedFormat = {
label: "npm",
message: "v5.0.2",
color: "#cb3837",
style: "for-the-badge",
logoBase64: "data:image/svg+xml;base64,...",
links: ["https://npmjs.com/package/badge-maker", "https://github.com/badges/shields"]
};
const advancedSvg = makeBadge(advancedFormat);
// Error handling
try {
makeBadge({}); // Missing required message field
} catch (error) {
if (error instanceof ValidationError) {
console.error("Validation failed:", error.message);
}
}Generate SVG badges with configurable appearance and content.
function makeBadge(format: Format): string;The makeBadge function creates an SVG badge based on the provided format configuration. It validates all input parameters and returns a complete SVG string ready for use in web pages, documentation, or other applications.
Parameters:
format (Format): Badge configuration object containing label, message, colors, style, and optional logo/linksReturns: SVG string representing the generated badge
Throws: ValidationError when format validation fails
Custom error class for validation failures.
class ValidationError extends Error {
constructor(message: string);
}The ValidationError class is thrown when invalid parameters are passed to makeBadge. Common validation errors include missing required fields, invalid field types, or unsupported values.
interface Format {
label?: string;
message: string;
labelColor?: string;
color?: string;
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social';
logoBase64?: string;
links?: Array<string>;
idSuffix?: string;
}Properties:
label (optional): Text displayed on the left side of the badge (e.g., "build", "npm", "version"). If empty string provided, badge displays only the message section.message (required): Text displayed on the right side of the badge (e.g., "passing", "v1.0.0", "stable")labelColor (optional): Background color for the label sectioncolor (optional): Background color for the message sectionstyle (optional): Visual appearance of the badge, defaults to "flat"logoBase64 (optional): Base64-encoded logo data (data URI format) to display on the left. Logo appears with default height of 14px.links (optional): Array of up to 2 URLs for making badge sections clickable. First URL applies to label section, second to message section.idSuffix (optional): Unique identifier suffix for multiple badges on the same page to prevent CSS conflicts when badges are embedded inline in HTMLBadge Maker supports multiple color specification methods:
Built-in color names for common use cases:
brightgreen (#4c1) - Success statesgreen (#97ca00) - Passing testsyellow (#dfb317) - Warningsyellowgreen (#a4a61d) - Moderate successorange (#fe7d37) - Cautionsred (#e05d44) - Failuresblue (#007ec6) - Informationgrey (#555) - Neutral stateslightgrey (#9f9f9f) - Inactive statesSemantic color names that map to the named colors above:
gray → greylightgray → lightgreycritical → redimportant → orangesuccess → brightgreeninformational → blueinactive → lightgrey#rgb or #rrggbb format (e.g., #4c1, #cb3837)steelblue, rgb(255, 0, 0))Badge Maker supports five distinct visual styles:
Clean, modern flat design with subtle gradients.
3D appearance with pronounced gradients and highlights.
Minimalist flat design with sharp, square corners.
Large, bold style popular in GitHub README files.
Social media style with drop shadows and rounded appearance.
Badge Maker includes a command-line interface for quick badge generation through the badge command:
npm install -g badge-maker
# Basic usage with named color (colon prefix)
badge build passing :brightgreen > badge.svg
# Using custom hex colors
badge npm v5.0.2 "#cb3837" > npm-badge.svg
# With label color and message color
badge tests 95% brightgreen lightgrey > coverage.svg
# Adding style with @ prefix
badge cactus grown :green @flat > example.svgCLI Syntax:
badge label message [:color] [@style]
badge label message color [labelColor] [@style]label: Badge label textmessage: Badge message text (required):color: Named color with colon prefix (e.g., :brightgreen, :red)color: Custom color without colon (hex, CSS color names, etc.)labelColor: Optional label background color (when using custom colors)@style: Style with @ prefix (e.g., @plastic, @social, @for-the-badge)Examples:
badge cactus grown :green @flat - Named color with stylebadge build failed red - Custom colorbadge test 95% green lightgrey @flat-square - Both colors with style// Passing build
const passingBuild = makeBadge({
label: "build",
message: "passing",
color: "brightgreen"
});
// Failed build
const failedBuild = makeBadge({
label: "build",
message: "failed",
color: "red"
});// NPM version with logo
const npmVersion = makeBadge({
label: "npm",
message: "v5.0.2",
color: "#cb3837",
style: "flat-square",
logoBase64: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCI+PHBhdGggZD0iTTAgMGg0MHY0MEgweiIgZmlsbD0iI2NiMzgzNyIvPjwvc3ZnPg=="
});// Social style with links
const socialBadge = makeBadge({
label: "follow",
message: "@shields_io",
color: "blue",
style: "social",
links: ["https://twitter.com/shields_io"]
});
// For-the-badge style
const largeBadge = makeBadge({
label: "MADE WITH",
message: "JAVASCRIPT",
color: "yellow",
labelColor: "black",
style: "for-the-badge"
});// When displaying multiple badges on the same page
const badge1 = makeBadge({
label: "test",
message: "passing",
color: "green",
idSuffix: "1"
});
const badge2 = makeBadge({
label: "coverage",
message: "95%",
color: "brightgreen",
idSuffix: "2"
});Badge Maker performs comprehensive validation and provides detailed error messages:
import { makeBadge, ValidationError } from "badge-maker";
try {
makeBadge({
// Missing required 'message' field
label: "test"
});
} catch (error) {
if (error instanceof ValidationError) {
console.log(error.message); // "Field `message` is required"
}
}
// Common validation errors:
// - "makeBadge takes an argument of type object"
// - "Field `message` is required"
// - "Field `labelColor` must be of type string"
// - "Field `color` must be of type string"
// - "Field `message` must be of type string"
// - "Field `label` must be of type string"
// - "Field `logoBase64` must be of type string"
// - "Field `links` must be an array of strings"
// - "Field `links` must not have more than 2 elements"
// - "Field `style` must be one of (plastic,flat,flat-square,for-the-badge,social)"
// - "Field `idSuffix` must contain only numbers, letters, -, and _"
// - "Unexpected field 'invalidField'. Allowed values are (label,message,labelColor,color,style,logoBase64,links,idSuffix)"