diff --git a/package-lock.json b/package-lock.json index a0ad6b1..d7cf893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.11.0", + "version": "4.12.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.11.0", + "version": "4.12.0", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", diff --git a/package.json b/package.json index 94ff718..34db0d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.11.0", + "version": "4.12.0", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", diff --git a/src/helpers/Color.ts b/src/helpers/Color.ts index 0a55821..e6783bf 100644 --- a/src/helpers/Color.ts +++ b/src/helpers/Color.ts @@ -175,49 +175,72 @@ export class Color { * Paint http method. */ static get GET(): ChalkInstance { - return this.purple + return Color.chalk.bgHex('#7628c8').bold } /** * Paint http method. */ static get HEAD(): ChalkInstance { - return this.cyan + return Color.chalk.bgCyan.bold } /** * Paint http method. */ static get PUT(): ChalkInstance { - return this.orange + return Color.chalk.bgHex('#f18b0e').bold } /** * Paint http method. */ static get PATCH(): ChalkInstance { - return this.yellow + return Color.chalk.bgYellow.bold } /** * Paint http method. */ static get POST(): ChalkInstance { - return this.green + return Color.chalk.bgGreen.bold } /** * Paint http method. */ static get DELETE(): ChalkInstance { - return this.red + return Color.chalk.bgRed.bold } /** * Paint http method. */ static get OPTIONS(): ChalkInstance { - return this.cyan + return Color.chalk.bgCyan.bold + } + + /** + * Get the color by status code. + */ + public static statusCode(statusCode: number): ChalkInstance { + if (statusCode >= 200 && statusCode < 300) { + return Color.chalk.green + } + + if (statusCode >= 300 && statusCode < 400) { + return Color.chalk.cyan + } + + if (statusCode >= 400 && statusCode < 500) { + return Color.chalk.yellow + } + + if (statusCode >= 500) { + return Color.chalk.red + } + + return Color.chalk.grey } /**