badge-urls
Version:
Helper functions to generate URLs for all badges / shields from shields.io
7 lines (6 loc) • 482 B
JavaScript
import { urlWithOptions } from "./options";
import replaceAll from "../utils/replaceAll";
const colorWithoutHash = (color) => color.startsWith("#") ? color.slice(1) : color;
const escapeString = (s) => replaceAll(replaceAll(s, "-", "--"), "_", "__");
/** Static badges https://img.shields.io */
export const staticBadge = (label, message, color, options) => urlWithOptions(`/badge/${escapeString(label)}-${escapeString(message)}-${escapeString(colorWithoutHash(color))}`, options);