UNPKG

1.22 kBJavaScriptView Raw
1"use strict";
2/**
3 Shares the same API as a native browser's localStorage but uses in-memory cache
4 instead of fs.
5 */
6Object.defineProperty(exports, "__esModule", { value: true });
7var LocalCache = /** @class */ (function () {
8 function LocalCache() {
9 this.cache = {};
10 }
11 LocalCache.prototype.getItem = function (key) {
12 if (this.cache.hasOwnProperty(key)) {
13 return this.cache[key];
14 }
15 return null;
16 };
17 LocalCache.prototype.setItem = function (key, value) {
18 this.cache[key] = value;
19 };
20 LocalCache.prototype.removeItem = function (key) {
21 delete this.cache[key];
22 };
23 LocalCache.prototype.key = function (n) {
24 return Object.keys(this.cache)[n];
25 };
26 LocalCache.prototype.clear = function () {
27 Object.keys(this.cache).forEach(function (key) {
28 delete this.cache[key];
29 });
30 };
31 Object.defineProperty(LocalCache.prototype, "length", {
32 get: function () {
33 return Object.keys(this.cache).length;
34 },
35 enumerable: true,
36 configurable: true
37 });
38 return LocalCache;
39}());
40exports.LocalCache = LocalCache;
41//# sourceMappingURL=local-cache.js.map
\No newline at end of file