function getCookie(name, _document = document) {
  const match = _document.cookie.match(new RegExp(`(^|;\\s*)(${name})=([^;]*)`));
  return match ? decodeURIComponent(match[3]) : null;
}
@param {string} name the cookie name
@param {Document | { cookie: string }} _document overwriteable for testing
@returns {string | null}