@ar-nelson/foldcase

中文文档
1.0.1发布于 2019/09/11ISCCommonJS零依赖近 30 天下载 2264

Unicode Case Folding, both Simple and Full

原始使用文档
文档目录6 节
  1. API
  2. foldcase(String)
  3. foldcase.full(String)
  4. foldcase.simple(String)
  5. foldcase.charFull(String)
  6. foldcase.charSimple(String)

foldcase: JavaScript implementation of the Unicode Case Folding Algorithm

This is a small Node module that implements the Unicode Case Folding Algorithm, in both Simple and Full variants, by generating a conversion table from the official case folding table at unicode.org.

const foldcase = require('@ar-nelson/foldcase');

foldcase('ABC123'); // => 'abc123'

foldcase is similar to String.prototype.toLowerCase, but not the same. Its intended use is case-insensitive string comparisons.

Case folding remains the same across Unicode versions, although toLowerCase's behavior may change. For example, because the Cherokee script originally had only uppercase characters in Unicode, and lowercase characters were added later, foldcase converts Cherokee text to uppercase.

foldcase('ꮳꮃꭹ'); // => 'ᏣᎳᎩ'

This module has no dependencies, and should run in Node and on modern browsers. Because it uses a few ES6 features (\u{…} escapes, Array.from), it won't run on any version of IE without transpilation and polyfills.

Use npm test to lint and test. Use npm run codegen to regenerate case-tables.js from the table at unicode.org (probably only works on Linux).

Caveat emptor: Because it's implemented in pure JS, and it operates on 32-bit codepoints instead of 16-bit characters, this algorithm is slow. Only use this over toLowerCase if you know you need it for compatibility.

API

foldcase(String)

Alias for foldcase.full.

foldcase.full(String)

Applies the full Unicode case folding algorithm. This algorithm may convert some single characters into multiple characters.

foldcase.full('Weiß'); // => 'weiss'

foldcase.simple(String)

Applies the simple Unicode case folding algorithm. The simple algorithm will not change the length (in code points) of its input string.

foldcase.simple('Weiß'); // => 'weiß'

foldcase.charFull(String)

Applies the full Unicode case folding algorithm to a single code point. The code point may be a surrogate pair, so the argument may be a string of length 1 or 2. If the argument is not a single code point, or does not have a case folding conversion, the argument will be returned unchanged.

foldcase.charFull('A');   // => 'a'
foldcase.charFull('FOO'); // => 'FOO'

This version of case folding may convert single characters to multiple characters.

foldcase.charFull('ß'); // => 'ss'

foldcase.charSimple(String)

Applies the simple Unicode case folding algorithm to a single code point. The code point may be a surrogate pair, so the argument may be a string of length 1 or 2. If the argument is not a single code point, or does not have a case folding conversion, the argument will be returned unchanged.

foldcase.charSimple('A');   // => 'a'
foldcase.charSimple('FOO'); // => 'FOO'

This version of case folding always returns a single code point when given a single code point.

foldcase.charSimple('ß'); // => 'ß'

版本与发布记录

@ar-nelson/foldcase 共发布 2 个版本,首次发布于 2019/09/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2019/09/117 年前
1.0.02019/09/107 年前

关于 @ar-nelson/foldcase 的常见问题

@ar-nelson/foldcase 是什么?

Unicode Case Folding, both Simple and Full

如何安装 @ar-nelson/foldcase?

在项目目录运行 npm install @ar-nelson/foldcase,或使用 pnpm add / yarn add / bun add。

@ar-nelson/foldcase 支持 TypeScript 吗?

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

@ar-nelson/foldcase 支持 ESM 还是 CommonJS?

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

@ar-nelson/foldcase 可以商用吗?

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

@ar-nelson/foldcase 的下载量有多少?

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

@ar-nelson/foldcase 还在维护吗?

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