Interface ILocalStorageService
- Namespace
- NuvTools.AspNetCore.Blazor.JSInterop
- Assembly
- NuvTools.AspNetCore.Blazor.dll
Provides JavaScript interop functionality for browser localStorage operations.
public interface ILocalStorageService
Methods
ClearAsync()
Clears all items from localStorage.
ValueTask ClearAsync()
Returns
ContainKeyAsync(string)
Checks if a key exists in localStorage.
ValueTask<bool> ContainKeyAsync(string key)
Parameters
keystringThe key to check for existence.
Returns
- ValueTask<bool>
A ValueTask<TResult> representing the asynchronous operation, containing true if the key exists, otherwise false.
GetItemAsStringAsync(string)
Gets an item from localStorage as a raw string.
ValueTask<string?> GetItemAsStringAsync(string key)
Parameters
keystringThe key of the item to retrieve.
Returns
- ValueTask<string>
A ValueTask<TResult> representing the asynchronous operation, containing the stored string value or null if not found.
GetItemAsync<T>(string)
Gets an item from localStorage and deserializes it from JSON.
ValueTask<T?> GetItemAsync<T>(string key)
Parameters
keystringThe key of the item to retrieve.
Returns
- ValueTask<T>
A ValueTask<TResult> representing the asynchronous operation, containing the deserialized value or default if not found.
Type Parameters
TThe type to deserialize the stored value to.
KeyAsync(int)
Gets the key at the specified index in localStorage.
ValueTask<string?> KeyAsync(int index)
Parameters
indexintThe zero-based index of the key to retrieve.
Returns
- ValueTask<string>
A ValueTask<TResult> representing the asynchronous operation, containing the key at the specified index or null if the index is out of range.
LengthAsync()
Gets the number of items stored in localStorage.
ValueTask<int> LengthAsync()
Returns
- ValueTask<int>
A ValueTask<TResult> representing the asynchronous operation, containing the number of stored items.
RemoveItemAsync(string)
Removes an item from localStorage.
ValueTask RemoveItemAsync(string key)
Parameters
keystringThe key of the item to remove.
Returns
SetItemAsStringAsync(string, string)
Sets an item in localStorage as a raw string.
ValueTask SetItemAsStringAsync(string key, string value)
Parameters
Returns
SetItemAsync<T>(string, T)
Sets an item in localStorage by serializing the value to JSON.
ValueTask SetItemAsync<T>(string key, T value)
Parameters
keystringThe key of the item to set.
valueTThe value to serialize and store.
Returns
Type Parameters
TThe type of the value to store.