Skip to content

Instantly share code, notes, and snippets.

@GianlucaGuarini
Last active December 12, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GianlucaGuarini/dde731e5ae34b90c1774bf0728a5384f to your computer and use it in GitHub Desktop.
Save GianlucaGuarini/dde731e5ae34b90c1774bf0728a5384f to your computer and use it in GitHub Desktop.
Simple function to read a named cookie from the document.cookie string
@GianlucaGuarini
Copy link
Author

GianlucaGuarini commented Dec 12, 2016

Usage

Test string:

django_language=de; csrftoken=SuktrIZlUwvk4E0LoKyIHVraBlG0UiLn; _ga=GA1.1.409523848.1476253469; __atuvc=32%7C46%2C0%7C47%2C0%7C48%2C33%7C49%2C143%7C50; ajs_user_id=null; ajs_group_id=null; ajs_anonymous_id=%222646bc13-49e5-43ae-a204-7641fd6027ca%22; intercom-id-pcdclcus=c489b10f-34c4-4fc2-8d9c-fa190b3ab937; __atuvs=584e8c24077fa261047; created_snowflakes="e12e3901-c966-4088-abdb-7415e232dfad\054c08669a1-e11e-4f75-8d78-a45001f6fe97"

const lang = readCookie('django_language') // 'de'
const userId = readCookie('ajs_user_id') // 'null'
const createdSnowflakes = readCookie('created_snowflakes') // 'e12e3901-c966-4088-abdb-7415e232dfad\054c08669a1-e11e-4f75-8d78-a45001f6fe97'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment