I've recently replaced the cookie manager I wrote back in 2012 with a more robust cookie manager I found at MDN. You can read its documentation here.