Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/pkg/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, beforeAll } from "vitest";
import { checkSilenceUpdate, cleanFileName, stringMatching } from "./utils";
import { checkSilenceUpdate, cleanFileName, stringMatching, toCamelCase } from "./utils";
import { ltever, versionCompare } from "@App/pkg/utils/semver";
import { nextTime } from "./cron";
import dayjs from "dayjs";
Expand Down Expand Up @@ -331,3 +331,21 @@ describe.concurrent("stringMatching", () => {
});
});
});

describe.concurrent("toCamelCase", () => {
it.concurrent("应当将蛇形命名转换为驼峰命名", () => {
expect(toCamelCase("cloud_sync")).toBe("CloudSync");
expect(toCamelCase("cat_file_storage")).toBe("CatFileStorage");
expect(toCamelCase("enable_eslint")).toBe("EnableEslint");
expect(toCamelCase("eslint_config")).toBe("EslintConfig");
});

it.concurrent("应当正确处理单词配置键", () => {
expect(toCamelCase("language")).toBe("Language");
});

it.concurrent("应当正确处理多下划线配置键", () => {
expect(toCamelCase("editor_type_definition")).toBe("EditorTypeDefinition");
expect(toCamelCase("script_list_column_width")).toBe("ScriptListColumnWidth");
});
});
2 changes: 1 addition & 1 deletion src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const obtainBlackList = (strBlacklist: string | null | undefined) => {

// 将蛇形的 key 转换为驼峰的函数名
export function toCamelCase(key: SystemConfigKey) {
return key.replace(/_([a-z])/g, (g) => g[1].toUpperCase()).replace(/^([a-z])/, (g) => g.toUpperCase());
return key.replace(/^[a-z]|_([a-z])/g, (_, c = _) => c.toUpperCase());
}

export function cleanFileName(name: string): string {
Expand Down
Loading