@sebgroup/frontend-tools
Version:
A set of frontend tools
51 lines (50 loc) • 1.75 kB
TypeScript
export interface SetItemOptions {
/** Expiration Date */
expires?: Date;
/** Maximum age in seconds */
maxAge?: number;
}
/**
* CookieStorage is a handler for reading and writing cookies in Javascript
* Usage is similar to `localStorage` and `sessionStorage`
*/
export declare class CookieStorage implements Storage {
get length(): number;
/**
* Retrieve an item from the stored cookie
* @param key The key of the cookie to be retrieved
* @returns The value of the cookie, `null` if it doesn't exist
*/
getItem(key: string): string;
/**
* Sets an item to the stored cookie
* @param key The key of the cookie to be set
* @param value The value of the cookie
* @param options Available options are `expires`, `maxAge` and `secure` @see SetItemOptions interface for reference
* @returns `true` if successful
*/
setItem(key: string, value: any, options?: SetItemOptions): boolean;
/**
* Remove an item from the stored cookie
* @param {string} key The key of the cookie to be removed
* @returns {boolean} `true` if successful
*/
removeItem(key: string): boolean;
/**
* Verifies if an item exists in the cookie
* @param {string} key The key of the item to be verified
* @returns {boolean} `true` if it exists
*/
hasItem(key: string): boolean;
clear(): void;
/**
* Retrives the list of keys in the stored cookie
* @returns The list of keys in the stored cookie
*/
keys(): Array<string>;
/**
* @param index The index of the array of keys
* @returns The key at the given index, if any
*/
key(index: number): string;
}