Something went wrong. Try again.
atmosphere explorer pds.ls
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566export const formatFileSize = (bytes: number): string => { if (bytes === 0) return "0 B"; const k = 1024; const sizes = ["B", "KiB", "MiB", "GiB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${(bytes / Math.pow(k, i)).toFixed(i === 0 ? 0 : 1)} ${sizes[i]}`;};
/** * A size limit in decimal units, e.g. a lexicon's maxSize of 1000000 as "1 MB": limits are set * in round thousands, which binary units would turn into "976.6 KiB". */export const formatSizeLimit = (bytes: number) => bytes >= 1_000_000 ? `${+(bytes / 1_000_000).toFixed(1)} MB` : bytes >= 1000 ? `${+(bytes / 1000).toFixed(1)} kB` : `${bytes} B`;
export const localDateFromTimestamp = (timestamp: number) => new Date(timestamp - new Date().getTimezoneOffset() * 60 * 1000) .toISOString() .split(".")[0] .replace("T", " ");
const RELATIVE_UNITS: [Intl.RelativeTimeFormatUnit, number][] = [ ["year", 365 * 24 * 60 * 60 * 1000], ["month", 30 * 24 * 60 * 60 * 1000], ["week", 7 * 24 * 60 * 60 * 1000], ["day", 24 * 60 * 60 * 1000], ["hour", 60 * 60 * 1000], ["minute", 60 * 1000],];
const relativeTimeFormat = new Intl.RelativeTimeFormat("en", { numeric: "always" });
/** * How far a time is from now, in its largest whole unit: "3 days ago" for the past, or * "in 3 days" for the future. */export const relativeTimeFromTimestamp = (timestamp: number) => { const elapsed = Date.now() - timestamp; const distance = Math.abs(elapsed); for (const [unit, ms] of RELATIVE_UNITS) { if (distance >= ms) { const count = Math.floor(distance / ms); return relativeTimeFormat.format(elapsed >= 0 ? -count : count, unit); } } return "just now";};
/** * A copy of a JSON value with each object's keys in alphabetical order, as PDS implementations * return them in different orders. `$type` sorts first, since `$` comes before letters and digits. */export const sortKeys = <T>(value: T): T => { if (Array.isArray(value)) return value.map(sortKeys) as T; if (value === null || typeof value !== "object") return value; return Object.fromEntries( Object.keys(value) .sort() .map((key) => [key, sortKeys((value as Record<string, unknown>)[key])]), ) as T;};