From 6f4874fa20d4fa156dd762d5dacefd8a2e656bf0 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Tue, 8 Mar 2022 23:07:09 -0500 Subject: Lots of changes --- webAO/utils/getCookie.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 webAO/utils/getCookie.js (limited to 'webAO/utils/getCookie.js') 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 -- cgit From cb6a2ddb36d27abd12a6d0b9aa493194d4c242a2 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Tue, 8 Mar 2022 23:08:13 -0500 Subject: ESLint --- webAO/utils/getCookie.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'webAO/utils/getCookie.js') diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js index 000c870..3be0733 100644 --- a/webAO/utils/getCookie.js +++ b/webAO/utils/getCookie.js @@ -5,22 +5,22 @@ * @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); - } + 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 ''; } + return ''; + } catch (error) { + return ''; } - export default getCookie; \ No newline at end of file +}; +export default getCookie; -- cgit