webstorage-decorators/lib/webstorage.d.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-01-28 10:24:11 -05:00
/**
* Options to be used with WebStorage decorators
*/
export interface WebStorageOptions {
/** Default value to provide if storage is empty */
default?: any;
2021-01-28 13:15:46 -05:00
/** Key to prevent plain text storage **/
encryptWith?: string;
2021-01-28 10:24:11 -05:00
/** Key to save under */
key?: string;
}
/**
* Automatically syncs localStorage with the decorated property.
*
* **Example**
* ```
* class Example {
* @LocalStorage() lastLogin: string;
* @LocalStorage(false, {key: '_hideMenu'}) hideMenu: boolean;
* }
* ```
*
* @param defaultValue Default value to return if property does no exist inside localStorage.
* @param opts Any additional options
*/
export declare function LocalStorage(defaultValue?: any, opts?: WebStorageOptions): (target: object, key: string) => void;
/**
* Automatically syncs sessionStorage with the decorated property.
*
* **Example**
* ```
* class Example {
* @SessionStorage() lastLogin: string;
* @SessionStorage(false, {key: '_hideMenu'}) hideMenu: boolean;
* }
* ```
*
* @param defaultValue Default value to return if property does no exist inside sessionStorage.
* @param opts Any additional options
*/
export declare function SessionStorage(defaultValue?: any, opts?: WebStorageOptions): (target: object, key: string) => void;