hangul-toolkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,141 @@
1
+ /**
2
+ * 한글 음절 분해/조합 유틸리티
3
+ * Hangul syllable decomposition & composition
4
+ */
5
+ declare const CHOSEONG_LIST: readonly ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
6
+ declare const JUNGSEONG_LIST: readonly ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
7
+ declare const JONGSEONG_LIST: readonly ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
8
+ interface DecomposedSyllable {
9
+ choseong: string;
10
+ jungseong: string;
11
+ jongseong: string | null;
12
+ }
13
+ /** 한글 음절(가~힣)인지 확인 */
14
+ declare function isHangulSyllable(char: string): boolean;
15
+ /** 음절을 초성/중성/종성으로 분해 */
16
+ declare function decompose(char: string): DecomposedSyllable;
17
+ /** 초성/중성(/종성)을 조합해 음절 생성 */
18
+ declare function compose(choseong: string, jungseong: string, jongseong?: string | null): string;
19
+ /** 문자가 받침(종성)으로 끝나는지 확인 */
20
+ declare function hasBatchim(char: string): boolean;
21
+ /**
22
+ * 문자열을 자모 단위로 분해
23
+ * @example disassemble('값') // 'ㄱㅏㅂㅅ'
24
+ * @example disassemble('한글') // 'ㅎㅏㄴㄱㅡㄹ'
25
+ */
26
+ declare function disassemble(text: string): string;
27
+ /**
28
+ * 자모 나열을 음절로 조합 (disassemble의 역함수)
29
+ * @example assemble('ㄱㅏㅂㅅ') // '값'
30
+ * @example assemble('ㄱㅏㅂㅅㅏ') // '갑사'
31
+ */
32
+ declare function assemble(jamo: string): string;
33
+
34
+ /**
35
+ * 한국어 조사(은/는, 이/가, 을/를...) 자동 선택
36
+ * Automatic Korean particle (josa) picker
37
+ */
38
+ type JosaPair = readonly [string, string];
39
+ /** 지원하는 조사 쌍: [받침 있음, 받침 없음] */
40
+ declare const JOSA_PAIRS: Record<string, JosaPair>;
41
+ /**
42
+ * 단어에 맞는 조사를 골라 반환
43
+ * @example pickJosa('사과', '은/는') // '는'
44
+ * @example pickJosa('책', '은/는') // '은'
45
+ * @example pickJosa('서울', '으로/로') // '로'
46
+ */
47
+ declare function pickJosa(word: string, pair: keyof typeof JOSA_PAIRS | string): string;
48
+ /**
49
+ * 단어 뒤에 올바른 조사를 붙여 반환
50
+ * @example josa('사과', '을/를') // '사과를'
51
+ * @example josa('부산', '으로/로') // '부산으로'
52
+ * @example josa('3', '이/가') // '3이' (숫자는 발음 기준)
53
+ */
54
+ declare function josa(word: string | number, pair: keyof typeof JOSA_PAIRS | string): string;
55
+ /** 지원하는 조사 쌍 목록 */
56
+ declare function supportedJosaPairs(): string[];
57
+
58
+ /**
59
+ * 숫자 → 한글 수사 변환
60
+ * Number to Korean words
61
+ */
62
+ /**
63
+ * 정수를 한글 수사로 변환
64
+ * @example numberToKorean(0) // '영'
65
+ * @example numberToKorean(1004) // '천사'
66
+ * @example numberToKorean(123456789) // '일억이천삼백사십오만육천칠백팔십구'
67
+ */
68
+ declare function numberToKorean(num: number): string;
69
+ /**
70
+ * 금액을 한글로 변환 (원 단위)
71
+ * @example formatWon(50000) // '오만원'
72
+ * @example formatWon(1234567) // '백이십삼만사천오백육십칠원'
73
+ */
74
+ declare function formatWon(amount: number): string;
75
+
76
+ /**
77
+ * 한국어 텍스트 개인정보(PII) 탐지 및 마스킹
78
+ * 프롬프트를 LLM API로 별내기 전 전처리 용도로 설계
79
+ *
80
+ * Korean PII detection & masking — designed for preprocessing
81
+ * prompts before sending them to LLM APIs
82
+ */
83
+ type PIIType = 'rrn' | 'phone' | 'email' | 'card' | 'driverLicense' | 'account';
84
+ interface PIIMatch {
85
+ type: PIIType;
86
+ value: string;
87
+ start: number;
88
+ end: number;
89
+ }
90
+ interface MaskPIIOptions {
91
+ /** 마스킹할 PII 유형 (기본: rrn, phone, email, card, driverLicense) */
92
+ types?: PIIType[];
93
+ /** 마스킹 문자 (기본: '*') */
94
+ maskChar?: string;
95
+ /** 마지막 N글자는 남겨두기 (기본: 0 = 전부 마스킹) */
96
+ keepLast?: number;
97
+ }
98
+ /**
99
+ * 텍스트에서 개인정보 패턴 탐지
100
+ * @example detectPII('연락처 010-1234-5678')
101
+ * // [{ type: 'phone', value: '010-1234-5678', start: 4, end: 17 }]
102
+ */
103
+ declare function detectPII(text: string, types?: PIIType[]): PIIMatch[];
104
+ /**
105
+ * 텍스트 내 개인정보를 마스킹 (구분자 -, 공백은 유지)
106
+ * @example maskPII('연락처 010-1234-5678')
107
+ * // '연락처 ***-****-****'
108
+ * @example maskPII('카드 1234-5678-9012-3456', { keepLast: 4 })
109
+ * // '카드 ****-****-****-3456'
110
+ */
111
+ declare function maskPII(text: string, options?: MaskPIIOptions): string;
112
+ /**
113
+ * 한국어 이름 마스킹
114
+ * @example maskName('김철수') // '김*수'
115
+ * @example maskName('홍길') // '홍*'
116
+ * @example maskName('남궁민수') // '남**수'
117
+ */
118
+ declare function maskName(name: string, maskChar?: string): string;
119
+
120
+ /**
121
+ * 한국 각종 번호 유효성 검증
122
+ * Validators for Korean identification numbers
123
+ */
124
+ /**
125
+ * 주민등록번호 유효성 검증 (체크섬 포함)
126
+ * @example isValidRRN('900101-1******') // 체크섬이 맞으면 true
127
+ */
128
+ declare function isValidRRN(input: string): boolean;
129
+ /**
130
+ * 사업자등록번호 유효성 검증 (체크섬 포함)
131
+ * @example isValidBusinessNumber('123-45-67890')
132
+ */
133
+ declare function isValidBusinessNumber(input: string): boolean;
134
+ /**
135
+ * 한국 전화번호 형식 검증 (휴대폰 + 일반전화)
136
+ * @example isValidPhoneNumber('010-1234-5678') // true
137
+ * @example isValidPhoneNumber('02-123-4567') // true
138
+ */
139
+ declare function isValidPhoneNumber(input: string): boolean;
140
+
141
+ export { CHOSEONG_LIST, type DecomposedSyllable, JONGSEONG_LIST, JUNGSEONG_LIST, type MaskPIIOptions, type PIIMatch, type PIIType, assemble, compose, decompose, detectPII, disassemble, formatWon, hasBatchim, isHangulSyllable, isValidBusinessNumber, isValidPhoneNumber, isValidRRN, josa, maskName, maskPII, numberToKorean, pickJosa, supportedJosaPairs };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * 한글 음절 분해/조합 유틸리티
3
+ * Hangul syllable decomposition & composition
4
+ */
5
+ declare const CHOSEONG_LIST: readonly ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
6
+ declare const JUNGSEONG_LIST: readonly ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
7
+ declare const JONGSEONG_LIST: readonly ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
8
+ interface DecomposedSyllable {
9
+ choseong: string;
10
+ jungseong: string;
11
+ jongseong: string | null;
12
+ }
13
+ /** 한글 음절(가~힣)인지 확인 */
14
+ declare function isHangulSyllable(char: string): boolean;
15
+ /** 음절을 초성/중성/종성으로 분해 */
16
+ declare function decompose(char: string): DecomposedSyllable;
17
+ /** 초성/중성(/종성)을 조합해 음절 생성 */
18
+ declare function compose(choseong: string, jungseong: string, jongseong?: string | null): string;
19
+ /** 문자가 받침(종성)으로 끝나는지 확인 */
20
+ declare function hasBatchim(char: string): boolean;
21
+ /**
22
+ * 문자열을 자모 단위로 분해
23
+ * @example disassemble('값') // 'ㄱㅏㅂㅅ'
24
+ * @example disassemble('한글') // 'ㅎㅏㄴㄱㅡㄹ'
25
+ */
26
+ declare function disassemble(text: string): string;
27
+ /**
28
+ * 자모 나열을 음절로 조합 (disassemble의 역함수)
29
+ * @example assemble('ㄱㅏㅂㅅ') // '값'
30
+ * @example assemble('ㄱㅏㅂㅅㅏ') // '갑사'
31
+ */
32
+ declare function assemble(jamo: string): string;
33
+
34
+ /**
35
+ * 한국어 조사(은/는, 이/가, 을/를...) 자동 선택
36
+ * Automatic Korean particle (josa) picker
37
+ */
38
+ type JosaPair = readonly [string, string];
39
+ /** 지원하는 조사 쌍: [받침 있음, 받침 없음] */
40
+ declare const JOSA_PAIRS: Record<string, JosaPair>;
41
+ /**
42
+ * 단어에 맞는 조사를 골라 반환
43
+ * @example pickJosa('사과', '은/는') // '는'
44
+ * @example pickJosa('책', '은/는') // '은'
45
+ * @example pickJosa('서울', '으로/로') // '로'
46
+ */
47
+ declare function pickJosa(word: string, pair: keyof typeof JOSA_PAIRS | string): string;
48
+ /**
49
+ * 단어 뒤에 올바른 조사를 붙여 반환
50
+ * @example josa('사과', '을/를') // '사과를'
51
+ * @example josa('부산', '으로/로') // '부산으로'
52
+ * @example josa('3', '이/가') // '3이' (숫자는 발음 기준)
53
+ */
54
+ declare function josa(word: string | number, pair: keyof typeof JOSA_PAIRS | string): string;
55
+ /** 지원하는 조사 쌍 목록 */
56
+ declare function supportedJosaPairs(): string[];
57
+
58
+ /**
59
+ * 숫자 → 한글 수사 변환
60
+ * Number to Korean words
61
+ */
62
+ /**
63
+ * 정수를 한글 수사로 변환
64
+ * @example numberToKorean(0) // '영'
65
+ * @example numberToKorean(1004) // '천사'
66
+ * @example numberToKorean(123456789) // '일억이천삼백사십오만육천칠백팔십구'
67
+ */
68
+ declare function numberToKorean(num: number): string;
69
+ /**
70
+ * 금액을 한글로 변환 (원 단위)
71
+ * @example formatWon(50000) // '오만원'
72
+ * @example formatWon(1234567) // '백이십삼만사천오백육십칠원'
73
+ */
74
+ declare function formatWon(amount: number): string;
75
+
76
+ /**
77
+ * 한국어 텍스트 개인정보(PII) 탐지 및 마스킹
78
+ * 프롬프트를 LLM API로 별내기 전 전처리 용도로 설계
79
+ *
80
+ * Korean PII detection & masking — designed for preprocessing
81
+ * prompts before sending them to LLM APIs
82
+ */
83
+ type PIIType = 'rrn' | 'phone' | 'email' | 'card' | 'driverLicense' | 'account';
84
+ interface PIIMatch {
85
+ type: PIIType;
86
+ value: string;
87
+ start: number;
88
+ end: number;
89
+ }
90
+ interface MaskPIIOptions {
91
+ /** 마스킹할 PII 유형 (기본: rrn, phone, email, card, driverLicense) */
92
+ types?: PIIType[];
93
+ /** 마스킹 문자 (기본: '*') */
94
+ maskChar?: string;
95
+ /** 마지막 N글자는 남겨두기 (기본: 0 = 전부 마스킹) */
96
+ keepLast?: number;
97
+ }
98
+ /**
99
+ * 텍스트에서 개인정보 패턴 탐지
100
+ * @example detectPII('연락처 010-1234-5678')
101
+ * // [{ type: 'phone', value: '010-1234-5678', start: 4, end: 17 }]
102
+ */
103
+ declare function detectPII(text: string, types?: PIIType[]): PIIMatch[];
104
+ /**
105
+ * 텍스트 내 개인정보를 마스킹 (구분자 -, 공백은 유지)
106
+ * @example maskPII('연락처 010-1234-5678')
107
+ * // '연락처 ***-****-****'
108
+ * @example maskPII('카드 1234-5678-9012-3456', { keepLast: 4 })
109
+ * // '카드 ****-****-****-3456'
110
+ */
111
+ declare function maskPII(text: string, options?: MaskPIIOptions): string;
112
+ /**
113
+ * 한국어 이름 마스킹
114
+ * @example maskName('김철수') // '김*수'
115
+ * @example maskName('홍길') // '홍*'
116
+ * @example maskName('남궁민수') // '남**수'
117
+ */
118
+ declare function maskName(name: string, maskChar?: string): string;
119
+
120
+ /**
121
+ * 한국 각종 번호 유효성 검증
122
+ * Validators for Korean identification numbers
123
+ */
124
+ /**
125
+ * 주민등록번호 유효성 검증 (체크섬 포함)
126
+ * @example isValidRRN('900101-1******') // 체크섬이 맞으면 true
127
+ */
128
+ declare function isValidRRN(input: string): boolean;
129
+ /**
130
+ * 사업자등록번호 유효성 검증 (체크섬 포함)
131
+ * @example isValidBusinessNumber('123-45-67890')
132
+ */
133
+ declare function isValidBusinessNumber(input: string): boolean;
134
+ /**
135
+ * 한국 전화번호 형식 검증 (휴대폰 + 일반전화)
136
+ * @example isValidPhoneNumber('010-1234-5678') // true
137
+ * @example isValidPhoneNumber('02-123-4567') // true
138
+ */
139
+ declare function isValidPhoneNumber(input: string): boolean;
140
+
141
+ export { CHOSEONG_LIST, type DecomposedSyllable, JONGSEONG_LIST, JUNGSEONG_LIST, type MaskPIIOptions, type PIIMatch, type PIIType, assemble, compose, decompose, detectPII, disassemble, formatWon, hasBatchim, isHangulSyllable, isValidBusinessNumber, isValidPhoneNumber, isValidRRN, josa, maskName, maskPII, numberToKorean, pickJosa, supportedJosaPairs };