cookie.js插件

/*! cookiejs v1.0.23 | MIT (c) 2018 kenny wong | https://github.com/jaywcjlove/cookie.js */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.cookie=t()}(this,function(){"use strict";function c(e){return"string"==typeof(e=JSON.stringify(e))&&/^{[sS]*}$/.test(e)}function o(){if(!(this instanceof o))return new o}o.prototype={get:function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){for(var o=n[r];" "==o.charAt(0);)o=o.substring(1,o.length);if(0==o.indexOf(t))return decodeURI(o.substring(t.length,o.length))}return!1},set:function(e,t,n){if(c(e))for(var r in e)this.set(r,e[r],t,n);else if("string"==typeof e){var o=c(n)?n:{expires:n},i=void 0!==o.expires?o.expires:"",f=void 0!==o.path?";path="+o.path:";path=/",s=o.domain?";domain="+o.domain:"",u=o.secure?";secure":"";"string"==typeof i&&""!==i?i=new Date(i):"number"==typeof i&&(i=new Date(+new Date+864e5*i)),""!==i&&"toGMTString"in i&&(i=";expires="+i.toGMTString()),document.cookie=e+"="+encodeURI(t)+i+f+s+u}},remove:function(e){for(var t=0,n=(e=e instanceof Array?e:Array.prototype.slice.call(arguments)).length;t<n;t++)this.set(e[t],"",-1);return e},clear:function(e){return this.remove(e||function(e){var t=[],n="";for(n in e)t.push(n);return t}(this.all()))},all:function(){if(""===document.cookie)return{};for(var e=document.cookie.split("; "),t={},n=0,r=e.length;n<r;n++){var o=e[n].split("=");t[decodeURI(o[0])]=decodeURI(o[1])}return t}};var i=null,e=function(e,t,n){var r=arguments;return i||(i=o()),0===r.length?i.all():1===r.length&&null===e?i.clear():2!==r.length||t?"string"!=typeof e||t?"string"==typeof e&&t||c(e)?i.set(e,t,n):void 0:i.get(e):i.clear(e)};for(var t in o.prototype)e[t]=o.prototype[t];return e});

原文地址:https://www.cnblogs.com/shangjun6/p/10719169.html