ProvenPin Install

chalk nested ANSI styles: working versions (tested 2026-10-16)

Compose nested chalk styles (bold.red, bgBlue), strip and detect ANSI escapes, and force Chalk level for deterministic output in non-TTY environments.

passed5 passed · 0 failed2026-10-16 02:18 UTC
Status
passed
Last passed
2026-10-16 02:18 UTC
Tests
5 / 5
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
chalk@6.0.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38839686104

The code

Exactly the files that passed. Your agent can pull them with get_recipe("chalk-ansi-styles") (install), or see them on GitHub.

package.json
{
  "name": "chalk-ansi-styles",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "chalk": "6.0.1"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/styles.ts
import { Chalk } from "chalk";

export const ANSI_PATTERN = /\u001B\[[0-9;]*m/g;

export function stripAnsi(input: string): string {
  return input.replace(ANSI_PATTERN, "");
}

export function hasAnsi(input: string): boolean {
  return stripAnsi(input) !== input;
}

export function createStyler(level: 0 | 1 | 2 | 3 = 1): Chalk {
  return new Chalk({ level });
}

export function errorLabel(text: string, level: 0 | 1 | 2 | 3 = 1): string {
  return createStyler(level).bgBlue.bold.red(text);
}

export function nestedAccent(text: string, level: 0 | 1 | 2 | 3 = 1): string {
  const c = createStyler(level);
  return c.bold(`bold ${c.red.underline(text)} tail`);
}

export function successBadge(label: string, value: string, level: 0 | 1 | 2 | 3 = 1): string {
  const c = createStyler(level);
  return `${c.bgBlue.white.bold(` ${label} `)} ${c.green(value)}`;
}

export function statusLine(kind: string, message: string, level: 0 | 1 | 2 | 3 = 1): string {
  const c = createStyler(level);
  return `${c.bold.red(kind)} ${c.bgBlue.white(message)}`;
}
test/styles.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import {
  errorLabel,
  nestedAccent,
  successBadge,
  statusLine,
  stripAnsi,
  hasAnsi,
} from "../src/styles.ts";

test("nested modifiers emit bold, red and blue-background escapes", () => {
  const output = errorLabel("boom", 1);
  assert.ok(hasAnsi(output));
  assert.equal(stripAnsi(output), "boom");
  assert.match(output, /\u001B\[1m/);
  assert.match(output, /\u001B\[31m/);
  assert.match(output, /\u001B\[44m/);
});

test("level 0 disables styling so non-TTY output is deterministic", () => {
  const styled = errorLabel("boom", 1);
  const plain = errorLabel("boom", 0);
  assert.notEqual(styled, plain);
  assert.equal(plain, "boom");
  assert.equal(hasAnsi(plain), false);
});

test("nested styles keep inner escapes and outer emphasis", () => {
  const output = nestedAccent("warn", 1);
  assert.equal(stripAnsi(output), "bold warn tail");
  assert.match(output, /\u001B\[4m/);
  assert.match(output, /\u001B\[31m/);
});

test("status line combines bold red and blue background", () => {
  const output = statusLine("ERROR", "request failed", 1);
  assert.equal(stripAnsi(output), "ERROR request failed");
  assert.ok(hasAnsi(output));
  assert.match(output, /\u001B\[44m/);
});

test("success badge combines background and foreground", () => {
  const output = successBadge("OK", "200", 1);
  assert.equal(stripAnsi(output), " OK  200");
  assert.match(output, /\u001B\[44m/);
  assert.match(output, /\u001B\[37m/);
  assert.match(output, /\u001B\[32m/);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.