New helpers and comments

This commit is contained in:
Hri7566 2023-09-09 01:37:43 -04:00
parent 9da5e17587
commit e8f1453eed
1 changed files with 28 additions and 0 deletions

View File

@ -1,7 +1,9 @@
// Gray console text
export function unimportant(str: string) {
return `\x1b[90m${str}\x1b[0m`;
}
// Pad time strings
export function padNum(
num: number,
padAmount: number,
@ -12,3 +14,29 @@ export function padNum(
? num.toString().padStart(padAmount, padChar)
: num.toString().padEnd(padAmount, padChar);
}
// ArrayBuffer to text
export const decoder = new TextDecoder();
export const encoder = new TextEncoder();
// Property checks
export function hasOwn(obj: any, property: string | number | Symbol) {
return (Object as unknown as any).hasOwn(obj, property);
}
// Channel color2
export function darken(hex: string) {
try {
let r = parseInt(hex.substring(1, 3), 16);
let g = parseInt(hex.substring(3, 5), 16);
let b = parseInt(hex.substring(5, 7), 16);
let newR = Math.min(r - 64, 0);
let newG = Math.min(g - 64, 0);
let newB = Math.min(b - 64, 0);
return `#${newR.toString(16).padStart(2, "0")}${newG
.toString(16)
.padStart(2, "0")}${newB.toString(16).padStart(2, "0")}`;
} catch (err) {}
}