Skip to content

Commit

Permalink
Merge pull request #75 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat(color): get the color by status code
  • Loading branch information
jlenon7 authored Sep 22, 2023
2 parents 7b3bb2c + 5028ed4 commit c6b446b
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 c6b446b

Please sign in to comment.