ngx-webstorage-service
Version:
Angular service wrappers for the webstorage API
74 lines (73 loc) • 3.91 kB
TypeScript
import { BaseStorageService } from './base-storage.service';
/**
* An implementation of `StorageService` interface that uses an underlying (web) `Storage` object, such as `localStorage` and
* `sessionStorage`, as backing data store. This class basically wraps the `Storage` object so it can be accessed through the
* `StorageService` interface.
*/
export declare class WebStorageService extends BaseStorageService<any> {
private readonly storage;
/**
* Creates a new `WebStorageService` instance that uses the specified (web) storage object as underlying backing storage.
*
* @param storage Storage object which is to be wrapped in a class that implements the `StorageService` interface.
*/
constructor(storage: Storage);
/**
* Checks whether an entry with the specified key exists in the storage.
*
* @param key Identifier of the entry for which its presence in the storage is to be checked.
* @returns `true` if an entry with the specified key exists in the storage, `false` if not.
*/
has(key: string): boolean;
/**
* Removes the entry that is identified by the specified key. Attempting to remove an entry for an unknown key will have no effect.
* Attempting to retrieve an entry via the `get` method after it has been removed will result in `undefined`.
*
* @param key Identifier of the entry which is to be removed.
*/
remove(key: string): void;
/**
* Clears the storage by removing all entries. Subsequent `get(x)` calls for a key *x* will return `undefined`, until a new value is set
* for key *x*.
*/
clear(): void;
/**
* Performs the actual retrieval of a value from storage.
*
* @param key Identifier of the entry whose value is to be retrieved.
* @returns The value that is stored for the specified entry or `undefined` if no entry exists for the specified key.
*/
protected getItem(key: string): string | undefined;
/**
* Stores the provided value using specified key in the storage.
*
* @param key Identifier of the entry for which the value is to be stored.
* @param value The value that is to be stored.
*/
protected setItem(key: string, value: string): void;
}
/**
* Checks whether the specified (web) storage is available and functional. This might not be the case for older browsers. However even
* certain browsers that do support the web storage API can, under some circumstances, have non functional storage objects. For example,
* Safari is known to have `localStorage` and `sessionStorage` throw exceptions in private mode.
*
* @param storage Storage object which is to be tested for availability.
* @returns `true` if the specified storage can be used, `false` if not.
*/
export declare function isStorageAvailable(storage: Storage): boolean;
/**
* Checks whether session storage is available and functional. This might not be the case for older browsers. However even certain browsers
* that do support the web storage API can, under some circumstances, have non functional storage objects. For example, Safari is known to
* have `sessionStorage` throw exceptions in private mode.
*
* @returns `true` if session storage can be used, `false` if not.
*/
export declare function isSessionStorageAvailable(): boolean;
/**
* Checks whether local storage is available and functional. This might not be the case for older browsers. However even certain browsers
* that do support the web storage API can, under some circumstances, have non functional storage objects. For example, Safari is known to
* have `localStorage` throw exceptions in private mode.
*
* @returns `true` if local storage can be used, `false` if not.
*/
export declare function isLocalStorageAvailable(): boolean;