-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gradient numbers in logMessages, plural util
- Loading branch information
Showing
5 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import chalk from "chalk"; | ||
|
||
const colors: chalk.Chalk[] = [ | ||
chalk.redBright, | ||
chalk.red, | ||
chalk.yellowBright, | ||
chalk.yellow, | ||
chalk.greenBright, | ||
chalk.green | ||
]; | ||
/* | ||
Returns a colorized number depending on its value | ||
Lower numbers are red, | ||
Medium numbers yellow, | ||
High values green | ||
if reverse is true, this list is reversed | ||
*/ | ||
export const gradientNumber = ( | ||
number: number, | ||
low: number, | ||
high: number, | ||
reverse = false | ||
): string => { | ||
const diffPerColor = (high - low) / colors.length; | ||
const colorIndex = Math.floor(number / diffPerColor); | ||
|
||
// Clamp between the length of array | ||
|
||
const ci = Math.max(0, Math.min(colorIndex, colors.length - 1)); | ||
|
||
return (reverse ? colors.reverse() : colors)[ci](number); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Adds an 's' if the number is not equal to 0 | ||
*/ | ||
export const plural = (count: number): "" | "s" => (count != 1 ? "s" : ""); |