fix: fix Invalid regular expression on iOS <= 16.3

This commit is contained in:
Ljzd PRO 2024-09-16 23:40:41 +08:00 committed by GitHub
parent 7d7a12d7d6
commit 2645b30fb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 6 deletions

View File

@ -3,9 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
const enRegex1 = /(?<=n)a/gi;
const enRegex2 = /(?<=morn)ing/gi;
const enRegex3 = /(?<=every)one/gi;
const koRegex1 = /[나-낳]/g;
const koRegex2 = /(다$)|(다(?=\.))|(다(?= ))|(다(?=!))|(다(?=\?))/gm;
const koRegex3 = /(야(?=\?))|(야$)|(야(?= ))/gm;
@ -15,9 +12,12 @@ export function nyaize(text: string): string {
// ja-JP
.replaceAll('な', 'にゃ').replaceAll('ナ', 'ニャ').replaceAll('ナ', 'ニャ')
// en-US
.replace(enRegex1, x => x === 'A' ? 'YA' : 'ya')
.replace(enRegex2, x => x === 'ING' ? 'YAN' : 'yan')
.replace(enRegex3, x => x === 'ONE' ? 'NYAN' : 'nyan')
.replaceAll('na', 'nya')
.replaceAll('NA', 'NYA')
.replaceAll('morning', 'mornyan')
.replaceAll('MORNING', 'MORNYAN')
.replaceAll('everyone', 'everynyan')
.replaceAll('EVERYONE', 'EVERYNYAN')
// ko-KR
.replace(koRegex1, match => !isNaN(match.charCodeAt(0)) ? String.fromCharCode(
match.charCodeAt(0) + '냐'.charCodeAt(0) - '나'.charCodeAt(0),