simple-storage-tools
Version:
a library for projects that allow you to work with local and session storage in typescript
67 lines (66 loc) • 3.52 kB
TypeScript
export declare class Storage {
/**
* this method will look for a storage with the key name of storage.
* @author Seyed Ali Roshan
* @param key the string name of your storage.
* @param fromLocalStorage default value is `false`. if true, will look
* in localStorage instead of SessionStorage.
* by default it's false because the main setter method (next method)
* store the values in `sessionStorage` by default.
* @param toJson default value is `true`. if true, automatically cast
* and return JSON object. if put it to true and your storage is not
* in JSON shape, it will return what it finds as an string.
* @param throwOnNotFound default value is `false`. if true, it will
* throw an Exception with `-1` message if it wont found the storage
* with given name and enviroment (local or session Storage).
* @returns an string or a JSON Object depend on `toJson` parameter.
* it will return null or an Exception with `-1` message depend on
* `throwOnNotFound` parameter if there is no localStorage founds.
*/
static get(key: string, fromLocalStorage?: boolean, toJson?: boolean, throwOnNotFound?: boolean): string | any | null;
/**
* this method will store an input value in a storage with the given
* name as its key.
* @author Seyed Ali Roshan
* @param key the string name that you want your storage created with.
* @param str the Object you want it to be stored.
* it should be in string or JSON Object. if you don't put JSON Object
* (nor string), it will put the string of your Object by `toString()`
* method.
* @param inLocalStorage default value is `false`. if true, your input
* will store in a localStorage instead of SessionStorage.
* by default it's false because `localStorage` has store limits and
* you should store things you want access to in all the tabs of your
* application for example user Token whcih needed by API every time.
* @param fromJson default value is `true`. if true, you are telling it,
* my input Object is a JSON Object and it will automatically cast your
* input Object to string. if put it on true and your input is not a
* JSON Object (for example a number), it throws an Exception.
* @param ignoreJsonException default value is `true`. if true it will
* ignore any error that casting to JSON is caused and store the string
* of your Object by using `toString()` method.
*/
static set(key: string, str: string | any, inLocalStorage?: boolean, fromJson?: boolean, ignoreJsonException?: boolean): void;
/**
* this method will remove a storage.
* @author Seyed Ali Roshan
* @param key the string name of your storage.
* @param fromLocalStorage default value is `false`. if true, will look
* in localStorage instead of SessionStorage.
*/
static remove(key: string, fromLocalStorage?: boolean): void;
/**
* this method will remove all storages in an storage enviroments
* (local or session storage)
* @author Seyed Ali Roshan
* @param local default value is `false`. if true, it's clear localStorage
* enviroment instead of sessionStorage.
*/
static clear(local?: boolean): void;
/**
* this method will remove all storages from all storage enviroments
* (both local and session Storage).
* @author Seyed Ali Roshan
*/
static clearAll(): void;
}