"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cache = exports.SEPARATOR = void 0;
exports.getKey = getKey;
exports.setItem = setItem;
exports.getItem = getItem;
exports.getAll = getAll;
exports.SEPARATOR = '/';
function getKey(path) {
    const key = path.map(btoa).join(exports.SEPARATOR);
    return key;
}
function setItem(path, value) {
    const key = getKey(path);
    const item = JSON.stringify(value);
    localStorage.setItem(key, item);
}
function getItem(path) {
    const key = getKey(path);
    const item = localStorage.getItem(key);
    if (item !== undefined && item !== null) {
        return JSON.parse(item);
    }
    else {
        return null;
    }
}
function getAll(id) {
    const all = {};
    const start = `${btoa(id)}/`;
    const startLength = start.length;
    for (let i = 0; i < localStorage.length; i++) {
        const key = localStorage.key(i);
        if (key && key.startsWith(start)) {
            const item = localStorage.getItem(key);
            const k = key.slice(startLength);
            if (item) {
                all[atob(k)] = JSON.parse(item);
            }
        }
    }
    return all;
}
class Cache {
    constructor(id) {
        this._key = (path) => {
            return [this._id].concat([path]);
        };
        this._id = id;
    }
    getItem(path) {
        return getItem(this._key(path));
    }
    setItem(path, value) {
        return setItem(this._key(path), value);
    }
    getAll() {
        return getAll(this._id);
    }
}
exports.Cache = Cache;
//# sourceMappingURL=cache.js.map