Skip to content

Instantly share code, notes, and snippets.

@firestar300
Created February 4, 2019 10:58
Show Gist options
  • Save firestar300/65958ebaada86852560314e4bebaf2bd to your computer and use it in GitHub Desktop.
Save firestar300/65958ebaada86852560314e4bebaf2bd to your computer and use it in GitHub Desktop.
set cookie method
/**
* Set a new cookie
* @param {String} cname Name of the cookie
* @param {String} cvalue Value of the cookie
* @param {Number} exdays Number of days until cookie should expire
*/
export const setCookie = (cname, cvalue, exdays) => {
const d = new Date()
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
const expires = `expires=${d.toUTCString()}`
document.cookie = `${cname}=${cvalue};${expires};path=/`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment