Skip to content

Instantly share code, notes, and snippets.

View bulebrainbrand's full-sized avatar

bulebrainbrand bulebrainbrand

  • Japan
View GitHub Profile
import { styleText } from 'node:util';
type Format = Extract<Parameters<typeof styleText>[0], string>;
type Chalk = ((text: string) => string) & { [K in Format]: Chalk };
const create = (format: Format[]) =>
new Proxy((text: string) => text, {
get: (_, prop) => create([...format, prop as Format]),
apply: (_, __, [text]: [string]) => styleText(format, text),
}) as Chalk;