1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

统一转换方式名称&显示排序;统一转换函数;项目目录结构微调;补全测试用例并全部测试通过

This commit is contained in:
程序员小墨 2024-04-05 00:59:57 +08:00
parent 4b734d219a
commit d926a6d768
17 changed files with 574 additions and 401 deletions

16
GPT.md
View File

@ -272,4 +272,20 @@ vsce publish
(4) vscode-更换图标主题VSCode Icons._vscode更改不了icon-CSDN博客. https://blog.csdn.net/xiaomizhou66a/article/details/81260347. (4) vscode-更换图标主题VSCode Icons._vscode更改不了icon-CSDN博客. https://blog.csdn.net/xiaomizhou66a/article/details/81260347.
(5) 【VSCode插件】之插件图标设置 - 掘金. https://juejin.cn/post/7315373969833754624. (5) 【VSCode插件】之插件图标设置 - 掘金. https://juejin.cn/post/7315373969833754624.
==========
我正在用 typescript 开发 VSCode 插件,我想做一个命名方式转换工具,我已经实现了转换的逻辑(就是传入一个字符串,然后可以将其转换成各种命名方式比如下划线、小驼峰、连字符等),我想实现用户选中一个单词,然后用户多次按下快捷键,实现按照 小驼峰、大驼峰、连字符、下划线、全大写、全小写 的顺序循环转换(或者光标处在一个单词的位置,按下快捷键的时候自动选中这部分,然后再和前面一样的操作),选中区域取消选中,或者选择其他区域,或者用户手动编辑后,这个循环转换顺序就取消。但是我想知道如何记录用户初始的选中内容以便转换呢?
比如 foo-bar 按顺序就应该是按下 Shift + T 依次转换为 fooBar FooBar foo-bar foo_bar FOO-BAR foo-bar
如果我直接每次都根据上一次转换结果调用转换函数,那么就变成 fooBar FooBar foo-bar foo_bar FOO_BAR foo_bar(最后面两个的间隔符不对了)
所以应该每次都需要从用户的输入进行转换
这块逻辑应该如何实现呢》特别是当用户按下快捷键后,选中内容已经替换成上次转换的结果了,我怎么知道用户之前的选中以进行下次转换呢
我就是不知道如何通过vscode提供的api来实现可以把代码在写具体点吗convertText代码我已经有了这个不用写了
我还是有点不太明白,可以帮我继续完善这个代码吗,谢谢你!

View File

@ -45,37 +45,45 @@
// group-1-camel // group-1-camel
{ {
"command": "variable-conversion.toCamelCase", "command": "variable-conversion.toCamelCase",
"title": "小驼峰 / 驼峰命名 (Camel Case) [ fooBar ]" "title": "小驼峰(驼峰)命名 (Camel Case) [ fooBar ]"
}, },
{ {
"command": "variable-conversion.toPascalCase", "command": "variable-conversion.toPascalCase",
"title": "大驼峰 / 帕斯卡命名 (Pascal Case) [ FooBar ]" "title": "大驼峰(帕斯卡)命名 (Pascal Case) [ FooBar ]"
}, },
// group-2-snake // group-2-snake
{ {
"command": "variable-conversion.toSnakeCase", "command": "variable-conversion.toSnakeCase",
"title": "下划线 / 蛇形命名 (Snake Case) [ foo_bar ]" "title": "下划线(蛇形)命名 (Snake Case) [ foo_bar ]"
}, },
{ {
"command": "variable-conversion.toSnakeUpperCase", "command": "variable-conversion.toSnakeUpperCase",
"title": "下划线大写命名 (Snake Upper Case) [ FOO_BAR ]" "title": "下划线(蛇形) + 全大写命名 (Snake Upper Case) [ FOO_BAR ]"
}, },
{ {
"command": "variable-conversion.toCamelSnakeCase", "command": "variable-conversion.toSnakePascalCase",
"title": "驼峰蛇形命名 (Camel Snake Case) [ Foo_Bar ]" "title": "下划线(蛇形) + 大驼峰(帕斯卡)命名 (Snake Pascal Case) [ Foo_Bar ]"
},
{
"command": "variable-conversion.toSnakeCamelCase",
"title": "下划线(蛇形) + 小驼峰(驼峰)命名 (Snake Camel Case) [ foo_Bar ]"
}, },
// group-3-kebab // group-3-kebab
{ {
"command": "variable-conversion.toKebabCase", "command": "variable-conversion.toKebabCase",
"title": "连字符 / 脊柱式命名 (Kebab Case / Spinal Case) [ foo-bar ]" "title": "连字符(脊柱式)命名 (Kebab/Spinal Case) [ foo-bar ]"
}, },
{ {
"command": "variable-conversion.toKebabUpperCase", "command": "variable-conversion.toKebabUpperCase",
"title": "连字符大写命名 (Kebab Upper Case) [ FOO-BAR ]" "title": "连字符(脊柱式) + 全大写命名 (Kebab Upper Case) [ FOO-BAR ]"
}, },
{ {
"command": "variable-conversion.toCamelKebabCase", "command": "variable-conversion.toKebabPascalCase",
"title": "驼峰脊柱式命名 (Kebab Upper Case) [ Foo-Bar ]" "title": "连字符(脊柱式) + 大驼峰(帕斯卡)命名 (Kebab Pascal Case) [ Foo-Bar ]"
},
{
"command": "variable-conversion.toKebabCamelCase",
"title": "连字符(脊柱式) + 小驼峰(驼峰)命名 (Kebab Camel Case) [ foo-Bar ]"
}, },
// group-4-upper-lower // group-4-upper-lower
{ {
@ -163,9 +171,13 @@
"group": "group-2-snake@2" "group": "group-2-snake@2"
}, },
{ {
"command": "variable-conversion.toCamelSnakeCase", "command": "variable-conversion.toSnakePascalCase",
"group": "group-2-snake@3" "group": "group-2-snake@3"
}, },
{
"command": "variable-conversion.toSnakeCamelCase",
"group": "group-2-snake@4"
},
{ {
"command": "variable-conversion.toKebabCase", "command": "variable-conversion.toKebabCase",
"group": "group-3-kebab@1" "group": "group-3-kebab@1"
@ -175,9 +187,13 @@
"group": "group-3-kebab@2" "group": "group-3-kebab@2"
}, },
{ {
"command": "variable-conversion.toCamelKebabCase", "command": "variable-conversion.toKebabPascalCase",
"group": "group-3-kebab@3" "group": "group-3-kebab@3"
}, },
{
"command": "variable-conversion.toKebabCamelCase",
"group": "group-3-kebab@4"
},
{ {
"command": "variable-conversion.toLowerCase", "command": "variable-conversion.toLowerCase",
"group": "group-4-upper-lower@1" "group": "group-4-upper-lower@1"

View File

@ -35,35 +35,43 @@
}, },
{ {
"command": "variable-conversion.toCamelCase", "command": "variable-conversion.toCamelCase",
"title": "小驼峰 / 驼峰命名 (Camel Case) [ fooBar ]" "title": "小驼峰(驼峰)命名 (Camel Case) [ fooBar ]"
}, },
{ {
"command": "variable-conversion.toPascalCase", "command": "variable-conversion.toPascalCase",
"title": "大驼峰 / 帕斯卡命名 (Pascal Case) [ FooBar ]" "title": "大驼峰(帕斯卡)命名 (Pascal Case) [ FooBar ]"
}, },
{ {
"command": "variable-conversion.toSnakeCase", "command": "variable-conversion.toSnakeCase",
"title": "下划线 / 蛇形命名 (Snake Case) [ foo_bar ]" "title": "下划线(蛇形)命名 (Snake Case) [ foo_bar ]"
}, },
{ {
"command": "variable-conversion.toSnakeUpperCase", "command": "variable-conversion.toSnakeUpperCase",
"title": "下划线大写命名 (Snake Upper Case) [ FOO_BAR ]" "title": "下划线(蛇形) + 全大写命名 (Snake Upper Case) [ FOO_BAR ]"
}, },
{ {
"command": "variable-conversion.toCamelSnakeCase", "command": "variable-conversion.toSnakePascalCase",
"title": "驼峰蛇形命名 (Camel Snake Case) [ Foo_Bar ]" "title": "下划线(蛇形) + 大驼峰(帕斯卡)命名 (Snake Pascal Case) [ Foo_Bar ]"
},
{
"command": "variable-conversion.toSnakeCamelCase",
"title": "下划线(蛇形) + 小驼峰(驼峰)命名 (Snake Camel Case) [ foo_Bar ]"
}, },
{ {
"command": "variable-conversion.toKebabCase", "command": "variable-conversion.toKebabCase",
"title": "连字符 / 脊柱式命名 (Kebab Case / Spinal Case) [ foo-bar ]" "title": "连字符(脊柱式)命名 (Kebab/Spinal Case) [ foo-bar ]"
}, },
{ {
"command": "variable-conversion.toKebabUpperCase", "command": "variable-conversion.toKebabUpperCase",
"title": "连字符大写命名 (Kebab Upper Case) [ FOO-BAR ]" "title": "连字符(脊柱式) + 全大写命名 (Kebab Upper Case) [ FOO-BAR ]"
}, },
{ {
"command": "variable-conversion.toCamelKebabCase", "command": "variable-conversion.toKebabPascalCase",
"title": "驼峰脊柱式命名 (Kebab Upper Case) [ Foo-Bar ]" "title": "连字符(脊柱式) + 大驼峰(帕斯卡)命名 (Kebab Pascal Case) [ Foo-Bar ]"
},
{
"command": "variable-conversion.toKebabCamelCase",
"title": "连字符(脊柱式) + 小驼峰(驼峰)命名 (Kebab Camel Case) [ foo-Bar ]"
}, },
{ {
"command": "variable-conversion.toLowerCase", "command": "variable-conversion.toLowerCase",
@ -112,9 +120,13 @@
"group": "group-2-snake@2" "group": "group-2-snake@2"
}, },
{ {
"command": "variable-conversion.toCamelSnakeCase", "command": "variable-conversion.toSnakePascalCase",
"group": "group-2-snake@3" "group": "group-2-snake@3"
}, },
{
"command": "variable-conversion.toSnakeCamelCase",
"group": "group-2-snake@4"
},
{ {
"command": "variable-conversion.toKebabCase", "command": "variable-conversion.toKebabCase",
"group": "group-3-kebab@1" "group": "group-3-kebab@1"
@ -124,9 +136,13 @@
"group": "group-3-kebab@2" "group": "group-3-kebab@2"
}, },
{ {
"command": "variable-conversion.toCamelKebabCase", "command": "variable-conversion.toKebabPascalCase",
"group": "group-3-kebab@3" "group": "group-3-kebab@3"
}, },
{
"command": "variable-conversion.toKebabCamelCase",
"group": "group-3-kebab@4"
},
{ {
"command": "variable-conversion.toLowerCase", "command": "variable-conversion.toLowerCase",
"group": "group-4-upper-lower@1" "group": "group-4-upper-lower@1"

View File

@ -1,5 +1,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { ConvertFunction, EOL } from '../type-definition/convert-function-type'; import { EOL } from '../type-definition/EOLType';
import { caseConversion } from '../main-code/conversion';
import { SupportCase } from '../type-definition/SupportCaseType';
/** /**
* *
@ -7,7 +9,7 @@ import { ConvertFunction, EOL } from '../type-definition/convert-function-type';
* @param convertFunction * @param convertFunction
* @returns * @returns
*/ */
const handleEditorReplace = (convertFunction: ConvertFunction) => { const handleEditorReplace = (targetCase: SupportCase) => {
// 获取当前编辑器 // 获取当前编辑器
let editor = vscode.window.activeTextEditor; let editor = vscode.window.activeTextEditor;
if (!editor) { if (!editor) {
@ -23,7 +25,7 @@ const handleEditorReplace = (convertFunction: ConvertFunction) => {
let text = document.getText(selection); let text = document.getText(selection);
// 转换文本 // 转换文本
const converted = convertFunction(text, eol); const converted = caseConversion(targetCase, text, eol);
console.log('converted', converted); console.log('converted', converted);
// 无法转换时,跳过转换 // 无法转换时,跳过转换

View File

@ -1,5 +1,5 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import QuickPickItemEx from "../type-definition/extended-quick-pick-item-type"; import QuickPickItemEx from "../type-definition/QuickPickItemExType";
/** /**
* *

View File

@ -1,10 +1,9 @@
// The module 'vscode' contains the VS Code extensibility API // The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below // Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as TextConversion from './main-code/variable-conversion';
import { ConvertFunction, EOL } from './type-definition/convert-function-type';
import handleEditorReplace from './extension-handler/editor-submenu-handler'; import handleEditorReplace from './extension-handler/editor-submenu-handler';
import { handleQuickPick } from './extension-handler/quick-pick-handler'; import { handleQuickPick } from './extension-handler/quick-pick-handler';
import { SupportCase } from './type-definition/SupportCaseType';
// This method is called when your extension is activated // This method is called when your extension is activated
// Your extension is activated the very first time the command is executed // Your extension is activated the very first time the command is executed
@ -42,22 +41,24 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.showInformationMessage('editor is undefined'); vscode.window.showInformationMessage('editor is undefined');
} }
const commands: Array<{ command: string; convertFunction: ConvertFunction }> = [ const commands: Array<{ command: string; targetCase: SupportCase }> = [
{ command: 'variable-conversion.toCamelCase', convertFunction: TextConversion.toCamelCase }, { command: 'variable-conversion.toCamelCase', targetCase: SupportCase.CAMEL_CASE },
{ command: 'variable-conversion.toPascalCase', convertFunction: TextConversion.toPascalCase }, { command: 'variable-conversion.toPascalCase', targetCase: SupportCase.PASCAL_CASE },
{ command: 'variable-conversion.toKebabCase', convertFunction: TextConversion.toKebabCase }, { command: 'variable-conversion.toSnakeCase', targetCase: SupportCase.SNAKE_CASE },
{ command: 'variable-conversion.toCamelKebabCase', convertFunction: TextConversion.toCamelKebabCase }, { command: 'variable-conversion.toSnakeUpperCase', targetCase: SupportCase.SNAKE_UPPER_CASE },
{ command: 'variable-conversion.toKebabUpperCase', convertFunction: TextConversion.toKebabUpperCase }, { command: 'variable-conversion.toSnakePascalCase', targetCase: SupportCase.SNAKE_PASCAL_CASE },
// { command: 'variable-conversion.toSnakeCase', convertFunction: TextConversion.toSnakeCase }, { command: 'variable-conversion.toSnakeCamelCase', targetCase: SupportCase.SNAKE_CAMEL_CASE },
// { command: 'variable-conversion.toCamelSnakeCase', convertFunction: TextConversion.toCamelSnakeCase }, { command: 'variable-conversion.toKebabCase', targetCase: SupportCase.KEBAB_CASE },
// { command: 'variable-conversion.toSnakeUpperCase', convertFunction: TextConversion.toSnakeUpperCase }, { command: 'variable-conversion.toKebabUpperCase', targetCase: SupportCase.KEBAB_UPPER_CASE },
{ command: 'variable-conversion.toUpperCase', convertFunction: TextConversion.toUpperCase }, { command: 'variable-conversion.toKebabPascalCase', targetCase: SupportCase.KEBAB_PASCAL_CASE },
{ command: 'variable-conversion.toLowerCase', convertFunction: TextConversion.toLowerCase }, { command: 'variable-conversion.toKebabCamelCase', targetCase: SupportCase.KEBAB_CAMEL_CASE },
{ command: 'variable-conversion.toLowerCase', targetCase: SupportCase.LOWER_CASE },
{ command: 'variable-conversion.toUpperCase', targetCase: SupportCase.UPPER_CASE },
]; ];
for (const { command, convertFunction } of commands) { for (const { command, targetCase } of commands) {
let disposable = vscode.commands.registerCommand(command, () => { let disposable = vscode.commands.registerCommand(command, () => {
handleEditorReplace(convertFunction); handleEditorReplace(targetCase);
}); });
context.subscriptions.push(disposable); context.subscriptions.push(disposable);
} }

115
src/main-code/conversion.ts Normal file
View File

@ -0,0 +1,115 @@
import { EOL } from '../type-definition/EOLType';
import { SupportCase } from '../type-definition/SupportCaseType';
import { TransformTextResult } from '../type-definition/TransformTextResultType';
import { transformMutliLineText, transformText } from './transform';
/**
*
*
* @param {SupportCase} targetCase
* @param {string} str user selection
* @param {EOL} eol
* @returns
* @since 2024-04-04
*/
export function caseConversion(targetCase: SupportCase, str: string, eol: EOL): string {
let spaceCharacter: '-' | '_' | ' ' | undefined = undefined;
switch (targetCase) {
default:
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
spaceCharacter = undefined;
break;
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
spaceCharacter = '_';
break;
case SupportCase.KEBAB_CASE: // 连字符(脊柱式)命名
case SupportCase.KEBAB_CAMEL_CASE: // 连字符(脊柱式) + 小驼峰(驼峰)命名
case SupportCase.KEBAB_PASCAL_CASE: // 连字符(脊柱式) + 大驼峰(帕斯卡)命名
case SupportCase.KEBAB_UPPER_CASE: // 连字符(脊柱式) + 全大写命名
spaceCharacter = '-';
break;
case SupportCase.LOWER_CASE: // 全小写
return str.toLowerCase();
case SupportCase.UPPER_CASE: // 全大写
return str.toUpperCase();
}
// Cut text 切割文本
const results: Array<TransformTextResult> = transformMutliLineText(str);
// console.log('results', results);
const transformedLines: Array<string> = [];
for (const result of results) {
// Post Process 后置处理
const words = result.trimResult.split('|');
let isFirstWord: boolean = true;// [驼峰写法] 用于判断首词小写
let isPreviousWordSpecial = true; // 用于判断上一个词是 单词 or 特殊字符
const transformedWords: Array<string> = [];
for (let index = 0; index < words.length; index++) {
const word = words[index];
const firstLetter = word.charAt(0);
const pascalCaseWord = firstLetter.toUpperCase() + word.slice(1);
// 当前 word 是否是特殊单词
// const isCurrentWordNormal = firstLetter !== firstLetter.toUpperCase(); // 是小写 a-z (不是特殊字符)
const isCurrentWordNormal = /^[A-Za-z]+$/.test(word);
// /^[A-Za-z]+$/.test("") false
// /^[A-Za-z]+$/.test("苹果") true
// /^[A-Za-z]+$/.test("apple") true
const isCurrentWordSpecial = !isCurrentWordNormal;
// 添加连字符
if (!isPreviousWordSpecial && !isCurrentWordSpecial) {
spaceCharacter !== undefined
&& transformedWords.push(spaceCharacter);
}
// 根据目标情况转换单词
switch (targetCase) {
case SupportCase.CAMEL_CASE: // 小驼峰(驼峰)命名
case SupportCase.SNAKE_CAMEL_CASE: // 下划线(蛇形) + 小驼峰(驼峰)命名
case SupportCase.KEBAB_CAMEL_CASE: // 连字符(脊柱式) + 小驼峰(驼峰)命名
if (isFirstWord) {
transformedWords.push(word);
if (isCurrentWordNormal) {
isFirstWord = false;
}
} else {
transformedWords.push(pascalCaseWord);
}
break;
case SupportCase.PASCAL_CASE: // 大驼峰(帕斯卡)命名
case SupportCase.SNAKE_PASCAL_CASE: // 下划线(蛇形) + 大驼峰(帕斯卡)命名
case SupportCase.KEBAB_PASCAL_CASE: // 连字符(脊柱式) + 大驼峰(帕斯卡)命名
transformedWords.push(pascalCaseWord);
break;
case SupportCase.SNAKE_CASE: // 下划线(蛇形)命名
case SupportCase.KEBAB_CASE: // 转连字符 / 脊柱式命名
transformedWords.push(word);
break;
case SupportCase.SNAKE_UPPER_CASE: // 下划线(蛇形) + 全大写命名
case SupportCase.KEBAB_UPPER_CASE: // 连字符(脊柱式) + 全大写命名
transformedWords.push(word.toUpperCase());
break;
default:
throw new Error(`Unsupported case: ${targetCase}`);
}
if (word === '\n' || word === '\r\n') {
isFirstWord = true; // 换行后,重新计算首词
}
isPreviousWordSpecial = isCurrentWordSpecial;
}
const transformedLine = result.leadingSpace + transformedWords.join('') + result.trailingSpace;
transformedLines.push(transformedLine);
}
return transformedLines.join(eol);
}

View File

@ -1,4 +1,4 @@
import { TransformTextResult } from "../type-definition/variable-transform-type"; import { TransformTextResult } from "../type-definition/TransformTextResultType";
const logDebugInfo = false; const logDebugInfo = false;

View File

@ -1,177 +0,0 @@
import { ConvertFunction, EOL } from '../type-definition/convert-function-type';
import { TransformTextResult } from '../type-definition/variable-transform-type';
import { transformMutliLineText, transformText } from './variable-transform';
/**
* to Camel Case
*
* @param {string} str user selection
* @returns
* @since 2024-03-28
*/
export const toCamelCase: ConvertFunction = (str: string, eol: EOL): string => {
// Cut text 切割文本
const results: Array<TransformTextResult> = transformMutliLineText(str);
// console.log('results', results);
const transformedLines: Array<string> = [];
for (const result of results) {
// Post Process 后置处理
const words = result.trimResult.split('|');
let isFirstWord: boolean = true;// 用于判断首词小写
const camelCaseWords: Array<string> = [];
for (let index = 0; index < words.length; index++) {
const word = words[index];
const firstLetter = word.charAt(0);
const pascalCaseWord = firstLetter.toUpperCase() + word.slice(1);
if (isFirstWord) {
camelCaseWords.push(word);
if (firstLetter !== firstLetter.toUpperCase()) {
// 是大写 (A-Z), 再后面的词句不再是首词
isFirstWord = false;
}
} else {
camelCaseWords.push(pascalCaseWord);
}
if (word === '\n' || word === '\r\n') {
isFirstWord = true; // 换行后,重新计算首词
}
}
const transformedLine = result.leadingSpace + camelCaseWords.join('') + result.trailingSpace;
transformedLines.push(transformedLine);
}
return transformedLines.join(eol);
// return str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
};
/**
* to Pascal Case
*
* @param {string} str user selection
* @returns
* @since 2024-03-28
*/
export const toPascalCase: ConvertFunction = (str: string, eol: EOL): string => {
// Cut text 切割文本
const results: Array<TransformTextResult> = transformMutliLineText(str);
// console.log('results', results);
const transformedLines: Array<string> = [];
for (const result of results) {
const words = result.trimResult.split('|');
const pascalCaseWords = words.map((word, index) => {
// 首字母大写
return word.charAt(0).toUpperCase() + word.slice(1);
});
const transformedLine = result.leadingSpace + pascalCaseWords.join('') + result.trailingSpace;
transformedLines.push(transformedLine);
}
return transformedLines.join(eol);
// return str.replace(/(^\w|_\w)/g, (g) => g.toUpperCase().replace('_', ''));
};
/**
* / to Kebab Case / Spinal Case
*
* @param {string} str user selection
* @returns
* @since 2024-04-03
*/
export const toKebabCase: ConvertFunction = (str: string, eol: EOL): string => {
// Cut text 切割文本
const results: Array<TransformTextResult> = transformMutliLineText(str);
// console.log('results', results);
const transformedLines: Array<string> = [];
for (const result of results) {
const words = result.trimResult.split('|');
let isPreviousWordSpecial = true;
const transformedWords = [];
for (let index = 0; index < words.length; index++) {
const word = words[index];
const isCurrentWordSpecial = !/^[A-Za-z]+$/.test(word);
if (!isPreviousWordSpecial && !isCurrentWordSpecial) {
transformedWords.push('-');
}
transformedWords.push(word);
isPreviousWordSpecial = isCurrentWordSpecial;
}
const transformedLine = result.leadingSpace + transformedWords.join('') + result.trailingSpace;
transformedLines.push(transformedLine);
}
return transformedLines.join(eol);
};
/**
* to Camel Kebab Case
*
* @param {string} str user selection
* @returns
* @since 2024-04-03
*/
export const toCamelKebabCase: ConvertFunction = (str: string, eol: EOL): string => {
// Cut text 切割文本
const results: Array<TransformTextResult> = transformMutliLineText(str);
// console.log('results', results);
const transformedLines: Array<string> = [];
for (const result of results) {
const words = result.trimResult.split('|');
let isPreviousWordSpecial = true;
const transformedWords = [];
for (let index = 0; index < words.length; index++) {
const word = words[index];
const isCurrentWordSpecial = !/^[A-Za-z]+$/.test(word);
if (!isPreviousWordSpecial && !isCurrentWordSpecial) {
transformedWords.push('-');
}
const pascalCaseWord = word.charAt(0).toUpperCase() + word.slice(1);
transformedWords.push(pascalCaseWord);
isPreviousWordSpecial = isCurrentWordSpecial;
}
const transformedLine = result.leadingSpace + transformedWords.join('') + result.trailingSpace;
transformedLines.push(transformedLine);
}
return transformedLines.join(eol);
};
/**
* to Kebab Upper Case
*
* @param {string} str user selection
* @returns
* @since 2024-04-03
*/
export const toKebabUpperCase: ConvertFunction = (str: string, eol: EOL): string => {
return toKebabCase(str, eol).toUpperCase();
};
/**
* to Upper Case
*
* @param {string} str user selection
* @returns
* @since 2024-03-28
*/
export const toUpperCase: ConvertFunction = (str: string, eol: EOL): string => {
return str.toUpperCase();
};
/**
* to Lower Case
*
* @param {string} str user selection
* @returns
* @since 2024-03-28
*/
export const toLowerCase: ConvertFunction = (str: string, eol: EOL): string => {
return str.toLowerCase();
};

View File

@ -4,10 +4,11 @@ import * as assert from 'assert';
// as well as import your extension to test it // as well as import your extension to test it
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import testGroups from './test-case'; import testGroups from './test-case';
import { TestCase, TestCaseGroup } from '../type-definition/test-case-type'; import { TestCase, TestCaseGroup } from '../type-definition/TestCaseType';
import { transformMutliLineText, transformText } from '../main-code/variable-transform'; import { transformMutliLineText, transformText } from '../main-code/transform';
import { toCamelCase, toCamelKebabCase, toKebabCase, toKebabUpperCase, toLowerCase, toPascalCase, toUpperCase } from '../main-code/variable-conversion'; import { caseConversion } from '../main-code/conversion';
import { TransformTextResult } from '../type-definition/variable-transform-type'; import { SupportCase } from '../type-definition/SupportCaseType';
import { TransformTextResult } from '../type-definition/TransformTextResultType';
// import * as myExtension from '../../extension'; // import * as myExtension from '../../extension';
/* /*
@ -24,9 +25,6 @@ suite('Extension Test Suite', () => {
suite('Extension Test: run test case', () => { suite('Extension Test: run test case', () => {
vscode.window.showInformationMessage('Start all tests.'); vscode.window.showInformationMessage('Start all tests.');
// transform to camel case
const groups: Array<TestCaseGroup> = testGroups; const groups: Array<TestCaseGroup> = testGroups;
for (const testGroup of groups) { for (const testGroup of groups) {
const testTitle = testGroup.testTitle; const testTitle = testGroup.testTitle;
@ -51,17 +49,22 @@ suite('Extension Test: run test case', () => {
} }
// 验证转换 // 验证转换
for (let eol of eolList) { for (let eol of eolList) {
assert.strictEqual(testCase.output.camelCase, toCamelCase(input, eol)); assert.strictEqual(testCase.output.camelCase, caseConversion(SupportCase.CAMEL_CASE, input, eol));
assert.strictEqual(testCase.output.pascalCase, toPascalCase(input, eol)); assert.strictEqual(testCase.output.pascalCase, caseConversion(SupportCase.PASCAL_CASE, input, eol));
if (testCase.output.upperCase !== undefined) { assert.strictEqual(testCase.output.snakeCase, caseConversion(SupportCase.SNAKE_CASE, input, eol));
assert.strictEqual(testCase.output.upperCase, toUpperCase(input, eol)); assert.strictEqual(testCase.output.snakeCamelCase, caseConversion(SupportCase.SNAKE_CAMEL_CASE, input, eol));
} assert.strictEqual(testCase.output.snakePascalCase, caseConversion(SupportCase.SNAKE_PASCAL_CASE, input, eol));
assert.strictEqual(testCase.output.snakeUpperCase, caseConversion(SupportCase.SNAKE_UPPER_CASE, input, eol));
assert.strictEqual(testCase.output.kebabCase, caseConversion(SupportCase.KEBAB_CASE, input, eol));
assert.strictEqual(testCase.output.kebabCamelCase, caseConversion(SupportCase.KEBAB_CAMEL_CASE, input, eol));
assert.strictEqual(testCase.output.kebabPascalCase, caseConversion(SupportCase.KEBAB_PASCAL_CASE, input, eol));
assert.strictEqual(testCase.output.kebabUpperCase, caseConversion(SupportCase.KEBAB_UPPER_CASE, input, eol));
if (testCase.output.lowerCase !== undefined) { if (testCase.output.lowerCase !== undefined) {
assert.strictEqual(testCase.output.lowerCase, toLowerCase(input, eol)); assert.strictEqual(testCase.output.lowerCase, caseConversion(SupportCase.LOWER_CASE, input, eol));
}
if (testCase.output.upperCase !== undefined) {
assert.strictEqual(testCase.output.upperCase, caseConversion(SupportCase.UPPER_CASE, input, eol));
} }
assert.strictEqual(testCase.output.kebabCase, toKebabCase(input, eol));
assert.strictEqual(testCase.output.camelkebabCase, toCamelKebabCase(input, eol));
assert.strictEqual(testCase.output.kebabUpperCase, toKebabUpperCase(input, eol));
} }
} }
}); });

View File

@ -1,4 +1,4 @@
import { TestCaseGroup } from "../type-definition/test-case-type"; import { TestCaseGroup } from "../type-definition/TestCaseType";
const LF = '\n'; const LF = '\n';
const CRLF = '\r\n'; const CRLF = '\r\n';
@ -19,11 +19,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: '', camelCase: '',
pascalCase: '', pascalCase: '',
upperCase: '', snakeCase: '',
lowerCase: '', snakeCamelCase: '',
snakePascalCase: '',
snakeUpperCase: '',
kebabCase: '', kebabCase: '',
camelkebabCase: '', kebabCamelCase: '',
kebabPascalCase: '',
kebabUpperCase: '', kebabUpperCase: '',
lowerCase: '',
upperCase: '',
}, },
}, },
{ {
@ -36,11 +41,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' ', camelCase: ' ',
pascalCase: ' ', pascalCase: ' ',
upperCase: ' ', snakeCase: ' ',
lowerCase: ' ', snakeCamelCase: ' ',
snakePascalCase: ' ',
snakeUpperCase: ' ',
kebabCase: ' ', kebabCase: ' ',
camelkebabCase: ' ', kebabCamelCase: ' ',
kebabPascalCase: ' ',
kebabUpperCase: ' ', kebabUpperCase: ' ',
lowerCase: ' ',
upperCase: ' ',
}, },
}, },
{ {
@ -54,11 +64,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' \r\n ', camelCase: ' \r\n ',
pascalCase: ' \r\n ', pascalCase: ' \r\n ',
upperCase: ' \r\n ', snakeCase: ' \r\n ',
lowerCase: ' \r\n ', snakeCamelCase: ' \r\n ',
snakePascalCase: ' \r\n ',
snakeUpperCase: ' \r\n ',
kebabCase: ' \r\n ', kebabCase: ' \r\n ',
camelkebabCase: ' \r\n ', kebabCamelCase: ' \r\n ',
kebabPascalCase: ' \r\n ',
kebabUpperCase: ' \r\n ', kebabUpperCase: ' \r\n ',
lowerCase: ' \r\n ',
upperCase: ' \r\n ',
}, },
}, },
{ {
@ -72,11 +87,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' x \r\ny ', camelCase: ' x \r\ny ',
pascalCase: ' X \r\nY ', pascalCase: ' X \r\nY ',
upperCase: ' X \r\nY ', snakeCase: ' x \r\ny ',
lowerCase: ' x \r\ny ', snakeCamelCase: ' x \r\ny ',
snakePascalCase: ' X \r\nY ',
snakeUpperCase: ' X \r\nY ',
kebabCase: ' x \r\ny ', kebabCase: ' x \r\ny ',
camelkebabCase: ' X \r\nY ', kebabCamelCase: ' x \r\ny ',
kebabPascalCase: ' X \r\nY ',
kebabUpperCase: ' X \r\nY ', kebabUpperCase: ' X \r\nY ',
lowerCase: ' x \r\ny ',
upperCase: ' X \r\nY ',
}, },
}, },
{ {
@ -90,11 +110,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' \n ', camelCase: ' \n ',
pascalCase: ' \n ', pascalCase: ' \n ',
upperCase: ' \n ', snakeCase: ' \n ',
lowerCase: ' \n ', snakeCamelCase: ' \n ',
snakePascalCase: ' \n ',
snakeUpperCase: ' \n ',
kebabCase: ' \n ', kebabCase: ' \n ',
camelkebabCase: ' \n ', kebabCamelCase: ' \n ',
kebabPascalCase: ' \n ',
kebabUpperCase: ' \n ', kebabUpperCase: ' \n ',
lowerCase: ' \n ',
upperCase: ' \n ',
}, },
}, },
{ {
@ -108,11 +133,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' a\nb ', camelCase: ' a\nb ',
pascalCase: ' A\nB ', pascalCase: ' A\nB ',
upperCase: ' A\nB ', snakeCase: ' a\nb ',
lowerCase: ' a\nb ', snakeCamelCase: ' a\nb ',
snakePascalCase: ' A\nB ',
snakeUpperCase: ' A\nB ',
kebabCase: ' a\nb ', kebabCase: ' a\nb ',
camelkebabCase: ' A\nB ', kebabCamelCase: ' a\nb ',
kebabPascalCase: ' A\nB ',
kebabUpperCase: ' A\nB ', kebabUpperCase: ' A\nB ',
lowerCase: ' a\nb ',
upperCase: ' A\nB ',
}, },
}, },
// 输入长文本 // 输入长文本
@ -132,21 +162,36 @@ const testGroups: Array<TestCaseGroup> = [
pascalCase: pascalCase:
"China'SFactoryActivityExpandedInMarchAfterFiveConsecutiveMonthsOfContraction,AnOfficialSurveyRevealedOnSunday,AddingToARunOfIndicatorsThatSuggestTheStabilizationOfTheWorld'SSecondLargestEconomy." "China'SFactoryActivityExpandedInMarchAfterFiveConsecutiveMonthsOfContraction,AnOfficialSurveyRevealedOnSunday,AddingToARunOfIndicatorsThatSuggestTheStabilizationOfTheWorld'SSecondLargestEconomy."
, ,
upperCase: snakeCase:
"CHINA'S FACTORY ACTIVITY EXPANDED IN MARCH AFTER FIVE CONSECUTIVE MONTHS OF CONTRACTION, AN OFFICIAL SURVEY REVEALED ON SUNDAY, ADDING TO A RUN OF INDICATORS THAT SUGGEST THE STABILIZATION OF THE WORLD'S SECOND-LARGEST ECONOMY." "china's_factory_activity_expanded_in_march_after_five_consecutive_months_of_contraction,an_official_survey_revealed_on_sunday,adding_to_a_run_of_indicators_that_suggest_the_stabilization_of_the_world's_second_largest_economy."
, ,
lowerCase: snakeCamelCase:
"china's factory activity expanded in march after five consecutive months of contraction, an official survey revealed on sunday, adding to a run of indicators that suggest the stabilization of the world's second-largest economy." "china'S_Factory_Activity_Expanded_In_March_After_Five_Consecutive_Months_Of_Contraction,An_Official_Survey_Revealed_On_Sunday,Adding_To_A_Run_Of_Indicators_That_Suggest_The_Stabilization_Of_The_World'S_Second_Largest_Economy."
,
snakePascalCase:
"China'S_Factory_Activity_Expanded_In_March_After_Five_Consecutive_Months_Of_Contraction,An_Official_Survey_Revealed_On_Sunday,Adding_To_A_Run_Of_Indicators_That_Suggest_The_Stabilization_Of_The_World'S_Second_Largest_Economy."
,
snakeUpperCase:
"CHINA'S_FACTORY_ACTIVITY_EXPANDED_IN_MARCH_AFTER_FIVE_CONSECUTIVE_MONTHS_OF_CONTRACTION,AN_OFFICIAL_SURVEY_REVEALED_ON_SUNDAY,ADDING_TO_A_RUN_OF_INDICATORS_THAT_SUGGEST_THE_STABILIZATION_OF_THE_WORLD'S_SECOND_LARGEST_ECONOMY."
, ,
kebabCase: kebabCase:
"china's-factory-activity-expanded-in-march-after-five-consecutive-months-of-contraction,an-official-survey-revealed-on-sunday,adding-to-a-run-of-indicators-that-suggest-the-stabilization-of-the-world's-second-largest-economy." "china's-factory-activity-expanded-in-march-after-five-consecutive-months-of-contraction,an-official-survey-revealed-on-sunday,adding-to-a-run-of-indicators-that-suggest-the-stabilization-of-the-world's-second-largest-economy."
, ,
camelkebabCase: kebabCamelCase:
"china'S-Factory-Activity-Expanded-In-March-After-Five-Consecutive-Months-Of-Contraction,An-Official-Survey-Revealed-On-Sunday,Adding-To-A-Run-Of-Indicators-That-Suggest-The-Stabilization-Of-The-World'S-Second-Largest-Economy."
,
kebabPascalCase:
"China'S-Factory-Activity-Expanded-In-March-After-Five-Consecutive-Months-Of-Contraction,An-Official-Survey-Revealed-On-Sunday,Adding-To-A-Run-Of-Indicators-That-Suggest-The-Stabilization-Of-The-World'S-Second-Largest-Economy." "China'S-Factory-Activity-Expanded-In-March-After-Five-Consecutive-Months-Of-Contraction,An-Official-Survey-Revealed-On-Sunday,Adding-To-A-Run-Of-Indicators-That-Suggest-The-Stabilization-Of-The-World'S-Second-Largest-Economy."
, ,
kebabUpperCase: kebabUpperCase:
"CHINA'S-FACTORY-ACTIVITY-EXPANDED-IN-MARCH-AFTER-FIVE-CONSECUTIVE-MONTHS-OF-CONTRACTION,AN-OFFICIAL-SURVEY-REVEALED-ON-SUNDAY,ADDING-TO-A-RUN-OF-INDICATORS-THAT-SUGGEST-THE-STABILIZATION-OF-THE-WORLD'S-SECOND-LARGEST-ECONOMY." "CHINA'S-FACTORY-ACTIVITY-EXPANDED-IN-MARCH-AFTER-FIVE-CONSECUTIVE-MONTHS-OF-CONTRACTION,AN-OFFICIAL-SURVEY-REVEALED-ON-SUNDAY,ADDING-TO-A-RUN-OF-INDICATORS-THAT-SUGGEST-THE-STABILIZATION-OF-THE-WORLD'S-SECOND-LARGEST-ECONOMY."
, ,
lowerCase:
"china's factory activity expanded in march after five consecutive months of contraction, an official survey revealed on sunday, adding to a run of indicators that suggest the stabilization of the world's second-largest economy."
,
upperCase:
"CHINA'S FACTORY ACTIVITY EXPANDED IN MARCH AFTER FIVE CONSECUTIVE MONTHS OF CONTRACTION, AN OFFICIAL SURVEY REVEALED ON SUNDAY, ADDING TO A RUN OF INDICATORS THAT SUGGEST THE STABILIZATION OF THE WORLD'S SECOND-LARGEST ECONOMY."
,
}, },
}, },
// 输入包含数字 // 输入包含数字
@ -160,11 +205,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'entity2Map', camelCase: 'entity2Map',
pascalCase: 'Entity2Map', pascalCase: 'Entity2Map',
upperCase: 'ENTITY2MAP', snakeCase: 'entity2map',
lowerCase: 'entity2map', snakeCamelCase: 'entity2Map',
snakePascalCase: 'Entity2Map',
snakeUpperCase: 'ENTITY2MAP',
kebabCase: 'entity2map', kebabCase: 'entity2map',
camelkebabCase: 'Entity2Map', kebabCamelCase: 'entity2Map',
kebabPascalCase: 'Entity2Map',
kebabUpperCase: 'ENTITY2MAP', kebabUpperCase: 'ENTITY2MAP',
lowerCase: 'entity2map',
upperCase: 'ENTITY2MAP',
}, },
}, },
// 输入包含换行 // 输入包含换行
@ -181,11 +231,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'howDoYou\bDo?\n howDoYou\tDo!', camelCase: 'howDoYou\bDo?\n howDoYou\tDo!',
pascalCase: 'HowDoYou\bDo?\n HowDoYou\tDo!', pascalCase: 'HowDoYou\bDo?\n HowDoYou\tDo!',
upperCase: 'HOW DO YOU\bDO?\n HOW DO YOU\tDO!', snakeCase: 'how_do_you\bdo?\n how_do_you\tdo!',
lowerCase: 'how do you\bdo?\n how do you\tdo!', snakeCamelCase: 'how_Do_You\bDo?\n how_Do_You\tDo!',
snakePascalCase: 'How_Do_You\bDo?\n How_Do_You\tDo!',
snakeUpperCase: 'HOW_DO_YOU\bDO?\n HOW_DO_YOU\tDO!',
kebabCase: 'how-do-you\bdo?\n how-do-you\tdo!', kebabCase: 'how-do-you\bdo?\n how-do-you\tdo!',
camelkebabCase: 'How-Do-You\bDo?\n How-Do-You\tDo!', kebabCamelCase: 'how-Do-You\bDo?\n how-Do-You\tDo!',
kebabPascalCase: 'How-Do-You\bDo?\n How-Do-You\tDo!',
kebabUpperCase: 'HOW-DO-YOU\bDO?\n HOW-DO-YOU\tDO!', kebabUpperCase: 'HOW-DO-YOU\bDO?\n HOW-DO-YOU\tDO!',
lowerCase: 'how do you\bdo?\n how do you\tdo!',
upperCase: 'HOW DO YOU\bDO?\n HOW DO YOU\tDO!',
}, },
}, },
// 非英文字符,特殊字符 // 非英文字符,特殊字符
@ -201,11 +256,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: '今天是星期日', camelCase: '今天是星期日',
pascalCase: '今天是星期日', pascalCase: '今天是星期日',
upperCase: '今天是星期日', snakeCase: '今天是星期日',
lowerCase: '今天是星期日', snakeCamelCase: '今天是星期日',
snakePascalCase: '今天是星期日',
snakeUpperCase: '今天是星期日',
kebabCase: '今天是星期日', kebabCase: '今天是星期日',
camelkebabCase: '今天是星期日', kebabCamelCase: '今天是星期日',
kebabPascalCase: '今天是星期日',
kebabUpperCase: '今天是星期日', kebabUpperCase: '今天是星期日',
lowerCase: '今天是星期日',
upperCase: '今天是星期日',
}, },
}, },
{ {
@ -220,11 +280,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: '担心你dAf=Coffee—爸妈不在家— ', camelCase: '担心你dAf=Coffee—爸妈不在家— ',
pascalCase: '担心你DAf=Coffee—爸妈不在家— ', pascalCase: '担心你DAf=Coffee—爸妈不在家— ',
upperCase: '--担心你DAF_=COFFEE—爸妈不在家_— ', snakeCase: '担心你d_af=coffee—爸妈不在家— ',
lowerCase: '--担心你daf_=coffee—爸妈不在家_— ', snakeCamelCase: '担心你d_Af=Coffee—爸妈不在家— ',
snakePascalCase: '担心你D_Af=Coffee—爸妈不在家— ',
snakeUpperCase: '担心你D_AF=COFFEE—爸妈不在家— ',
kebabCase: '担心你d-af=coffee—爸妈不在家— ', kebabCase: '担心你d-af=coffee—爸妈不在家— ',
camelkebabCase: '担心你D-Af=Coffee—爸妈不在家— ', kebabCamelCase: '担心你d-Af=Coffee—爸妈不在家— ',
kebabPascalCase: '担心你D-Af=Coffee—爸妈不在家— ',
kebabUpperCase: '担心你D-AF=COFFEE—爸妈不在家— ', kebabUpperCase: '担心你D-AF=COFFEE—爸妈不在家— ',
lowerCase: '--担心你daf_=coffee—爸妈不在家_— ',
upperCase: '--担心你DAF_=COFFEE—爸妈不在家_— ',
}, },
}, },
{ {
@ -239,11 +304,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: '🥰aCup/OfCoffee🍻,Please!. ', camelCase: '🥰aCup/OfCoffee🍻,Please!. ',
pascalCase: '🥰ACup/OfCoffee🍻,Please!. ', pascalCase: '🥰ACup/OfCoffee🍻,Please!. ',
upperCase: '🥰 A-CUP/_OF COFFEE🍻,-_PLEASE!. ', snakeCase: '🥰a_cup/of_coffee🍻,please!. ',
lowerCase: '🥰 a-cup/_of coffee🍻,-_please!. ', snakeCamelCase: '🥰a_Cup/Of_Coffee🍻,Please!. ',
snakePascalCase: '🥰A_Cup/Of_Coffee🍻,Please!. ',
snakeUpperCase: '🥰A_CUP/OF_COFFEE🍻,PLEASE!. ',
kebabCase: '🥰a-cup/of-coffee🍻,please!. ', kebabCase: '🥰a-cup/of-coffee🍻,please!. ',
camelkebabCase: '🥰A-Cup/Of-Coffee🍻,Please!. ', kebabCamelCase: '🥰a-Cup/Of-Coffee🍻,Please!. ',
kebabPascalCase: '🥰A-Cup/Of-Coffee🍻,Please!. ',
kebabUpperCase: '🥰A-CUP/OF-COFFEE🍻,PLEASE!. ', kebabUpperCase: '🥰A-CUP/OF-COFFEE🍻,PLEASE!. ',
lowerCase: '🥰 a-cup/_of coffee🍻,-_please!. ',
upperCase: '🥰 A-CUP/_OF COFFEE🍻,-_PLEASE!. ',
}, },
}, },
{ {
@ -258,11 +328,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'takeARest😊HaPPy,😢TriSte,Enfadado,驚きました,❤️,笑,😎COol,😳Embarrassed', camelCase: 'takeARest😊HaPPy,😢TriSte,Enfadado,驚きました,❤️,笑,😎COol,😳Embarrassed',
pascalCase: 'TakeARest😊HaPPy,😢TriSte,Enfadado,驚きました,❤️,笑,😎COol,😳Embarrassed', pascalCase: 'TakeARest😊HaPPy,😢TriSte,Enfadado,驚きました,❤️,笑,😎COol,😳Embarrassed',
upperCase: 'TAKEAREST😊HAPPY,😢TRISTE,ENFADADO, 驚きました,❤️, 笑, 😎COOL, 😳-EMBARRASSED', snakeCase: 'take_a_rest😊ha_p_py,😢tri_ste,enfadado,驚きました,❤️,笑,😎c_ool,😳embarrassed',
lowerCase: 'takearest😊happy,😢triste,enfadado, 驚きました,❤️, 笑, 😎cool, 😳-embarrassed', snakeCamelCase: 'take_A_Rest😊Ha_P_Py,😢Tri_Ste,Enfadado,驚きました,❤️,笑,😎C_Ool,😳Embarrassed',
snakePascalCase: 'Take_A_Rest😊Ha_P_Py,😢Tri_Ste,Enfadado,驚きました,❤️,笑,😎C_Ool,😳Embarrassed',
snakeUpperCase: 'TAKE_A_REST😊HA_P_PY,😢TRI_STE,ENFADADO,驚きました,❤️,笑,😎C_OOL,😳EMBARRASSED',
kebabCase: 'take-a-rest😊ha-p-py,😢tri-ste,enfadado,驚きました,❤️,笑,😎c-ool,😳embarrassed', kebabCase: 'take-a-rest😊ha-p-py,😢tri-ste,enfadado,驚きました,❤️,笑,😎c-ool,😳embarrassed',
camelkebabCase: 'Take-A-Rest😊Ha-P-Py,😢Tri-Ste,Enfadado,驚きました,❤️,笑,😎C-Ool,😳Embarrassed', kebabCamelCase: 'take-A-Rest😊Ha-P-Py,😢Tri-Ste,Enfadado,驚きました,❤️,笑,😎C-Ool,😳Embarrassed',
kebabPascalCase: 'Take-A-Rest😊Ha-P-Py,😢Tri-Ste,Enfadado,驚きました,❤️,笑,😎C-Ool,😳Embarrassed',
kebabUpperCase: 'TAKE-A-REST😊HA-P-PY,😢TRI-STE,ENFADADO,驚きました,❤️,笑,😎C-OOL,😳EMBARRASSED', kebabUpperCase: 'TAKE-A-REST😊HA-P-PY,😢TRI-STE,ENFADADO,驚きました,❤️,笑,😎C-OOL,😳EMBARRASSED',
lowerCase: 'takearest😊happy,😢triste,enfadado, 驚きました,❤️, 笑, 😎cool, 😳-embarrassed',
upperCase: 'TAKEAREST😊HAPPY,😢TRISTE,ENFADADO, 驚きました,❤️, 笑, 😎COOL, 😳-EMBARRASSED',
}, },
}, },
{ {
@ -277,34 +352,20 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' nHDAs+90Usz&* ', camelCase: ' nHDAs+90Usz&* ',
pascalCase: ' NHDAs+90Usz&* ', pascalCase: ' NHDAs+90Usz&* ',
upperCase: ' NHDAS--+90-USZ&* ', snakeCase: ' n_h_d_as+90usz&* ',
lowerCase: ' nhdas--+90-usz&* ', snakeCamelCase: ' n_H_D_As+90Usz&* ',
snakePascalCase: ' N_H_D_As+90Usz&* ',
snakeUpperCase: ' N_H_D_AS+90USZ&* ',
kebabCase: ' n-h-d-as+90usz&* ', kebabCase: ' n-h-d-as+90usz&* ',
camelkebabCase: ' N-H-D-As+90Usz&* ', kebabCamelCase: ' n-H-D-As+90Usz&* ',
kebabPascalCase: ' N-H-D-As+90Usz&* ',
kebabUpperCase: ' N-H-D-AS+90USZ&* ', kebabUpperCase: ' N-H-D-AS+90USZ&* ',
lowerCase: ' nhdas--+90-usz&* ',
upperCase: ' NHDAS--+90-USZ&* ',
}, },
}, },
{ {
title: 'Mixed input 1', title: 'Mixed input 1',
input:
'--担心你鸿dAf_=coffee—_— '
,
eol: [LF, CRLF],
transformText: [
'担心你鸿|d|af|=|coffee|—|— ',
],
output: {
camelCase: '担心你鸿dAf=Coffee—— ',
pascalCase: '担心你鸿DAf=Coffee—— ',
upperCase: '--担心你鸿DAF_=COFFEE—_— ',
lowerCase: '--担心你鸿daf_=coffee—_— ',
kebabCase: '担心你鸿d-af=coffee—— ',
camelkebabCase: '担心你鸿D-Af=Coffee—— ',
kebabUpperCase: '担心你鸿D-AF=COFFEE—— ',
},
},
{
title: 'Mixed input 2',
input: input:
'fsdi_sdacsaf+desd' 'fsdi_sdacsaf+desd'
, ,
@ -315,11 +376,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'fsdiSdacsaf+Desd', camelCase: 'fsdiSdacsaf+Desd',
pascalCase: 'FsdiSdacsaf+Desd', pascalCase: 'FsdiSdacsaf+Desd',
upperCase: 'FSDI_SDACSAF+DESD', snakeCase: 'fsdi_sdacsaf+desd',
lowerCase: 'fsdi_sdacsaf+desd', snakeCamelCase: 'fsdi_Sdacsaf+Desd',
snakePascalCase: 'Fsdi_Sdacsaf+Desd',
snakeUpperCase: 'FSDI_SDACSAF+DESD',
kebabCase: 'fsdi-sdacsaf+desd', kebabCase: 'fsdi-sdacsaf+desd',
camelkebabCase: 'Fsdi-Sdacsaf+Desd', kebabCamelCase: 'fsdi-Sdacsaf+Desd',
kebabPascalCase: 'Fsdi-Sdacsaf+Desd',
kebabUpperCase: 'FSDI-SDACSAF+DESD', kebabUpperCase: 'FSDI-SDACSAF+DESD',
lowerCase: 'fsdi_sdacsaf+desd',
upperCase: 'FSDI_SDACSAF+DESD',
}, },
}, },
// add more cases... // add more cases...
@ -344,11 +410,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'fooBar', camelCase: 'fooBar',
pascalCase: 'FooBar', pascalCase: 'FooBar',
// upperCase: 'FOO--BAR', snakeCase: 'foo_bar',
// lowerCase: 'foo--bar', snakeCamelCase: 'foo_Bar',
snakePascalCase: 'Foo_Bar',
snakeUpperCase: 'FOO_BAR',
kebabCase: 'foo-bar', kebabCase: 'foo-bar',
camelkebabCase: 'Foo-Bar', kebabCamelCase: 'foo-Bar',
kebabPascalCase: 'Foo-Bar',
kebabUpperCase: 'FOO-BAR', kebabUpperCase: 'FOO-BAR',
// lowerCase: 'foo--bar',
// upperCase: 'FOO--BAR',
}, },
}, },
{ {
@ -368,11 +439,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'testCase', camelCase: 'testCase',
pascalCase: 'TestCase', pascalCase: 'TestCase',
// upperCase: 'TEST CASE', snakeCase: 'test_case',
// lowerCase: 'test case', snakeCamelCase: 'test_Case',
snakePascalCase: 'Test_Case',
snakeUpperCase: 'TEST_CASE',
kebabCase: 'test-case', kebabCase: 'test-case',
camelkebabCase: 'Test-Case', kebabCamelCase: 'test-Case',
kebabPascalCase: 'Test-Case',
kebabUpperCase: 'TEST-CASE', kebabUpperCase: 'TEST-CASE',
// lowerCase: 'test case',
// upperCase: 'TEST CASE',
}, },
}, },
{ {
@ -389,11 +465,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'apple', camelCase: 'apple',
pascalCase: 'Apple', pascalCase: 'Apple',
upperCase: 'APPLE', snakeCase: 'apple',
lowerCase: 'apple', snakeCamelCase: 'apple',
snakePascalCase: 'Apple',
snakeUpperCase: 'APPLE',
kebabCase: 'apple', kebabCase: 'apple',
camelkebabCase: 'Apple', kebabCamelCase: 'apple',
kebabPascalCase: 'Apple',
kebabUpperCase: 'APPLE', kebabUpperCase: 'APPLE',
lowerCase: 'apple',
upperCase: 'APPLE',
}, },
}, },
{ {
@ -408,11 +489,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'pineApple', camelCase: 'pineApple',
pascalCase: 'PineApple', pascalCase: 'PineApple',
upperCase: 'PINEAPPLE', snakeCase: 'pine_apple',
lowerCase: 'pineapple', snakeCamelCase: 'pine_Apple',
snakePascalCase: 'Pine_Apple',
snakeUpperCase: 'PINE_APPLE',
kebabCase: 'pine-apple', kebabCase: 'pine-apple',
camelkebabCase: 'Pine-Apple', kebabCamelCase: 'pine-Apple',
kebabPascalCase: 'Pine-Apple',
kebabUpperCase: 'PINE-APPLE', kebabUpperCase: 'PINE-APPLE',
lowerCase: 'pineapple',
upperCase: 'PINEAPPLE',
}, },
}, },
{ {
@ -436,11 +522,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'haveANiceDay!', camelCase: 'haveANiceDay!',
pascalCase: 'HaveANiceDay!', pascalCase: 'HaveANiceDay!',
// upperCase: 'HAVE A NICE DAY!', snakeCase: 'have_a_nice_day!',
// lowerCase: 'have a nice day!', snakeCamelCase: 'have_A_Nice_Day!',
snakePascalCase: 'Have_A_Nice_Day!',
snakeUpperCase: 'HAVE_A_NICE_DAY!',
kebabCase: 'have-a-nice-day!', kebabCase: 'have-a-nice-day!',
camelkebabCase: 'Have-A-Nice-Day!', kebabCamelCase: 'have-A-Nice-Day!',
kebabPascalCase: 'Have-A-Nice-Day!',
kebabUpperCase: 'HAVE-A-NICE-DAY!', kebabUpperCase: 'HAVE-A-NICE-DAY!',
// lowerCase: 'have a nice day!',
// upperCase: 'HAVE A NICE DAY!',
}, },
}, },
{ {
@ -462,11 +553,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' aNiceDay! ', camelCase: ' aNiceDay! ',
pascalCase: ' ANiceDay! ', pascalCase: ' ANiceDay! ',
// upperCase: ' A NICE DAY! ', snakeCase: ' a_nice_day! ',
// lowerCase: ' a nice day! ', snakeCamelCase: ' a_Nice_Day! ',
snakePascalCase: ' A_Nice_Day! ',
snakeUpperCase: ' A_NICE_DAY! ',
kebabCase: ' a-nice-day! ', kebabCase: ' a-nice-day! ',
camelkebabCase: ' A-Nice-Day! ', kebabCamelCase: ' a-Nice-Day! ',
kebabPascalCase: ' A-Nice-Day! ',
kebabUpperCase: ' A-NICE-DAY! ', kebabUpperCase: ' A-NICE-DAY! ',
// lowerCase: ' a nice day! ',
// upperCase: ' A NICE DAY! ',
}, },
}, },
{ {
@ -482,11 +578,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' aNiceDay', camelCase: ' aNiceDay',
pascalCase: ' ANiceDay', pascalCase: ' ANiceDay',
// upperCase: ' A NICE-DAY-', snakeCase: ' a_nice_day',
// lowerCase: ' a nice-day-', snakeCamelCase: ' a_Nice_Day',
snakePascalCase: ' A_Nice_Day',
snakeUpperCase: ' A_NICE_DAY',
kebabCase: ' a-nice-day', kebabCase: ' a-nice-day',
camelkebabCase: ' A-Nice-Day', kebabCamelCase: ' a-Nice-Day',
kebabPascalCase: ' A-Nice-Day',
kebabUpperCase: ' A-NICE-DAY', kebabUpperCase: ' A-NICE-DAY',
// lowerCase: ' a nice-day-',
// upperCase: ' A NICE-DAY-',
}, },
}, },
{ {
@ -501,18 +602,23 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: 'tomLikesEatIceCream.', camelCase: 'tomLikesEatIceCream.',
pascalCase: 'TomLikesEatIceCream.', pascalCase: 'TomLikesEatIceCream.',
upperCase: 'TOMLIKES EAT ICECREAM.', snakeCase: 'tom_likes_eat_ice_cream.',
lowerCase: 'tomlikes eat icecream.', snakeCamelCase: 'tom_Likes_Eat_Ice_Cream.',
snakePascalCase: 'Tom_Likes_Eat_Ice_Cream.',
snakeUpperCase: 'TOM_LIKES_EAT_ICE_CREAM.',
kebabCase: 'tom-likes-eat-ice-cream.', kebabCase: 'tom-likes-eat-ice-cream.',
camelkebabCase: 'Tom-Likes-Eat-Ice-Cream.', kebabCamelCase: 'tom-Likes-Eat-Ice-Cream.',
kebabPascalCase: 'Tom-Likes-Eat-Ice-Cream.',
kebabUpperCase: 'TOM-LIKES-EAT-ICE-CREAM.', kebabUpperCase: 'TOM-LIKES-EAT-ICE-CREAM.',
lowerCase: 'tomlikes eat icecream.',
upperCase: 'TOMLIKES EAT ICECREAM.',
}, },
}, },
{ {
title: 'Normal input (apple-2-Tree)', title: 'Normal input (apple-2-Tree)',
input: [ input: [
' apple2-Tree ', ' apple2-Tree ',
// ' apple2Tree ', ' apple2Tree ',
], ],
eol: [LF, CRLF], eol: [LF, CRLF],
transformText: [ transformText: [
@ -521,11 +627,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' apple2Tree ', camelCase: ' apple2Tree ',
pascalCase: ' Apple2Tree ', pascalCase: ' Apple2Tree ',
upperCase: ' APPLE2-TREE ', snakeCase: ' apple2tree ',
lowerCase: ' apple2-tree ', snakeCamelCase: ' apple2Tree ',
snakePascalCase: ' Apple2Tree ',
snakeUpperCase: ' APPLE2TREE ',
kebabCase: ' apple2tree ', kebabCase: ' apple2tree ',
camelkebabCase: ' Apple2Tree ', kebabCamelCase: ' apple2Tree ',
kebabPascalCase: ' Apple2Tree ',
kebabUpperCase: ' APPLE2TREE ', kebabUpperCase: ' APPLE2TREE ',
// lowerCase: ' apple2-tree ',
// upperCase: ' APPLE2-TREE ',
}, },
}, },
{ {
@ -540,11 +651,16 @@ const testGroups: Array<TestCaseGroup> = [
output: { output: {
camelCase: ' juliusCaesar,WilliamShakespeare,AlbertEinstein,MarieCurie,WolfgangAmadeusMozart,VincentVanGogh. ', camelCase: ' juliusCaesar,WilliamShakespeare,AlbertEinstein,MarieCurie,WolfgangAmadeusMozart,VincentVanGogh. ',
pascalCase: ' JuliusCaesar,WilliamShakespeare,AlbertEinstein,MarieCurie,WolfgangAmadeusMozart,VincentVanGogh. ', pascalCase: ' JuliusCaesar,WilliamShakespeare,AlbertEinstein,MarieCurie,WolfgangAmadeusMozart,VincentVanGogh. ',
upperCase: ' JULIUS_CAESAR, WILLIAM_SHAKESPEARE, ALBERT_EINSTEIN, MARIE_CURIE, WOLFGANGAMADEUSMOZART, VINCENT-VAN-GOGH. ', snakeCase: ' julius_caesar,william_shakespeare,albert_einstein,marie_curie,wolfgang_amadeus_mozart,vincent_van_gogh. ',
lowerCase: ' julius_caesar, william_shakespeare, albert_einstein, marie_curie, wolfgangamadeusmozart, vincent-van-gogh. ', snakeCamelCase: ' julius_Caesar,William_Shakespeare,Albert_Einstein,Marie_Curie,Wolfgang_Amadeus_Mozart,Vincent_Van_Gogh. ',
snakePascalCase: ' Julius_Caesar,William_Shakespeare,Albert_Einstein,Marie_Curie,Wolfgang_Amadeus_Mozart,Vincent_Van_Gogh. ',
snakeUpperCase: ' JULIUS_CAESAR,WILLIAM_SHAKESPEARE,ALBERT_EINSTEIN,MARIE_CURIE,WOLFGANG_AMADEUS_MOZART,VINCENT_VAN_GOGH. ',
kebabCase: ' julius-caesar,william-shakespeare,albert-einstein,marie-curie,wolfgang-amadeus-mozart,vincent-van-gogh. ', kebabCase: ' julius-caesar,william-shakespeare,albert-einstein,marie-curie,wolfgang-amadeus-mozart,vincent-van-gogh. ',
camelkebabCase: ' Julius-Caesar,William-Shakespeare,Albert-Einstein,Marie-Curie,Wolfgang-Amadeus-Mozart,Vincent-Van-Gogh. ', kebabCamelCase: ' julius-Caesar,William-Shakespeare,Albert-Einstein,Marie-Curie,Wolfgang-Amadeus-Mozart,Vincent-Van-Gogh. ',
kebabPascalCase: ' Julius-Caesar,William-Shakespeare,Albert-Einstein,Marie-Curie,Wolfgang-Amadeus-Mozart,Vincent-Van-Gogh. ',
kebabUpperCase: ' JULIUS-CAESAR,WILLIAM-SHAKESPEARE,ALBERT-EINSTEIN,MARIE-CURIE,WOLFGANG-AMADEUS-MOZART,VINCENT-VAN-GOGH. ', kebabUpperCase: ' JULIUS-CAESAR,WILLIAM-SHAKESPEARE,ALBERT-EINSTEIN,MARIE-CURIE,WOLFGANG-AMADEUS-MOZART,VINCENT-VAN-GOGH. ',
lowerCase: ' julius_caesar, william_shakespeare, albert_einstein, marie_curie, wolfgangamadeusmozart, vincent-van-gogh. ',
upperCase: ' JULIUS_CAESAR, WILLIAM_SHAKESPEARE, ALBERT_EINSTEIN, MARIE_CURIE, WOLFGANGAMADEUSMOZART, VINCENT-VAN-GOGH. ',
}, },
}, },
{ {
@ -567,19 +683,31 @@ const testGroups: Array<TestCaseGroup> = [
' &Quot;You&Quot;(Or&Quot;Your&Quot;)ShallMeanAnIndividualOrLegalEntity\n' + ' &Quot;You&Quot;(Or&Quot;Your&Quot;)ShallMeanAnIndividualOrLegalEntity\n' +
' ExercisingPermissionsGrantedByThisLicense.' ' ExercisingPermissionsGrantedByThisLicense.'
, ,
upperCase: snakeCase:
' &QUOT;YOU&QUOT; (OR &QUOT;YOUR&QUOT;) SHALL MEAN AN INDIVIDUAL OR LEGAL ENTITY\n' + ' &quot;you&quot;(or&quot;your&quot;)shall_mean_an_individual_or_legal_entity\n' +
' EXERCISING PERMISSIONS GRANTED BY THIS LICENSE.' ' exercising_permissions_granted_by_this_license.'
, ,
lowerCase: snakeCamelCase:
' &quot;you&quot; (or &quot;your&quot;) shall mean an individual or legal entity\n' + ' &quot;You&Quot;(Or&Quot;Your&Quot;)Shall_Mean_An_Individual_Or_Legal_Entity\n' +
' exercising permissions granted by this license.' ' exercising_Permissions_Granted_By_This_License.'
,
snakePascalCase:
' &Quot;You&Quot;(Or&Quot;Your&Quot;)Shall_Mean_An_Individual_Or_Legal_Entity\n' +
' Exercising_Permissions_Granted_By_This_License.'
,
snakeUpperCase:
' &QUOT;YOU&QUOT;(OR&QUOT;YOUR&QUOT;)SHALL_MEAN_AN_INDIVIDUAL_OR_LEGAL_ENTITY\n' +
' EXERCISING_PERMISSIONS_GRANTED_BY_THIS_LICENSE.'
, ,
kebabCase: kebabCase:
' &quot;you&quot;(or&quot;your&quot;)shall-mean-an-individual-or-legal-entity\n' + ' &quot;you&quot;(or&quot;your&quot;)shall-mean-an-individual-or-legal-entity\n' +
' exercising-permissions-granted-by-this-license.' ' exercising-permissions-granted-by-this-license.'
, ,
camelkebabCase: kebabCamelCase:
' &quot;You&Quot;(Or&Quot;Your&Quot;)Shall-Mean-An-Individual-Or-Legal-Entity\n' +
' exercising-Permissions-Granted-By-This-License.'
,
kebabPascalCase:
' &Quot;You&Quot;(Or&Quot;Your&Quot;)Shall-Mean-An-Individual-Or-Legal-Entity\n' + ' &Quot;You&Quot;(Or&Quot;Your&Quot;)Shall-Mean-An-Individual-Or-Legal-Entity\n' +
' Exercising-Permissions-Granted-By-This-License.' ' Exercising-Permissions-Granted-By-This-License.'
, ,
@ -587,6 +715,14 @@ const testGroups: Array<TestCaseGroup> = [
' &QUOT;YOU&QUOT;(OR&QUOT;YOUR&QUOT;)SHALL-MEAN-AN-INDIVIDUAL-OR-LEGAL-ENTITY\n' + ' &QUOT;YOU&QUOT;(OR&QUOT;YOUR&QUOT;)SHALL-MEAN-AN-INDIVIDUAL-OR-LEGAL-ENTITY\n' +
' EXERCISING-PERMISSIONS-GRANTED-BY-THIS-LICENSE.' ' EXERCISING-PERMISSIONS-GRANTED-BY-THIS-LICENSE.'
, ,
lowerCase:
' &quot;you&quot; (or &quot;your&quot;) shall mean an individual or legal entity\n' +
' exercising permissions granted by this license.'
,
upperCase:
' &QUOT;YOU&QUOT; (OR &QUOT;YOUR&QUOT;) SHALL MEAN AN INDIVIDUAL OR LEGAL ENTITY\n' +
' EXERCISING PERMISSIONS GRANTED BY THIS LICENSE.'
,
}, },
}, },
// add more cases... // add more cases...
@ -616,11 +752,16 @@ const testGroups: Array<TestCaseGroup> = [
// output: { // output: {
// camelCase: '', // camelCase: '',
// pascalCase: '', // pascalCase: '',
// upperCase: '', // snakeCase: '',
// lowerCase: '', // snakeCamelCase: '',
// snakePascalCase: '',
// snakeUpperCase: '',
// kebabCase: '', // kebabCase: '',
// camelkebabCase: '', // kebabCamelCase: '',
// kebabPascalCase: '',
// kebabUpperCase: '', // kebabUpperCase: '',
// lowerCase: '',
// upperCase: '',
// }, // },
// }, // },
// add more cases... // add more cases...

View File

@ -0,0 +1 @@
export type EOL = '\n' | '\r\n';

View File

@ -4,6 +4,7 @@
* Code: * Code:
* - Add `commands`, `menus` parts in package.json (and package-comment.jsonc) * - Add `commands`, `menus` parts in package.json (and package-comment.jsonc)
* - Add main conversion logic in src/main-code/variable-conversion.ts * - Add main conversion logic in src/main-code/variable-conversion.ts
* - Add disposable in src/extension.ts
* *
* Test: * Test:
* - Add test case type definition in src/type-definition/test-case-type.ts * - Add test case type definition in src/type-definition/test-case-type.ts
@ -16,8 +17,9 @@
* - Add changes in CHANGELOG.md * - Add changes in CHANGELOG.md
*/ */
export enum SupportCase { export enum SupportCase {
/** /**
* / * ()
* Camel Case * Camel Case
* e.g. fooBar * e.g. fooBar
* *
@ -27,7 +29,7 @@ export enum SupportCase {
CAMEL_CASE, CAMEL_CASE,
/** /**
* / * ()
* Pascal Case * Pascal Case
* e.g. FooBar * e.g. FooBar
* *
@ -37,7 +39,47 @@ export enum SupportCase {
PASCAL_CASE, PASCAL_CASE,
/** /**
* / * 线()
* Snake Case
* e.g. foo_bar
*
* @alias: snakeCase / SnakeCase / snake case / snake_case / SNAKE_CASE
* @since 2024-04-02
*/
SNAKE_CASE,
/**
* 线() + ()
* Snake Camel Case
* e.g. foo_Bar
*
* @alias: snakeCamelCase / SnakeCamelCase / snake camel case / snake_camel_case / SNAKE_CAMEL_CASE
* @since 2024-04-02
*/
SNAKE_CAMEL_CASE,
/**
* 线() + ()
* Snake Pascal Case
* e.g. Foo_Bar
*
* @alias: snakePascalCase / SnakePascalCase / snake pascal case / snake_pascal_case / SNAKE_PASCAL_CASE
* @since 2024-04-02
*/
SNAKE_PASCAL_CASE,
/**
* 线() +
* Snake Upper Case
* e.g. FOO_BAR
*
* @alias: snakeUpperCase / SnakeUpperCase / snake upper case / snake_upper_case / SNAKE_UPPER_CASE
* @since 2024-04-02
*/
SNAKE_UPPER_CASE,
/**
* ()
* Kebab Case / Spinal Case * Kebab Case / Spinal Case
* e.g. foo-bar * e.g. foo-bar
* *
@ -48,17 +90,27 @@ export enum SupportCase {
KEBAB_CASE, KEBAB_CASE,
/** /**
* * () + ()
* Camel Kebab Case * Kebab Camel Case
* e.g. Foo-Bar * e.g. foo-Bar
* *
* @alias: camelkebabCase / CamelKebabCase / camel kebab case / camel_kebab_case / CAMEL_UPPER_CASE * @alias: kebabCamelCase / KebabCamelCase / kebab camel case / kebab_camel_case / KEBAB_CAMEL_CASE
* @since 2024-04-03 * @since 2024-04-03
*/ */
CAMEL_UPPER_CASE, KEBAB_CAMEL_CASE,
/** /**
* * () + ()
* Kebab Pascal Case
* e.g. Foo-Bar
*
* @alias: kebabPascalCase / KebabPascalCase / kebab pascal case / kebab_pascal_case / KEBAB_PASCAL_CASE
* @since 2024-04-03
*/
KEBAB_PASCAL_CASE,
/**
* () +
* Kebab Upper Case * Kebab Upper Case
* e.g. FOO-BAR * e.g. FOO-BAR
* *
@ -67,46 +119,6 @@ export enum SupportCase {
*/ */
KEBAB_UPPER_CASE, KEBAB_UPPER_CASE,
/**
* 线 /
* Snake Case
* e.g. foo_bar
*
* @alias: snakeCase / SnakeCase / snake case / snake_case / SNAKE_CASE
* @since 2024-04-02
*/
SNAKE_CASE,
/**
*
* Camel Snake Case
* e.g. Foo_Bar
*
* @alias: camelSnakeCase / CamelSnakeCase / camel snake case / camel_snake_case / CAMEL_SNAKE_CASE
* @since 2024-04-02
*/
CAMEL_SNAKE_CASE,
/**
* 线
* Snake Upper Case
* e.g. FOO_BAR
*
* @alias: snakeUpperCase / SnakeUpperCase / snake upper case / snake_upper_case / SNAKE_UPPER_CASE
* @since 2024-04-02
*/
SNAKE_UPPER_CASE,
/**
*
* Upper Case
* e.g. FOO_BAR / FOOBAR
*
* @alias: upperCase / UpperCase / upper case / upper_case / UPPER_CASE
* @since 2024-04-02
*/
UPPER_CASE,
/** /**
* *
* Lower Case * Lower Case
@ -116,4 +128,29 @@ export enum SupportCase {
* @since 2024-04-02 * @since 2024-04-02
*/ */
LOWER_CASE, LOWER_CASE,
/**
*
* Upper Case
* e.g. FOO_BAR / FOOBAR
*
* @alias: upperCase / UpperCase / upper case / upper_case / UPPER_CASE
* @since 2024-04-02
*/
UPPER_CASE,
} }
export const AllSupportCase = [
SupportCase.CAMEL_CASE,
SupportCase.PASCAL_CASE,
SupportCase.SNAKE_CASE,
SupportCase.SNAKE_CAMEL_CASE,
SupportCase.SNAKE_PASCAL_CASE,
SupportCase.SNAKE_UPPER_CASE,
SupportCase.KEBAB_CASE,
SupportCase.KEBAB_CAMEL_CASE,
SupportCase.KEBAB_PASCAL_CASE,
SupportCase.KEBAB_UPPER_CASE,
SupportCase.LOWER_CASE,
SupportCase.UPPER_CASE,
];

View File

@ -1,4 +1,4 @@
import { EOL } from "./convert-function-type"; import { EOL } from "./EOLType";
export type TestCaseGroup = { export type TestCaseGroup = {
group: string group: string
@ -14,10 +14,15 @@ export type TestCase = {
output: { output: {
camelCase: string camelCase: string
pascalCase: string pascalCase: string
upperCase?: string snakeCase: string
lowerCase?: string snakeCamelCase: string
snakePascalCase: string
snakeUpperCase: string
kebabCase: string kebabCase: string
camelkebabCase: string kebabCamelCase: string
kebabPascalCase: string
kebabUpperCase: string kebabUpperCase: string
lowerCase?: string
upperCase?: string
} }
}; };

View File

@ -1,3 +0,0 @@
export type EOL = '\n' | '\r\n';
export type ConvertFunction = (selectionText: string, eol: EOL) => string;