strip-ansi-modern
v1.0.0
Published
A modern, TypeScript-first, zero-dependency ANSI escape sequence stripper.
Maintainers
Readme
strip-ansi-modern
Modern, TypeScript-first, zero-dependency replacement for legacy strip-ansi. Correctly removes ANSI escape sequences (SGR colors, cursor movement, erases, OSC, and more) with a compact implementation.
Installation
npm install strip-ansi-modernUsage
ESM
import stripAnsi, { stripAnsi as strip } from 'strip-ansi-modern';
console.log(stripAnsi('\x1B[31mRed\x1B[0m')); // "Red"
console.log(strip('\x1B[1mBold\x1B[0m text')); // "Bold text"CommonJS
const pkg = require('strip-ansi-modern');
const stripAnsi = pkg.default; // default export
// Or named export:
// const { stripAnsi } = require('strip-ansi-modern');
console.log(stripAnsi('\x1B[32mGreen\x1B[0m')); // "Green"API
stripAnsi(input: string): string— returnsinputwith all ANSI/ECMA-48 escape sequences removed.
Why this package?
- TypeScript-first with generated
d.tstypes. - Zero runtime dependencies.
- ESM + CJS builds:
dist/index.mjs,dist/index.cjs. - Small output with tree-shaking and minification.
Build, Test, Benchmark
- Build:
npm run build - Test:
npm test - Benchmark:
npm run build && node scripts/benchmark.js
Publish Checklist
- Ensure Node and npm are up-to-date.
- Clean install:
npm ci - Lint & tests:
npm run lint && npm test - Build:
npm run build - Publish to npm:
npm publish --access public - (Optional) Measure size:
npx size-limitor inspectdist/artifacts.
Notes
This package intends to be a drop-in, modern replacement for strip-ansi, prioritizing correctness across common terminal sequences while keeping code size small and dependencies at zero.
