(() => {
if (!String.prototype.includes) {
String.prototype.includes = function (str) {
return this.indexOf(str) > -1
}
}
})();
function Cookie(key, value, options) {
if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
options = options || {};
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
let days = options.expires,
t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
document.cookie = [encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join('');
return;
}
options = value || {};
let decode = options.raw ? function (s) {
return s;
} : decodeURIComponent;
let pairs = document.cookie.split('; ');
for (let i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
if (decode(pair[0]) === key)
return decode(pair[1] || '');
}
}
Cookie('name', value , {path: '/'});
Cookie('name')
sessionStorage.setItem('name', value);
sessionStorage.setItem('name', JSON.stringify(obj));
sessionStorage.getItem('name');
JSON.parse(sessionStorage.getItem('name'));