global: opreturn part 4

This commit is contained in:
nym21
2026-07-19 09:34:03 +02:00
parent 5161ae2012
commit 0fc61d7932
19 changed files with 510 additions and 108 deletions
+26
View File
@@ -3,6 +3,15 @@ export const HALVING_EPOCH_BLOCKS = 210_000;
export const MAX_BLOCK_WEIGHT = 4_000_000;
const RELATIVE_TIME = new Intl.RelativeTimeFormat(undefined);
const RELATIVE_UNITS = /** @type {const} */ ([
["year", 31_557_600],
["month", 2_629_800],
["day", 86_400],
["hour", 3_600],
["minute", 60],
]);
/** @param {number} value */
export function formatNumber(value) {
return value.toLocaleString();
@@ -22,6 +31,23 @@ export function formatDateTime(unixSeconds) {
});
}
/** @param {number} unixSeconds */
export function formatDateAndAge(unixSeconds) {
const date = new Date(unixSeconds * 1_000).toLocaleDateString(undefined, {
dateStyle: "medium",
});
const difference = unixSeconds - Date.now() / 1_000;
const absolute = Math.abs(difference);
if (absolute < 60) return `${date} · just now`;
const [unit, seconds] = RELATIVE_UNITS.find(([, duration]) => {
return absolute >= duration;
}) ?? RELATIVE_UNITS.at(-1);
return `${date} · ${RELATIVE_TIME.format(Math.trunc(difference / seconds), unit)}`;
}
/** @param {number} bytes */
export function formatBytes(bytes) {
return bytes >= 1_000_000