@frogpond/titlecase

中文文档
2.0.4发布于 2022/04/21MITTypeScriptCommonJS零依赖近 30 天下载 4412

Intelligently converting strings to title case (an enhanced fork of David Gouch's library; now forked from @rvagg's fork)

原始使用文档
文档目录7 节
  1. rvagg's README
  2. Original README
  3. History
  4. 2.1 / 2013-11-03
  5. 2.0.1 / 2012-01-06
  6. 2.0 / 2012-01-06
  7. License

David Gouch's String#toTitleCase() for Node.js

This is a fork of @rvagg's fork of David Gouch's excellent String#toTitleCase() method inspired by John Gruber's post on the topic

I've removed the default export, forcing you to choose between toTitleCase and toLaxTitleCase.

rvagg's README

I've simply taken it off the String prototype and exported it from a simple module.

let { toTitleCase } = require("titlecase")

console.log(toTitleCase("foo bar baz"))

See Gouch's page with inline converter. Also see this excellent table of test case results for different converters.

In addition, I've added a more comprehensive list of words to not capitalise that includes articles, prepositions and conjunctions (see source files for lists), I'm calling this "lax title case", use it like so:

let { toLaxTitleCase } = require("titlecase")

console.log(toLaxTitleCase("foo bar baz"))

Original README

To Title Case for JavaScript

Instructions: Include the dist/index.js script and use the toTitleCase() function on the string you want converted.

History

2.1 / 2013-11-03

  • Acknowledge characters outside of US-ASCII
  • Fix bug related to hyphenated small words
  • Replace baby's first testing script with the QUnit framework

2.0.1 / 2012-01-06

  • Fixed IE 7 breakage introduced in 2.0. Don't treat strings like character arrays.

2.0 / 2012-01-06

  • 15% less code and 35% easier to understand.
  • Small words list moved to variable for easy modification.
  • Test titles rewritten to focus on a single issue per title.
  • More braces to make style guides and JSLint happier.

License

Copyright © 2008–2013 David Gouch. Licensed under the MIT License.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

版本与发布记录

@frogpond/titlecase 共发布 6 个版本,首次发布于 2018/12/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.4latest2022/04/214 年前
2.0.32022/04/204 年前
2.0.22022/04/204 年前
2.0.12022/04/204 年前
2.0.02022/04/194 年前
1.0.02018/12/097 年前

关于 @frogpond/titlecase 的常见问题

@frogpond/titlecase 是什么?

Intelligently converting strings to title case (an enhanced fork of David Gouch's library; now forked from @rvagg's fork)

如何安装 @frogpond/titlecase?

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

@frogpond/titlecase 支持 TypeScript 吗?

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

@frogpond/titlecase 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@frogpond/titlecase 可以商用吗?

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

@frogpond/titlecase 的下载量有多少?

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

@frogpond/titlecase 还在维护吗?

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