🕵️♂️ Reveal and clean invisible Unicode characters from text — both as a CLI and a library.
Invisible characters like zero-width spaces (U+200B), byte-order marks, or directionality markers can sneak into text files, source code, or user input — often causing frustrating bugs or unexpected behavior.
show-invisibles helps you:
- ✅ Identify and make invisible characters visible in your text.
- 🧹 Clean unwanted or problematic characters.
- ⚒️ Customize how these characters are shown or replaced.
- 🧪 Use as a CLI tool or integrate as a Node.js library.
- Supports a wide range of invisible and control characters.
- Offers two main operations:
mark: Replaces invisible characters with visible placeholders.clean: Removes or replaces problematic invisible characters.
- Customizable format for marked output:
%u(unicode),%n(name), or your own syntax. --allflag to show even standard control characters (like\n,\t,\r).- Emits statistics to
stderr(characters found and/or replaced). - ES Modules support and typings included.
npm install -g show-invisiblesOr use locally in a Node project:
npm install show-invisiblesshow-invisibles [file|-] [options]| Flag | Description |
|---|---|
--clean |
Remove or replace invisible characters (instead of marking them). |
--all |
Include common control characters like \n, \r, \t. |
--format |
Format string for replacements (default: [%u]). |
--help |
Show usage help. |
You can use custom format strings for how invisible characters are displayed:
%u– Unicode code point (e.g.U+200B)%n– Character name (e.g.ZERO_WIDTH_SPACE)%%– Literal%
Examples:
# Reveal all invisible characters with default format
cat suspicious.txt | show-invisibles
# Clean all invisibles in a file
show-invisibles --clean suspicious.txt
# Show control chars too, use name instead of code
show-invisibles some.txt --all --format="[%n]"
# Use custom format
show-invisibles --format="!!%u!!" some.txtimport {
markInvisibles,
cleanInvisibles,
formatReplacement,
} from 'show-invisibles'
const input = 'Some\u200Btext'
const { result, count } = markInvisibles(input, false, '[%n]')
// result => 'Some[ZERO_WIDTH_SPACE]text'
// count => 1
const cleaned = cleanInvisibles(input)
// cleaned.result => 'Sometext'
// cleaned.count => 1Includes:
- Zero-width characters (
U+200B,U+200C, etc.) - Directionality markers (
U+202A–U+202E,U+2066–U+2069) - Byte Order Mark (
U+FEFF) - Figure space (
U+2007) - Control characters (optional):
\n,\r,\t,\f, etc.
npm run buildnpm testMIT © 2025