From 325aa41d1216facbb7228743930a8ad21afec7aa Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Tue, 30 Aug 2022 20:58:25 +0200 Subject: convert cookie stuff to ts --- webAO/utils/getCookie.js | 26 -------------------------- webAO/utils/getCookie.ts | 26 ++++++++++++++++++++++++++ webAO/utils/setCookie.js | 10 ---------- webAO/utils/setCookie.ts | 10 ++++++++++ 4 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 webAO/utils/getCookie.js create mode 100644 webAO/utils/getCookie.ts delete mode 100644 webAO/utils/setCookie.js create mode 100644 webAO/utils/setCookie.ts (limited to 'webAO/utils') diff --git a/webAO/utils/getCookie.js b/webAO/utils/getCookie.js deleted file mode 100644 index 3be0733..0000000 --- a/webAO/utils/getCookie.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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; diff --git a/webAO/utils/getCookie.ts b/webAO/utils/getCookie.ts new file mode 100644 index 0000000..f5b9679 --- /dev/null +++ b/webAO/utils/getCookie.ts @@ -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: String) => { + 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; diff --git a/webAO/utils/setCookie.js b/webAO/utils/setCookie.js deleted file mode 100644 index 9734eae..0000000 --- a/webAO/utils/setCookie.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * set a cookie - * the version from w3schools expects these to expire - * @param {String} cname The name of the cookie to return - * @param {String} value The value of that cookie option - */ -const setCookie = (cname, value) => { - document.cookie = `${cname}=${value}`; -}; -export default setCookie; diff --git a/webAO/utils/setCookie.ts b/webAO/utils/setCookie.ts new file mode 100644 index 0000000..084fa20 --- /dev/null +++ b/webAO/utils/setCookie.ts @@ -0,0 +1,10 @@ +/** + * set a cookie + * the version from w3schools expects these to expire + * @param {String} cname The name of the cookie to return + * @param {any} value The value of that cookie option + */ +const setCookie = (cname: String, value: any) => { + document.cookie = `${cname}=${value}`; +}; +export default setCookie; -- cgit