summaryrefslogtreecommitdiff
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-05-15 04:37:12 +0700
committerpolwex <polwex@sortug.com>2025-05-15 04:37:12 +0700
commitdf7ffaf4cb722890ca3159c3839c61552f7195d3 (patch)
treec87b7e5e7556f370cfb8ea5486c36aabcd8c8d3b /src/lib/utils.ts
all working now...
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
new file mode 100644
index 0000000..113c874
--- /dev/null
+++ b/src/lib/utils.ts
@@ -0,0 +1,51 @@
+import { type ClassValue, clsx } from "clsx";
+import { twMerge } from "tailwind-merge";
+import type { Result } from "@/lib/types";
+
+export function cn(...inputs: ClassValue[]) {
+ return twMerge(clsx(inputs));
+}
+
+export function wordFactorial(words: string[]): Set<string> {
+ const combinations: Set<string> = new Set([]);
+ for (let i = 0; i < words.length; i++) {
+ let inner = "";
+ for (let ii = i; ii < words.length; ii++) {
+ inner += (ii > i ? " " : "") + words[ii]!.toLowerCase();
+ combinations.add(inner);
+ }
+ }
+ return combinations;
+}
+
+export function getSyllableCount(ipa: string): number {
+ const syllables = ipa
+ .replace(/\//g, "")
+ .split(/[ˌ\.ˈ]/)
+ .filter(Boolean);
+ return syllables.length;
+}
+export function getStressedSyllable(ipa: string): Result<number> {
+ const split = ipa.replace(/\//g, "").split(/ˈ/);
+ if (split.length === 1) {
+ if (getSyllableCount(ipa) === 1) return { ok: 1 };
+ else return { error: "No stress mark" };
+ }
+ const preSplit = split[0];
+ if (!preSplit) return { ok: 1 };
+ else {
+ const pp = preSplit.split(/[ˌ\.]/g);
+ return { ok: pp.length + 1 };
+ }
+}
+
+export function getDBOffset(page: number, pageSize: number) {
+ return (page - 1) * pageSize;
+}
+
+export function handlePromise<T>(
+ settlement: PromiseSettledResult<T>,
+): T | string {
+ if (settlement.status === "fulfilled") return settlement.value;
+ else return `${settlement.reason}`;
+}