Skip to content

Remove kleur #478

@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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions