refactor: clamp\storage dry

This commit is contained in:
2026-10-09 22:09:02 +05:00
parent d58f6c90be
commit 07c6475c21
15 changed files with 68 additions and 77 deletions
+2 -5
View File
@@ -2,6 +2,7 @@ import { formatStamp } from "./core/datefmt";
import type { OutputMime } from "./core/io";
import type { PixelImage } from "./core/types";
import { t } from "./i18n/t";
import { safeSetItem, storage } from "./storage";
import {
CHAIN_VERSION,
parseChain,
@@ -19,10 +20,6 @@ export interface NamedChain {
const STORE_KEY = "chains:named";
function storage(): Storage | null {
return typeof localStorage === "undefined" ? null : localStorage;
}
export function autoChainName(date = new Date()): string {
return t("savedChains.autoName", {
stamp: formatStamp(date, "YYYY-MM-DD hh:mm"),
@@ -92,7 +89,7 @@ function readAll(): NamedChain[] {
}
function writeAll(chains: NamedChain[]): void {
storage()?.setItem(STORE_KEY, JSON.stringify(serializeNamedChains(chains)));
safeSetItem(STORE_KEY, JSON.stringify(serializeNamedChains(chains)));
}
/** Newest first. */