aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-02 23:37:57 -0800
committerAdam Soltys <[email protected]>2026-03-02 23:37:57 -0800
commit68684395a080a834d823b39e2e9641372bbafbfd (patch)
treed9a02ed31ef3be0fe7c274b08597271e7dac8f15 /src/lib/utils.ts
parent97fffca3e63e2edb4818305abdbcbb8953344aa3 (diff)
downloadcoinos-ui-68684395a080a834d823b39e2e9641372bbafbfd.tar.gz
coinos-ui-68684395a080a834d823b39e2e9641372bbafbfd.zip
dependency audit
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 7a4030d5..6815a5b2 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -6,12 +6,7 @@ import { sha256 } from "@noble/hashes/sha2.js";
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
import { fail as svelteFail, redirect } from "@sveltejs/kit";
import { toast } from "@zerodevx/svelte-toast";
-import {
- differenceInDays,
- differenceInHours,
- differenceInMinutes,
- differenceInSeconds,
-} from "date-fns";
+
import { get as getStore } from "svelte/store";
export function scroll(section: any) {
@@ -484,20 +479,23 @@ export const versions = {
export const str = (s) => s.toString();
-export const ago = (t) => {
- const now = new Date();
- const date = new Date(t * 1000);
- const seconds = differenceInSeconds(now, date);
- if (seconds < 60) return `${seconds}s`;
-
- const minutes = differenceInMinutes(now, date);
- if (minutes < 60) return `${minutes}m`;
+const localeTagMap: Record<string, string> = {
+ en: "en-US",
+ fa: "fa-IR",
+ zh: "zh-CN",
+ ar: "ar-SA",
+};
+export const toLocaleTag = (lang = "en") => localeTagMap[lang] || lang;
- const hours = differenceInHours(now, date);
- if (hours < 24) return `${hours}h`;
+export const formatDate = (date: Date, lang = "en", opts: Intl.DateTimeFormatOptions = {}) =>
+ new Intl.DateTimeFormat(toLocaleTag(lang), opts).format(date);
- const days = differenceInDays(now, date);
- return `${days}d`;
+export const ago = (t) => {
+ const diff = Math.floor((Date.now() - t * 1000) / 1000);
+ if (diff < 60) return `${diff}s`;
+ if (diff < 3600) return `${Math.floor(diff / 60)}m`;
+ if (diff < 86400) return `${Math.floor(diff / 3600)}h`;
+ return `${Math.floor(diff / 86400)}d`;
};
export const register = async (