add phonenumber convert
This commit is contained in:
parent
eeb241360e
commit
99ab9428df
2 changed files with 27 additions and 9 deletions
15
packages/utils/phoneNumberKorean.ts
Normal file
15
packages/utils/phoneNumberKorean.ts
Normal 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
|
||||||
|
] ?? "";
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import CallingNumberKorean from "./callingNumberKorean";
|
import CallingNumberKorean from "./callingNumberKorean";
|
||||||
import FloatKorean from "./floatKorean";
|
import FloatKorean from "./floatKorean";
|
||||||
import IntegerKorean from "./integerKorean";
|
import IntegerKorean from "./integerKorean";
|
||||||
|
import PhoneNumberKorean from "./phoneNumberKorean";
|
||||||
|
|
||||||
export const IsolatedSymbolMap = {
|
export const IsolatedSymbolMap = {
|
||||||
"?": "물음표",
|
"?": "물음표",
|
||||||
|
|
@ -79,6 +80,13 @@ export const LangPrefixs = {
|
||||||
"tsx": "리액트 타입스크립트",
|
"tsx": "리액트 타입스크립트",
|
||||||
"jsx": "리액트 자바스크립트",
|
"jsx": "리액트 자바스크립트",
|
||||||
};
|
};
|
||||||
|
export const LangPrefixMaxLength = (()=>{
|
||||||
|
let max = 0;
|
||||||
|
for (const key in LangPrefixs) {
|
||||||
|
max = Math.max(key.length, max);
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
})();
|
||||||
export const ChoseongMap = {
|
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 = {
|
export const SIPrefix = {
|
||||||
"k": "킬로",
|
"k": "킬로",
|
||||||
|
|
@ -126,12 +127,10 @@ export const SIPrefix = {
|
||||||
"y": "요타",
|
"y": "요타",
|
||||||
"yi": "요비",
|
"yi": "요비",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LiterPrefix = {
|
export const LiterPrefix = {
|
||||||
"m": "밀리",
|
"m": "밀리",
|
||||||
"": "",
|
"": "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MeterPrefix = {
|
export const MeterPrefix = {
|
||||||
"m": "밀리",
|
"m": "밀리",
|
||||||
"c": "센치",
|
"c": "센치",
|
||||||
|
|
@ -205,6 +204,10 @@ export function saferKorean(input: string): string {
|
||||||
.replace(/[ㄱ-ㅎㄲㄸㅃㅆㅉ]/g, (char: string) => ChoseongMap[char as keyof typeof ChoseongMap])
|
.replace(/[ㄱ-ㅎㄲㄸㅃㅆㅉ]/g, (char: string) => ChoseongMap[char as keyof typeof ChoseongMap])
|
||||||
|
|
||||||
// Process number, unit
|
// 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) => {
|
.replace(/([\d,]+)([kKMmgGtTpP][iI]?)[bB]/g, (_, num: string, mod: string) => {
|
||||||
// 10kib => 십키비바이트
|
// 10kib => 십키비바이트
|
||||||
num = IntegerKorean.convertFromString(num);
|
num = IntegerKorean.convertFromString(num);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue