add phonenumber convert

This commit is contained in:
kimpure 2026-05-21 15:11:05 +00:00
parent eeb241360e
commit 99ab9428df
No known key found for this signature in database
2 changed files with 27 additions and 9 deletions

View file

@ -0,0 +1,15 @@
export default class PhoneNumberKorean {
static DigitName = [ "공", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구" ];
static Dash = " ";
static convert(phone: string): string {
return phone.replace(/[\d\- \+]/g, (char: string) => {
if (char == "-") return PhoneNumberKorean.Dash;
if (char == " ") return " ";
if (char == "+") return "플러스";
return PhoneNumberKorean.DigitName[
parseInt(char) as number
] ?? "";
})
}
}

View file

@ -1,6 +1,7 @@
import CallingNumberKorean from "./callingNumberKorean";
import FloatKorean from "./floatKorean";
import IntegerKorean from "./integerKorean";
import PhoneNumberKorean from "./phoneNumberKorean";
export const IsolatedSymbolMap = {
"?": "물음표",
@ -79,6 +80,13 @@ export const LangPrefixs = {
"tsx": "리액트 타입스크립트",
"jsx": "리액트 자바스크립트",
};
export const LangPrefixMaxLength = (()=>{
let max = 0;
for (const key in LangPrefixs) {
max = Math.max(key.length, max);
}
return max;
})();
export const ChoseongMap = {
"ㄱ": "기역",
"ㄴ": "니은",
@ -100,13 +108,6 @@ export const ChoseongMap = {
"ㅆ": "쌍시옷",
"ㅉ": "쌍지읒",
};
export const LangPrefixMaxLength = (()=>{
let max = 0;
for (const key in LangPrefixs) {
max = Math.max(key.length, max);
}
return max;
})();
export const SIPrefix = {
"k": "킬로",
@ -126,12 +127,10 @@ export const SIPrefix = {
"y": "요타",
"yi": "요비",
};
export const LiterPrefix = {
"m": "밀리",
"": "",
};
export const MeterPrefix = {
"m": "밀리",
"c": "센치",
@ -205,6 +204,10 @@ export function saferKorean(input: string): string {
.replace(/[ㄱ-ㅎㄲㄸㅃㅆㅉ]/g, (char: string) => ChoseongMap[char as keyof typeof ChoseongMap])
// Process number, unit
.replace(/[\d\-]+/g, (phone: string) => {
if (!phone.includes("-")) return phone;
return PhoneNumberKorean.convert(phone);
})
.replace(/([\d,]+)([kKMmgGtTpP][iI]?)[bB]/g, (_, num: string, mod: string) => {
// 10kib => 십키비바이트
num = IntegerKorean.convertFromString(num);