Skip to content

Instantly share code, notes, and snippets.

@russo97
Created March 3, 2024 00:43
Show Gist options
  • Save russo97/0f59062d947b60cc5d494e82ebc6164c to your computer and use it in GitHub Desktop.
Save russo97/0f59062d947b60cc5d494e82ebc6164c to your computer and use it in GitHub Desktop.
get cookie from browser if its exists
/**
*
* @param name {string}
* @returns {string | false}
*/
function getCookie (name) {
const selectedCookie = document.cookie
.split(COOKIE_SEPARATOR)
.find(cookie => {
const { name: cookieName } = splitCookie(cookie)
return cookieName === name
})
return selectedCookie
? splitCookie(selectedCookie).value
: false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment