kit
    Preparing search index...
    • Utility to create a storage instance to interact with localStorage using encrypted (encoded) key/values.

      Type Parameters

      Parameters

      • config: Partial<T>
      • OptionaluseSessionStorage: boolean

      Returns {
          watch: <TKey extends string | number | symbol>(
              keyToWatch: TKey,
              onRemoved?: () => void,
              onAdded?: () => void,
          ) => () => void | undefined;
          clear(): void;
          get<TKey extends string>(
              key: TKey,
              defaultValue?: T[TKey] | null,
          ): T[TKey] | null;
          getAll(defaultValues?: Partial<T>): T;
          has<TKey extends string>(key: TKey): any;
          remove<TKey extends string>(key: TKey): void;
          set<TKey extends string>(key: TKey, value?: T[TKey]): void;
          setMany(newValues: Partial<T>): void;
      }

      • watch: <TKey extends string | number | symbol>(
            keyToWatch: TKey,
            onRemoved?: () => void,
            onAdded?: () => void,
        ) => () => void | undefined

        Watch a storage value changes, this needs to be executed only in browser context (it uses window.addEventListener("storage")).

        Inspiration from Multi Tab Logout in React — Redux

      • clear: function
        • Clear all storage values (it uses localStorage.remove()).

          Returns void

      • get: function
        • Get all storage value (it uses localStorage.get()).

          Unparseable values with JSON.parse() return their value as it is. On ssr or if the given key argument is not found defaultValue is returned, otherwise null.

          Type Parameters

          • TKey extends string

          Parameters

          • key: TKey
          • OptionaldefaultValue: T[TKey] | null

          Returns T[TKey] | null

      • getAll: function
        • Get all storage values (it uses localStorage.get()).

          undefined and null values are not returned.

          Parameters

          • OptionaldefaultValues: Partial<T>

          Returns T

      • has: function
        • Check if a storage value is truthy (it uses localStorage.get()).

          Type Parameters

          • TKey extends string

          Parameters

          • key: TKey

          Returns any

      • remove: function
        • Remove a storage value (it uses localStorage.remove()).

          Type Parameters

          • TKey extends string

          Parameters

          • key: TKey

          Returns void

      • set: function
        • Set a storage value (it uses localStorage.set()).

          Non-string values are stringified with JSON.stringify()

          Type Parameters

          • TKey extends string

          Parameters

          • key: TKey
          • Optionalvalue: T[TKey]

          Returns void

      • setMany: function
        • Set all given storage values (it uses localStorage.set()).

          Non-string values are stringified with JSON.stringify(), undefined and null values are removed from the storage

          Parameters

          • newValues: Partial<T>

          Returns void