GeoLeaf Core API - v3.0.0
    Preparing search index...
    StorageHelperModule: {
        setItem(key: string, value: unknown, validator?: ValidatorLike): boolean;
        getItem(
            key: string,
            defaultValue: unknown,
            validator?: ValidatorLike,
        ): unknown;
        removeItem(key: string): boolean;
        parseJSON(json: string | null | undefined, defaultValue: unknown): unknown;
        stringifyJSON(data: unknown, defaultValue?: string): string;
        openDatabase(
            name: string,
            version: number,
            upgradeCallback?: (event: IDBVersionChangeEvent) => void,
            timeout?: number,
        ): Promise<IDBDatabase>;
        validateBeforeStore(
            data: Record<string, unknown>,
            schema: Record<string, SchemaRules>,
        ): boolean;
        _validateField(
            key: string,
            rules: SchemaRules,
            data: Record<string, unknown>,
            errors: string[],
        ): void;
    } = StorageHelper

    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.

    Type Declaration

    • setItem: function
      • Set item in localStorage with validation

        Parameters

        • key: string

          Storage key

        • value: unknown

          Value to store

        • Optionalvalidator: ValidatorLike

          Optional validator with validate() and sanitize() methods

        Returns boolean

        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 }));
    • getItem: function
      • Get item from localStorage with validation and fallback

        Parameters

        • key: string

          Storage key

        • defaultValue: unknown

          Default value if key not found or invalid

        • Optionalvalidator: ValidatorLike

          Optional validator with validate() method

        Returns unknown

        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);
    • removeItem: function
    • parseJSON: function
      • Parse JSON safely with fallback

        Parameters

        • json: string | null | undefined

          JSON string to parse

        • defaultValue: unknown

          Default value if parsing fails

        Returns unknown

        Parsed object or defaultValue

        const config = StorageHelper.parseJSON(stored, { theme: 'dark' });
        
    • stringifyJSON: function
      • Stringify JSON safely

        Parameters

        • data: unknown

          Data to stringify

        • OptionaldefaultValue: string = "null"

          Default value if stringifying fails

        Returns string

        JSON string or defaultValue

        const json = StorageHelper.stringifyJSON({ theme: 'dark' });
        
    • openDatabase: function
      • Open IndexedDB database with timeout and unified error handling

        Parameters

        • name: string

          Database name

        • version: number

          Database version

        • OptionalupgradeCallback: (event: IDBVersionChangeEvent) => void

          Upgrade callback for onupgradeneeded

        • Optionaltimeout: number = 5000

          Timeout in milliseconds

        Returns Promise<IDBDatabase>

        const db = await StorageHelper.openDatabase('geoleaf-db', 2, (event) => {
        const db = event.target.result;
        if (!db.objectStoreNames.contains('layers')) {
        db.createObjectStore('layers', { keyPath: 'id' });
        }
        });
    • validateBeforeStore: function
      • Validate data against schema before storing

        Parameters

        • data: Record<string, unknown>

          Data to validate

        • schema: Record<string, SchemaRules>

          Schema definition with field rules

        Returns boolean

        True if valid

        Validation error with details

        const schema = {
        id: { type: 'string', required: true },
        data: { type: 'object', required: true }
        };
        StorageHelper.validateBeforeStore(layer, schema);
    • _validateField: function
      • 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).

        Parameters

        • key: string
        • rules: SchemaRules
        • data: Record<string, unknown>
        • errors: string[]

        Returns void