-
Notifications
You must be signed in to change notification settings - Fork 11
/
Cookie.min.js
19 lines (16 loc) · 3.87 KB
/
Cookie.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Cookie.js, v1.6.0
A tiny (1.24 KB gzipped), stand-alone JavaScript utility for
managing cookies in the browser.
https://github.com/jonlabelle/cookie-js
Copyright (c) 2012-2020 Jon LaBelle
Licensed under MIT (http://creativecommons.org/licenses/MIT/)
*/
(function(m,g){"object"===typeof exports&&"undefined"!==typeof module?module.exports=g():"function"===typeof define&&define.amd?define(g):m.Cookie=g()})(this,function(){function m(a,b){for(var c in a)a.hasOwnProperty(c)&&b(c,a[c])}var g=encodeURIComponent,k=decodeURIComponent;return{createCookieString:function(a,b,c,d){d=d||{};a=g(a)+"="+(c?g(b):b);b=d.expires;c=d.path||"/";var e=d.domain,f=d.sameSite||"Lax";if("object"===typeof d){if(b instanceof Date)a+="; expires="+b.toUTCString();else if(!isNaN(parseFloat(b))&&
isFinite(b)){var h=new Date;h.setDate(h.getDate()+b);a+="; expires="+h.toUTCString()}"string"===typeof c&&""!==c&&(a+="; path="+c);"string"===typeof e&&""!==e&&(a+="; domain="+e);!0===d.secure&&(a+="; secure");"string"===typeof f&&""!==f&&(a+="; SameSite="+f)}return a},createCookieHashString:function(a){if("object"!==typeof a)return"";var b=[];m(a,function(c,d){"function"!==typeof d&&"undefined"!==typeof d&&b.push(g(c)+"="+g(String(d)))});return b.join("&")},parseCookieHash:function(a){var b=a.split("&"),
c={};if(a.length)for(var d=0,e=b.length;d<e;d++)a=b[d].split("="),c[k(a[0])]=k(a[1]);return c},parseCookieString:function(a,b,c){var d={};if("string"===typeof a&&0<a.length){b=!1===b?function(n){return n}:k;a=a.split(/;\s/g);for(var e=null,f=null,h=null,l=0,p=a.length;l<p;l++){h=a[l].match(/([^=]+)=/i);if(h instanceof Array)try{e=k(h[1]),f=b(a[l].substring(h[1].length+1))}catch(n){}else e=k(a[l]),f="";"undefined"!==typeof c&&c.reverseCookieLoading?"undefined"===typeof d[e]&&(d[e]=f):d[e]=f}}return d},
exists:function(a){return"string"!==typeof a||""===a?!1:this.parseCookieString(document.cookie,!0).hasOwnProperty(a)},get:function(a,b){if("function"===typeof b){var c=b;b={}}else"object"===typeof b?c=b.converter:b={};var d=this.parseCookieString(document.cookie,!b.raw,b)[a];return"undefined"===typeof d?null:"function"===typeof c?c(d):d},getSub:function(a,b,c,d){a=this.getSubs(a,d);return null===a||"string"!==typeof b||""===b||"undefined"===typeof a[b]?null:"function"===typeof c?c(a[b]):a[b]},getSubs:function(a,
b){var c=this.parseCookieString(document.cookie,!1,b);return"string"===typeof c[a]?this.parseCookieHash(c[a]):null},remove:function(a,b){if("string"!==typeof a||""===a)return"";var c=b||{},d={expires:new Date(0)};if(c instanceof Array)b=c.concat(d);else{var e={},f;for(f in c)c.hasOwnProperty(f)&&(e[f]=c[f]);for(f in d)d.hasOwnProperty(f)&&(e[f]=d[f]);b=e}return this.set(a,"",b)},removeSub:function(a,b,c){if("string"!==typeof a||""===a||"string"!==typeof b||""===b)return"";c=c||{};var d=this.getSubs(a);
if("object"===typeof d&&d.hasOwnProperty(b)){delete d[b];if(c.removeIfEmpty){for(var e in d)if(d.hasOwnProperty(e)&&"function"!==typeof d[e]&&"undefined"!==typeof d[e])return this.setSubs(a,d,c);return this.remove(a,c)}return this.setSubs(a,d,c)}return""},set:function(a,b,c){if("string"!==typeof a||""===a||"undefined"===typeof b)return null;c=c||{};a=this.createCookieString(a,b,!c.raw,c);return document.cookie=a},setSub:function(a,b,c,d){if("string"!==typeof a||""===a||"string"!==typeof b||""===b||
"undefined"===typeof c)return"";var e=this.getSubs(a);e||(e={});e[b]=c;return this.setSubs(a,e,d)},setSubs:function(a,b,c){if("string"!==typeof a||""===a||"object"!==typeof b)return"";a=this.createCookieString(a,this.createCookieHashString(b),!1,c);return document.cookie=a},enabled:function(){if(navigator.cookieEnabled)return!0;var a=!1;this.set("_ismjclbf","ok");"ok"===this.get("_ismjclbf")&&(a=!0,this.remove("_ismjclbf"));return a},clear:function(){for(var a=document.cookie.split(";"),b=0;b<a.length;b++){var c=
a[b],d=c.indexOf("=");c=-1<d?c.substr(0,d):c;document.cookie=c+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT"}}}});