@cloudfour/simple-svg-placeholder

中文文档
1.2.0发布于 2026/08/26MITESM + CJS零依赖近 30 天下载 1万

A very simple placeholder image generator with zero dependencies. Returns a data URI (or raw SVG source) as a string for use in templates.

原始使用文档
文档目录19 节
  1. Getting Started
  2. Examples
  3. Default
  4. Dimensions
  5. Text
  6. Colors
  7. Font
  8. Option Reference
  9. width {Number}
  10. height {Number}
  11. text {String}
  12. fontFamily {String}
  13. fontWeight {String}
  14. fontSize {Number}
  15. dy {Number}
  16. bgColor {String}
  17. textColor {String}
  18. dataUri {Boolean}
  19. charset {String}

Simple SVG Placeholder

NPM version Build Status Renovate

A very simple placeholder image generator with zero dependencies. Returns a data URI (or raw SVG source) as a string for use in templates.

Getting Started

The package is available to install via npm:

npm i --save @cloudfour/simple-svg-placeholder

Once installed, you may import the function as an ES or CommonJS module:

// Module
import simpleSvgPlaceholder from '@cloudfour/simple-svg-placeholder';

// CommonJS
const simpleSvgPlaceholder = require('@cloudfour/simple-svg-placeholder');

Then call the function to generate placeholder SVGs:

const placeholder = simpleSvgPlaceholder(/* options */);
// => 'data:image/svg+xml;...'

Examples

Default

simpleSvgPlaceholder();

Dimensions

simpleSvgPlaceholder({
  width: 180,
  height: 135,
});

Text

simpleSvgPlaceholder({
  text: 'Hello world!',
});

Colors

simpleSvgPlaceholder({
  bgColor: '#0F1C3F',
  textColor: '#7FDBFF',
});

Font

simpleSvgPlaceholder({
  fontFamily: 'Georgia, serif',
  fontWeight: 'normal',
});

Option Reference

width {Number}

Defaults to 300, the default width of SVG elements in most browsers.

height {Number}

Defaults to 150, the default height of SVG elements in most browsers.

text {String}

The text to display. Defaults to the image dimensions.

This is treated as literal text, not markup: characters that are significant in XML (&, <, >, ") are escaped for you, so 'Tom & Jerry' renders as written rather than producing an SVG the browser refuses to parse.

fontFamily {String}

The font to use for the text. For data URIs, this needs to be a system-installed font. Defaults to 'sans-serif'.

fontWeight {String}

Defaults to 'bold'.

fontSize {Number}

Defaults to 20% of the shortest image dimension, rounded down.

dy {Number}

Adjustment applied to the dy attribute of the text element so it will appear vertically centered. Defaults to 35% of the fontSize.

bgColor {String}

The background color of the image. Defaults to #ddd.

textColor {String}

The color of the text. For transparency, use an rgba or hsla color value. Defaults to rgba(0,0,0,0.5).

dataUri {Boolean}

If true, the function will return an encoded string for use as an img element's src value. If false, the function will return the unencoded SVG source, suitable for inlining into a document. Defaults to true.

charset {String}

Defaults to UTF-8, but if your source HTML document's character set is different, you may want to update this to match.

版本与发布记录

@cloudfour/simple-svg-placeholder 共发布 5 个版本,首次发布于 2020/01/04;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.2.0latest2026/08/262 个月前
1.1.02022/09/234 年前
1.0.22020/01/076 年前
1.0.12020/01/046 年前
1.0.02020/01/046 年前

关于 @cloudfour/simple-svg-placeholder 的常见问题

@cloudfour/simple-svg-placeholder 是什么?

A very simple placeholder image generator with zero dependencies. Returns a data URI (or raw SVG source) as a string for use in templates.

如何安装 @cloudfour/simple-svg-placeholder?

在项目目录运行 npm install @cloudfour/simple-svg-placeholder,或使用 pnpm add / yarn add / bun add。

@cloudfour/simple-svg-placeholder 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cloudfour__simple-svg-placeholder 是否存在。

@cloudfour/simple-svg-placeholder 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cloudfour/simple-svg-placeholder 可以商用吗?

@cloudfour/simple-svg-placeholder 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cloudfour/simple-svg-placeholder 的下载量有多少?

根据 npm 官方下载统计,@cloudfour/simple-svg-placeholder 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,411 次,日均约 347 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cloudfour/simple-svg-placeholder 还在维护吗?

最新版本 1.2.0 发布于 2026/08/26(2 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/01/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。