Skip to content

Commit

Permalink
feat(color): get the color by status code
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Sep 22, 2023
1 parent b0f1981 commit 5028ed4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
37 changes: 30 additions & 7 deletions src/helpers/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 5028ed4

Please sign in to comment.