aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/getCookie.js
diff options
context:
space:
mode:
authorcaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-08 23:07:09 -0500
committercaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-08 23:07:09 -0500
commit6f4874fa20d4fa156dd762d5dacefd8a2e656bf0 (patch)
treeb2258517e17d4b1971789959fa3868c5c58d2e59 /webAO/utils/getCookie.js
parent63a282481d033640a87f97b74f31136410c93717 (diff)
Lots of changes
Diffstat (limited to 'webAO/utils/getCookie.js')
-rw-r--r--webAO/utils/getCookie.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js
new file mode 100644
index 0000000..000c870
--- /dev/null
+++ b/webAO/utils/getCookie.js
@@ -0,0 +1,26 @@
+/**
+ * read a cookie from storage
+ * got this from w3schools
+ * https://www.w3schools.com/js/js_cookies.asp
+ * @param {String} cname The name of the cookie to return
+ */
+const getCookie = (cname) => {
+ try {
+ const name = `${cname}=`;
+ const decodedCookie = decodeURIComponent(document.cookie);
+ const ca = decodedCookie.split(';');
+ for (let i = 0; i < ca.length; i++) {
+ let c = ca[i];
+ while (c.charAt(0) === ' ') {
+ c = c.substring(1);
+ }
+ if (c.indexOf(name) === 0) {
+ return c.substring(name.length, c.length);
+ }
+ }
+ return '';
+ } catch (error) {
+ return '';
+ }
+ }
+ export default getCookie; \ No newline at end of file