Skip to main content

🦕 Utilities to trim and parse ANSI escape code

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
82%
Published
2 months ago (1.0.3)

ansi-escape-code

jsr denoland deno doc Test

Utilities to trim and parse ANSI escape sequence.

Usage

import { assertEquals } from "https://deno.land/std@0.164.0/testing/asserts.ts";
import { trimAndParse } from "https://deno.land/x/ansi_escape_code/mod.ts";

const [trimmed, annotations] = trimAndParse(
  "\x1b[1mHe\x1b[30mll\x1b[31mo\x1b[m world",
);

assertEquals(trimmed, "Hello world");
assertEquals(annotations, [
  { offset: 0, raw: "\x1b[1m", csi: { sgr: { bold: true } } },
  { offset: 2, raw: "\x1b[30m", csi: { sgr: { foreground: 0 } } },
  { offset: 4, raw: "\x1b[31m", csi: { sgr: { foreground: 1 } } },
  { offset: 5, raw: "\x1b[m", csi: { sgr: { reset: true } } },
]);

License

The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @lambdalisue/ansi-escape-code

Import symbol

import * as mod from "@lambdalisue/ansi-escape-code";

Add Package

npx jsr add @lambdalisue/ansi-escape-code

Import symbol

import * as mod from "@lambdalisue/ansi-escape-code";

Add Package

yarn dlx jsr add @lambdalisue/ansi-escape-code

Import symbol

import * as mod from "@lambdalisue/ansi-escape-code";

Add Package

pnpm dlx jsr add @lambdalisue/ansi-escape-code

Import symbol

import * as mod from "@lambdalisue/ansi-escape-code";

Add Package

bunx jsr add @lambdalisue/ansi-escape-code

Import symbol

import * as mod from "@lambdalisue/ansi-escape-code";