@textjs/font

中文文档
1.1.0发布于 2026/11/03MIT AND BSD-3-ClauseTypeScriptES Module零依赖

FIGlet 2.2 .flf parser and renderer for Text.js, with 17 bundled, tree-shakable fonts.

原始使用文档
文档目录4 节
  1. API
  2. Fonts
  3. Licensing
  4. Development

@textjs/font

A FIGfont 2 (.flf) parser and renderer whose output matches the figlet program, plus 17 bundled fonts, one module each.

import { FigletText } from "@textjs/font/react";
import { slant } from "@textjs/font/slant";

<FigletText font={slant} color="accent">Text.js</FigletText>;
  ______          __      _
 /_  __/__  _  __/ /_    (_)____
  / / / _ \| |/_/ __/   / / ___/
 / / /  __/>  </ /__   / (__  )
/_/  \___/_/|_|\__(_)_/ /____/
                   /___/

API

import { renderFiglet, parseFont } from "@textjs/font";
import { standard } from "@textjs/font/standard";

renderFiglet(standard, "Hello", { layout: "fitted", width: 60, align: "center" }); // string[]
standard.render("Hello"); // same, default options

const doom = parseFont(await (await fetch("/fonts/doom.flf")).text(), "Doom");
OptionValuesDefault
layout"default" (font's), "full" (-W), "fitted" (-k), "smushed" (-S), "universal" (-o), or a -m number"default"
verticalLayout"full", "fitted", "smushed", "universal", "default" (font's)"full" (FIGlet 2.2.5 has no vertical layout)
widthmaximum output columns; wraps at word breaks like figlet -w width+1unlimited
align"left", "center", "right" within width, or within the widest row"left", "right" for RTL fonts
direction"default", "ltr", "rtl"font's
paragraphjoin single newlines (-p)false

<AsciiFont font={slant} text="Text.js" /> from @textjs/react also accepts any loaded font.

Implemented: header and comment lines, hardblanks, endmarks, the 102 required characters, code-tagged characters (decimal, octal, hex, negative), the missing character (code 0), full width / fitting / smushing with all six horizontal rules and universal smushing, right-to-left printing, FIGlet's word wrapping and justification, and the five vertical rules plus supersmushing. TOIlet tlf2a fonts parse, rendered as plain text. Not implemented: control files (.flc), zipped fonts.

Fonts

standard, slant, small, smslant, big, banner, block, lean, shadow, smshadow, script, smscript, mini, bubble, digital, ivrit (right to left), term. Import each from @textjs/font/<name>; @textjs/font/all exports every font and BUNDLED_FONTS for galleries. Fonts parse lazily on first render.

All glyphs use printable ASCII and Latin-1, so they stay cell-exact in Menlo/SF Mono. (bubble, digital and term draw input U+0080–U+009F, the C1 control characters, as itself.)

Licensing

The code is MIT. The fonts are the FIGlet 2.2.5 distribution fonts, byte-identical to figlet-2.2.5.tar.gz, under FIGlet's BSD 3-Clause license (LICENSES/FIGLET.txt); each keeps its credits in its comment lines (font.comment). Fonts without a redistribution grant (Doom, Larry 3D, ANSI Shadow, Calvin S, …) are not bundled. See NOTICE.

Development

bun run --cwd packages/font generate     # fonts/*.flf → src/fonts/*.ts
bun run --cwd packages/font references   # needs `figlet` 2.2.5 on PATH
bun test packages/font

test/fixtures/references.json holds 273 outputs from the real figlet 2.2.5 binary (17 fonts × layouts × inputs, plus FIGlet's own regression input with its run-tests.sh flags); the test suite replays each one.

版本与发布记录

@textjs/font 共发布 7 个版本,首次发布于 2026/11/01;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.1.0latest2026/11/03今天
1.0.42026/11/021 天前
1.0.32026/11/021 天前
1.0.22026/11/021 天前
1.0.12026/11/021 天前
1.0.02026/11/011 天前

关于 @textjs/font 的常见问题

@textjs/font 是什么?

FIGlet 2.2.用于Text.js的flf解析器和渲染器,具有17种捆绑的树可动摇字体。

如何安装 @textjs/font?

在项目目录运行 npm install @textjs/font,或使用 pnpm add / yarn add / bun add。

@textjs/font 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@textjs/font 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@textjs/font 可以商用吗?

@textjs/font 使用 MIT AND BSD-3-Clause 许可。声明的许可为 MIT AND BSD-3-Clause,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@textjs/font 还在维护吗?

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