mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
central cookie function
This commit is contained in:
19
vue3/src/utils/cookie.ts
Normal file
19
vue3/src/utils/cookie.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* simple function to retrieve a cookie by name
|
||||
* @param name name of the cookie
|
||||
*/
|
||||
export function getCookie(name: string) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
Reference in New Issue
Block a user