Skip to content

Commit 0f9418f

Browse files
committed
fix: enhance translatedVariableDictionary
Signed-off-by: sunrabbit123 <[email protected]>
1 parent a49d7c8 commit 0f9418f

File tree

3 files changed

+202
-62
lines changed

3 files changed

+202
-62
lines changed

src/constant/index.ts

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1 @@
1-
/**
2-
* @description if you modify this properties, you should upgrade the minor version because it will be a break changes
3-
* @ignore `~명`과 같은 이름을 지칭하는 변수의 경우 `Name`으로 끝나야함, 예외적으로 구분명은 `Division`으로 끝남
4-
* @ignore `~코드`와 같은 이름을 지칭하는 변수의 경우 `Code`로 끝나야함
5-
* @ignore `~일자`와 같은 이름을 지칭하는 변수의 경우 `Date`로 끝나야함
6-
* @ignore `~구분`과 같은 이름을 지칭하는 변수의 경우 `Division`으로 끝나야함, 만약 `구분명`이라면 `Division`을 사용
7-
* @ignore `~처리`과 같은 이름을 지칭하는 변수의 경우 `Process`으로 끝나야함
8-
* @ignore `~상정`과 같은 이름을 지칭하는 변수의 경우 `Present`으로 끝나야함
9-
* @ignore `~회부`과 같은 이름을 지칭하는 변수의 경우 `Submit`으로 끝나야함
10-
* @ignore `~의결`과 같은 이름을 지칭하는 변수의 경우 `Resolution`으로 끝나야함
11-
*/
12-
export const translatedVariableDictionary = {
13-
국회의원코드: 'lawmakerCode',
14-
국회의원명: 'lawmakerName',
15-
국회의원한자명: 'lawmakerChineseName',
16-
국회의원영문명: 'lawmakerEnglishName',
17-
생일구분코드: 'birthdayDivisionCode',
18-
생일일자: 'birthday',
19-
직책명: 'dutyName',
20-
정당명: 'politicalPartyName',
21-
선거구명: 'electoralDistrictName',
22-
선거구구분명: 'electoralDistrictDivisionName',
23-
위원회명: 'committeeName',
24-
소속위원회명: 'belongingCommitteeName',
25-
재선구분명: 'reElectionClassificationDivision',
26-
당선대수: 'electionCongress',
27-
성별: 'gender',
28-
전화번호: 'phoneNumber',
29-
국회의원이메일주소: 'email',
30-
국회의원홈페이지URL: 'homepage',
31-
보좌관: 'aide',
32-
비서관: 'seniorSecretary',
33-
비서: 'secretary',
34-
약력: 'profile',
35-
사무실호실: 'officeRoom',
36-
사진: 'picture',
37-
38-
// 의안 관련 추가
39-
의안ID: 'billID',
40-
의안번호: 'billNumber',
41-
: 'age',
42-
의안명: 'billName',
43-
제안자: 'proposer',
44-
제안자구분: 'proposerDivision',
45-
제안일: 'proposeDate',
46-
소관위코드: 'jurisdictionCommitteeCode',
47-
소관위: 'jurisdictionCommittee',
48-
소관위회부일: 'jurisdictionCommitteeSubmitDate',
49-
위원회심사_처리일: 'committeeReviewProcessDate',
50-
의안상세정보_URL: 'billDetailUrl',
51-
대표발의자: 'leadProposer',
52-
법사위처리결과: 'legislationAndJudiciaryCommitteeProcessResult',
53-
법사위처리일: 'legislationAndJudiciaryCommitteeProcessDate',
54-
법사위상정일: 'legislationAndJudiciaryCommitteePresentDate',
55-
법사위회부일: 'legislationAndJudiciaryCommitteeSubmitDate',
56-
소관위처리결과: 'jurisdictionCommitteeProcessResult',
57-
소관위처리일: 'jurisdictionCommitteeProcessDate',
58-
소관위상정일: 'jurisdictionCommitteePresentDate',
59-
대표발의자코드: 'leadProposerCode',
60-
본회의심의결과: 'plenarySessionReviewResult',
61-
의결일: 'resolutionDate',
62-
} as const;
1+
export { translatedVariableDictionary } from './translatedVariableDictionary';
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { describe, it, expectTypeOf, expect } from 'vitest';
2+
import {
3+
firstLetterLowerCase,
4+
FirstLetterLowerCase,
5+
MergeString,
6+
translatedVariableDictionary,
7+
variable,
8+
} from './translatedVariableDictionary';
9+
10+
describe('MergeString', () => {
11+
it('should merge an array of strings into a single string', () => {
12+
// Test with a single string
13+
expectTypeOf<MergeString<['hello']>>().toEqualTypeOf<'hello'>();
14+
15+
// Test with two strings
16+
expectTypeOf<MergeString<['hello', 'world']>>().toEqualTypeOf<'helloworld'>();
17+
18+
// Test with multiple strings
19+
expectTypeOf<MergeString<['hello', 'world', '123']>>().toEqualTypeOf<'helloworld123'>();
20+
21+
// Test with an empty array (should never happen)
22+
expectTypeOf<MergeString<[]>>().toEqualTypeOf<never>();
23+
});
24+
});
25+
26+
describe('FirstLetterLowerCase', () => {
27+
it('should convert the first letter of a string to lowercase', () => {
28+
// Test with an uppercase string
29+
expectTypeOf<FirstLetterLowerCase<'HELLO'>>().toEqualTypeOf<'hELLO'>();
30+
31+
// Test with a mixed-case string
32+
expectTypeOf<FirstLetterLowerCase<'HelloWorld'>>().toEqualTypeOf<'helloWorld'>();
33+
34+
// Test with a single-letter string
35+
expectTypeOf<FirstLetterLowerCase<'A'>>().toEqualTypeOf<'a'>();
36+
37+
// Test with an empty string (should return the same string)
38+
expectTypeOf<FirstLetterLowerCase<''>>().toEqualTypeOf<''>();
39+
});
40+
});
41+
42+
describe('firstLetterLowerCase', () => {
43+
it('should convert the first letter of a string to lowercase', () => {
44+
// Test with an uppercase string
45+
expect(firstLetterLowerCase('HELLO')).toBe('hELLO');
46+
47+
// Test with a mixed-case string
48+
expect(firstLetterLowerCase('HelloWorld')).toBe('helloWorld');
49+
50+
// Test with a single-letter string
51+
expect(firstLetterLowerCase('A')).toBe('a');
52+
53+
// Test with an empty string
54+
expect(firstLetterLowerCase('')).toBe('');
55+
});
56+
});
57+
58+
describe('variable', () => {
59+
it('should merge and format strings correctly', () => {
60+
// Test with a single string
61+
expect(variable`hello`).toBe('hello');
62+
63+
// Test with two strings
64+
expect(variable`hello${'world'}`).toBe('helloworld');
65+
66+
// Test with multiple strings and formatting
67+
expect(variable`hello${'World'}${'123'}`).toBe('helloWorld123');
68+
69+
// Test with an empty template string
70+
expect(variable``).toBe('');
71+
72+
// Test with strings that should have their first letter lowercased
73+
expect(variable`Hello${'World'}`).toBe('helloWorld');
74+
});
75+
});
76+
77+
describe('translatedVariableDictionary', () => {
78+
it('should have correct types', () => {
79+
// Test the type of the entire object
80+
expectTypeOf(translatedVariableDictionary).toEqualTypeOf<typeof translatedVariableDictionary>();
81+
82+
// Test the types of individual properties
83+
expectTypeOf(translatedVariableDictionary.국회의원코드).toEqualTypeOf<'lawmakerCode'>();
84+
expect(translatedVariableDictionary.국회의원코드).toBe('lawmakerCode');
85+
86+
expectTypeOf(translatedVariableDictionary.국회의원명).toEqualTypeOf<'lawmakerName'>();
87+
expect(translatedVariableDictionary.국회의원명).toBe('lawmakerName');
88+
89+
expectTypeOf(translatedVariableDictionary.국회의원한자명).toEqualTypeOf<'lawmakerChineseName'>();
90+
expect(translatedVariableDictionary.국회의원한자명).toBe('lawmakerChineseName');
91+
92+
expectTypeOf(translatedVariableDictionary.국회의원영문명).toEqualTypeOf<'lawmakerEnglishName'>();
93+
expect(translatedVariableDictionary.국회의원영문명).toBe('lawmakerEnglishName');
94+
95+
expectTypeOf(translatedVariableDictionary.생일구분코드).toEqualTypeOf<'birthdayDivisionCode'>();
96+
expect(translatedVariableDictionary.생일구분코드).toBe('birthdayDivisionCode');
97+
});
98+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
export type MergeString<T extends ReadonlyArray<string>> = T extends [infer Word extends string]
2+
? `${Word}`
3+
: T extends [infer First extends string, infer Last extends string]
4+
? `${First}${Last}`
5+
: T extends [infer First extends string, ...infer Rest extends string[]]
6+
? `${First}${MergeString<Rest>}`
7+
: never;
8+
9+
export type FirstLetterLowerCase<T extends string> = T extends `${infer First}${infer Rest}`
10+
? `${Lowercase<First>}${Rest}`
11+
: T;
12+
13+
export const firstLetterLowerCase = <T extends string>(str: T) =>
14+
`${str.charAt(0).toLowerCase()}${str.slice(1)}` as FirstLetterLowerCase<T>;
15+
16+
export const variable = <T extends ReadonlyArray<string>>(_template: TemplateStringsArray, ...args: T) =>
17+
args.reduce((prev, cur, idx) => {
18+
return idx === 0 ? firstLetterLowerCase(cur) : `${prev}${cur}`;
19+
}, '') as T extends [infer First extends string, ...infer Rest extends ReadonlyArray<string>]
20+
? MergeString<[FirstLetterLowerCase<First>, ...Rest]>
21+
: MergeString<T>;
22+
23+
/**
24+
* @description if you modify this properties, you should upgrade the minor version because it will be a break changes
25+
*/
26+
27+
const 국회의원 = 'Lawmaker';
28+
const 코드 = 'Code';
29+
const = 'Name';
30+
const 한자명 = `Chinese${}`;
31+
const 영문명 = `English${}`;
32+
const 구분 = 'Division';
33+
const 구분명 = `${구분}`;
34+
const 생일 = 'Birthday';
35+
const 직책 = 'Duty';
36+
const 정당 = 'PoliticalParty';
37+
const 선거구 = 'ElectoralDistrict';
38+
const 위원회 = 'Committee';
39+
const 소속위원회 = 'BelongingCommittee';
40+
const 선거 = 'Election';
41+
const 재선 = `Re${선거}`;
42+
const 의안 = `Bill`;
43+
const 번호 = 'Number';
44+
const 제안자 = 'Proposer';
45+
const 대표발의자 = `Lead${제안자}`;
46+
const 소관위원회 = `Jurisdiction${위원회}`;
47+
const 법제사법위원회 = `LegislationAndJudiciary${위원회}`;
48+
const 처리 = 'Process';
49+
const 일자 = `Date`;
50+
const 처리결과 = `${처리}Result`;
51+
const 처리일 = `${처리}${일자}`;
52+
const 회부일 = `Submit${일자}`;
53+
const 상정일 = `Present${일자}`;
54+
export const translatedVariableDictionary = {
55+
국회의원코드: variable`${국회의원}${코드}`,
56+
국회의원명: variable`${국회의원}${}`,
57+
국회의원한자명: variable`${국회의원}${한자명}`,
58+
국회의원영문명: variable`${국회의원}${영문명}`,
59+
생일구분코드: variable`${생일}${구분}${코드}`,
60+
생일일자: variable`${생일}`,
61+
직책명: variable`${직책}${}`,
62+
정당명: variable`${정당}${}`,
63+
선거구명: variable`${선거구}${}`,
64+
선거구구분명: variable`${선거구}${구분명}`,
65+
위원회명: variable`${위원회}${}`,
66+
소속위원회명: variable`${소속위원회}${}`,
67+
재선구분명: variable`${재선}${구분명}`,
68+
당선대수: variable`${선거}Congress`,
69+
성별: 'gender',
70+
전화번호: 'phoneNumber',
71+
국회의원이메일주소: 'email',
72+
국회의원홈페이지URL: 'homepage',
73+
보좌관: 'aide',
74+
비서관: 'seniorSecretary',
75+
비서: 'secretary',
76+
약력: 'profile',
77+
사무실호실: 'officeRoom',
78+
사진: 'picture',
79+
80+
의안ID: variable`${의안}ID`,
81+
의안번호: variable`${의안}${번호}`,
82+
: 'age',
83+
의안명: variable`${의안}${}`,
84+
제안자,
85+
제안자구분: variable`${제안자}${구분}`,
86+
제안일: 'proposeDate',
87+
소관위코드: variable`${소관위원회}${코드}`,
88+
소관위: variable`${소관위원회}`,
89+
소관위회부일: variable`${소관위원회}${회부일}`,
90+
위원회심사_처리일: `${위원회}Review${처리일}`,
91+
의안상세정보_URL: variable`${의안}DetailUrl`,
92+
대표발의자: variable`${대표발의자}`,
93+
법사위처리결과: variable`${법제사법위원회}${처리결과}`,
94+
법사위처리일: variable`${법제사법위원회}${처리일}`,
95+
법사위상정일: variable`${법제사법위원회}${상정일}`,
96+
법사위회부일: variable`${법제사법위원회}${회부일}`,
97+
소관위처리결과: variable`${소관위원회}${처리결과}`,
98+
소관위처리일: variable`${소관위원회}${처리일}`,
99+
소관위상정일: variable`${소관위원회}${상정일}`,
100+
대표발의자코드: variable`${대표발의자}${코드}`,
101+
본회의심의결과: 'plenarySessionReviewResult',
102+
의결일: 'resolutionDate',
103+
} as const;

0 commit comments

Comments
 (0)