hedera-web/js/vn/cookie.js

64 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

/**
* Brownser cookie handler.
2022-05-26 06:08:31 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports =
{
set: function(key, value, days) {
var strCookie = key + '=' + value + ';';
if (days != undefined) {
var date = Date.vnNew();
date.setTime(date.getTime() + days * 86400000);
strCookie += 'expires=' + date.toGMTString();
}
document.cookie = strCookie;
}
,unset: function(key) {
this.set(key, '', -1);
}
,get: function(key) {
var cookie = new String(document.cookie);
var start = cookie.indexOf(key + '=');
if (start != -1) {
var end;
start += key.length + 1;
end = cookie.indexOf(';', start);
if (end > 0)
return cookie.substring(start, end);
else
return cookie.substring(start);
}
return null;
}
,getInt: function(key) {
var value = this.get(key);
if (value != null)
return parseInt(value);
return null;
}
,getFloat: function(key) {
var value = this.get(key);
if (value != null)
return parseFloat(value);
return null;
}
,check: function(key) {
return this.get(key) != null;
}
};