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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mock-svg

v1.0.0

Published

用于生成 SVG 图片的 Base64 数据 URL 的工具类。

Readme

MockSVG

用于生成 SVG 图片的 Base64 数据 URL 的工具类。

功能

  • 自定义尺寸、背景色和文本的占位符 SVG 图片。
  • 支持自定义文本颜色、字体大小、字体族和字体粗细。
  • 可通过 slot 添加额外的 SVG 元素。

安装

无需安装,直接将脚本引入项目即可。


使用方法

  1. 将类引入项目中:

    import MockSVG from 'mock-svg';
  2. 使用 generate 方法生成 Base64 数据 URL:

    const svgDataUrl = MockSVG.generate({
      size: [400, 300],
      bgColor: '#eeeeee',
      text: 'Hello, SVG!',
      textColor: '#333333',
      fontSize: 24,
      fontFamily: 'Verdana, sans-serif',
      fontWeight: 'bold',
      slot: '<circle cx="200" cy="150" r="50" fill="blue" />',
    });
    
    // 在图片标签中使用生成的 Data URL:
    document.getElementById('svgImage').src = svgDataUrl;
  3. 示例输出:

    • 生成的 Base64 数据 URL 可用作 SVG 图像。

API 文档

MockSVG.generate(options)

| 参数 | 类型 | 默认值 | 描述 | |--------------|---------|----------------------|----------------------------------------| | size | 数组 | [320, 280] | 包含宽度和高度的数组,单位为像素。 | | bgColor | 字符串 | "#f2f5f7" | SVG 的背景颜色。 | | text | 字符串 | "placeholder" | 显示在 SVG 中心的文本。 | | textColor | 字符串 | "#00000033" | 文本颜色。 | | fontSize | 数字 | 32 | 文本的字体大小。 | | fontFamily | 字符串 | "Arial, sans-serif"| 文本的字体族。 | | fontWeight | 字符串 | "normal" | 文本的字体粗细。 | | slot | 字符串 | "" | 额外的 SVG 元素字符串。 |

返回值:

返回表示 SVG 图片的 Base64 数据 URL 字符串。