@binance/fingerprint
Version:
binance web fingerprint
55 lines (54 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.deleteCookie = exports.getCookie = exports.setCookie = void 0;
var _getSubDomain = function() {
var hostname = window.location.hostname;
var hns = hostname.split(".");
hns[0] = "";
return hns.join(".");
};
var setCookie = function(name, value) {
var days = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 365, withSubDomain = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
if (typeof document === "undefined") return;
var date = new Date();
var expires;
if (days) {
// eslint-disable-next-line no-mixed-operators
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
// @ts-ignore
expires = "; expires=".concat(date.toGMTString());
} else {
expires = "";
}
var domain = withSubDomain ? "; domain=".concat(_getSubDomain()) : "";
document.cookie = "".concat(name, "=").concat(value).concat(expires).concat(domain, "; path=/; secure=true;");
};
exports.setCookie = setCookie;
var getCookie = function(name) {
var ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _cookie = ref.cookie, cookie = _cookie === void 0 ? "" : _cookie;
var cookieStr = "";
if (typeof document === "undefined") {
cookieStr = cookie;
} else {
cookieStr = document.cookie;
}
var nameEQ = "".concat(name, "=");
var ca = cookieStr.split(";");
for(var i = 0; i < ca.length; i++){
var c = ca[i];
while(c.charAt(0) === " "){
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
};
exports.getCookie = getCookie;
var deleteCookie = function(name) {
setCookie(name, "", -1, false);
};
exports.deleteCookie = deleteCookie;