Is there a good 'cookie' library for javascript?

Is there a JavaScript library or easily working with cookies?

  • Set-Cookie header not setting cookie in Chrome
  • Get JSESSIONID value and create Cookie in AngularJS
  • how can set cookie with Ajax/jQuery?
  • Google analytics illegal cookie breaks Python backend
  • Why doesn't document.cookie show all the cookie for the site?
  • Preventing multiple web notifications?
  • JSON encoded array converted to string when saved as cookie
  • Using $cookies and $stateChangeStart to check for sessionID exeeding maximum callstack
  • Delete cookie on browser close not on page refresh
  • How to get cookie expiration date / creation date from javascript?
  • Use this JavaScript to load cookie into variable
  • Updating unique views using cookies
  • One Solution collect form web for “Is there a good 'cookie' library for javascript?”

    vanilla javascript FTW

    /*********************************************************
    gets the value of a cookie
    **********************************************************/
    document.getCookie = function(sName)
    {
        sName = sName.toLowerCase();
        var oCrumbles = document.cookie.split(';');
        for(var i=0; i<oCrumbles.length;i++)
        {
            var oPair= oCrumbles[i].split('=');
            var sKey = decodeURIComponent(oPair[0].trim().toLowerCase());
            var sValue = oPair.length>1?oPair[1]:'';
            if(sKey == sName)
                return decodeURIComponent(sValue);
        }
        return '';
    }
    /*********************************************************
    sets the value of a cookie
    **********************************************************/
    document.setCookie = function(sName,sValue)
    {
        var oDate = new Date();
        oDate.setYear(oDate.getFullYear()+1);
        var sCookie = encodeURIComponent(sName) + '=' + encodeURIComponent(sValue) + ';expires=' + oDate.toGMTString() + ';path=/';
        document.cookie= sCookie;
    }
    /*********************************************************
    removes the value of a cookie
    **********************************************************/
    document.clearCookie = function(sName)
    {
        setCookie(sName,'');
    }