Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lambdalisue/deno-ansi-escape-code

🦕 Utilities to trim and parse ANSI escape code
https://github.com/lambdalisue/deno-ansi-escape-code

ansi-escape-code deno jsr

Last synced: 3 months ago
JSON representation

🦕 Utilities to trim and parse ANSI escape code

Awesome Lists containing this project

README

        

# ansi-escape-code

[![jsr](https://img.shields.io/jsr/v/%40lambdalisue/ansi-escape-code?logo=javascript&logoColor=white)](https://jsr.io/@lambdalisue/ansi-escape-code)
[![denoland](https://img.shields.io/github/v/release/lambdalisue/deno-ansi-escape-code?logo=deno&label=denoland)](https://github.com/lambdalisue/deno-ansi-escape-code/releases)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/ansi_escape_code/mod.ts)
[![Test](https://github.com/lambdalisue/deno-ansi-escape-code/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-ansi-escape-code/actions?query=workflow%3ATest)

Utilities to trim and parse ANSI escape sequence.

[deno]: https://deno.land/

## Usage

```typescript
import { assertEquals } from "https://deno.land/[email protected]/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](./LICENSE). Contributors need
to agree that any modifications sent in this repository follow the license.