Refactor Code to typescript

This commit is contained in:
Benjamin Toby
2025-01-10 20:10:28 +01:00
parent 549d0abc02
commit eb0992f28d
270 changed files with 3535 additions and 9062 deletions
-2
View File
@@ -1,2 +0,0 @@
declare function _exports(): {} | null;
export = _exports;
-65
View File
@@ -1,65 +0,0 @@
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
/**
* Parse request cookies
* ==============================================================================
*
* @description This function takes in a request object and returns the cookies as a JS object
*
* @async
*
* @param {object} params - main params object
* @param {object} params.request - HTTPS request object
*
* @returns {{}|null}
*/
module.exports = function () {
/**
* Check inputs
*
* @description Check inputs
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** @type {string|null} */
const cookieString = document.cookie;
if (!cookieString || typeof cookieString !== "string") {
return null;
}
/** @type {string[]} */
const cookieSplitArray = cookieString.split(";");
let cookieObject = {};
cookieSplitArray.forEach((keyValueString) => {
const [key, value] = keyValueString.split("=");
if (key && typeof key == "string") {
cookieObject[key.replace(/^ +| +$/, "")] = value && typeof value == "string" ? value.replace(/^ +| +$/, "") : null;
}
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Make https request
*
* @description make a request to datasquirel.com
*/
return cookieObject;
};
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
+34
View File
@@ -0,0 +1,34 @@
/**
* Parse request cookies
* ============================================================================== *
* @description This function takes in a request object and returns the cookies as a JS object
*/
export default function (): { [s: string]: any } | null {
/**
* Check inputs
*
* @description Check inputs
*/
const cookieString: string | null = document.cookie;
if (!cookieString || typeof cookieString !== "string") {
return null;
}
const cookieSplitArray: string[] = cookieString.split(";");
let cookieObject: { [s: string]: any } = {};
cookieSplitArray.forEach((keyValueString) => {
const [key, value] = keyValueString.split("=");
if (key && typeof key == "string") {
cookieObject[key.replace(/^ +| +$/, "")] =
value && typeof value == "string"
? value.replace(/^ +| +$/, "")
: null;
}
});
return cookieObject;
}