ConstSet item in localStorage with validation
Storage key
Value to store
Optionalvalidator: ValidatorLike
Optional validator with validate() and sanitize() methods
Success status
// With a validator — a `{ validate?, sanitize? }` object, provided by the caller.
// ⚠️ There is NO pre-built validator on `GeoLeaf.Validators` for this role:
// this example used to cite `GeoLeaf.Validators.Theme`, which never existed
// (fixed on 27/07/2026, defect found by `typecheck-docs-examples`).
const themeValidator = {
validate: (v: unknown) => v === "light" || v === "dark",
sanitize: () => "light",
};
StorageHelper.setItem("theme", "dark", themeValidator);
// Without a validator
StorageHelper.setItem("config", JSON.stringify({ zoom: 12 }));
Get item from localStorage with validation and fallback
Storage key
Default value if key not found or invalid
Optionalvalidator: ValidatorLike
Optional validator with validate() method
Retrieved value or defaultValue
// With a validator and default value — same `{ validate?, sanitize? }` contract.
const themeValidator = { validate: (v: unknown) => v === "light" || v === "dark" };
const theme = StorageHelper.getItem("theme", "dark", themeValidator);
// Lecture simple
const config = StorageHelper.getItem("config", null);
Remove item from localStorage
Storage key
Success status
Open IndexedDB database with timeout and unified error handling
Database name
Database version
OptionalupgradeCallback: (event: IDBVersionChangeEvent) => void
Upgrade callback for onupgradeneeded
Optionaltimeout: number = 5000
Timeout in milliseconds
Validate data against schema before storing
Data to validate
Schema definition with field rules
True if valid
Validates a single schema field against data, pushing any failure messages onto
errors. Extracted from validateBeforeStore to keep that method within the
core cyclomatic-complexity budget (≤ 20). Behaviour is identical (a continue in the
former loop maps to an early return here).
Public name of the StorageHelper module: validated localStorage access (
setItem/getItem/removeItem), safe JSON round-tripping, IndexedDB opening with a timeout, and schema validation before storing.Exported under an alias so the module keeps one public name across the engine; the TSDoc lives here too, since a consumer hovering the import sees the alias, not the object it points at.