Class TJSLocalStorage
Hierarchy
- TJSWebStorage
- TJSLocalStorage (View Summary)
Index
Constructors
Methods
Constructors
constructor
- new TJSLocalStorage(): TJSLocalStorage
Returns TJSLocalStorage
Methods
entries
- entries<T>(regex?: RegExp): IterableIterator<[string, Writable<T>], any, any>
Type Parameters
Parameters
Optional
regex: RegExpOptional regular expression to filter by storage keys.
Returns IterableIterator<[string, Writable<T>], any, any>
Iterable iterator of keys and stores.
getItem
- getItem(key: string, defaultValue?: any): any
Get value from the storage API.
Parameters
- key: string
Key to lookup in storage API.
Optional
defaultValue: anyA default value to return if key not present in session storage.
Returns any
Value from session storage or if not defined any default value provided.
- key: string
getStore
- getStore<T>(
key: string,
defaultValue?: T,
storageStores?: StorageStores,
): Writable<T> Returns the backing Svelte store for the given key; potentially sets a default value if the key is not already set.
Type Parameters
Parameters
- key: string
Key to lookup in storage API.
Optional
defaultValue: TA default value to return if key not present in session storage.
Optional
storageStores: StorageStoresAdditional store creation options.
Returns Writable<T>
The Svelte store for this key.
- key: string
hasStore
keys
- keys(regex?: RegExp): IterableIterator<string, any, any>
Returns an iterable for the session storage keys from existing stores.
Parameters
Optional
regex: RegExpOptional regular expression to filter by storage keys.
Returns IterableIterator<string, any, any>
Iterable iterator of session storage keys.
setItem
stores
- stores<T>(regex?: RegExp): IterableIterator<Writable<T>, any, any>
Type Parameters
Parameters
Optional
regex: RegExpOptional regular expression to filter by storage keys.
Returns IterableIterator<Writable<T>, any, any>
Iterable iterator of stores.
swapItemBoolean
- swapItemBoolean(key: string, defaultValue?: boolean): boolean
Convenience method to swap a boolean value stored in storage API updating the associated store value.
Parameters
- key: string
Key to lookup in storage API.
Optional
defaultValue: booleanA default value to return if key not present in session storage.
Returns boolean
The boolean swap for the given key.
- key: string
Provides a TJSWebStorage instance for standard browser local storage use cases.