-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcookiet.min.js
1 lines (1 loc) · 2.43 KB
/
cookiet.min.js
1
!function(e,t){"use strict";function n(e){return encodeURIComponent(e)}function i(e){return decodeURIComponent(e)}function r(e){return e instanceof Array}var o={read:function(t){var n=t.name;if(n){var r=e.cookie.split(n+"=");return 2===r.length?i(r.pop().split(";").shift()):void 0}},create:function(t){if(t.name=t.name||!1,t.value=t.value||"",t.expires=t.expires||!1,t.path=t.path||"/",t.name){var i=n(t.name)+"="+n(t.value)+";",r="path="+t.path+";",o=t.domain?"domain="+t.domain+";":"",a=t.secure?"secure;":"",s=t.httpOnly?"httpOnly;":"",u="";return t.expires&&(t.expires=new Date((new Date).getTime()+1e3*parseInt(t.expires,10)*60*60*24),u="expires="+t.expires.toUTCString()+";"),e.cookie=i+u+r+o+a+s,!0}return!1},keys:function(){var t=[],n=e.cookie?e.cookie.split("; "):[],r=n.length;if(!n)return n;for(;r--;){var o=n[r].split("=");t.push(i(o[0]))}return t},values:function(){var t=[],n=e.cookie?e.cookie.split("; "):[],r=n.length;if(!n)return n;for(;r--;){var o=n[r].split("=");t.push(i(o[1]))}return t},exists:function(e){if(e&&e.name)return!!this.read(e)},listAsString:function(){var t,n="",r=e.cookie?e.cookie.split("; "):[],o=r.length;if(!r)return n;for(;o--;)t=r[o].split("="),n+=[o]+" "+i(t[0])+"="+i(t[1])+"\n";return n.trim()},listAsObject:function(){var t,n={},r=e.cookie?e.cookie.split("; "):[],o=r.length;if(!r)return n;for(;o--;)t=r[o].split("="),n[i(t[0])]=i(t[1]);return n},listAsArray:function(){var t,n=[],r=e.cookie?e.cookie.split("; "):[],o=r.length;if(!r)return n;for(;o--;)t=r[o].split("="),n.push({name:i(t[0]),value:i(t[1])});return n},listAs2dArray:function(){var t,n=[],r=e.cookie?e.cookie.split("; "):[],o=r.length;if(!r)return n;for(;o--;)t=r[o].split("="),n.push([i(t[0]),i(t[1])]);return n},remove:function(e){if(e)return!!this.read(e)&&this.create({name:e.name,value:"",expires:-1,path:e.path,domain:e.domain})},clear:function(e){function t(e){for(var t=0;t<e.length;t++)this.remove({name:e[t]})}if(!e){var n=this.keys();return void t.call(this,n)}if(r(e.name)){var i=e.name;t.call(this,i)}else this.remove(e)},enabled:function(){if(navigator.cookieEnabled){this.create({name:"test",value:"$0bee9a46d9d9f14cwjafa&45f&dg88"});var e="$0bee9a46d9d9f14cwjafa&45f&dg88"===this.read({name:"test"});return this.remove({name:"test"}),!!e}return!1},get length(){return e.cookie.split("; ").length},get help(){return Object.keys(this)},get VERSION(){return"1.2"}};"function"==typeof define&&define.amd?define([],function(){return o}):t.cookiet=o}(document,window);