@flasd/whatsapp-formatting

中文文档
0.2.0发布于 2025/08/29MITESM + CJS零依赖近 30 天下载 8638

WhatsApp allows you to format selected text inside your messages.

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. Supported Formatting
  4. MIT License

whatsapp formatting for the web

Build Status Coverage Status npm version npm downloads per month

What if you could use an awesome text formatting syntax that millions of people are already used to in your app? Oh wait! You can! cue Whatsapp formatting. You can use *bold*, _italic_, ~strikethrough~, ```monospace```, or `inline code`. (it's only 510 bytes gzip!)

Installation

$ yarn add @flasd/whatsapp-formatting

// or if you are feeling old school
$ npm install @flasd/whatsapp-formatting

Usage

The API is very very simple.

import { format } from "@flasd/whatsapp-formatting";

format("*hello* _world_");
// « '<strong>hello</strong> <i>world</i>'

format("~how are you?~");
// « '<s>how are you?</s>'

format("```monospace text```");
// « '<code>monospace text</code>'

format("`inline code`");
// « '<code>inline code</code>'

format(`
multiline
string
`);
// « '<br>multiline<br>string<br>'

Supported Formatting

This library supports the following WhatsApp text formatting:

  • Bold: *text* → <strong>text</strong>
  • Italic: _text_ → <i>text</i>
  • Strikethrough: ~text~ → <s>text</s>
  • Monospace: ```text``` → <code>text</code>
  • Inline Code: `text` → <code>text</code>
  • Line breaks: \n → <br>

You can mix and match all of the formatters. OH! And you can customize the formatting rules if you want to:

import { format, whatsappRules } from "@flasd/whatsapp-formatting";

const customRules = [
  ...whatsappRules,
  {
    wildcard: "|",
    openTag: '<span style="font-family:monospace">',
    closeTag: "</span>",
  },
];

format("|some awesome code|", customRules);
// « '<span style="font-family:monospace">some awesome code</span>'

MIT License

Copyright 2020 Marcel de Oliveira Coelho under the MIT License. Go Crazy. :rocket:

版本与发布记录

@flasd/whatsapp-formatting 共发布 6 个版本,首次发布于 2020/01/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2025/08/291.2 年前
0.1.42020/11/116 年前
0.1.32020/11/116 年前
0.1.22020/11/106 年前
0.1.12020/01/156 年前
0.1.02020/01/156 年前

关于 @flasd/whatsapp-formatting 的常见问题

@flasd/whatsapp-formatting 是什么?

WhatsApp allows you to format selected text inside your messages.

如何安装 @flasd/whatsapp-formatting?

在项目目录运行 npm install @flasd/whatsapp-formatting,或使用 pnpm add / yarn add / bun add。

@flasd/whatsapp-formatting 支持 TypeScript 吗?

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

@flasd/whatsapp-formatting 支持 ESM 还是 CommonJS?

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

@flasd/whatsapp-formatting 可以商用吗?

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

@flasd/whatsapp-formatting 的下载量有多少?

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

@flasd/whatsapp-formatting 还在维护吗?

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