UNPKG

persistent-storage

Version:

Abstracts access to any storage object implementing the webstorage Storage interface, offering optional compression using lz-string and optional encryption using crypto

58 lines (57 loc) 1.68 kB
/// <reference types="node" /> import I = require('./interfaces'); /** * Constructs a new PersistentStorage instead * @param opts * @param {boolean=false} opts.useCompression * @param {string=} opts.keyPrefix * @param opts.storageBackend * @constructor */ declare class PersistentStorage { private config; private store; private cache; constructor(opts: I.Config); static generateSalt(lengthBytes: number): string; static generateIV(lengthBytes: number): Buffer; readonly length: number; /** * Sets a value in the persistent storage * @param {string} key - Key to associate this value with * @param {*} value - Value to store, if undefined will delete the given key */ setItem(key: string, value: any): void; /** * Gets a value from the persistant storage, uses in memory cache if possible * @param {string} key - Key to retrieve * @returns {*} */ getItem(key: string): any; /** * Gets the nth key in the store, note that the order of keys is not guaranteed but * will be consistent so long as the key set stays the same. * @param {number} n * @returns {string} */ key(n: number): string; /** * Gets an array of the keys in the store * @returns {string[]} */ keys(): string[]; /** * Removes an item from the store * @param {string} key */ removeItem(key: string): void; /** * Clears all items from the store */ clear(): void; /** * Clears all items from the cache */ purgeCache(): void; } export = PersistentStorage;