Skip to content

Remove kleur #637

@fraxken

Description

@fraxken

Remove kleur and use Node.js styleText with the following implementation:

// Import Node.js Dependencies
import {
  styleText,
  type InspectColorForeground,
  type InspectColorBackground,
  type InspectColorModifier
} from "node:util";

type StyleName = InspectColorForeground | InspectColorBackground | InspectColorModifier;

type Formatter = {
  (text: string): string;
} & {
  [K in StyleName]: Formatter;
};

function createFormatter(styles: StyleName[] = []): Formatter {
  return new Proxy(
    (text: string) => styleText(styles, text),
    {
      get: (_, prop: string) => createFormatter([...styles, prop as StyleName])
    }
  ) as Formatter;
}

const formatter = createFormatter();

export default formatter;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions