{"size": 803, "ext": "js", "max_stars_repo_path": "src/lib/cookie-util.js", "max_stars_repo_name": "Emolyze/sdconnect-chat-public", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/cookie-util.js", "max_issues_repo_name": "Emolyze/sdconnect-chat-public", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/cookie-util.js", "max_forks_repo_name": "Emolyze/sdconnect-chat-public", "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": 25.09375, "max_line_length": 78, "alphanum_fraction": 0.6861768369}
// Helper functions for storing values in localStorage.
// By default localStorage can store only strings, not objects or other types.

import Cookies from "js-cookie";

export const AUTH_TOKEN_NAME = "auth-token";

export default class CookieUtil {
  // Replace old object with the new one.
  static setObject(key, value) {
    Cookies.set(key, JSON.stringify(value));
  }

  // Get stored object.
  static getObject(key) {
    const value = Cookies.get(key);
    if (!value) return false;
    return value && JSON.parse(value);
  }

  // Partially or wholly update stored object.
  static updateObject(key, value) {
    const oldVal = this.getObject(key);
    this.setObject(key, Object.assign(oldVal || {}, value));
  }

  // Just a wrapper.
  static removeItem(key) {
    Cookies.remove(key);
  }
}
