Visualize and inspect invisible whitespace characters in any file. Tabs, spaces, CRs, NBSP, zero-width β nothing hides.
Invisible characters cause real bugs:
- Mixed tabs and spaces break Python indentation and YAML configs
- Trailing whitespace creates noisy git diffs and fails lint rules
- Carriage returns sneak into files when someone edits on Windows
- Non-breaking spaces (NBSP) look identical to regular spaces but break parsers
- Zero-width characters hide in copy-pasted text and cause mysterious comparison failures
Your editor "shows whitespace" but only partially. whitespace-cli reveals everything β in any file, from any pipeline.
npx @kszongic/whitespace-cli --show config.ymlnpm install -g @kszongic/whitespace-cliOr run directly without installing:
npx @kszongic/whitespace-cli file.txt# Visualize all whitespace in a file
whitespace file.txt
# Pipe from stdin
echo "hello world" | whitespace --show
# Count whitespace characters by type
whitespace --count src/index.js
# Find lines with leading/trailing whitespace
whitespace --trim src/index.jsReplaces invisible characters with visible symbols:
| Character | Symbol | Unicode |
|---|---|---|
| Space | Β· |
U+0020 |
| Tab | β₯ |
U+0009 |
CR (\r) |
β |
U+000D |
LF (\n) |
β΅ |
U+000A |
| NBSP | β½ |
U+00A0 |
| Zero-width space | β
|
U+200B |
whitespace --count package.jsonspaces: 42
tabs: 8
CR (\r): 0
LF (\n): 15
NBSP: 0
ZWSP: 0
other: 0
total: 65
whitespace --trim src/index.js 1 | [lead:4] function main() {
2 | return 0;
3 | [lead:4, trail:2] }
find src -name "*.js" -exec whitespace --count {} + | grep tabsgit ls-files | xargs -I{} sh -c 'whitespace --count "{}" | grep -q "CR.*[1-9]" && echo "CRLF found: {}"'#!/bin/sh
# .git/hooks/pre-commit
for file in $(git diff --cached --name-only); do
if whitespace --trim "$file" | grep -q "trail:"; then
echo "Trailing whitespace in $file"
exit 1
fi
done# GitHub Actions
- name: Check whitespace
run: |
npm install -g @kszongic/whitespace-cli
find src -name "*.ts" | xargs -I{} sh -c '
if whitespace --count "{}" | grep -q "NBSP.*[1-9]"; then
echo "NBSP found in {}" && exit 1
fi
'Text copied from web pages or PDFs often contains invisible zero-width characters:
echo "suspicious string" | whitespace --show
# reveals zero-width spaces hiding between characters{
"scripts": {
"lint:whitespace": "whitespace --count src/index.js",
"check:trailing": "whitespace --trim src/**/*.js | grep trail && exit 1 || exit 0"
}
}- Code review β Spot mixed indentation before it reaches the PR
- YAML/Python debugging β Find that invisible tab breaking your config
- Cross-platform projects β Detect CRLF line endings from Windows contributors
- Security auditing β Find zero-width characters in homograph attacks
- Data cleaning β Identify NBSP and Unicode whitespace in CSV/JSON data
- Documentation β Ensure Markdown files have consistent formatting
| Flag | Description |
|---|---|
-s, --show |
Show whitespace as visible symbols (default) |
-c, --count |
Count whitespace characters by type |
-t, --trim |
Show leading/trailing whitespace per line |
-h, --help |
Show help |
-v, --version |
Show version |
Reads the file (or stdin) as a UTF-8 string, then walks each character checking against a map of whitespace Unicode code points. In --show mode, each whitespace character is replaced with its visible symbol. In --count mode, it tallies by category. In --trim mode, it measures leading/trailing lengths per line. No regex, no dependencies β just character-by-character inspection.
| Tool | Zero deps | Cross-platform | Visualize | Count | Trailing detect | NBSP/ZWSP |
|---|---|---|---|---|---|---|
| whitespace-cli | β | β Win/Mac/Linux | β | β | β | β |
cat -A |
N/A | β Unix only | Partial | β | β | β |
cat -vet |
N/A | β Unix only | Partial | β | β | β |
| VS Code whitespace | N/A | β | In editor | β | β | β |
hexdump / xxd |
N/A | β Unix only | Raw bytes | β | β | Manual |
Part of a zero-dependency CLI toolkit:
- env-lint-cli β Lint .env files against .env.example
- checksum-verify-cli β Verify file checksums cross-platform
- string-hash-cli β Hash strings from the command line
- freq-table-cli β Frequency tables from stdin
- detect-lang-cli β Detect programming language of files
MIT Β© kszongic