Skip to content

Commit

Permalink
feat: 스네이크 케이스인지 확인하는 함수
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansanghyeon committed Jan 10, 2024
1 parent 9fbe896 commit bbebf9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/is-snake-case/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#codeing_case

텍스트가 스네이크 케이스인지 확인하는 함수
14 changes: 14 additions & 0 deletions src/is-snake-case/is-snake-case.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest';
import { isSnakeCase } from './is-snake-case.ts';

describe('isSnakeCase', () => {
it('should return true for valid snake case strings', () => {
expect(isSnakeCase('this_is_snake_case')).toBe(true);
expect(isSnakeCase('snake_case')).toBe(true);
expect(isSnakeCase('snake_case123')).toBe(false);
});

it('should return false for non-snake case strings', () => {
expect(isSnakeCase('ThisIsNotSnakeCase')).toBe(false);
});
});
4 changes: 4 additions & 0 deletions src/is-snake-case/is-snake-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isSnakeCase(text: string): boolean {
const snakeCaseRegex = /^[a-z0-9]+(_[a-z0-9]+)*$/;
return snakeCaseRegex.test(text);
}

0 comments on commit bbebf9c

Please sign in to comment.