{"size": 983, "ext": "js", "max_stars_repo_path": "src/server.js", "max_stars_repo_name": "gregorysl/date-minder", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/server.js", "max_issues_repo_name": "gregorysl/date-minder", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/server.js", "max_forks_repo_name": "gregorysl/date-minder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.8604651163, "max_line_length": 61, "alphanum_fraction": 0.4628687691}
const db = function () {
    let localData = JSON.parse(localStorage.getItem("data"));
    return localData || { index: 0, items: [] };
};
const save = function (data) {
    localStorage.setItem("data", JSON.stringify(data));
};
let server = {
    add(item) {
        const data = db();
        item.id = data.index;
        data.index++;
        data.items.push(item);
        save(data);
        return data;
    },
    update(item) {
        const id = item.id;
        const data = db();
        for (let i in data.items) {
            if (data.items[i].id == id) {
                data.items[id] = item;
            }
        }
        save(data);
        return data;
    },
    delete(id) {
        const data = db();
        for (let i in data.items) {
            if (data.items[i].id == id) {
                delete data.items[id];
            }
        }
        save(data);
        return data;
    },
    getData() {
        return db();
    }
};

export default server;