diff --git a/src/Utils/Logger.js b/src/Utils/Logger.js index 8dad1cd..82fa786 100644 --- a/src/Utils/Logger.js +++ b/src/Utils/Logger.js @@ -1,15 +1,33 @@ +/** + * @constant {string[]} LOGGING_TYPES - An array of valid logging types. + */ const LOGGING_TYPES = ['log', 'debug', 'error', 'warn', 'info']; -function Logger (data, type = 'debug') { - if(!process.env.DEBUG) return; - if(LOGGING_TYPES.indexOf(type) < 0) type = 'log'; - console[type](...(Array.isArray(data) ? data : [data])); -} - -for(const k of LOGGING_TYPES) { - Logger[k] = function() { - Logger(arguments, k); +const Logger = (function() { + /** + * @function + * @name Logger + * @description A logging utility function that logs data to the console based on the specified type. + * @param {*|Array} data - The data to be logged. Can be a single value or an array of values. + * @param {string} [type='debug'] - The type of logging. Valid types are 'log', 'debug', 'error', 'warn', and 'info'. + * @returns {void} + */ + function Logger(data, type = 'debug') { + if(!process.env.DEBUG) return; + if (!LOGGING_TYPES.includes(type)) type = 'log'; + console[type](...(Array.isArray(data) ? data : [data])); } -} + + /** + * adding the general logging types as their own logging methods + */ + for (const k of LOGGING_TYPES) { + Logger[k] = function() { + Logger(arguments, k); + }; + } + + return Logger; +})(); export default Logger; diff --git a/src/Utils/RequestParser.js b/src/Utils/RequestParser.js index 800343d..b68482c 100644 --- a/src/Utils/RequestParser.js +++ b/src/Utils/RequestParser.js @@ -1,4 +1,11 @@ import Logger from './Logger'; +/** + * Parses form data from a request. + * + * @param {Request} req - The request object. + * @param {boolean} [multipart=false] - Indicates if the form data is multipart. + * @returns {Promise} A promise that resolves to the parsed form data. + */ export async function parseFormData(req, multipart = false) { const data = await req.formData(); @@ -13,6 +20,12 @@ export async function parseFormData(req, multipart = false) { return data; } +/** + * Parses the request body based on the content type. + * + * @param {Request} req - The request object. + * @returns {Promise<*>} A promise that resolves to the parsed request body. + */ export default async function RequestParser(req) { try { const contentType = req.headers.get('Content-Type')?.toLowerCase(); diff --git a/src/Views/DefaultLoader.js b/src/Views/DefaultLoader.js index cfcfd66..862587f 100644 --- a/src/Views/DefaultLoader.js +++ b/src/Views/DefaultLoader.js @@ -1,12 +1,30 @@ +/** + * @class DefaultLoader + * @description A default loader class for handling file content. + */ export default class DefaultLoader { + /** + * @param {string} filepath - The path to the file to be loaded. + */ constructor(filepath) { this.content = filepath; } + /** + * Loads the file content. + * + * @returns {Promise} - A promise that resolves to the file content. + */ async load() { return this.content; } + /** + * Parses the file content with the provided data and options. + * + * @param {Object} [data=null] - The data to be used for parsing. + * @returns {Promise} - A promise that resolves to an object containing the parsed content and data. + */ parse(data = null) { return this.content; }