Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(color): get the color by status code #75

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading