add 1,000 원 replace to 천원

This commit is contained in:
kimpure 2026-05-21 13:55:29 +00:00
parent 2e6483a36e
commit 8c793863aa
No known key found for this signature in database

View file

@ -130,11 +130,14 @@ export function processDots(input: string): string {
export function saferKorean(input: string): string {
return processDots(input)
// Process isolated symbols
.replace(/^[\?\!\'\"]+$/, (total)=>(
[...total].map(element => IsolatedSymbolMap[
element as keyof typeof IsolatedSymbolMap
]).join("")
))
// Process codeblock
.replace(/\`\`\`([\s\S]*?)\`\`\`/g, (_, content: string)=>{
const code = content.substring(0, LangPrefixMaxLength).toLowerCase();
let lang = "";
@ -146,6 +149,8 @@ export function saferKorean(input: string): string {
}
return lang + "코드블럭";
})
// Process koreans
.replace(/ㅋ{2,}/g, (content) => "크".repeat(content.length))
.replace(/[아ㅏ]{3,}/g, "아아아")
.replace(/https\S+/g, "링크")
@ -158,12 +163,17 @@ export function saferKorean(input: string): string {
}
return content;
})
.replace(/[ㄱ-ㅎㄲㄸㅃㅆㅉ]/g, (char: string) => ChoseongMap[char as keyof typeof ChoseongMap])
// Process number, unit
.replace(/(\d+)([kKMmgGtTpP][iI]?)[bB]/g, (_, num: string, mod: string) => {
// 10kib => 10키비바이트
num = IntegerKorean.convertFromString(num);
mod = SIPrefix[mod.toLowerCase() as keyof typeof SIPrefix];
return `${num} ${mod}바이트 `;
})
.replace(/([\d.]+)[ \t\n]*([개살시평명])/g, (_, num: string, postfix: string)=>{
.replace(/([\d\.]+)[ \t\n]*([개살시평명])/g, (_, num: string, postfix: string)=>{
// 10명 => 열명
if (num.includes(".")) {
return num + postfix;
}
@ -174,7 +184,12 @@ export function saferKorean(input: string): string {
return IntegerKorean.convertFromString(num) + postfix;
}
})
.replace(/[ㄱ-ㅎㄲㄸㅃㅆㅉ]/g, (char: string) => ChoseongMap[char as keyof typeof ChoseongMap])
.replace(/[\d,]+/g, (num: string) => {
// 1,000 원 => 천원
if (!num.includes(",")) return num;
num = num.replace(/,/g, "");
return IntegerKorean.convertFromString(num);
})
.replace(/(v?)([\d\.]+)([ab]?)/g, (_, suffix: string, num: string, postfix: string) => {
const dotCount = [...num.matchAll(/\./g)].length;
const hasNoSuffix = suffix == "";
@ -206,10 +221,12 @@ export function saferKorean(input: string): string {
return FloatKorean.convert(num) + postfix;
}
})
.replace(/㎡/g, "제곱미터")
.replace(/㎢/g, "제곱킬로미터")
// Process symbol
.replace(/[\%\^\&\*\#\@\.\-\+\_\=\/\\♡\$]/g, (t) => (
SymbolMap[t as keyof typeof SymbolMap]
))
.replace(/㎡/g, "제곱미터")
.replace(/㎢/g, "제곱킬로미터")
.replace(/([\?\!]+)/g, (_, content: string) => content[0])
}