Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.4 KB
Raw Blame
import { detectNamingStyle, type NamingStyle } from "./namingStyleDetector";
import { convertToNamingStyle, SINGLE_IDENTIFIER_PATTERN } from "./namingStyleTransformers";

export interface NamingStyleConversionResult {
  text: string;
  style: NamingStyle;
}

const STYLE_CYCLE: NamingStyle[] = ["camelCase", "PascalCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case"];

function getNextStyle(currentStyle: NamingStyle): NamingStyle {
  const currentIndex = STYLE_CYCLE.indexOf(currentStyle);
  const nextIndex = (currentIndex + 1) % STYLE_CYCLE.length;
  return STYLE_CYCLE[nextIndex];
}

/**
 * Convert to the next naming style in the cycle:
 * camelCase → PascalCase → snake_case → SCREAMING_SNAKE_CASE → kebab-case.
 *
 * Returns the original text unchanged (no-op) when the trimmed content is not
 * a single identifier — e.g. selections containing whitespace, operators,
 * comments, CJK/Cyrillic letters, or line breaks. Whitespace surrounding the
 * identifier is preserved.
 */
export function convertToNextNamingStyle(text: string, currentStyle?: NamingStyle): NamingStyleConversionResult {
  const core = text.trim();
  const detectedStyle = currentStyle ?? detectNamingStyle(core);
  if (!detectedStyle || !SINGLE_IDENTIFIER_PATTERN.test(core)) {
    return { text, style: detectedStyle ?? "camelCase" };
  }

  const nextStyle = getNextStyle(detectedStyle);
  return { text: convertToNamingStyle(text, nextStyle), style: nextStyle };
}