From 31648a4805c1162081768ac14a546d467bf2f2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Wed, 3 Apr 2024 00:15:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E5=B0=8F=E9=A9=BC=E5=B3=B0=EF=BC=8C?= =?UTF-8?q?=E8=BD=AC=E5=A4=A7=E9=A9=BC=E5=B3=B0=E9=80=9A=E8=BF=87=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main-code/text-conversion.ts | 24 ++++++++++++++---------- src/test/test-case.ts | 8 ++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main-code/text-conversion.ts b/src/main-code/text-conversion.ts index 8e3b4de..3275532 100644 --- a/src/main-code/text-conversion.ts +++ b/src/main-code/text-conversion.ts @@ -12,7 +12,7 @@ import { transformMutliLineText, transformText } from './text-transform'; export const toCamelCase: ConvertFunction = (str: string, eol: EOL): string => { // Cut text 切割文本 const results: Array = transformMutliLineText(str); - console.log('results', results); + // console.log('results', results); const transformedLines: Array = []; for (const result of results) { @@ -54,16 +54,20 @@ export const toCamelCase: ConvertFunction = (str: string, eol: EOL): string => { */ export const toPascalCase: ConvertFunction = (str: string, eol: EOL): string => { // Cut text 切割文本 - let result = transformText(str); - console.log('result', result); + const results: Array = transformMutliLineText(str); + // console.log('results', results); - // Post Process 后置处理 - const words = result.trimResult.split('|'); - const pascalCaseWords = words.map((word, index) => { - // 首字母大写 - return word.charAt(0).toUpperCase() + word.slice(1); - }); - return result.leadingSpace + pascalCaseWords.join('') + result.trailingSpace; + const transformedLines: Array = []; + 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('_', '')); }; diff --git a/src/test/test-case.ts b/src/test/test-case.ts index 1e3fb6c..5f02323 100644 --- a/src/test/test-case.ts +++ b/src/test/test-case.ts @@ -123,13 +123,13 @@ const testGroups: Array = [ input: 'How do you\bdo?\n How do you\tdo!' , - eol: [LF, CRLF], + eol: [LF], transformText: [ 'how|do|you|\b|do|?', ' how|do|you|\t|do|!', ], output: { - camelCase: 'howDoYou\bDo?\n HowDoYou\tDo!', + camelCase: 'howDoYou\bDo?\n howDoYou\tDo!', pascalCase: 'HowDoYou\bDo?\n HowDoYou\tDo!', }, }, @@ -366,8 +366,8 @@ const testGroups: Array = [ ' exercisingPermissionsGrantedByThisLicense.' , pascalCase: - ' "You" (or "Your") shall mean an individual or Legal Entity\n' + - ' exercising permissions granted by this License.' + ' &Quot;You&Quot;(Or&Quot;Your&Quot;)ShallMeanAnIndividualOrLegalEntity\n' + + ' ExercisingPermissionsGrantedByThisLicense.' , }, },