UNPKG

built.io-browserify

Version:

SDK for Built.io Backend which is compatible with Browserify

27 lines (22 loc) 879 B
var setCookie = module.exports.set = function(cname, cvalue) { document.cookie = cname + "=" + cvalue + ";domain=" + getDomainParameter() + ";path=/"; } module.exports.delete = function(cname) { setCookie(cname, ""); } module.exports.get = function(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1); if (c.indexOf(name) != -1) return c.substring(name.length, c.length); } return ""; } function getDomainParameter() { // var ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/ if (window.location.host.match('localhost') /* || window.location.host.match(ipRegex)*/ ) return '' return "." + window.location.host }