chore(docs) mainly docs; Logger improvements
This commit is contained in:
@@ -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'];
|
||||||
|
|
||||||
|
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') {
|
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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adding the general logging types as their own logging methods
|
||||||
|
*/
|
||||||
for (const k of LOGGING_TYPES) {
|
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;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user