Repository URL to install this package:
|
Version:
2.0.1 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
var storage = {
/**
* Reads a cookie and returns its value. Defaults to undefined.
* @param {string} key The key of the cookie to retrieve
* @param {() -> string} [options.getCookie] An optional function used to read the cookie. `document.cookie` will be used otherwise.
* @returns {string|undefined}
*/
getCookie: function getCookie(key) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var cookies = (options.getCookie && options.getCookie() || document.cookie).split('; ');
return cookies.reduce(function (result, cookie) {
var searchKey = "".concat(key, "=");
if (cookie.indexOf(searchKey) === 0) {
return cookie.substring(searchKey.length);
}
return result;
}, undefined);
},
/**
* @param {string} token The token value
* @param {string} domain The domain in which to set the cookie
*/
setCookie: function setCookie(key, value, expirationInDays, domain) {
var cookie = "".concat(key, "=").concat(value, ";path=/");
if (expirationInDays) {
var expires = new Date(new Date().getTime() + ONE_DAY_IN_MILLIS * expirationInDays);
cookie += ";expires=".concat(expires.toUTCString(), ")");
}
if (domain) {
cookie += ";domain=".concat(encodeURIComponent(domain));
}
document.cookie = cookie;
}
};
var _default = storage;
exports["default"] = _default;