summaryrefslogtreecommitdiff
path: root/src/lib/lang/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/lang/utils.ts')
-rw-r--r--src/lib/lang/utils.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/lang/utils.ts b/src/lib/lang/utils.ts
new file mode 100644
index 0000000..b6c5bae
--- /dev/null
+++ b/src/lib/lang/utils.ts
@@ -0,0 +1,28 @@
+const TONE_LETTER_REGEX = new RegExp(
+ /[\u{02E5}-\u{02EE}\u{A700}-\u{A71F}\u{A789}-\u{A78A}]/u,
+);
+const TONE_NUMBERS_REGEX = new RegExp(/\w(\d{2,})\s/);
+
+export function isTonal(text: string): boolean {
+ return !!TONE_LETTER_REGEX.exec(text) || !!TONE_NUMBERS_REGEX.exec(text);
+}
+
+export function isLongVowel(text: string): boolean {
+ return text.includes("ː");
+}
+
+// In this order!
+export const thaiTones = {
+ "˧": "M",
+ "˨˩": "L",
+ "˦˥": "H",
+ "˥˩": "F",
+ "˩˩˦": "R",
+};
+
+export const mandarinTones = {
+ "˥˥": 1,
+ "˧˥": 2,
+ "˨˩˦": 3,
+ "˥˩": 4,
+};