@art-suite/art-core-ts-string-case

中文文档
0.2.2发布于 2026/06/19MITTypeScriptESM + CJS近 30 天下载 3248

A TypeScript string library for converting strings to different 'code word' cases: camelCase, snake_case, kebab-case, PascalCase, etc.

原始使用文档
文档目录6 节
  1. Why This Module?
  2. Example Installation and Use (Required)
  3. Functional Overview
  4. Code Word Extraction
  5. Case Conversion Functions
  6. Word Case Utilities

@art-suite/art-core-ts-string-case

Effortless, lossless conversion between all common string case formats in programming.

Why This Module?

The Why: There are several common ways to represent words without spaces in programming—camelCase, snake_case, dash-case, and more. Converting between them is a frequent need, but handling edge cases (especially acronyms) is tricky and error-prone. There is no clear standard for how to represent acronyms as "code words," and most libraries lose information when converting between formats.

The How: This library makes one key assumption: acronyms are treated as words. For example, "HTML" is treated as the word "Html" for the purpose of code words. This enables lossless, round-trip conversion between all supported formats—so you can always convert back and forth without losing word boundaries or acronym information.

The What: A comprehensive set of functions for converting between camelCase, PascalCase, snake_case, UPPER_SNAKE_CASE, dash-case, Capitalized-Dash-Case, and more, all with robust handling of acronyms.

Example Installation and Use (Required)

Install with npm:

npm install @art-suite/art-core-ts-string-case

Basic usage:

import {
  getCodeWords,
  lowerCamelCase,
  upperCamelCase,
  snakeCase,
  upperSnakeCase,
  dashCase,
  capitalizedDashCase,
  pascalCase,
  kebabCase,
  constantCase,
  camelCase,
} from "@art-suite/art-core-ts-string-case";

getCodeWords("toHTML"); // ["to", "Html"]
lowerCamelCase("to HTML"); // "toHtml"
upperCamelCase("to HTML"); // "ToHtml"
snakeCase("to HTML"); // "to_html"
upperSnakeCase("to HTML"); // "TO_HTML"
dashCase("to HTML"); // "to-html"
capitalizedDashCase("to HTML"); // "To-Html"

// Aliases
pascalCase("to HTML"); // "ToHtml"
kebabCase("to HTML"); // "to-html"
constantCase("to HTML"); // "TO_HTML"
camelCase("to HTML"); // "toHtml"

// All converters accept an optional second parameter: the joiner string
upperCamelCase("to HTML", " "); // "To Html"
snakeCase("to HTML", "--"); // "to--html"

Functional Overview

Code Word Extraction

  • getCodeWords(str) — Extracts an array of code words from any string, treating acronyms as words (e.g., "toHTML" → ["to", "Html"]).

Case Conversion Functions

All converters accept an optional second parameter, joiner, which is the string inserted between each word (default varies by converter).

  • lowerCamelCase(str, joiner?) — Converts to lowerCamelCase.
  • upperCamelCase(str, joiner?) — Converts to UpperCamelCase (PascalCase).
  • snakeCase(str, joiner?) — Converts to snake_case.
  • upperSnakeCase(str, joiner?) — Converts to UPPER_SNAKE_CASE.
  • dashCase(str, joiner?) — Converts to dash-case.
  • capitalizedDashCase(str, joiner?) — Converts to Capitalized-Dash-Case.
  • pascalCase(str, joiner?) — Alias for upperCamelCase.
  • kebabCase(str, joiner?) — Alias for dashCase.
  • constantCase(str, joiner?) — Alias for upperSnakeCase.
  • camelCase(str, joiner?) — Alias for lowerCamelCase.

Word Case Utilities

  • lowerCase(str)

版本与发布记录

@art-suite/art-core-ts-string-case 共发布 19 个版本,首次发布于 2025/05/12;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.2.2latest2026/06/194 个月前
0.2.12026/03/297 个月前
0.2.02026/03/277 个月前
0.1.172025/12/0511 个月前
0.1.162025/12/0511 个月前
0.1.152025/12/0411 个月前

关于 @art-suite/art-core-ts-string-case 的常见问题

@art-suite/art-core-ts-string-case 是什么?

A TypeScript string library for converting strings to different 'code word' cases: camelCase, snake_case, kebab-case, PascalCase, etc.

如何安装 @art-suite/art-core-ts-string-case?

在项目目录运行 npm install @art-suite/art-core-ts-string-case,或使用 pnpm add / yarn add / bun add。

@art-suite/art-core-ts-string-case 支持 TypeScript 吗?

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

@art-suite/art-core-ts-string-case 支持 ESM 还是 CommonJS?

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

@art-suite/art-core-ts-string-case 可以商用吗?

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

@art-suite/art-core-ts-string-case 的下载量有多少?

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

@art-suite/art-core-ts-string-case 还在维护吗?

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