Table of Contents

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

ValueTask

A ValueTask representing the asynchronous operation.

ContainKeyAsync(string)

Checks if a key exists in localStorage.

ValueTask<bool> ContainKeyAsync(string key)

Parameters

key string

The 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

key string

The 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

key string

The 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

T

The type to deserialize the stored value to.

KeyAsync(int)

Gets the key at the specified index in localStorage.

ValueTask<string?> KeyAsync(int index)

Parameters

index int

The 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

key string

The key of the item to remove.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

SetItemAsStringAsync(string, string)

Sets an item in localStorage as a raw string.

ValueTask SetItemAsStringAsync(string key, string value)

Parameters

key string

The key of the item to set.

value string

The string value to store.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

SetItemAsync<T>(string, T)

Sets an item in localStorage by serializing the value to JSON.

ValueTask SetItemAsync<T>(string key, T value)

Parameters

key string

The key of the item to set.

value T

The value to serialize and store.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

Type Parameters

T

The type of the value to store.