videogen/apps/mobile/components/team/retention-format.ts
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

63 lines
2.3 KiB
TypeScript

/**
* Pure, dependency-free helpers for the workspace data-retention editor:
* formatting a retention window / timestamp for display and validating the
* free-text "days" input before it becomes a `PUT` body. These never touch the
* network and never mutate their inputs — they only shape what the editor shows
* and gate what it will submit.
*/
/** The largest retention window the editor accepts (~27 years); guards typos. */
export const MAX_RETENTION_DAYS = 10000;
/** Human-readable label for a retention window (`null` = keep forever). */
export function formatWindow(days: number | null): string {
if (days === null) return "Keep forever";
if (days === 0) return "Delete immediately (0 days)";
return `${days} day${days === 1 ? "" : "s"}`;
}
/** Render an ISO-8601 timestamp as a short local date-time, or a dash. */
export function formatTimestamp(iso: string | null): string {
if (!iso) return "—";
const parsed = new Date(iso);
if (Number.isNaN(parsed.getTime())) return iso;
return parsed.toLocaleString();
}
/** The seed text for a numeric input given a window (`null` -> empty string). */
export function daysToInput(days: number | null): string {
return days === null ? "" : String(days);
}
/** Result of validating a single free-text "days" input. */
export interface DaysInputResult {
/** The parsed non-negative integer, or `null` for keep-forever / empty. */
value: number | null;
/** A user-facing validation message, or `null` when the input is valid. */
error: string | null;
}
/**
* Validate a free-text retention-days input. An empty / whitespace value is a
* valid keep-forever (`null`). Otherwise it must be a non-negative WHOLE number
* no greater than {@link MAX_RETENTION_DAYS}; anything else yields an `error`.
*/
export function parseDaysInput(text: string): DaysInputResult {
const trimmed = text.trim();
if (trimmed.length === 0) return { value: null, error: null };
if (!/^\d+$/.test(trimmed)) {
return { value: null, error: "Enter a whole number of days, or leave blank." };
}
const value = Number(trimmed);
if (!Number.isFinite(value)) {
return { value: null, error: "Enter a whole number of days, or leave blank." };
}
if (value > MAX_RETENTION_DAYS) {
return {
value: null,
error: `Must be ${MAX_RETENTION_DAYS} days or fewer.`,
};
}
return { value, error: null };
}