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

hqvt-font-manager

v1.0.1

Published

一个简单易用的字体管理包,支持中英文字体注册和CSS生成。

Readme

HQVT Font Manager

一个简单易用的字体管理包,支持中英文字体注册和CSS生成。

安装

ash npm install hqvt-font-manager

功能特性

  • 支持中英文字体管理
  • 自动生成CSS字体声明
  • 支持多种字体格式(OTF、TTF)
  • 简单易用的API

快速开始

1. 基本使用

`javascript const { getAvailableFonts, generateFontCSS, writeCSSFile } = require('./index.js');

// 获取可用字体 const fonts = getAvailableFonts();

// 生成单个字体CSS const css = generateFontCSS('OpenSans-Regular', { fontWeight: 'bold' });

// 生成CSS文件 writeCSSFile(['OpenSans-Regular', 'OpenSans-Bold'], 'output.css'); `

2. 获取所有可用字体

`javascript const { getAvailableFonts } = require('./index.js');

// 获取所有可用字体 const fonts = getAvailableFonts(); console.log('可用字体:', fonts); // 输出: ['1635950212302373', '1635950212489300', 'OpenSans-Bold', 'OpenSans-Regular', ...] `

3. 生成单个字体CSS

`javascript const { generateFontCSS } = require('./index.js');

// 生成单个字体的CSS const css = generateFontCSS('OpenSans-Regular'); console.log(css); // 输出: @font-face { font-family: 'OpenSans-Regular'; src: url('...') format('truetype'); ... } `

4. 生成CSS文件

`javascript const { writeCSSFile } = require('./index.js');

// 生成包含多个字体的CSS文件 writeCSSFile( ['OpenSans-Regular', 'OpenSans-Bold', '1635950212302373'], './fonts.css' ); `

API 文档

便捷方法

包提供了一些便捷的导出方法,可以直接使用:

javascript const { getAvailableFonts, getFontInfo, generateFontCSS, generateCSSFile, writeCSSFile } = require('./index.js');

getAvailableFonts()

获取所有可用的字体名称列表。

返回值: Array - 字体名称数组

getFontInfo(fontName)

获取指定字体的详细信息。

参数:

  • fontName (string): 字体名称

返回值: Object - 字体信息对象 javascript { path: '字体文件路径', type: 'chinese' | 'english', fileName: '字体文件名' }

generateFontCSS(fontName, options)

生成单个字体的CSS声明。

参数:

  • fontName (string): 字体名称
  • options (Object, 可选): 配置选项
    • fontWeight (string): 字体粗细,默认 'normal'
    • fontStyle (string): 字体样式,默认 'normal'
    • fontDisplay (string): 字体显示方式,默认 'swap'

返回值: string - CSS字符串

generateCSSFile(fontNames, options)

生成包含多个字体的完整CSS内容。

参数:

  • fontNames (string|Array): 字体名称或字体名称数组
  • options (Object, 可选): 配置选项

返回值: string - 完整CSS内容

writeCSSFile(fontNames, outputPath, options)

将CSS内容写入文件。

参数:

  • fontNames (string|Array): 字体名称或字体名称数组
  • outputPath (string): 输出文件路径
  • options (Object, 可选): 配置选项

字体文件结构

包中的字体文件按以下结构组织:

hqvt-font-manager/ index.js fonts/ chineseFint/ # 中文字体目录 1635950212302373.otf 1635950212489300.otf ... englishFonts/ # 英文字体目录 OpenSans-Regular.ttf OpenSans-Bold.ttf ... README.md

使用示例

在Web项目中使用

`javascript const { writeCSSFile } = require('./index.js');

// 生成字体CSS文件 writeCSSFile(['OpenSans-Regular', 'OpenSans-Bold'], './public/fonts.css'); `

然后在HTML中引入:

`html

在Node.js项目中使用

`javascript const { generateFontCSS } = require('./index.js');

// 生成CSS并写入到响应中 app.get('/fonts.css', (req, res) => { const css = generateFontCSS('OpenSans-Regular'); res.setHeader('Content-Type', 'text/css'); res.send(css); }); `

注意事项

  1. 字体文件会随包一起发布,请确保字体文件有合法的使用授权
  2. 字体名称会自动清理特殊字符以确保CSS兼容性
  3. 支持 .otf 和 .ttf 格式的字体文件
  4. 如果字体不存在,会抛出错误或显示警告

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

1.0.0

  • 初始版本发布
  • 支持中英文字体管理
  • 支持CSS生成和文件输出