UNPKG

angular-webstorage-service

Version:
48 lines (47 loc) 2.66 kB
import { StorageService } from './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 implements StorageService { private 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); /** * Retrieves the value stored for the entry that is associated with the specified key. If no such entry exists or if the service for * some reason is unable to fetch the value of the entry then `null` will be returned. * * @param key Identifier of the entry whose value is to be retrieved. * @returns Value of the entry that is identified by the specified key or `null` if the entry does not exist or cannot be loaded. */ get(key: string): any; /** * Creates or updates the entry identified by the specified key with the given value. Storing a value into the storage service will * ensure that an equivalent of the value can be read back, i.e. the data and structure of the value will be the same. It, however, does * not necessarily return the same value, i.e. the same reference. * * @param key Identifier of the entry which is to be created or updated. * @param value Value which is to be stored. */ set(key: string, value: any): void; /** * 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 `null`. * * @param key Identifier of the entry which is to be removed. */ remove(key: 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. */ export declare function isStorageAvailable(storage: Storage): boolean;