Skip to content

Commit

Permalink
refactor: date의 확장을 고려해 폴더구조를 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BO-LIKE-CHICKEN committed Aug 9, 2024
1 parent d84d271 commit 87b0b41
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
20 changes: 0 additions & 20 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,3 @@ export const SUSA_CLASSIFIER_MAP = {
4: '네',
20: '스무',
} as const;

export const DATE_DAYS_MAP = {
1: '하루',
2: '이틀',
3: '사흘',
4: '나흘',
5: '닷새',
6: '엿새',
7: '이레',
8: '여드레',
9: '아흐레',
10: '열',
20: '스무',
} as const;

export const DATE_DAYS_ONLY_TENS_MAP = {
10: '열흘',
20: '스무날',
30: '서른날',
} as const;
2 changes: 1 addition & 1 deletion src/date.spec.ts → src/date/date.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { days } from './date';
import { days } from '.';

describe('date', () => {
describe('days', () => {
Expand Down
19 changes: 19 additions & 0 deletions src/date/days.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const DAYS_MAP = {
1: '하루',
2: '이틀',
3: '사흘',
4: '나흘',
5: '닷새',
6: '엿새',
7: '이레',
8: '여드레',
9: '아흐레',
10: '열',
20: '스무',
} as const;

export const DAYS_ONLY_TENS_MAP = {
10: '열흘',
20: '스무날',
30: '서른날',
} as const;
12 changes: 6 additions & 6 deletions src/date.ts → src/date/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasProperty } from './_internal';
import { DATE_DAYS_MAP, DATE_DAYS_ONLY_TENS_MAP } from './constants';
import { hasProperty } from '../_internal';
import { DAYS_MAP, DAYS_ONLY_TENS_MAP } from './days.constants';

export function days(num: number): string {
return getNumberWord(num);
Expand All @@ -11,12 +11,12 @@ function getNumberWord(num: number): string {
const tens = Math.floor(num / 10) * 10;
const ones = num % 10;

if (ones === 0 && hasProperty(DATE_DAYS_ONLY_TENS_MAP, tens)) {
return DATE_DAYS_ONLY_TENS_MAP[tens];
if (ones === 0 && hasProperty(DAYS_ONLY_TENS_MAP, tens)) {
return DAYS_ONLY_TENS_MAP[tens];
}

const tensWord = hasProperty(DATE_DAYS_MAP, tens) ? DATE_DAYS_MAP[tens] : '';
const onesWord = hasProperty(DATE_DAYS_MAP, ones) ? DATE_DAYS_MAP[ones] : '';
const tensWord = hasProperty(DAYS_MAP, tens) ? DAYS_MAP[tens] : '';
const onesWord = hasProperty(DAYS_MAP, ones) ? DAYS_MAP[ones] : '';

return `${tensWord}${onesWord}`;
}
Expand Down

0 comments on commit 87b0b41

Please sign in to comment.