From 606c1c60ae5ace3623cf06bc8f9f36697e986785 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sat, 8 Nov 2025 23:00:02 +0900 Subject: [PATCH 1/4] =?UTF-8?q?toCamelCase=20=E5=BE=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pkg/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/utils/utils.ts b/src/pkg/utils/utils.ts index d4b62df4b..555f72011 100644 --- a/src/pkg/utils/utils.ts +++ b/src/pkg/utils/utils.ts @@ -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 { From 57d8e294207ecdbac3d764a4f885946803c0c57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Sat, 8 Nov 2025 22:17:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/utils.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/utils.test.ts b/tests/utils.test.ts index e1e602f38..cb12def7d 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -5,6 +5,7 @@ import { newMockXhr } from "mock-xmlhttprequest"; import type { Script, ScriptRunResource } from "@App/app/repo/scripts"; import { ScriptDAO } from "@App/app/repo/scripts"; import GMApi from "@App/app/service/content/gm_api"; +import { toCamelCase } from "@App/pkg/utils/utils"; describe("测试GMApi环境", async () => { const msg = initTestGMApi(); @@ -51,3 +52,23 @@ describe("测试GMApi环境", async () => { expect(onload.mock.calls[0][0]).toBe("example"); }); }); + +describe("测试工具函数", () => { + describe("toCamelCase", () => { + it("应当将蛇形命名转换为驼峰命名", () => { + 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("应当正确处理单词配置键", () => { + expect(toCamelCase("language")).toBe("Language"); + }); + + it("应当正确处理多下划线配置键", () => { + expect(toCamelCase("editor_type_definition")).toBe("EditorTypeDefinition"); + expect(toCamelCase("script_list_column_width")).toBe("ScriptListColumnWidth"); + }); + }); +}); From 839aba84cf9b2ce2fba2ac1558b018987d520239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Sat, 8 Nov 2025 22:18:01 +0800 Subject: [PATCH 3/4] concurrent --- tests/utils.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/utils.test.ts b/tests/utils.test.ts index cb12def7d..d04992682 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -55,18 +55,18 @@ describe("测试GMApi环境", async () => { describe("测试工具函数", () => { describe("toCamelCase", () => { - it("应当将蛇形命名转换为驼峰命名", () => { + 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("应当正确处理单词配置键", () => { + it.concurrent("应当正确处理单词配置键", () => { expect(toCamelCase("language")).toBe("Language"); }); - it("应当正确处理多下划线配置键", () => { + it.concurrent("应当正确处理多下划线配置键", () => { expect(toCamelCase("editor_type_definition")).toBe("EditorTypeDefinition"); expect(toCamelCase("script_list_column_width")).toBe("ScriptListColumnWidth"); }); From 64d54483dbb60b209554f862fe85ae706e193eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Sat, 8 Nov 2025 22:19:13 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pkg/utils/utils.test.ts | 20 +++++++++++++++++++- tests/utils.test.ts | 21 --------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/pkg/utils/utils.test.ts b/src/pkg/utils/utils.test.ts index 4aeb59197..8acb1b9f0 100644 --- a/src/pkg/utils/utils.test.ts +++ b/src/pkg/utils/utils.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } 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"; @@ -326,3 +326,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"); + }); +}); diff --git a/tests/utils.test.ts b/tests/utils.test.ts index d04992682..e1e602f38 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -5,7 +5,6 @@ import { newMockXhr } from "mock-xmlhttprequest"; import type { Script, ScriptRunResource } from "@App/app/repo/scripts"; import { ScriptDAO } from "@App/app/repo/scripts"; import GMApi from "@App/app/service/content/gm_api"; -import { toCamelCase } from "@App/pkg/utils/utils"; describe("测试GMApi环境", async () => { const msg = initTestGMApi(); @@ -52,23 +51,3 @@ describe("测试GMApi环境", async () => { expect(onload.mock.calls[0][0]).toBe("example"); }); }); - -describe("测试工具函数", () => { - describe("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"); - }); - }); -});