UNPKG

@empathyco/x-storage-service

Version:
61 lines 1.59 kB
/** * In memory implementation of the storage service. * * @public */ var InMemoryStorageService = /** @class */ (function () { function InMemoryStorageService() { this.storage = {}; } /** * Adds a new item in the storage. * * @param key - The key of the item. * @param item - The item to save. * * @public */ InMemoryStorageService.prototype.setItem = function (key, item) { this.storage[key] = item; }; /** * Retrieves an item by its key. * * @param key - The key of the item. * @returns The founded item or null. * * @public */ InMemoryStorageService.prototype.getItem = function (key) { var _a; return (_a = this.storage[key]) !== null && _a !== void 0 ? _a : null; }; /** * Removes an item by its key. * * @param key - The key of the item. * @returns The removed item or null. * * @public */ InMemoryStorageService.prototype.removeItem = function (key) { var item = this.storage[key]; delete this.storage[key]; return item; }; /** * Clears the storage.. * * @returns The number of removed items. * * @public */ InMemoryStorageService.prototype.clear = function () { var numberOfRemovedItems = Object.keys(this.storage).length; this.storage = {}; return numberOfRemovedItems; }; return InMemoryStorageService; }()); export { InMemoryStorageService }; //# sourceMappingURL=in-memory-storage-service.js.map