Skip to content

Instantly share code, notes, and snippets.

@firestar300
Created February 4, 2019 10:58
Show Gist options
  • Save firestar300/403e39e9901fb8fcd3bf135f48e3a1a6 to your computer and use it in GitHub Desktop.
Save firestar300/403e39e9901fb8fcd3bf135f48e3a1a6 to your computer and use it in GitHub Desktop.
get cookie method
/**
* Get a cookie by cookie name
* @param {String} cname Name of the cookie
*/
export const getCookie = (cname) => {
const name = `${cname}=`
const decodedCookie = decodeURIComponent(document.cookie)
const ca = decodedCookie.split(';')
for(var i = 0; i < ca.length; i++) {
var c = ca[i]
while (c.charAt(0) === ' ') {
c = c.substring(1)
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}
return ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment