mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
refactor: clamp\storage dry
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user