@directus/format-title

中文文档
13.0.0发布于 2026/06/11MITES Module零依赖构建来源已验证近 30 天下载 11万

Custom formatter that converts any string into Title Case

原始使用文档
文档目录4 节
  1. Installation
  2. Usage
  3. License
  4. Additional Resources

@directus/format-title

Custom formatter that converts any string into Title Case.

Capital letters are used for principal words. Articles, conjunctions, and prepositions do not get capital letters unless they start or end the title.

InputOutput
snowWhiteAndTheSevenDwarfsSnow White and the Seven Dwarfs
NewcastleUponTyneNewcastle Upon Tyne
brighton_on_seaBrighton on Sea
apple_releases_new_ipadApple Releases New iPad
7-food-trends7 Food Trends

The package contains a list of words that use some sort of special casing, for example: McDonalds, iPhone, and YouTube.

Installation

npm install @directus/format-title

Usage

The package by default converts camelCase, PascalCase, underscore, and "regular" sentences to Title Case.

formatTitle(string, [separator]);

formatTitle('snowWhiteAndTheSevenDwarfs');
// => Snow White and the Seven Dwarfs

You can provide an optional separator regex as a second parameter to support splitting the string on different characters. By default, this regex is set to /\s|-|_/g.

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Additional Resources

版本与发布记录

@directus/format-title 共发布 171 个版本,首次发布于 2018/03/28;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
13.0.0latest2026/06/115 个月前
13.0.0-rc.0canary2026/05/295 个月前
12.1.22026/03/257 个月前
12.1.12025/11/051 年前
12.1.02025/09/171.2 年前
12.0.12025/03/261.6 年前

关于 @directus/format-title 的常见问题

@directus/format-title 是什么?

Custom formatter that converts any string into Title Case

如何安装 @directus/format-title?

在项目目录运行 npm install @directus/format-title,或使用 pnpm add / yarn add / bun add。

@directus/format-title 支持 TypeScript 吗?

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

@directus/format-title 支持 ESM 还是 CommonJS?

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

@directus/format-title 可以商用吗?

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

@directus/format-title 的下载量有多少?

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

@directus/format-title 还在维护吗?

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