/**
 * @param name
 * @param value
 * @param path
 * @param duration
 */
export function writeCookie(name, value, path, duration) {
  var cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);

  if (path) {
    cookie += '; path=' + path;
  }

  if (duration) {
    var date = new Date();
    date.setTime(date.getTime() + duration * 24 * 60 * 60 * 1000);
    cookie += '; expires=' + date.toUTCString();
  }

  document.cookie = cookie;
}
/**
 * @param name
 * @return {*}
 */

export function readCookie(name) {
  var value = document.cookie.match(new RegExp('(?:^|;)\\s*' + name + '=([^;]*)'));
  return value ? decodeURIComponent(value[1]) : null;
}