chore(docs) mainly docs; Logger improvements

This commit is contained in:
gh0sTedBuddy
2024-04-01 22:24:05 +01:00
parent ecf46d083f
commit 8ca93a9394
3 changed files with 59 additions and 10 deletions

View File

@@ -1,15 +1,33 @@
/**
* @constant {string[]} LOGGING_TYPES - An array of valid logging types.
*/
const LOGGING_TYPES = ['log', 'debug', 'error', 'warn', 'info']; const LOGGING_TYPES = ['log', 'debug', 'error', 'warn', 'info'];
function Logger (data, type = 'debug') {
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(!process.env.DEBUG) return;
if(LOGGING_TYPES.indexOf(type) < 0) type = 'log'; if (!LOGGING_TYPES.includes(type)) type = 'log';
console[type](...(Array.isArray(data) ? data : [data])); console[type](...(Array.isArray(data) ? data : [data]));
} }
for(const k of LOGGING_TYPES) { /**
* adding the general logging types as their own logging methods
*/
for (const k of LOGGING_TYPES) {
Logger[k] = function() { Logger[k] = function() {
Logger(arguments, k); Logger(arguments, k);
};
} }
}
return Logger;
})();
export default Logger; export default Logger;

View File

@@ -1,4 +1,11 @@
import Logger from './Logger'; 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<FormData>} A promise that resolves to the parsed form data.
*/
export async function parseFormData(req, multipart = false) { export async function parseFormData(req, multipart = false) {
const data = await req.formData(); const data = await req.formData();
@@ -13,6 +20,12 @@ export async function parseFormData(req, multipart = false) {
return data; 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) { export default async function RequestParser(req) {
try { try {
const contentType = req.headers.get('Content-Type')?.toLowerCase(); const contentType = req.headers.get('Content-Type')?.toLowerCase();

View File

@@ -1,12 +1,30 @@
/**
* @class DefaultLoader
* @description A default loader class for handling file content.
*/
export default class DefaultLoader { export default class DefaultLoader {
/**
* @param {string} filepath - The path to the file to be loaded.
*/
constructor(filepath) { constructor(filepath) {
this.content = filepath; this.content = filepath;
} }
/**
* Loads the file content.
*
* @returns {Promise<string>} - A promise that resolves to the file content.
*/
async load() { async load() {
return this.content; 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<Object>} - A promise that resolves to an object containing the parsed content and data.
*/
parse(data = null) { parse(data = null) {
return this.content; return this.content;
} }