-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5320f18
commit b7a2f65
Showing
5 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { camelToSnake } from './camel-to-snake.ts'; | ||
|
||
describe('camel-to-snake', () => { | ||
it('should convert camelCase to snake_case correctly', () => { | ||
// 테스트 케이스 정의 | ||
const cases = [ | ||
{ camel: 'simpleTest', snake: 'simple_test' }, | ||
{ camel: 'easy', snake: 'easy' }, | ||
{ camel: 'HTMLToPDF', snake: 'html_to_pdf' }, | ||
{ camel: 'PDFGenerator', snake: 'pdf_generator' }, | ||
{ camel: 'thisIsALongTestString', snake: 'this_is_a_long_test_string' } | ||
]; | ||
|
||
// 각 테스트 케이스 실행 | ||
cases.forEach(({ camel, snake }) => { | ||
expect(camelToSnake(camel)).toEqual(snake); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function camelToSnake(camel: string): string { | ||
// 연속된 대문자 또는 대문자와 소문자 사이에 밑줄을 추가 | ||
return camel | ||
.replace(/([a-z])([A-Z])/g, '$1_$2') // 소문자와 대문자 사이 | ||
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') // 연속된 대문자 다음에 소문자가 오는 경우 | ||
.toLowerCase(); // 전체 문자열을 소문자로 변환 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './is-snake-case/is-snake-case.fp.ts' | ||
export * from './snake-to-camel/snake-to-camel.ts' | ||
export * from './snake-to-camel/snake-to-camel.ts' | ||
export * from './camel-to-snake/camel-to-snake.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './css-to-json/css-to-json.ts' | ||
export * from './snake-to-camel/snake-to-camel.ts' | ||
export * from './snake-to-camel/snake-to-camel.ts' | ||
export * from './camel-to-snake/camel-to-snake.ts' |