diff --git a/src/util/helpers.ts b/src/util/helpers.ts index be635af..2fc6029 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -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) {} +}