ConstSet item in localStorage with validation
Storage key
Value to store
Optionalvalidator: ValidatorLikeOptional validator with validate() and sanitize() methods
Success status
// Avec validateur — un objet `{ validate?, sanitize? }`, fourni par l'appelant.
// ⚠️ Il n'existe PAS de validateur pré-fabriqué sur `GeoLeaf.Validators` pour ce
// rôle : cet exemple citait `GeoLeaf.Validators.Theme`, qui n'a jamais existé
// (corrigé le 27/07/2026, défaut trouvé par `typecheck-docs-examples`).
const themeValidator = {
validate: (v: unknown) => v === "light" || v === "dark",
sanitize: () => "light",
};
StorageHelper.setItem("theme", "dark", themeValidator);
// Sans validateur
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: ValidatorLikeOptional validator with validate() method
Retrieved value or defaultValue
// Avec validateur et valeur par défaut — même contrat `{ validate?, sanitize? }`.
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) => voidUpgrade callback for onupgradeneeded
Optionaltimeout: number = 5000Timeout 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.